konami code

This commit is contained in:
2023-02-24 17:42:55 +01:00
parent 8132530da3
commit 294abe6b6f
2 changed files with 30 additions and 4 deletions

View File

@@ -127,6 +127,11 @@ console={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194334,"key_label":0,"unicode":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194334,"key_label":0,"unicode":0,"echo":false,"script":null)
] ]
} }
cheat_start={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
]
}
[internationalization] [internationalization]

View File

@@ -3,6 +3,9 @@ using Godot.Collections;
public partial class console : PopupPanel public partial class console : PopupPanel
{ {
private string[] gamepadCheatcode = { "ui_up", "ui_up", "ui_down", "ui_down", "ui_left", "ui_right", "ui_left", "ui_right", "ui_cancel", "ui_accept", "cheat_start" };
private int gpCcIndexer = 0;
private InputEvent inputEvent;
private static RichTextLabel textblock; private static RichTextLabel textblock;
private LineEdit line; private LineEdit line;
private Dictionary commandDict; private Dictionary commandDict;
@@ -16,17 +19,35 @@ public partial class console : PopupPanel
line = GetNode<LineEdit>("v_box_container/line_edit"); line = GetNode<LineEdit>("v_box_container/line_edit");
commandDict = Json.ParseString(FileAccess.GetFileAsString("res://src/scene-scripts/console/commands.json").ToString()).AsGodotDictionary(); commandDict = Json.ParseString(FileAccess.GetFileAsString("res://src/scene-scripts/console/commands.json").ToString()).AsGodotDictionary();
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
//Cheatcode
if (Input.IsActionJustPressed(gamepadCheatcode[gpCcIndexer]))
{
gpCcIndexer++;
GetNode<Timer>("cheatcode_timer").Start();
if (gpCcIndexer == gamepadCheatcode.Length)
{
gpCcIndexer = 0;
ToggleVisible();
}
}
if (Input.IsActionJustPressed("ui_cancel"))
//Normal keyboard hotkey
if (Input.IsActionJustPressed("console")) if (Input.IsActionJustPressed("console"))
ToggleVisible();
//OS console
/*if (OS.ReadStringFromStdIn() != "") //not tested yet
OnLineEditTextSubmitted(OS.ReadStringFromStdIn());*/
}
private void ToggleVisible()
{ {
Visible = !Visible; Visible = !Visible;
player.allowMovement = !Visible; player.allowMovement = !Visible;
line.GrabFocus(); line.GrabFocus();
} }
/*if (OS.ReadStringFromStdIn() != "") //not tested yet
OnLineEditTextSubmitted(OS.ReadStringFromStdIn());*/
}
private void OnPopupHide() { if (dialog_bubble.isTalking == false) player.allowMovement = true; } private void OnPopupHide() { if (dialog_bubble.isTalking == false) player.allowMovement = true; }
private void OnLineEditTextSubmitted(string command) private void OnLineEditTextSubmitted(string command)
{ {