Compare commits

...

3 commits

Author SHA1 Message Date
66039b70d9 add basic player state 2025-11-22 11:03:45 -03:00
254f1af0b7 cleaner state machine debug print 2025-11-22 10:49:47 -03:00
7194503124 attempt static dict in state machine 2025-11-22 10:47:06 -03:00
4 changed files with 38 additions and 5 deletions

View file

@ -0,0 +1,32 @@
class_name PlayerState extends State
const IDLE = "Idle"
const WALKING = "Walking"
var player: Player
func _ready() -> void:
await owner.ready
player = owner as Player
assert(player != null, "The PlayerState state type must be used only in the player scene. It needs the owner to be a Player node.")
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
pass
func _exit() -> void:
pass
func _handle_input(_event: InputEvent) -> void:
pass
func _state_update(_delta: float) -> void:
pass
func _state_physics_update(_delta: float) -> void:
pass

View file

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

View file

@ -26,7 +26,7 @@ var is_active: bool = false:
## Called by the state machine upon changing the active state. The `data` parameter
## is a dictionary with arbitrary data the state can use to initialize itself.
@abstract func _enter(previous_state_path: String, data: Dictionary = {}) -> void
@abstract func _enter(previous_state_path: String, data: Dictionary[StringName, Variant] = {}) -> void
## Called by the state machine before changing the active state. Use this function
## to clean up the state.
@ -48,7 +48,7 @@ func state_physics_update(delta: float) -> void:
_state_physics_update(delta)
func enter(previous_state_path: String, data: Dictionary = {}) -> void:
func enter(previous_state_path: String, data: Dictionary[StringName, Variant] = {}) -> void:
is_active = true
_enter(previous_state_path, data)

View file

@ -41,9 +41,9 @@ func _get_initial_state() -> State:
## Transitions the active state out after receiving a finished signal.
func _transition_to_next_state(target_state_path: String, data: Dictionary[StringName, Variant] = {}) -> void:
print("+++ TRANSITION CALLED: ", target_state_path)
print("+++ has node? ", has_node(target_state_path))
print("+++ all children: ", get_children().map(func(c: Node) -> StringName: return c.name))
print(owner.name+"+++ TRANSITION CALLED: ", target_state_path)
print(owner.name+"+++ has node? ", has_node(target_state_path))
print(owner.name+"+++ all children: ", get_children().map(func(c: Node) -> StringName: return c.name))
assert(has_node(target_state_path), owner.name + ": Trying to transition to state " + target_state_path + " but it does not exist.")