From 2717b9b9042cdbfa574e299235d8a967db083dcb Mon Sep 17 00:00:00 2001 From: sebashtioon Date: Thu, 7 Nov 2024 12:54:20 +1100 Subject: [PATCH] add input tracking script and update Player scene to include it --- .../Debug/inputs_currently_pressing_SCRIPT.gd | 35 +++++++++++++++++++ Scenes and Scripts/Scenes/Player/Player.tscn | 4 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Scenes and Scripts/Scenes/Player/Debug/inputs_currently_pressing_SCRIPT.gd diff --git a/Scenes and Scripts/Scenes/Player/Debug/inputs_currently_pressing_SCRIPT.gd b/Scenes and Scripts/Scenes/Player/Debug/inputs_currently_pressing_SCRIPT.gd new file mode 100644 index 00000000..43d3ae1c --- /dev/null +++ b/Scenes and Scripts/Scenes/Player/Debug/inputs_currently_pressing_SCRIPT.gd @@ -0,0 +1,35 @@ +extends Label + +var pressed_inputs = {} + +func _process(_delta): + # List of actions to check + var actions = [ + {"name": "Jump", "action": "Jump"}, + {"name": "Move Forward", "action": "move_forward"}, + {"name": "Move Backward", "action": "move_backward"}, + {"name": "Move Left", "action": "move_left"}, + {"name": "Move Right", "action": "move_right"}, + {"name": "Quit", "action": "Quit"}, + {"name": "Sprint", "action": "Sprint"}, + {"name": "Reset", "action": "Reset"}, + {"name": "Exit", "action": "Exit"}, + {"name": "Inventory", "action": "Inventory"}, + {"name": "Inventory Click", "action": "inventory_click"}, + {"name": "Crouch", "action": "Crouch"}, + {"name": "Save Game", "action": "SaveGame"}, + {"name": "Interact", "action": "Interact"} + ] + + # Update the set of pressed inputs based on current state + for action_data in actions: + var action_name = action_data["name"] + var action = action_data["action"] + + if Input.is_action_pressed(action): + pressed_inputs[action_name] = true # Add or keep in the set + else: + pressed_inputs.erase(action_name) # Remove from the set if not pressed + + # Update the label's text with a comma-separated list of pressed inputs + self.text = ", ".join(pressed_inputs.keys()) diff --git a/Scenes and Scripts/Scenes/Player/Player.tscn b/Scenes and Scripts/Scenes/Player/Player.tscn index d0679f6a..f28f4258 100644 --- a/Scenes and Scripts/Scenes/Player/Player.tscn +++ b/Scenes and Scripts/Scenes/Player/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=42 format=3 uid="uid://cjm5lrxicdgsf"] +[gd_scene load_steps=43 format=3 uid="uid://cjm5lrxicdgsf"] [ext_resource type="Script" path="res://Scenes and Scripts/Scenes/Player/Player_SCRIPT.gd" id="1_5mhs1"] [ext_resource type="Script" path="res://Textures/Icons/Script Icons/Scripts/CameraIcon_SCRIPT.gd" id="2_37tst"] @@ -24,6 +24,7 @@ [ext_resource type="StyleBox" uid="uid://com3tix0pshhk" path="res://Resources/Styles and Themes/Styles/Default/Label/Default_Label.tres" id="19_nviyp"] [ext_resource type="Script" path="res://Scenes and Scripts/Scenes/Player/Settings/Volume/MusicSlider_SCRIPT.gd" id="20_124b5"] [ext_resource type="Script" path="res://Scenes and Scripts/Scenes/Player/Settings/Volume/SFXSlider_SCRIPT.gd" id="21_fi5yi"] +[ext_resource type="Script" path="res://Scenes and Scripts/Scenes/Player/Debug/inputs_currently_pressing_SCRIPT.gd" id="25_h5s3l"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_w6tro"] @@ -991,6 +992,7 @@ grow_vertical = 0 theme = ExtResource("17_rhxkt") horizontal_alignment = 1 vertical_alignment = 1 +script = ExtResource("25_h5s3l") [connection signal="timeout" from="AutoSaveTimer" to="." method="_on_auto_save_timer_timeout"] [connection signal="area_entered" from="Head/Camera3D/InventoryLayer/Boundary" to="." method="_on_boundary_area_entered"]