stickycamera and command not found mesage
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
public partial class console : PopupPanel
|
||||
{
|
||||
public RichTextLabel textblock;
|
||||
public LineEdit line;
|
||||
|
||||
public string error = "Not found! :(";
|
||||
|
||||
//functions with capital letters can't be used inside the console
|
||||
public override void _Ready()
|
||||
{
|
||||
textblock = GetNode<RichTextLabel>("v_box_container/rich_text_label");
|
||||
line = GetNode<LineEdit>("v_box_container/line_edit");
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("console"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
line.GrabFocus();
|
||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = !Visible;
|
||||
}
|
||||
}
|
||||
public void OnPopupHide()
|
||||
{
|
||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||
}
|
||||
public void OnLineEditTextSubmitted(string command)
|
||||
{
|
||||
line.Clear();
|
||||
if (command.Length != 0) textblock.AddText("\n>" + command);
|
||||
Variant args;
|
||||
if (command.Split(' ').Length == 2)
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i);
|
||||
Call(command.Split(' ')[0].ToLower(), args);
|
||||
}
|
||||
if (command.Split(' ').Length > 2)
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i).Split(' ');
|
||||
Callv(command.Split(' ')[0].ToLower(), args.AsGodotArray());
|
||||
}
|
||||
else Call(command.ToLower());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void help()
|
||||
{
|
||||
textblock.AddText("\n============ Help ============");
|
||||
textblock.AddText("\n1. consoleclear - Clears the console");
|
||||
textblock.AddText("\n2. speed <multiplier number> - Multiplies the player speed by the given value");
|
||||
textblock.AddText("\n3. playername <new name> - Renames the player");
|
||||
}
|
||||
public void consoleclear() => textblock.Clear();
|
||||
public void speed(float multiplier)
|
||||
{
|
||||
if (GetParent().Name == "player") GetParent<player>().speed = Mathf.Clamp(multiplier, 0.01f, 15f);
|
||||
textblock.AddText("\nSet speed to " + Mathf.Clamp(multiplier, 0.01f, 15f));
|
||||
}
|
||||
public void playername(string name)
|
||||
{
|
||||
if (GetParent().Name == "player")
|
||||
{
|
||||
GetParent<player>().playerName = name;
|
||||
GetParent<player>().ClearPlayerName();
|
||||
textblock.AddText("\nYour new name is now: " + GetParent<player>().playerName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
9
src/scene-scripts/console/commands.json
Normal file
9
src/scene-scripts/console/commands.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"help": " - Shows this help\n",
|
||||
"consoleclear": " - Clears the console\n",
|
||||
"speed": " <multiplier number> - Multiplies the player speed by the given value\n",
|
||||
"noclip": " - Toggles the player collision and lets you walk through walls and world barriers\n",
|
||||
"stickycamera": " - Toggles the camera mode. Stickycamera follows the player without limits and extra animation\n",
|
||||
"playername": " <new name> - Renames the player\n",
|
||||
"reload": " - Reloads the current level (for softlocks or other issues)\n"
|
||||
}
|
113
src/scene-scripts/console/console.cs
Normal file
113
src/scene-scripts/console/console.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class console : PopupPanel
|
||||
{
|
||||
public RichTextLabel textblock;
|
||||
public LineEdit line;
|
||||
public Dictionary commandDict;
|
||||
public string error = "Not found! :(\n";
|
||||
|
||||
//functions with capital letters can't be used inside the console
|
||||
public override void _Ready()
|
||||
{
|
||||
textblock = GetNode<RichTextLabel>("v_box_container/rich_text_label");
|
||||
line = GetNode<LineEdit>("v_box_container/line_edit");
|
||||
commandDict = Json.ParseString(FileAccess.GetFileAsString("res://src/scene-scripts/console/commands.json").ToString()).AsGodotDictionary();
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("console"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
line.GrabFocus();
|
||||
GetParent<player>().allowMovement = !Visible;
|
||||
}
|
||||
}
|
||||
public void OnPopupHide() => GetParent<player>().allowMovement = true;
|
||||
public void OnLineEditTextSubmitted(string command)
|
||||
{
|
||||
line.Clear();
|
||||
if (command.Length != 0) textblock.AddText(GetParent<player>().playerName + " > " + command + "\n");
|
||||
Variant args;
|
||||
if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower()))
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i);
|
||||
commandDict.ContainsKey(command.Split(' ')[0].ToLower());
|
||||
Call(command.Split(' ')[0].ToLower(), args);
|
||||
}
|
||||
else if (command.Split(' ').Length > 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower()))
|
||||
{
|
||||
int i = command.IndexOf(" ") + 1;
|
||||
args = command.Substring(i).Split(' ');
|
||||
commandDict.ContainsKey(command.Split(' ')[0].ToLower());
|
||||
Callv(command.Split(' ')[0].ToLower(), args.AsGodotArray());
|
||||
}
|
||||
else if (commandDict.ContainsKey(command.ToLower()))
|
||||
{
|
||||
Call(command.ToLower());
|
||||
}
|
||||
else textblock.AddText(error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void help(/*string key = ""*/) //bug: optional parameters aren't optional in Call()
|
||||
{
|
||||
/*if (key.Length == 0)
|
||||
{*/
|
||||
textblock.AddText("==================================== Help ====================================\n");
|
||||
for (int i = 0; i < commandDict.Count; i++)
|
||||
{
|
||||
textblock.AddText((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]);
|
||||
textblock.AddText(Json.ParseString(commandDict.Values.ToString()).AsStringArray()[i]);
|
||||
}
|
||||
/*}
|
||||
else if (commandDict.ContainsKey(key))
|
||||
{
|
||||
textblock.AddText(key);
|
||||
textblock.AddText(commandDict[key].ToString());
|
||||
}
|
||||
else textblock.AddText(error);*/
|
||||
}
|
||||
public void consoleclear() => textblock.Clear();
|
||||
public void speed(float multiplier)
|
||||
{
|
||||
GetParent<player>().speed = Mathf.Clamp(multiplier, 0.01f, 15f);
|
||||
textblock.AddText("Set speed to " + Mathf.Clamp(multiplier, 0.01f, 15f) + "\n");
|
||||
}
|
||||
public void noclip()
|
||||
{
|
||||
CollisionShape2D collision = GetParent<player>().GetNode<CollisionShape2D>("collision_shape");
|
||||
collision.Disabled = !collision.Disabled;
|
||||
textblock.AddText("Noclip is now set to: " + collision.Disabled + "\n");
|
||||
}
|
||||
public void stickycamera()
|
||||
{
|
||||
Camera2D cheatCam = GetParent<player>().GetNode<Camera2D>("cheat_cam");
|
||||
Camera2D mainCam = GetParent<player>().GetNode<Camera2D>("main_cam");
|
||||
if (mainCam.Enabled)
|
||||
{
|
||||
cheatCam.Enabled = true;
|
||||
mainCam.Enabled = false;
|
||||
textblock.AddText("cheat_cam has been enabled\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
cheatCam.Enabled = false;
|
||||
mainCam.Enabled = true;
|
||||
textblock.AddText("cheat_cam has been disabled\n");
|
||||
}
|
||||
}
|
||||
public void playername(string name)
|
||||
{
|
||||
if (GetParent().Name == "player")
|
||||
{
|
||||
GetParent<player>().playerName = name;
|
||||
GetParent<player>().ClearPlayerName();
|
||||
textblock.AddText("Your new name is now: " + GetParent<player>().playerName + "\n");
|
||||
}
|
||||
}
|
||||
public void reload() => GetTree().ReloadCurrentScene();
|
||||
}
|
Reference in New Issue
Block a user