2026-08-09 03:24:28 +02:00
|
|
|
class_name Player extends CharacterBody3D
|
2026-07-31 02:38:02 +02:00
|
|
|
|
2026-08-07 23:13:17 +02:00
|
|
|
@onready var camera = %PlayerCamera
|
2026-08-09 03:24:28 +02:00
|
|
|
@onready var ui: PlayerUI = %PlayerUi
|
|
|
|
|
@onready var prompt: Control = %Prompt
|
|
|
|
|
|
|
|
|
|
@export_category("Components")
|
|
|
|
|
@export var stamina_component: StaminaComponent
|
|
|
|
|
@export var flashlight_component: FlashlightComponent
|
2026-08-13 13:28:13 +02:00
|
|
|
@export var hotbar_component: HotbarComponent
|
2026-08-09 03:24:28 +02:00
|
|
|
@export var movement_component: MovementComponent
|
|
|
|
|
@export var input_controller: InputController
|
|
|
|
|
@export var procedural_animator: ProceduralAnimator
|
|
|
|
|
@export var sound_controller: SoundController
|
|
|
|
|
@export var player_state: PlayerState
|
2026-08-13 13:28:13 +02:00
|
|
|
@export var inventory_component: InventoryComponent
|
|
|
|
|
|
|
|
|
|
@export var equipped_backpack: Backpack
|
2026-08-09 03:24:28 +02:00
|
|
|
|
2026-08-12 01:47:15 +02:00
|
|
|
static var player: Player
|
|
|
|
|
|
2026-08-13 17:06:15 +02:00
|
|
|
func toggle_noclip():
|
|
|
|
|
%Noclip.toggle()
|
|
|
|
|
|
2026-07-31 02:38:02 +02:00
|
|
|
func _ready() -> void:
|
|
|
|
|
Console.context["player"] = self
|
2026-08-09 03:24:28 +02:00
|
|
|
GameState.player = self
|
|
|
|
|
|
2026-08-12 01:47:15 +02:00
|
|
|
#if player is the instance in server
|
|
|
|
|
# add logic for multiplayer
|
|
|
|
|
|
|
|
|
|
player = self
|
|
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
#signal connections
|
2026-08-13 13:28:13 +02:00
|
|
|
hotbar_component.select_item.connect(ui.select_item)
|
|
|
|
|
hotbar_component.add_item.connect(ui.add_item)
|
|
|
|
|
hotbar_component.remove_item.connect(ui.remove_item)
|
|
|
|
|
hotbar_component.added_inventory_slot.connect(ui.add_inventory_slot)
|
|
|
|
|
hotbar_component.removed_inventory_slot.connect(ui.remove_inventory_slot)
|
|
|
|
|
|
|
|
|
|
inventory_component.toggle.connect(ui.anti_toggle)
|
|
|
|
|
|
|
|
|
|
ui.visibility_changed.connect(movement_component.toggle_movement)
|
2026-08-09 03:24:28 +02:00
|
|
|
|
|
|
|
|
procedural_animator.breath.connect(sound_controller.play_breath_sound)
|
|
|
|
|
procedural_animator.footstep.connect(sound_controller.play_footstep_sound)
|
2026-08-12 01:47:15 +02:00
|
|
|
|
2026-08-09 03:24:28 +02:00
|
|
|
input_controller.toggle_flashlight.connect(flashlight_component.toggle_flashlight)
|
2026-08-12 01:47:15 +02:00
|
|
|
input_controller.charge_flashlight.connect(flashlight_component.charge_flashlight)
|
2026-08-09 03:24:28 +02:00
|
|
|
|
2026-08-09 23:18:13 +02:00
|
|
|
stamina_component.stamina_changed.connect(ui.set_stamina)
|
2026-08-10 01:25:55 +02:00
|
|
|
|
2026-08-13 17:06:15 +02:00
|
|
|
SignalSniffer.watch(stamina_component)
|
|
|
|
|
|
|
|
|
|
# TODO: why is it always called on every frame?????
|
|
|
|
|
|
2026-08-12 01:47:15 +02:00
|
|
|
flashlight_component.flashlight_charge_changed.connect(ui.set_flashlight)
|
|
|
|
|
flashlight_component.flashlight_toggled.connect(\
|
|
|
|
|
func (success):\
|
|
|
|
|
if success: \
|
|
|
|
|
sound_controller.play_flashlight_sound())
|
|
|
|
|
|
2026-08-09 23:18:13 +02:00
|
|
|
movement_component.jumped.connect(stamina_component.jump)
|
|
|
|
|
movement_component.jumped.connect(sound_controller.play_jump_sound)
|
|
|
|
|
movement_component.jumped.connect(player_state.jump)
|
2026-08-10 01:25:55 +02:00
|
|
|
movement_component.landed.connect(sound_controller.play_land_sound)
|
2026-08-12 01:47:15 +02:00
|
|
|
movement_component.state_changed.connect(\
|
|
|
|
|
func (state): \
|
|
|
|
|
if state == "running": \
|
|
|
|
|
stamina_component.run(true) \
|
|
|
|
|
else: \
|
|
|
|
|
stamina_component.run(false))
|
|
|
|
|
movement_component.state_changed.connect(player_state.handle_state_change)
|
2026-08-13 13:28:13 +02:00
|
|
|
|
2026-08-13 17:06:15 +02:00
|
|
|
SignalSniffer.watch(movement_component)
|
|
|
|
|
|
2026-08-13 13:28:13 +02:00
|
|
|
#temporary so i can prototype
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if Input.is_action_just_pressed("open_inventory"):
|
2026-08-13 17:06:15 +02:00
|
|
|
UiManager.toggle_inventory_menu(equipped_backpack, hotbar_component)
|