diff --git a/scenes/gui/console.tscn b/scenes/gui/console.tscn index a17afa4..bbe9874 100644 --- a/scenes/gui/console.tscn +++ b/scenes/gui/console.tscn @@ -1,12 +1,12 @@ -[gd_scene load_steps=2 format=3 uid="uid://bt4pohi6srcvi"] +[gd_scene load_steps=2 format=3 uid="uid://dlkpivjpbxnlg"] -[ext_resource type="Script" path="res://src/scene-scripts/console.cs" id="1_c6bre"] +[ext_resource type="Script" path="res://src/scene-scripts/console/console.cs" id="1_gdt1r"] [node name="popup_panel" type="PopupPanel"] transparent_bg = true size = Vector2i(1537, 193) visible = true -script = ExtResource("1_c6bre") +script = ExtResource("1_gdt1r") [node name="v_box_container" type="VBoxContainer" parent="."] offset_left = 4.0 @@ -17,17 +17,20 @@ offset_bottom = 189.0 [node name="rich_text_label" type="RichTextLabel" parent="v_box_container"] custom_minimum_size = Vector2(0, 150) layout_mode = 2 +focus_mode = 2 bbcode_enabled = true -text = "[color=red][b]USING CHEATS MAY DISABLE ACHIEVEMENTS[/b][/color]" +text = "[color=red][b]USING CHEATS MAY PAUSE ACHIEVEMENTS WHILE THE CHEATS ARE ACTIVE[/b][/color] +" scroll_following = true +selection_enabled = true [node name="line_edit" type="LineEdit" parent="v_box_container"] layout_mode = 2 placeholder_text = "Type in cheat or command. Use \"help\" for help." max_length = 200 +context_menu_enabled = false clear_button_enabled = true flat = true -draw_control_chars = true select_all_on_focus = true caret_blink = true caret_blink_interval = 0.5 diff --git a/scenes/overworld.tscn b/scenes/overworld.tscn index 83f3c35..5527987 100644 --- a/scenes/overworld.tscn +++ b/scenes/overworld.tscn @@ -45,7 +45,7 @@ metadata/_edit_lock_ = true [node name="player" parent="." instance=ExtResource("2_0skrb")] playerName = "Yannik" -[node name="camera_2d" parent="player" index="2"] +[node name="main_cam" parent="player" index="2"] limit_left = -1791 limit_top = -1023 limit_right = 1791 diff --git a/scenes/player.tscn b/scenes/player.tscn index e19f96a..d248f6d 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"] [ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"] [ext_resource type="PackedScene" uid="uid://bkm7365u1mm3o" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"] -[ext_resource type="PackedScene" uid="uid://bt4pohi6srcvi" path="res://scenes/gui/console.tscn" id="4_kw3hh"] +[ext_resource type="PackedScene" uid="uid://dlkpivjpbxnlg" path="res://scenes/gui/console.tscn" id="4_kw3hh"] [sub_resource type="AtlasTexture" id="AtlasTexture_tokqm"] atlas = ExtResource("2_yu1q5") @@ -87,7 +87,7 @@ animations = [{ [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"] radius = 7.99997 -height = 33.9946 +height = 32.0 [node name="player" type="CharacterBody2D"] process_mode = 1 @@ -114,9 +114,8 @@ sprite_frames = SubResource("SpriteFrames_2x1cy") animation = &"move_down" metadata/_edit_lock_ = true -[node name="camera_2d" type="Camera2D" parent="."] +[node name="main_cam" type="Camera2D" parent="."] zoom = Vector2(0.8, 0.8) -process_callback = 0 position_smoothing_enabled = true position_smoothing_speed = 3.0 drag_horizontal_enabled = true @@ -128,6 +127,10 @@ drag_bottom_margin = 0.15 editor_draw_drag_margin = true metadata/_edit_lock_ = true +[node name="cheat_cam" type="Camera2D" parent="."] +zoom = Vector2(0.8, 0.8) +metadata/_edit_lock_ = true + [node name="audio_listener_2d" type="AudioListener2D" parent="."] current = true metadata/_edit_lock_ = true diff --git a/src/scene-scripts/console.cs b/src/scene-scripts/console.cs deleted file mode 100644 index bb842a1..0000000 --- a/src/scene-scripts/console.cs +++ /dev/null @@ -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("v_box_container/rich_text_label"); - line = GetNode("v_box_container/line_edit"); - } - public override void _Process(double delta) - { - if (Input.IsActionJustPressed("console")) - { - Visible = !Visible; - line.GrabFocus(); - if (GetParent().Name == "player") GetParent().allowMovement = !Visible; - } - } - public void OnPopupHide() - { - if (GetParent().Name == "player") GetParent().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 - Multiplies the player speed by the given value"); - textblock.AddText("\n3. playername - Renames the player"); - } - public void consoleclear() => textblock.Clear(); - public void speed(float multiplier) - { - if (GetParent().Name == "player") GetParent().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().playerName = name; - GetParent().ClearPlayerName(); - textblock.AddText("\nYour new name is now: " + GetParent().playerName); - } - - } -} diff --git a/src/scene-scripts/console/commands.json b/src/scene-scripts/console/commands.json new file mode 100644 index 0000000..e639cbb --- /dev/null +++ b/src/scene-scripts/console/commands.json @@ -0,0 +1,9 @@ +{ + "help": " - Shows this help\n", + "consoleclear": " - Clears the console\n", + "speed": " - 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": " - Renames the player\n", + "reload": " - Reloads the current level (for softlocks or other issues)\n" +} \ No newline at end of file diff --git a/src/scene-scripts/console/console.cs b/src/scene-scripts/console/console.cs new file mode 100644 index 0000000..c10ef37 --- /dev/null +++ b/src/scene-scripts/console/console.cs @@ -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("v_box_container/rich_text_label"); + line = GetNode("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().allowMovement = !Visible; + } + } + public void OnPopupHide() => GetParent().allowMovement = true; + public void OnLineEditTextSubmitted(string command) + { + line.Clear(); + if (command.Length != 0) textblock.AddText(GetParent().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().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().GetNode("collision_shape"); + collision.Disabled = !collision.Disabled; + textblock.AddText("Noclip is now set to: " + collision.Disabled + "\n"); + } + public void stickycamera() + { + Camera2D cheatCam = GetParent().GetNode("cheat_cam"); + Camera2D mainCam = GetParent().GetNode("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().playerName = name; + GetParent().ClearPlayerName(); + textblock.AddText("Your new name is now: " + GetParent().playerName + "\n"); + } + } + public void reload() => GetTree().ReloadCurrentScene(); +}