little restructure again, added CONSOLE!!!!

somewhat working console, fully developed from the ground up

some things work with it, but its still pretty buggy

currently runs on global autoload because its the easiest way rn, later on have to change it so that only if the player is in the game and console is enabled it can be toggled
This commit is contained in:
Balogh Krisztián 2026-07-31 02:38:02 +02:00
parent 4869dcc3de
commit 6231073ad6
26 changed files with 979 additions and 224 deletions

View file

@ -67,7 +67,6 @@ mesh = SubResource("BoxMesh_yf5fn")
[node name="Player" parent="." unique_id=423228143 instance=ExtResource("1_s8b7j")] [node name="Player" parent="." unique_id=423228143 instance=ExtResource("1_s8b7j")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.77974355, 1.137004) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.77974355, 1.137004)
UI_MOVEMENT_SENSITIVITY = 1.0
[node name="OmniLight3D" type="OmniLight3D" parent="." unique_id=1317582521] [node name="OmniLight3D" type="OmniLight3D" parent="." unique_id=1317582521]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646)

View file

@ -0,0 +1,119 @@
[gd_scene format=3 uid="uid://chykk2a3opu0d"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="1_s8b7j"]
[ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="2_afrty"]
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"]
[sub_resource type="PlaneMesh" id="PlaneMesh_g4v7s"]
[sub_resource type="BoxShape3D" id="BoxShape3D_g4v7s"]
[sub_resource type="BoxMesh" id="BoxMesh_g4v7s"]
[sub_resource type="BoxShape3D" id="BoxShape3D_yf5fn"]
[sub_resource type="BoxMesh" id="BoxMesh_yf5fn"]
[sub_resource type="BoxShape3D" id="BoxShape3D_57qmd"]
size = Vector3(20.447998, 11.038544, 1)
[node name="DevMap" type="Node3D" unique_id=471389571]
[node name="Plane" type="StaticBody3D" parent="." unique_id=1943923809]
collision_layer = 17
collision_mask = 17
[node name="CollisionShape3D" type="CollisionShape3D" parent="Plane" unique_id=2072732464]
shape = SubResource("WorldBoundaryShape3D_g4v7s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Plane" unique_id=810695750]
transform = Transform3D(9.905844, 0, 0, 0, 1, 0, 0, 0, 9.900972, 0, 0, 0)
mesh = SubResource("PlaneMesh_g4v7s")
[node name="TestObject" type="RigidBody3D" parent="." unique_id=1889494210]
transform = Transform3D(0.9224609, 0.38609046, 0, -0.38609046, 0.9224609, 0, 0, 0, 1, 1.1603341, 0.9219521, -1.1464608)
collision_layer = 17
collision_mask = 17
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObject" unique_id=507616212]
shape = SubResource("BoxShape3D_g4v7s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObject" unique_id=1356474788]
mesh = SubResource("BoxMesh_g4v7s")
[node name="TestObjectGrabbable" type="RigidBody3D" parent="." unique_id=162241126 groups=["grabbable"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.776662, -3.2358055)
collision_layer = 17
collision_mask = 17
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObjectGrabbable" unique_id=2049402651]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObjectGrabbable" unique_id=1899834557]
mesh = SubResource("BoxMesh_yf5fn")
[node name="TestObjectEquippable" type="RigidBody3D" parent="." unique_id=1086000939]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.874709, 1.0290127, -3.1515453)
collision_layer = 17
collision_mask = 17
[node name="CollisionShape3D" type="CollisionShape3D" parent="TestObjectEquippable" unique_id=740741417]
shape = SubResource("BoxShape3D_yf5fn")
[node name="MeshInstance3D" type="MeshInstance3D" parent="TestObjectEquippable" unique_id=1967579265]
mesh = SubResource("BoxMesh_yf5fn")
[node name="Player" parent="." unique_id=423228143 instance=ExtResource("1_s8b7j")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.77974355, 1.137004)
[node name="OmniLight3D" type="OmniLight3D" parent="." unique_id=1317582521]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646)
[node name="SpatialAudio3D" type="AudioStreamPlayer3D" parent="." unique_id=351573539]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.887349, 4.01754, -1.2293816)
stream = ExtResource("2_afrty")
volume_db = -8.235
autoplay = true
max_distance = 1927.53
script = ExtResource("4_yb1w3")
occlusion_fadetime = 0.0
bass_proximity = 0
max_raycast_distance = 30
roomsize_multiplicator = 2.0
prox_reduction = 16.0
debug = true
metadata/_custom_type_script = "uid://y8x4svl5kej2"
[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=1656249102]
transform = Transform3D(1, 0, -1.7484555e-07, 0, 1, 0, 1.7484555e-07, 0, 1, 10.053528, 0, 9.284716)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=1173755237]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.723999, 5.019272, 0)
shape = SubResource("BoxShape3D_57qmd")
[node name="StaticBody3D2" type="StaticBody3D" parent="." unique_id=23077148]
transform = Transform3D(-4.371138e-08, 0, -1, 0, 1, 0, 1, 0, -4.371138e-08, 10.053528, 0, 8.284716)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D2" unique_id=1774765140]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.723999, 5.019272, 0)
shape = SubResource("BoxShape3D_57qmd")
[node name="StaticBody3D3" type="StaticBody3D" parent="." unique_id=2124365943]
transform = Transform3D(-1, 0, 8.742278e-08, 0, 1, 0, -8.742278e-08, 0, -1, -8.946472, 0, -10.715284)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D3" unique_id=652377662]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.723999, 5.019272, 0)
shape = SubResource("BoxShape3D_57qmd")
[node name="StaticBody3D4" type="StaticBody3D" parent="." unique_id=942386107]
transform = Transform3D(1.3113416e-07, 0, 1, 0, 1, 0, -1, 0, 1.3113416e-07, -8.946472, 0, -10.715284)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D4" unique_id=1055230632]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.723999, 5.019272, 0)
shape = SubResource("BoxShape3D_57qmd")
[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D4" unique_id=967910627]
transform = Transform3D(1, 1.3113416e-07, -1.3113416e-07, -1.3113416e-07, -4.371139e-08, -1, -1.3113416e-07, 1, -4.371137e-08, -9.723998, 10.984082, 10)
shape = SubResource("BoxShape3D_57qmd")

View file

@ -19,6 +19,15 @@ config/features=PackedStringArray("4.7", "Forward Plus")
run/max_fps=60 run/max_fps=60
config/icon="res://icon.svg" config/icon="res://icon.svg"
[audio]
buses/default_bus_layout="uid://bfh2c7jnwhac0"
[autoload]
Console="*uid://bojihx1fwf426"
PlayerProperties="*uid://l2rc674shj03"
[display] [display]
window/size/viewport_width=1920 window/size/viewport_width=1920
@ -49,6 +58,58 @@ grabbable="this object can be grabbed"
[input] [input]
ui_accept={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
ui_focus_next={
"deadzone": 0.5,
"events": []
}
ui_focus_prev={
"deadzone": 0.5,
"events": []
}
ui_up={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
]
}
ui_down={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
]
}
ui_text_completion_accept={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
ui_text_indent={
"deadzone": 0.5,
"events": []
}
ui_text_caret_up={
"deadzone": 0.5,
"events": []
}
ui_text_caret_down={
"deadzone": 0.5,
"events": []
}
ui_text_submit={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
forward={ forward={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
@ -104,6 +165,16 @@ select_item_3={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
] ]
} }
select_item_4={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
]
}
select_item_5={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":53,"key_label":0,"unicode":53,"location":0,"echo":false,"script":null)
]
}
next_item={ next_item={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(139, 22),"global_position":Vector2(148, 70),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(139, 22),"global_position":Vector2(148, 70),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
@ -134,6 +205,11 @@ grab={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(316, 15),"global_position":Vector2(325, 63),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(316, 15),"global_position":Vector2(325, 63),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
] ]
} }
toggle_console={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":47,"key_label":0,"unicode":45,"location":0,"echo":false,"script":null)
]
}
[layer_names] [layer_names]

View file

@ -0,0 +1,74 @@
[gd_scene format=3 uid="uid://bojihx1fwf426"]
[ext_resource type="Script" uid="uid://d05oodtjpja5k" path="res://scenes/console/console.gd" id="1_v2h8y"]
[node name="Console" type="Control" unique_id=1645877163]
layout_mode = 3
anchor_left = 0.3
anchor_right = 0.7
anchor_bottom = 0.193
grow_horizontal = 2
offset_transform_enabled = true
script = ExtResource("1_v2h8y")
[node name="Control" type="PanelContainer" parent="." unique_id=1597361814]
layout_mode = 1
anchors_preset = -1
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
[node name="MarginContainer" type="MarginContainer" parent="Control" unique_id=799180659]
layout_mode = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
[node name="VboxContainer" type="VBoxContainer" parent="Control/MarginContainer" unique_id=2024139519]
layout_mode = 2
[node name="ConsoleLog" type="RichTextLabel" parent="Control/MarginContainer/VboxContainer" unique_id=158641778]
unique_name_in_owner = true
custom_maximum_size = Vector2(-1, 230)
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 4.0
bbcode_enabled = true
scroll_following = true
text_direction = 1
[node name="ConsoleInputBox" type="HBoxContainer" parent="Control/MarginContainer/VboxContainer" unique_id=1042125568]
layout_mode = 2
size_flags_stretch_ratio = 0.5
[node name="Label" type="Label" parent="Control/MarginContainer/VboxContainer/ConsoleInputBox" unique_id=2023386683]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.01
theme_override_font_sizes/font_size = 25
text = ">"
horizontal_alignment = 2
[node name="ConsoleInput" type="LineEdit" parent="Control/MarginContainer/VboxContainer/ConsoleInputBox" unique_id=358247719]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.29
keep_editing_on_text_submit = true
expand_to_text_length = true
flat = true
draw_control_chars = true
caret_blink = true
caret_blink_interval = 0.12
[node name="SuggestionsList" type="ItemList" parent="." unique_id=220304513]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = -1
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
size_flags_stretch_ratio = 2.0
auto_height = true

175
scenes/console/console.gd Normal file
View file

@ -0,0 +1,175 @@
extends Control
@onready var console_log: RichTextLabel = %ConsoleLog
@onready var suggestions_list: ItemList = %SuggestionsList
@onready var console_input: LineEdit = %ConsoleInput
## maybe should change the arrays to dicts so we can give them descriptions
var context = {}
var spaces: Dictionary = {"player" : "everything that is to do with the player", "level" : "everything that is to do with the level", "server" : "everything that is to do with the server"}
var player_commands: Dictionary = {"add_inventory_slot" : "add a slot to your inventory. max inv slots = 5", "remove_inventory_slot" : "remove a slot from your inventory. min inv slots = 2"}
var avaliable_commands: Dictionary = {
"help" : "print the available commands. \"help player\" prints the available commands for the player",
"clear" : "clear the console",
"whoami" : "returns the player node as text",
"exit" : "currently just exits the game fully"}
var toggled: bool = false
## print to the console from the console line and empty it, like a submit
func print_to_console_from_console(...str:Array):
console_log.add_text("> " + console_input.text + "\n")
for x in str:
console_log.add_text(str(x))
console_log.add_text("\n\n")
console_input.clear()
func print_to_console(new_line:bool = false, ...str:Array, ):
for x in str:
console_log.add_text(str(x))
if new_line: console_log.add_text("\n\n")
func print_help(space:String = ""):
var help_text: String = ""
match space:
"player":
for x in player_commands:
help_text += x + " - " + player_commands[x]
help_text += "\n"
_:
for x in avaliable_commands:
help_text += x + " - " + avaliable_commands[x]
help_text += "\n"
help_text += "Avaliable spaces: \n"
for x in spaces:
help_text += "\t\t" + x + " - " + spaces[x]
help_text += "\n"
print_to_console_from_console(help_text)
func clear_console():
console_log.text = ""
print_to_console_from_console("Cleared console output.")
func toggle_caret(char:String = "_"):
print_to_console_from_console("toggle")
console_input.text += char
var selected_suggestion = 0
func fill_from_suggestion():
var cur_space = console_input.text.split(".")
if cur_space.size() > 1:
console_input.text = cur_space[0] + "." + suggestions_list.get_item_text(selected_suggestion).split(" ")[0]
else:
if suggestions_list.item_count > 0:
var fill = suggestions_list.get_item_text(selected_suggestion).split(" ")
if fill[0] in spaces.keys():
console_input.text = fill[0] + "."
suggestions_list.clear()
show_space_commands_suggestions(fill[0], "")
else:
console_input.text = fill[0] + " "
console_input.grab_focus()
console_input.caret_column = console_input.text.length()
selected_suggestion = 0
func show_space_suggestions(current_string:String):
for space: String in spaces:
if current_string in space:
suggestions_list.add_item(space + " - " + spaces[space])
func show_commands_suggestions(current_string:String):
if console_input.text != "" and not ("." in console_input.text):
for command: String in avaliable_commands:
if command.contains(current_string):
suggestions_list.add_item(command + " - " + avaliable_commands[command])
func show_space_commands_suggestions(space:String, command:String):
match space:
"player":
for player_command: String in player_commands:
if command in player_command:
suggestions_list.add_item(player_command + " - " + player_commands[player_command])
func show_suggestions(current_string: String):
suggestions_list.clear()
if !current_string.contains("."):
show_space_suggestions(current_string)
show_commands_suggestions(current_string)
else:
var space = current_string.split(".")
if space.size() > 1:
show_space_commands_suggestions(space[0], space[1])
func parsed_command(command:String):
if command == "":
return
var space = command.split(".")
var parts = command.split(" ", false)
if space.size() < 2:
match parts[0]:
"help":
print_help(parts[1] if (parts.size() > 1) else "")
"whoami":
print_to_console_from_console(context["player"] if context.has("player") else "bruh")
"clear":
clear_console()
_:
print(command)
print_to_console_from_console("\"", command, "\" command not found. Type \"help\" for a list of available commands.")
else:
match space[0]:
"player":
match space[1]:
"add_inventory_slot":
emit_signal("add_inventory")
print_to_console_from_console("Added inventory slot.")
"remove_inventory_slot":
emit_signal("remove_inventory")
print_to_console_from_console("Removed inventory slot.")
signal add_inventory
signal remove_inventory
func _ready() -> void:
console_input.caret_blink = true
console_input.text_submitted.connect(parsed_command)
console_input.text_changed.connect(show_suggestions)
suggestions_list.item_selected.connect(fill_from_suggestion)
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed("toggle_console") and not Input.is_key_pressed(KEY_SHIFT) or (toggled and Input.is_action_just_pressed("open_menu")):
toggled = !toggled
if toggled:
console_input.grab_focus()
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
else:
console_input.release_focus()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
get_tree().create_timer(.1).timeout.connect(console_input.clear)
if toggled and (Input.is_action_just_pressed("ui_text_completion_accept") or Input.is_key_pressed(KEY_ENTER)) and suggestions_list.item_count > 0:
fill_from_suggestion()
if toggled and suggestions_list.item_count > 0:
if Input.is_key_pressed(KEY_DOWN):
if selected_suggestion + 1 > suggestions_list.item_count - 1:
selected_suggestion = 0
else:
selected_suggestion = selected_suggestion + 1
if Input.is_key_pressed(KEY_UP):
if selected_suggestion - 1 < 0:
selected_suggestion = suggestions_list.item_count - 1
else:
selected_suggestion = selected_suggestion - 1
suggestions_list.select(selected_suggestion)
func _process(delta: float) -> void:
offset_transform_position_ratio.y = lerpf(offset_transform_position_ratio.y, -3 if !toggled else 0, delta * 10)

View file

@ -0,0 +1 @@
uid://d05oodtjpja5k

View file

@ -12,10 +12,12 @@ extends Node
@onready var cursor_raycast: RayCast3D = %CursorRaycast @onready var cursor_raycast: RayCast3D = %CursorRaycast
@onready var popup_panels: Control = %PopupPanels @onready var popup_panels: Control = %PopupPanels
@onready var stamina_reset: Timer = %StaminaReset @onready var stamina_reset: Timer = %StaminaReset
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
@onready var procedural_camera_mover: Node = %ProceduralCameraMover @onready var procedural_camera_mover: Node = %ProceduralCameraMover
@onready var camera: Camera3D = %PlayerCamera @onready var camera: Camera3D = %PlayerCamera
@onready var hold_position: Marker3D = %HoldPosition @onready var hold_position: Marker3D = %HoldPosition
@onready var player_manager: Node = %PlayerManager
@onready var ui: Control = %PlayerUi
var sensitivity: float = 0.002 var sensitivity: float = 0.002
@ -30,36 +32,52 @@ func toggle_flashlight():
sound_controller.play_flashlight_sound() sound_controller.play_flashlight_sound()
func _input(event): func _input(event):
if Input.is_action_just_pressed("open_menu"): if not Console.toggled:
ui_handler.toggle_menu() if Input.is_action_just_pressed("open_menu"):
ui_handler.toggle_menu()
if not player_state.in_menu: if Input.is_action_just_pressed("select_item_1"):
if event is InputEventMouseMotion: player_manager.select_item(0)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
mouse_motion += event.relative
mouse_motion_delta = event.relative
if Input.is_action_just_pressed("flashlight"): if Input.is_action_just_pressed("select_item_2"):
toggle_flashlight() player_manager.select_item(1)
if Input.is_action_just_released("jump") or Input.is_action_just_released("sprint"): if Input.is_action_just_pressed("select_item_3"):
stamina_reset.start() player_manager.select_item(2)
if Input.is_action_just_pressed("grab"): if Input.is_action_just_pressed("select_item_4"):
if cursor_raycast.is_colliding(): player_manager.select_item(3)
var hit_object = cursor_raycast.get_collider()
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable"): if Input.is_action_just_pressed("select_item_5"):
held_object = hit_object player_manager.select_item(4)
held_object.gravity_scale = 0.0
held_object.angular_damp = 5.0
popup_panels.visible = false
if Input.is_action_just_released("grab") and held_object != null: if not player_state.in_menu:
held_object.gravity_scale = 1.0 if event is InputEventMouseMotion:
held_object.angular_damp = 0.0 if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
held_object = null mouse_motion += event.relative
popup_panels.visible = true mouse_motion_delta = event.relative
if Input.is_action_just_pressed("flashlight"):
toggle_flashlight()
if Input.is_action_just_released("jump") or Input.is_action_just_released("sprint"):
stamina_reset.start()
if Input.is_action_just_pressed("grab"):
if cursor_raycast.is_colliding():
var hit_object = cursor_raycast.get_collider()
if hit_object is RigidBody3D and hit_object.is_in_group("grabbable"):
held_object = hit_object
held_object.gravity_scale = 0.0
held_object.angular_damp = 5.0
popup_panels.visible = false
if Input.is_action_just_released("grab") and held_object != null:
held_object.gravity_scale = 1.0
held_object.angular_damp = 0.0
held_object = null
popup_panels.visible = true
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
#handle grabbed object #handle grabbed object
@ -87,6 +105,13 @@ func _process(delta: float) -> void:
player.transform.basis = Basis.from_euler(Vector3(0, mouse_motion.x * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0)) player.transform.basis = Basis.from_euler(Vector3(0, mouse_motion.x * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0))
camera.transform.basis = lerp(camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0, 0)), delta * 10) camera.transform.basis = lerp(camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0, 0)), delta * 10)
if not Console.toggled:
if Input.is_action_just_pressed("next_item"):
player_manager.next_item()
if Input.is_action_just_pressed("prev_item"):
player_manager.prev_item()
#func _unhandled_input(event: InputEvent) -> void: #func _unhandled_input(event: InputEvent) -> void:
#if event is InputEventMouseMotion: #if event is InputEventMouseMotion:
#player_camera.rotate_y(-event.relative.x * sensitivity) #player_camera.rotate_y(-event.relative.x * sensitivity)

View file

@ -14,15 +14,15 @@ extends Node
@export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity @export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity
@export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel @export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel
@onready var camera_pivot: Node3D = %CameraPivot @onready var camera_pivot: Node3D = %CameraPivot
@onready var player_camera: Camera3D = %PlayerCamera @onready var player_camera: Camera3D = %PlayerCamera
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
@onready var player_state: Node = %PlayerState @onready var player_state: Node = %PlayerState
@onready var player_properties: Node = %PlayerProperties @onready var player_manager: Node = %PlayerManager
@onready var procedural_camera_mover: Node = %ProceduralCameraMover @onready var procedural_camera_mover: Node = %ProceduralCameraMover
@onready var player_hit_box: CollisionShape3D = $"../../PlayerHitBox" @onready var player_hit_box: CollisionShape3D = $"../../PlayerHitBox"
@onready var sound_controller: Node = %SoundController @onready var sound_controller: Node = %SoundController
@onready var ui: Control = %PlayerUi
func _ready() -> void: func _ready() -> void:
@ -32,11 +32,11 @@ func _physics_process(delta: float) -> void:
if not player.is_on_floor(): if not player.is_on_floor():
player.velocity += player.get_gravity() * delta player.velocity += player.get_gravity() * delta
if not player_state.in_menu: if not player_state.in_menu and not Console.toggled:
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_properties.stamina > JUMP_STAMINA_COST: if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_manager.stamina > JUMP_STAMINA_COST:
player.velocity.y = JUMP_VELOCITY player.velocity.y = JUMP_VELOCITY
player_properties.stamina -= JUMP_STAMINA_COST player_manager.stamina -= JUMP_STAMINA_COST
player_properties.stamina_recharge_off() player_manager.stamina_recharge_off()
var input_dir = Input.get_vector("left", "right", "forward", "backward") var input_dir = Input.get_vector("left", "right", "forward", "backward")
#var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() #var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
@ -60,11 +60,11 @@ func _physics_process(delta: float) -> void:
player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10) player_hit_box.shape.height = lerpf(player_hit_box.shape.height, 2, delta * 10)
player_state.is_crouched(false) player_state.is_crouched(false)
if Input.is_action_pressed("sprint") and player_properties.stamina > 0: if Input.is_action_pressed("sprint") and player_manager.stamina > 0:
target_speed *= SPRINT_MULTIPLIER target_speed *= SPRINT_MULTIPLIER
player_state.is_running(true) player_state.is_running(true)
player_properties.stamina -= delta * SPRINT_STAMINA_COST player_manager.stamina -= delta * SPRINT_STAMINA_COST
player_properties.stamina_recharge_off() player_manager.stamina_recharge_off()
else: else:
player_state.is_running(false) player_state.is_running(false)

4
scenes/player/player.gd Normal file
View file

@ -0,0 +1,4 @@
extends CharacterBody3D
func _ready() -> void:
Console.context["player"] = self

View file

@ -0,0 +1 @@
uid://bawpnca3v51gv

View file

@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://kqq30y24c6kd"] [gd_scene format=3 uid="uid://kqq30y24c6kd"]
[ext_resource type="Script" uid="uid://l2rc674shj03" path="res://scenes/player/player_manager.gd" id="1_eqqp1"] [ext_resource type="Script" uid="uid://bawpnca3v51gv" path="res://scenes/player/player.gd" id="1_76ube"]
[ext_resource type="AudioStream" uid="uid://he4huk3fb0vm" path="res://assets/sounds/walking/normal/normal walk-001.wav" id="2_32hag"] [ext_resource type="AudioStream" uid="uid://he4huk3fb0vm" path="res://assets/sounds/walking/normal/normal walk-001.wav" id="2_32hag"]
[ext_resource type="PackedScene" uid="uid://bsccbqq04umeg" path="res://scenes/player/player_ui.tscn" id="2_rkbax"] [ext_resource type="PackedScene" uid="uid://bsccbqq04umeg" path="res://scenes/player/player_ui.tscn" id="2_rkbax"]
[ext_resource type="PackedScene" uid="uid://y5f3db7clptv" path="res://scenes/player/in_game_menu.tscn" id="3_g1dw6"] [ext_resource type="PackedScene" uid="uid://y5f3db7clptv" path="res://scenes/player/in_game_menu.tscn" id="3_g1dw6"]
@ -71,7 +71,7 @@
[ext_resource type="Script" uid="uid://bvvwwkswavy5x" path="res://scenes/player/input_controller_component.gd" id="64_j3r50"] [ext_resource type="Script" uid="uid://bvvwwkswavy5x" path="res://scenes/player/input_controller_component.gd" id="64_j3r50"]
[ext_resource type="AudioStream" uid="uid://c1wt8hmiv44oe" path="res://assets/sounds/walking/jump_landing/Jump-landing-003.wav" id="65_3r8w6"] [ext_resource type="AudioStream" uid="uid://c1wt8hmiv44oe" path="res://assets/sounds/walking/jump_landing/Jump-landing-003.wav" id="65_3r8w6"]
[ext_resource type="Script" uid="uid://7hmwhf7acwpj" path="res://scenes/player/state_handler_component.gd" id="65_kssj8"] [ext_resource type="Script" uid="uid://7hmwhf7acwpj" path="res://scenes/player/state_handler_component.gd" id="65_kssj8"]
[ext_resource type="Script" uid="uid://cbdvyelf7nb1u" path="res://scenes/player/player_properties.gd" id="66_8lfxt"] [ext_resource type="Script" uid="uid://cbdvyelf7nb1u" path="res://scenes/player/player_manager.gd" id="66_8lfxt"]
[ext_resource type="AudioStream" uid="uid://bv4npi51e2gww" path="res://assets/sounds/walking/jump_landing/Jump-landing-004.wav" id="66_i816j"] [ext_resource type="AudioStream" uid="uid://bv4npi51e2gww" path="res://assets/sounds/walking/jump_landing/Jump-landing-004.wav" id="66_i816j"]
[ext_resource type="AudioStream" uid="uid://cv4ojt7yvqtac" path="res://assets/sounds/walking/jump_landing/Jump-landing-005.wav" id="67_laqvq"] [ext_resource type="AudioStream" uid="uid://cv4ojt7yvqtac" path="res://assets/sounds/walking/jump_landing/Jump-landing-005.wav" id="67_laqvq"]
[ext_resource type="AudioStream" uid="uid://wy8m1rr6delh" path="res://assets/sounds/walking/jump_landing/Jump-landing-006.wav" id="68_aq51r"] [ext_resource type="AudioStream" uid="uid://wy8m1rr6delh" path="res://assets/sounds/walking/jump_landing/Jump-landing-006.wav" id="68_aq51r"]
@ -237,13 +237,7 @@ curve_z = SubResource("Curve_7numd")
[node name="Player" type="CharacterBody3D" unique_id=423228143] [node name="Player" type="CharacterBody3D" unique_id=423228143]
collision_layer = 16 collision_layer = 16
collision_mask = 16 collision_mask = 16
script = ExtResource("1_eqqp1") script = ExtResource("1_76ube")
NORMAL_FOOTSTEP_SOUNDS = Array[AudioStreamWAV]([ExtResource("2_32hag"), ExtResource("3_tqiix"), ExtResource("4_e7oew"), ExtResource("5_c35mf"), ExtResource("6_65viv"), ExtResource("7_x7c3f"), ExtResource("8_bjvpn"), ExtResource("9_s7qer"), ExtResource("10_g4c7l"), ExtResource("11_knn7v"), ExtResource("12_7pqkx"), ExtResource("13_uw77l"), ExtResource("14_rptt4")])
HEAVY_FOOTSTEP_SOUNDS = Array[AudioStreamWAV]([ExtResource("15_n0b8q"), ExtResource("16_jfgyi"), ExtResource("17_237xx"), ExtResource("18_wpyo2"), ExtResource("19_7crtr"), ExtResource("20_vgvch"), ExtResource("21_a1u5o"), ExtResource("22_3dxkp"), ExtResource("23_6wior"), ExtResource("24_p5tca"), ExtResource("25_jbx34"), ExtResource("26_s3g0c"), ExtResource("27_35wys"), ExtResource("28_pjwc4"), ExtResource("29_or4qq"), ExtResource("30_hggc2")])
LIGHT_FOOTSTEP_SOUNDS = Array[AudioStreamWAV]([ExtResource("31_b2j0d"), ExtResource("32_7l6ig"), ExtResource("33_j3r50"), ExtResource("34_utr5e"), ExtResource("35_kewli"), ExtResource("36_do7qw"), ExtResource("37_2h6tc"), ExtResource("38_8rogd"), ExtResource("39_48p26"), ExtResource("40_anp34"), ExtResource("41_jdjat"), ExtResource("42_j420s"), ExtResource("43_kcq4v")])
SHUFFLE_FOOTSTEP_SOUNDS = Array[AudioStreamWAV]([ExtResource("44_qavcc"), ExtResource("45_bd26m"), ExtResource("46_lufic"), ExtResource("47_nxclr"), ExtResource("48_onxu2"), ExtResource("49_gci7n"), ExtResource("50_tcwf7")])
FLASHLIGHT_CLICK_SOUNDS = Array[AudioStreamWAV]([ExtResource("51_pjwc4"), ExtResource("52_or4qq"), ExtResource("53_hggc2"), ExtResource("55_7l6ig"), ExtResource("56_j3r50"), ExtResource("59_do7qw"), ExtResource("61_8rogd"), ExtResource("62_48p26")])
GRAB_PANEL = ExtResource("59_p5tca")
[node name="Components" type="Node" parent="." unique_id=1652812621] [node name="Components" type="Node" parent="." unique_id=1652812621]
@ -294,7 +288,7 @@ script = ExtResource("64_j3r50")
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("65_kssj8") script = ExtResource("65_kssj8")
[node name="PlayerProperties" type="Node" parent="Components" unique_id=1984191860] [node name="PlayerManager" type="Node" parent="Components" unique_id=1984191860]
unique_name_in_owner = true unique_name_in_owner = true
script = ExtResource("66_8lfxt") script = ExtResource("66_8lfxt")
@ -442,4 +436,4 @@ bus = &"wind"
[connection signal="body_entered" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_entered"] [connection signal="body_entered" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_entered"]
[connection signal="body_exited" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_exited"] [connection signal="body_exited" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_exited"]
[connection signal="timeout" from="StaminaReset" to="Components/PlayerProperties" method="_on_stamina_reset_timeout"] [connection signal="timeout" from="StaminaReset" to="Components/PlayerManager" method="_on_stamina_reset_timeout"]

View file

@ -1,57 +1,51 @@
extends CharacterBody3D extends Node
class_name PlayerCharacter
##TODO make it so that you can easily tweak settings from here, cascading to the components
@export_category("Movement")
@export var SPEED = 5.0 ##base walking speed
@export var SPRINT_MULTIPLIER = 1.5 ##how much faster should you move, when sprinting
@export var SPRINT_STAMINA_COST = 10.0 ##how much stamina should be consumed each frame while sprinting (delta * SPRINT_STAMINA_COST)
@export var CROUCH_SPEED_MULTIPLIER = .5 ##how much slower you should be going while crouching
@export_category("Jump")
@export var JUMP_VELOCITY = 4.5 ##how high you can jump
@export var JUMP_STAMINA_COST = 10 ##how much stamina each jump consumes
@export_category("Camera")
@export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity
@export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel
@export var CAMERA_BOB_FREQUENCY = 2.4 ##how quick the camera bobs whilst moving
@export var CAMERA_BOB_AMPLITUDE = 0.08 ##how hard the camera bobs whilst moving
@export var CAMERA_BOB_MULTIPLIER = 200.0 ##how much the ui reacts to head bobbing
@export var CAMERA_SIDEWAYS_BOB_AMPLITUDE = 0.003 ## how many degrees does the camera bob sideways
@export_category("UI")
@export var UI_SCALE: float = 1 ##rational scale of the ui
@export var UI_MOVEMENT_SENSITIVITY = 0.5 ##how much the UI moves when you move the camera
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
@export_category("Inventory") @export_category("Inventory")
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory @export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory @export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
@export_category("Audio") var stamina: float = 100.0
@export var AUDIO_LOUDNESS: float = 100.0 var flashlight_power: float = 100.0
@export var NORMAL_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##normal footsteps -- walking var selected_item: int = 0
@export var HEAVY_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##heavy footsteps -- running var stamina_recharge: bool = true
@export var LIGHT_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##light footsteps -- crouching var inventory: Array[PackedScene] = [null,null]
@export var SHUFFLE_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##shuffling -- random chance of playing while running
@export var FLASHLIGHT_CLICK_SOUNDS: Array[AudioStreamWAV] ##flashlight click
@export var SHUFFLE_CHANCE: float = 20 ##percentage of chance for a shuffle noise to be played whilst running
@export_category("Grabbing") @onready var ui: Control = %PlayerUi
@export var GRAB_POWER: float = 15.0 ##how fast the grabbed object snaps to the hold position @onready var flashlight: SpotLight3D = %Flashlight
@export var GRAB_ROTATION_POWER: float = 15.0 ##how fast the object rotates towards the player
@export var GRAB_PANEL: PackedScene ##panel that goes over the grabbable object to show its grabbable
@export_category("Player Physics") func next_item():
@export_flags_3d_physics var PLAYER_COLLISION_MASK: int = 16 if selected_item + 1 > len(inventory) - 1:
selected_item = 0
else:
selected_item += 1
select_item(selected_item)
func prev_item():
if selected_item - 1 < 0:
selected_item = len(inventory) - 1
else:
selected_item -= 1
select_item(selected_item)
func select_item(index:int):
selected_item = index
ui.select_item(index)
func get_selected_item() -> PackedScene:
return inventory[selected_item]
func stamina_recharge_off():
stamina_recharge = false
func _on_stamina_reset_timeout() -> void:
stamina_recharge = true
func _ready() -> void:
await get_tree().create_timer(0.1).timeout.connect(func (): select_item(0))
func _process(delta: float) -> void:
if stamina_recharge:
stamina = move_toward(stamina, 100, .5)
if flashlight.visible:
flashlight_power = move_toward(flashlight_power, 0, .2)
# components
@onready var procedural_camera_mover: Node = %ProceduralCameraMover
@onready var sound_controller: Node = %SoundController
@onready var ui_handler: Node = %UiHandler
@onready var input_controller: Node = %InputController
@onready var player_state: Node = %PlayerState
@onready var player_properties: Node = %PlayerProperties

View file

@ -1 +1 @@
uid://l2rc674shj03 uid://cbdvyelf7nb1u

View file

@ -1,62 +0,0 @@
extends Node
@export_category("Inventory")
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
var stamina: float = 100.0
var selected_item: int = 0
var stamina_recharge: bool = true
var inventory: Array[PackedScene] = []
signal selected_item_changed
func next_item():
if selected_item + 1 > INVENTORY_MAX - 1:
selected_item = 0
else:
selected_item += 1
select_item(selected_item)
func prev_item():
if selected_item - 1 < 0:
selected_item = INVENTORY_MAX - 1
else:
selected_item -= 1
select_item(selected_item)
func select_item(index:int):
selected_item = index
emit_signal("selected_item_changed")
func get_selected_item() -> PackedScene:
return inventory[selected_item]
func stamina_recharge_off():
stamina_recharge = false
func _on_stamina_reset_timeout() -> void:
stamina_recharge = true
func _ready() -> void:
select_item(0)
func _process(delta: float) -> void:
if stamina_recharge:
stamina = move_toward(stamina, 100, .5)
if Input.is_action_just_pressed("next_item"):
next_item()
if Input.is_action_just_pressed("prev_item"):
prev_item()
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed("select_item_1"):
select_item(0)
if Input.is_action_just_pressed("select_item_2"):
select_item(1)
if Input.is_action_just_pressed("select_item_3"):
select_item(2)

View file

@ -1 +0,0 @@
uid://cbdvyelf7nb1u

View file

@ -1,6 +1,9 @@
[gd_scene format=3 uid="uid://bsccbqq04umeg"] [gd_scene format=3 uid="uid://bsccbqq04umeg"]
[ext_resource type="Script" uid="uid://lkb0o8too0mj" path="res://scenes/player/player_ui_manager.gd" id="1_32d7b"] [ext_resource type="Script" uid="uid://lkb0o8too0mj" path="res://scenes/player/ui_manager_scene.gd" id="1_32d7b"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m6sn8"]
bg_color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824)
[node name="PlayerUi" type="Control" unique_id=454848358] [node name="PlayerUi" type="Control" unique_id=454848358]
layout_mode = 3 layout_mode = 3
@ -10,64 +13,126 @@ anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
offset_transform_enabled = true offset_transform_enabled = true
mouse_filter = 2
mouse_behavior_recursive = 2
script = ExtResource("1_32d7b") script = ExtResource("1_32d7b")
[node name="StaminaBar" type="ProgressBar" parent="." unique_id=1844702202] [node name="InvContainer" type="MarginContainer" parent="." unique_id=1895029439]
unique_name_in_owner = true
layout_mode = 1 layout_mode = 1
anchors_preset = -1 anchors_preset = -1
anchor_left = 0.05 anchor_left = 0.3
anchor_top = 0.91 anchor_top = 0.87
anchor_right = 0.2 anchor_right = 0.7
anchor_bottom = 0.95 anchor_bottom = 0.98
grow_vertical = 0
rotation = -0.39618975
offset_transform_enabled = true
show_percentage = false
[node name="InventoryPanels" type="HBoxContainer" parent="." unique_id=786436241]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.35
anchor_top = 0.9
anchor_right = 0.65
anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 grow_vertical = 0
offset_transform_enabled = true offset_transform_position = Vector2(0.295, 0)
[node name="InventoryPanels" type="HBoxContainer" parent="InvContainer" unique_id=786436241]
unique_name_in_owner = true
layout_mode = 2
offset_transform_position = Vector2(0, -29.25) offset_transform_position = Vector2(0, -29.25)
offset_transform_visual_only = false offset_transform_visual_only = false
alignment = 1 alignment = 1
[node name="Inv1" type="AspectRatioContainer" parent="InventoryPanels" unique_id=1895925047] [node name="AspectRatioContainer" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1753013707]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot1" type="ColorRect" parent="InventoryPanels/Inv1" unique_id=497482827] [node name="InvSlot1" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer" unique_id=1847508075]
unique_name_in_owner = true unique_name_in_owner = true
custom_minimum_size = Vector2(60, 60)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824) theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="Inv2" type="AspectRatioContainer" parent="InventoryPanels" unique_id=352737813] [node name="AspectRatioContainer2" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=305641278]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot2" type="ColorRect" parent="InventoryPanels/Inv2" unique_id=340220249] [node name="InvSlot2" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer2" unique_id=2121530771]
unique_name_in_owner = true unique_name_in_owner = true
custom_minimum_size = Vector2(60, 60)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824) theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="Inv3" type="AspectRatioContainer" parent="InventoryPanels" unique_id=263461479] [node name="AspectRatioContainer3" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1408216345]
visible = false
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot3" type="ColorRect" parent="InventoryPanels/Inv3" unique_id=398133665] [node name="InvSlot3" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer3" unique_id=1616781961]
unique_name_in_owner = true unique_name_in_owner = true
custom_minimum_size = Vector2(60, 60)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824) theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer4" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=876478547]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot4" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer4" unique_id=1782511400]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer5" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1510462561]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot5" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer5" unique_id=1512950913]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="StaminaBarMargin" type="MarginContainer" parent="." unique_id=707986637]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.07
anchor_top = 0.85
anchor_right = 0.27
anchor_bottom = 1.0
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_constants/margin_left = 0
theme_override_constants/margin_right = 0
[node name="StaminaBar" type="ProgressBar" parent="StaminaBarMargin" unique_id=1844702202]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 50)
layout_mode = 2
offset_transform_enabled = true
offset_transform_rotation = -0.34906584
show_percentage = false
[node name="FlashlightBarMargin" type="MarginContainer" parent="." unique_id=915568145]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.73
anchor_top = 0.85
anchor_right = 0.93
anchor_bottom = 1.0
offset_left = -4.0
offset_top = -4.0
grow_horizontal = 0
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="FlashlightBar" type="ProgressBar" parent="FlashlightBarMargin" unique_id=551784534]
unique_name_in_owner = true
custom_minimum_size = Vector2(50, 50)
layout_mode = 2
offset_transform_enabled = true
offset_transform_rotation = 0.34906584
fill_mode = 1
show_percentage = false

View file

@ -0,0 +1,202 @@
[gd_scene format=3 uid="uid://bsccbqq04umeg"]
[ext_resource type="Script" uid="uid://lkb0o8too0mj" path="res://scenes/player/ui_manager_scene.gd" id="1_32d7b"]
[ext_resource type="Script" uid="uid://cjgwqon6womc5" path="res://scenes/player/console_input.gd" id="2_m6sn8"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_m6sn8"]
bg_color = Color(0.23921569, 0.23921569, 0.23921569, 0.47058824)
[node name="PlayerUi" type="Control" unique_id=454848358]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
offset_transform_enabled = true
script = ExtResource("1_32d7b")
[node name="InvContainer" type="MarginContainer" parent="." unique_id=1895029439]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.3
anchor_top = 0.87
anchor_right = 0.7
anchor_bottom = 0.98
grow_horizontal = 2
grow_vertical = 0
offset_transform_position = Vector2(0.295, 0)
[node name="InventoryPanels" type="HBoxContainer" parent="InvContainer" unique_id=786436241]
unique_name_in_owner = true
layout_mode = 2
offset_transform_position = Vector2(0, -29.25)
offset_transform_visual_only = false
alignment = 1
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1753013707]
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot1" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer" unique_id=1847508075]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer2" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=305641278]
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot2" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer2" unique_id=2121530771]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer3" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1408216345]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot3" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer3" unique_id=1616781961]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer4" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=876478547]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot4" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer4" unique_id=1782511400]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="AspectRatioContainer5" type="AspectRatioContainer" parent="InvContainer/InventoryPanels" unique_id=1510462561]
visible = false
layout_mode = 2
size_flags_horizontal = 3
stretch_mode = 1
[node name="InvSlot5" type="PanelContainer" parent="InvContainer/InventoryPanels/AspectRatioContainer5" unique_id=1512950913]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_m6sn8")
[node name="StaminaBarMargin" type="MarginContainer" parent="." unique_id=707986637]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.07
anchor_top = 0.85
anchor_right = 0.27
anchor_bottom = 1.0
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_constants/margin_left = 0
theme_override_constants/margin_right = 0
[node name="StaminaBar" type="ProgressBar" parent="StaminaBarMargin" unique_id=1844702202]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 50)
layout_mode = 2
offset_transform_enabled = true
offset_transform_rotation = -0.34906584
show_percentage = false
[node name="FlashlightBarMargin" type="MarginContainer" parent="." unique_id=915568145]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.73
anchor_top = 0.85
anchor_right = 0.93
anchor_bottom = 1.0
offset_left = -4.0
offset_top = -4.0
grow_horizontal = 0
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="FlashlightBar" type="ProgressBar" parent="FlashlightBarMargin" unique_id=551784534]
unique_name_in_owner = true
custom_minimum_size = Vector2(50, 50)
layout_mode = 2
offset_transform_enabled = true
offset_transform_rotation = 0.34906584
fill_mode = 1
show_percentage = false
[node name="ConsoleContainer" type="PanelContainer" parent="." unique_id=1697520773]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = -1
anchor_left = 0.3
anchor_top = 0.05
anchor_right = 0.7
anchor_bottom = 0.05
offset_left = -34.25
offset_right = 34.25
offset_bottom = 400.0
grow_horizontal = 2
offset_transform_enabled = true
offset_transform_position_ratio = Vector2(0, -3)
[node name="MarginContainer" type="MarginContainer" parent="ConsoleContainer" unique_id=179894258]
layout_mode = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
[node name="VboxContainer" type="VBoxContainer" parent="ConsoleContainer/MarginContainer" unique_id=283620690]
layout_mode = 2
[node name="SuggestionsList" type="ItemList" parent="ConsoleContainer/MarginContainer/VboxContainer" unique_id=1321789715]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 2.0
[node name="ConsoleInputBox" type="HBoxContainer" parent="ConsoleContainer/MarginContainer/VboxContainer" unique_id=1910471159]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 0.5
[node name="Label" type="Label" parent="ConsoleContainer/MarginContainer/VboxContainer/ConsoleInputBox" unique_id=1508142291]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.01
theme_override_font_sizes/font_size = 25
text = ">"
horizontal_alignment = 2
[node name="ConsoleInput" type="LineEdit" parent="ConsoleContainer/MarginContainer/VboxContainer/ConsoleInputBox" unique_id=1359456780]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.29
keep_editing_on_text_submit = true
expand_to_text_length = true
flat = true
draw_control_chars = true
script = ExtResource("2_m6sn8")
[node name="CommandLog" type="RichTextLabel" parent="ConsoleContainer/MarginContainer/VboxContainer" unique_id=2092088894]
unique_name_in_owner = true
custom_maximum_size = Vector2(-1, 230)
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 4.0
bbcode_enabled = true
scroll_following = true
text_direction = 1

View file

@ -1,5 +0,0 @@
extends Control
@onready var stamina_bar: ProgressBar = %StaminaBar
@onready var inventory_slots_panels: Array = [%InvSlot1, %InvSlot2, %InvSlot3]
var inventory: Array = [null,null,null]

View file

@ -14,11 +14,11 @@ extends Node
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera @export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing @export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
@onready var sound_controller: Node = %SoundController @onready var sound_controller: Node = %SoundController
@onready var camera: Camera3D = %PlayerCamera @onready var camera: Camera3D = %PlayerCamera
@onready var ui: Control = %PlayerUi @onready var ui: Control = %PlayerUi
@onready var player_properties: Node = %PlayerProperties @onready var player_manager: Node = %PlayerManager
@onready var ui_base_position = ui.position @onready var ui_base_position = ui.position
@onready var ui_handler: Node = %UiHandler @onready var ui_handler: Node = %UiHandler
@onready var player_state: Node = %PlayerState @onready var player_state: Node = %PlayerState
@ -48,12 +48,11 @@ func _process(delta: float) -> void:
func do(delta): func do(delta):
ui.offset_transform_scale *= UI_SCALE ui.offset_transform_scale *= UI_SCALE
ui_movement_handling(delta) ui_movement_handling(delta)
ui_handler.set_stamina_bar(player_properties.stamina)
var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length() var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length()
if _breathing: if _breathing:
t_breath += delta * (100 / (40 + player_properties.stamina)) t_breath += delta * (100 / (40 + player_manager.stamina))
var target_pos = get_breathing_bob_offset_pos() var target_pos = get_breathing_bob_offset_pos()
var target_rot = get_breathing_bob_offset_rot() var target_rot = get_breathing_bob_offset_rot()

View file

@ -43,7 +43,7 @@ var _current_breath_out_sound = null
var _current_leg_is_right = false var _current_leg_is_right = false
@onready var player_state: Node = %PlayerState @onready var player_state: Node = %PlayerState
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
@onready var input_controller: Node = %InputController @onready var input_controller: Node = %InputController
@onready var left_foot: SpatialAudio3D = %LeftFoot @onready var left_foot: SpatialAudio3D = %LeftFoot

View file

@ -23,15 +23,15 @@ enum breath {
## 80 -- 100 --> calm ## 80 -- 100 --> calm
var _breath_change_points: Array[float] = [10, 20, 50, 80] var _breath_change_points: Array[float] = [10, 20, 50, 80]
@onready var player_properties: Node = %PlayerProperties @onready var player_manager: Node = %PlayerManager
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
var flying: bool = false var flying: bool = false
signal landed signal landed
signal jumped signal jumped
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
var stamina = player_properties.stamina var stamina = player_manager.stamina
if stamina == 0: if stamina == 0:
breathing_mode = breath.exhausted breathing_mode = breath.exhausted
elif stamina <= _breath_change_points[0]: elif stamina <= _breath_change_points[0]:

View file

@ -12,8 +12,8 @@ extends Node
@onready var ui: Control = %PlayerUi @onready var ui: Control = %PlayerUi
@onready var popup_panels: Control = %PopupPanels @onready var popup_panels: Control = %PopupPanels
@onready var player_state: Node = %PlayerState @onready var player_state: Node = %PlayerState
@onready var player_properties: Node = %PlayerProperties @onready var player_manager: Node = %PlayerManager
@onready var player: PlayerCharacter = $"../.." @onready var player: CharacterBody3D = $"../.."
@onready var cursor: TextureRect = %Cursor @onready var cursor: TextureRect = %Cursor
@onready var player_camera: Camera3D = %PlayerCamera @onready var player_camera: Camera3D = %PlayerCamera
@ -35,11 +35,7 @@ func _on_grabbable_finder_body_exited(body: Node3D) -> void:
grabbable_panel = null grabbable_panel = null
grabbable_panel_body = null grabbable_panel_body = null
func _ready() -> void:
player_properties.selected_item_changed.connect(set_selected_item)
func _process(delta: float) -> void: func _process(delta: float) -> void:
ui.stamina_bar.value = lerpf(ui.stamina_bar.value, player_properties.stamina, delta * 5)
if grabbable_panel != null: if grabbable_panel != null:
var target_position = cursor.position - player_camera.unproject_position(grabbable_panel_body.global_position) var target_position = cursor.position - player_camera.unproject_position(grabbable_panel_body.global_position)
grabbable_panel.position = grabbable_panel.position.lerp(-target_position / 2, delta * 50) grabbable_panel.position = grabbable_panel.position.lerp(-target_position / 2, delta * 50)
@ -60,18 +56,8 @@ func toggle_menu():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
player_state.in_menu = false player_state.in_menu = false
func set_stamina_bar(value:float):
ui.stamina_bar.value = value
func set_selected_item():
for i in len(ui.inventory_slots_panels):
if i == player_properties.selected_item:
ui.inventory_slots_panels[i].color = Color.hex(SELECTED_COLOR)
else:
ui.inventory_slots_panels[i].color = Color.hex(UNSELECTED_COLOR)
func put_item(index: int, item: PackedScene): func put_item(index: int, item: PackedScene):
player_properties.inventory[index] = item player_manager.inventory[index] = item
func set_ui_scale(scale:float) -> void: func set_ui_scale(scale:float) -> void:
pass pass

View file

@ -0,0 +1,59 @@
extends Control
@onready var stamina_bar: ProgressBar = %StaminaBar
@onready var flashlight_bar: ProgressBar = %FlashlightBar
@onready var inventory_slots_panels: Array[PanelContainer] = [%InvSlot1, %InvSlot2, %InvSlot3, %InvSlot4, %InvSlot5]
@onready var player_manager: Node = %PlayerManager
## returns true if successful
func add_inventory_slot() -> bool:
if len(player_manager.inventory) < 5:
player_manager.inventory.append(null)
var aspect = %InventoryPanels.get_child(len(player_manager.inventory) - 1)
if aspect is AspectRatioContainer:
aspect.visible = true
return true
return false
func add_inventory_slot_console():
Console.print_to_console(false, "Success" if add_inventory_slot() else "Failed")
## returns true if successful
func remove_inventory_slot() -> bool:
if len(player_manager.inventory) > 2:
var aspect = %InventoryPanels.get_child(len(player_manager.inventory) - 1)
if aspect is AspectRatioContainer:
aspect.visible = false
player_manager.inventory.remove_at(len(player_manager.inventory) - 1)
return true
return false
func remove_inventory_slot_console():
Console.print_to_console(false, "Success" if remove_inventory_slot() else "Failed")
const SELECTED_COLOR = 0xcfcfcf78
const UNSELECTED_COLOR = 0x3d3d3d78
var selected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
var unselected_stylebox: StyleBoxFlat = StyleBoxFlat.new()
func _ready():
selected_stylebox.bg_color = SELECTED_COLOR
unselected_stylebox.bg_color = UNSELECTED_COLOR
Console.add_inventory.connect(add_inventory_slot_console)
Console.remove_inventory.connect(remove_inventory_slot_console)
func select_item(index):
if inventory_slots_panels != [] and index >= 0 and index < len(player_manager.inventory):
print("selected item ", index)
for i in inventory_slots_panels:
i.add_theme_stylebox_override("panel", unselected_stylebox)
if index >= 0 and index < len(player_manager.inventory):
inventory_slots_panels[index].add_theme_stylebox_override("panel", selected_stylebox)
func _process(delta: float) -> void:
if player_manager != null:
stamina_bar.value = lerpf(stamina_bar.value, player_manager.stamina, delta * 5)
flashlight_bar.value = lerpf(flashlight_bar.value, player_manager.flashlight_power, delta * 5)

View file

@ -0,0 +1,49 @@
extends CharacterBody3D
class_name PlayerCharacter
##TODO make it so that you can easily tweak settings from here, cascading to the components
@export_category("Movement")
@export var SPEED = 5.0 ##base walking speed
@export var SPRINT_MULTIPLIER = 1.5 ##how much faster should you move, when sprinting
@export var SPRINT_STAMINA_COST = 10.0 ##how much stamina should be consumed each frame while sprinting (delta * SPRINT_STAMINA_COST)
@export var CROUCH_SPEED_MULTIPLIER = .5 ##how much slower you should be going while crouching
@export_category("Jump")
@export var JUMP_VELOCITY = 4.5 ##how high you can jump
@export var JUMP_STAMINA_COST = 10 ##how much stamina each jump consumes
@export_category("Camera")
@export var LOOK_SENSITIVITY = 1.0 ##camera sensitivity
@export var CAMERA_VELOCITY_MULTIPLIER = 1.5 ##how heavy should the UI movement feel
@export var CAMERA_BOB_FREQUENCY = 2.4 ##how quick the camera bobs whilst moving
@export var CAMERA_BOB_AMPLITUDE = 0.08 ##how hard the camera bobs whilst moving
@export var CAMERA_BOB_MULTIPLIER = 200.0 ##how much the ui reacts to head bobbing
@export var CAMERA_SIDEWAYS_BOB_AMPLITUDE = 0.003 ## how many degrees does the camera bob sideways
@export_category("UI")
@export var UI_SCALE: float = 1 ##rational scale of the ui
@export var UI_MOVEMENT_SENSITIVITY = 0.5 ##how much the UI moves when you move the camera
@export var UI_MOVEMENT_SPEED = 15.0 ##how fast the UI moves when you move the camera
@export var UI_MOVEMENT_VELOCITY_MULTIPLIER = 2.0 ##how much the ui leans when walking or strafing
@export_category("Inventory")
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
@export_category("Audio")
@export var AUDIO_LOUDNESS: float = 100.0
@export var NORMAL_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##normal footsteps -- walking
@export var HEAVY_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##heavy footsteps -- running
@export var LIGHT_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##light footsteps -- crouching
@export var SHUFFLE_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##shuffling -- random chance of playing while running
@export var FLASHLIGHT_CLICK_SOUNDS: Array[AudioStreamWAV] ##flashlight click
@export var SHUFFLE_CHANCE: float = 20 ##percentage of chance for a shuffle noise to be played whilst running
@export_category("Grabbing")
@export var GRAB_POWER: float = 15.0 ##how fast the grabbed object snaps to the hold position
@export var GRAB_ROTATION_POWER: float = 15.0 ##how fast the object rotates towards the player
@export var GRAB_PANEL: PackedScene ##panel that goes over the grabbable object to show its grabbable
@export_category("Player Physics")
@export_flags_3d_physics var PLAYER_COLLISION_MASK: int = 16

View file

@ -0,0 +1 @@
uid://l2rc674shj03