State machine and crosshair

This commit is contained in:
Rendo 2025-11-21 00:56:23 +05:00
commit a32ac09b04
12 changed files with 116 additions and 5 deletions

View file

@ -0,0 +1,36 @@
extends Node
class_name StateMachine
@export var current_state: State
var states: Dictionary[StringName,State] = {}
func _ready() -> void:
for child in get_children():
if child is State:
states[child.name] = child
child.transition.connect(on_transition_required)
else:
push_warning("Child of state machine is not state")
func on_transition_required(to: StringName):
if states.has(to) == false:
push_warning("Incorrect state request: " + to)
return
current_state.exit()
current_state = states[to]
current_state.enter()
func _process(delta: float) -> void:
if current_state == null:
push_error("State is not set")
return
current_state.update(delta)
func _physics_process(delta: float) -> void:
if current_state == null:
push_error("State is not set")
return
current_state.physics_update(delta)