Clean up path and names
This commit is contained in:
parent
92ccf7279d
commit
1aff1c2e38
46 changed files with 203 additions and 117 deletions
19
scripts/state_machine/state.gd
Normal file
19
scripts/state_machine/state.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
class_name State
|
||||
extends Node
|
||||
|
||||
var state_machine = null
|
||||
|
||||
func handle_input(_event: InputEvent):
|
||||
pass
|
||||
|
||||
func update(_delta: float):
|
||||
pass
|
||||
|
||||
func physics_update(_delta: float):
|
||||
pass
|
||||
|
||||
func enter(_msg: Dictionary = {}):
|
||||
pass
|
||||
|
||||
func exit():
|
||||
pass
|
34
scripts/state_machine/state_machine.gd
Normal file
34
scripts/state_machine/state_machine.gd
Normal file
|
@ -0,0 +1,34 @@
|
|||
class_name StateMachine
|
||||
extends Node
|
||||
|
||||
signal transitioned(state_name)
|
||||
@export var state: State
|
||||
|
||||
func _ready():
|
||||
await owner.ready
|
||||
|
||||
for child in get_children():
|
||||
child.state_machine = self
|
||||
|
||||
state.enter()
|
||||
|
||||
func _unhandled_input(event):
|
||||
state.handle_input(event)
|
||||
|
||||
func _process(delta):
|
||||
state.update(delta)
|
||||
|
||||
func _physics_process(delta):
|
||||
state.physics_update(delta)
|
||||
|
||||
func transition_to(target_state_name: String, msg: Dictionary = {}):
|
||||
if not has_node(target_state_name):
|
||||
push_warning("No state with name " + target_state_name)
|
||||
return
|
||||
|
||||
state.exit()
|
||||
state = get_node(target_state_name)
|
||||
state.enter(msg)
|
||||
emit_signal("transitioned", state.name)
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue