Initial Commit

This commit is contained in:
Mario Steele 2026-02-23 18:38:03 -06:00
commit 48a5e71e00
1136 changed files with 64347 additions and 0 deletions

View file

@ -0,0 +1,16 @@
extends Node
class_name State
signal transitioned(state: State, new_state_name: String)
func _enter() -> void:
pass
func _exit() -> void:
pass
func _update(_delta: float) -> void:
pass
func _physics_update(_delta: float) -> void:
pass

View file

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

View file

@ -0,0 +1,44 @@
extends Node
class_name StateMachine
@export var initial_state: State
signal state_changed(new_state: State)
var current_state: State
var states: Dictionary[String, State] = {}
func _ready() -> void:
for child in get_children():
if child is State:
states[child.name.to_lower()] = child
child.transitioned.connect(_handle_child_transition)
if initial_state:
initial_state._enter()
current_state = initial_state
func _process(delta) -> void:
if current_state:
current_state._update(delta)
func _physics_process(delta: float) -> void:
if current_state:
current_state._physics_update(delta)
func _handle_child_transition(state: State, new_state_name: String) -> void:
if state != current_state:
return
var new_state: State = states.get(new_state_name.to_lower(), null)
if not new_state:
return
if current_state:
current_state._exit()
new_state._enter()
current_state = new_state
state_changed.emit(new_state)

View file

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