From fb6f07989589c9d0888efab4d0e398f1f7b73365 Mon Sep 17 00:00:00 2001 From: cmod31 Date: Thu, 23 Feb 2023 12:33:25 +0100 Subject: [PATCH] console is now independent --- project.godot | 1 + scenes/player.tscn | 7 +--- src/scene-scripts/console/console.cs | 35 +++++++------------ .../dialogue-system/dialog_bubble.cs | 4 +-- src/scene-scripts/player.cs | 34 ++++++++++++++++-- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/project.godot b/project.godot index 8581f33..67d2ea4 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,7 @@ config/icon="res://assets/textures/debug/dummy-player-normal.png" Essential="res://src/essential.cs" PlayerVariables="*res://src/player_variables.cs" +Console="*res://scenes/gui/console.tscn" [display] diff --git a/scenes/player.tscn b/scenes/player.tscn index a9199a3..ffec80c 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=15 format=3 uid="uid://bxaheg7l4h1ip"] +[gd_scene load_steps=14 format=3 uid="uid://bxaheg7l4h1ip"] [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://dlkpivjpbxnlg" path="res://scenes/gui/console.tscn" id="4_kw3hh"] [sub_resource type="AtlasTexture" id="AtlasTexture_tokqm"] atlas = ExtResource("2_yu1q5") @@ -131,7 +130,6 @@ zoom = Vector2(0.8, 0.8) metadata/_edit_lock_ = true [node name="audio_listener_2d" type="AudioListener2D" parent="."] -current = true metadata/_edit_lock_ = true [node name="dialog_bubble" parent="." instance=ExtResource("3_8f573")] @@ -142,7 +140,4 @@ position = Vector2(0, 38) rotation = 1.57345 shape = SubResource("CapsuleShape2D_38v5o") -[node name="console" parent="." instance=ExtResource("4_kw3hh")] -visible = false - [connection signal="animation_changed" from="animated_sprite_2d" to="." method="OnAnimationChanged"] diff --git a/src/scene-scripts/console/console.cs b/src/scene-scripts/console/console.cs index 622d111..0c42217 100644 --- a/src/scene-scripts/console/console.cs +++ b/src/scene-scripts/console/console.cs @@ -11,6 +11,7 @@ public partial class console : PopupPanel //functions with capital letters can't be used inside the console public override void _Ready() { + Visible = false; 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(); @@ -19,12 +20,13 @@ public partial class console : PopupPanel { if (Input.IsActionJustPressed("console")) { + Visible = !Visible; line.GrabFocus(); - GetParent().allowMovement = !Visible; + player.allowMovement = !Visible; } } - private void OnPopupHide() => GetParent().allowMovement = true; + private void OnPopupHide() => player.allowMovement = true; private void OnLineEditTextSubmitted(string command) { line.Clear(); @@ -74,38 +76,27 @@ public partial class console : PopupPanel private void consoleclear() => textblock.Clear(); private void speed(float multiplier) { - GetParent().speed = Mathf.Clamp(multiplier, 0.01f, 15f); - textblock.AddText("Set speed to " + Mathf.Clamp(multiplier, 0.01f, 15f) + "\n"); + player.speed = Mathf.Clamp(multiplier, 0.01f, 15f); + textblock.AddText("Set player speed to " + Mathf.Clamp(multiplier, 0.01f, 15f) + "\n"); } private void noclip() { - CollisionShape2D collision = GetParent().GetNode("collision_shape"); - collision.Disabled = !collision.Disabled; - textblock.AddText("Noclip is now set to: " + collision.Disabled + "\n"); + try { textblock.AddText(player.CollisionToggle()); } catch { textblock.AddText("Player is not accessable\n"); } } private 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"); - } + try { textblock.AddText(player.CheatCam()); } catch { textblock.AddText("Player is not accessable\n"); } } private void playername(string name) { player_variables.PlayerName = name; textblock.AddText("Your new name is now: " + player_variables.PlayerName + "\n"); } - private void reload() => GetTree().ReloadCurrentScene(); + private void reload() + { + GetTree().ReloadCurrentScene(); + textblock.AddText("Level got reloaded!\n"); + } private void visiblecollision() { GetTree().DebugCollisionsHint = !GetTree().DebugCollisionsHint; diff --git a/src/scene-scripts/dialogue-system/dialog_bubble.cs b/src/scene-scripts/dialogue-system/dialog_bubble.cs index 1eb5f66..045e9fd 100644 --- a/src/scene-scripts/dialogue-system/dialog_bubble.cs +++ b/src/scene-scripts/dialogue-system/dialog_bubble.cs @@ -33,7 +33,7 @@ public partial class dialog_bubble : CanvasLayer if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager) GetNode