add audio_manager and code refactoring

This commit is contained in:
2026-04-16 15:35:05 +02:00
parent 2508ac96fa
commit cf285153cf
53 changed files with 303 additions and 46 deletions

View File

@@ -0,0 +1,20 @@
extends Node
class_name State
@export var state_id: String = ""
@warning_ignore("unused_signal")
signal transitioned(state, new_state_name)
func enter() -> void:
pass
func exit() -> void:
pass
func update(_delta) -> void:
pass
func physics_update(_delta) -> void:
pass

View File

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

View File

@@ -0,0 +1,46 @@
extends Node
class_name StateMachine
@export var initial_state: State
var current_state: State
var states: Dictionary = {}
var enable: bool = true:
set(value):
enable = value
toggle_enable()
func toggle_enable() -> void:
if !enable:
return
if !states.is_empty():
return
for state in get_children():
if state is State:
states[state.state_id] = state
state.transitioned.connect(_on_state_transition)
if initial_state:
current_state = initial_state
current_state.enter()
func physics_process(delta) -> void:
if current_state and enable:
current_state.update(delta)
func _on_state_transition(state: State, new_state_id: String) -> void:
if state != current_state:
return
var new_state = states.get(new_state_id)
if not new_state:
return
if current_state:
current_state.exit()
current_state = new_state
current_state.enter()

View File

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