Compare commits
3 commits
5e46d72790
...
66039b70d9
| Author | SHA1 | Date | |
|---|---|---|---|
| 66039b70d9 | |||
| 254f1af0b7 | |||
| 7194503124 |
4 changed files with 38 additions and 5 deletions
32
classes/state/player_state.gd
Normal file
32
classes/state/player_state.gd
Normal 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
|
||||||
1
classes/state/player_state.gd.uid
Normal file
1
classes/state/player_state.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bebe1y51hwns8
|
||||||
|
|
@ -26,7 +26,7 @@ var is_active: bool = false:
|
||||||
|
|
||||||
## Called by the state machine upon changing the active state. The `data` parameter
|
## 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.
|
## 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
|
## Called by the state machine before changing the active state. Use this function
|
||||||
## to clean up the state.
|
## to clean up the state.
|
||||||
|
|
@ -48,7 +48,7 @@ func state_physics_update(delta: float) -> void:
|
||||||
_state_physics_update(delta)
|
_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
|
is_active = true
|
||||||
_enter(previous_state_path, data)
|
_enter(previous_state_path, data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ func _get_initial_state() -> State:
|
||||||
|
|
||||||
## Transitions the active state out after receiving a finished signal.
|
## Transitions the active state out after receiving a finished signal.
|
||||||
func _transition_to_next_state(target_state_path: String, data: Dictionary[StringName, Variant] = {}) -> void:
|
func _transition_to_next_state(target_state_path: String, data: Dictionary[StringName, Variant] = {}) -> void:
|
||||||
print("+++ TRANSITION CALLED: ", target_state_path)
|
print(owner.name+"+++ TRANSITION CALLED: ", target_state_path)
|
||||||
print("+++ has node? ", has_node(target_state_path))
|
print(owner.name+"+++ has node? ", has_node(target_state_path))
|
||||||
print("+++ all children: ", get_children().map(func(c: Node) -> StringName: return c.name))
|
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.")
|
assert(has_node(target_state_path), owner.name + ": Trying to transition to state " + target_state_path + " but it does not exist.")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue