optional specific help key

This commit is contained in:
2023-02-23 16:20:56 +01:00
parent fb6f079895
commit cc25674987
2 changed files with 15 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
{ {
"help": " - Shows this help\n", "help": " [command] - Shows help or help for a specific command\n",
"consoleclear": " - Clears the console\n", "consoleclear": " - Clears the console\n",
"speed": " <multiplier number> - Multiplies the player speed by the given value\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", "noclip": " - Toggles the player collision and lets you walk through walls and world barriers\n",

View File

@@ -3,10 +3,10 @@ using Godot.Collections;
public partial class console : PopupPanel public partial class console : PopupPanel
{ {
public RichTextLabel textblock; private RichTextLabel textblock;
public LineEdit line; private LineEdit line;
public Dictionary commandDict; private Dictionary commandDict;
public string error = "Not found! :(\n"; private string error = "Not found! :(\n";
//functions with capital letters can't be used inside the console //functions with capital letters can't be used inside the console
public override void _Ready() public override void _Ready()
@@ -20,11 +20,12 @@ public partial class console : PopupPanel
{ {
if (Input.IsActionJustPressed("console")) if (Input.IsActionJustPressed("console"))
{ {
Visible = !Visible; Visible = !Visible;
line.GrabFocus(); line.GrabFocus();
player.allowMovement = !Visible; player.allowMovement = !Visible;
} }
/*if (OS.ReadStringFromStdIn() != "") //not tested yet
OnLineEditTextSubmitted(OS.ReadStringFromStdIn());*/
} }
private void OnPopupHide() => player.allowMovement = true; private void OnPopupHide() => player.allowMovement = true;
private void OnLineEditTextSubmitted(string command) private void OnLineEditTextSubmitted(string command)
@@ -55,23 +56,24 @@ public partial class console : PopupPanel
private void help(/*string key = ""*/) //bug: optional parameters aren't optional in Call() private void help()
{ {
/*if (key.Length == 0)
{*/
textblock.AddText("==================================== Help ====================================\n"); textblock.AddText("==================================== Help ====================================\n");
for (int i = 0; i < commandDict.Count; i++) for (int i = 0; i < commandDict.Count; i++)
{ {
textblock.AddText((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]); textblock.AddText((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]);
textblock.AddText(Json.ParseString(commandDict.Values.ToString()).AsStringArray()[i]); textblock.AddText(Json.ParseString(commandDict.Values.ToString()).AsStringArray()[i]);
} }
/*} }
else if (commandDict.ContainsKey(key)) private void help(string key) //Optional parameters aren't optional in Call()/Callv() so i use overloads instead
{
key = key.ToLower();
if (key.Length != 0 && commandDict.ContainsKey(key))
{ {
textblock.AddText(key); textblock.AddText(key);
textblock.AddText(commandDict[key].ToString()); textblock.AddText(commandDict[key].ToString());
} }
else textblock.AddText(error);*/ else textblock.AddText(error);
} }
private void consoleclear() => textblock.Clear(); private void consoleclear() => textblock.Clear();
private void speed(float multiplier) private void speed(float multiplier)