Add from state, signal based callback and processing state functions. I'm loking how this is turning out.

This commit is contained in:
Dustin 2025-03-17 00:04:19 -07:00
parent c2ad46f5ae
commit ae9256f083
2 changed files with 26 additions and 5 deletions

View File

@ -19,7 +19,7 @@ export var callable_state_machine :NodePath
var request_state_change: FuncRef
onready var desired_movement_vector: Vector2 = Vector2(0,0)
var current_movement_state:String
var current_movement_state: String
# Since animactor state machine can actually view properties from this type
# I'm thinking about moving the velocity tracker in here instead of player.
@ -43,19 +43,23 @@ const RIGHT = 1.0
func _ready():
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
current_state = get_node(callable_state_machine).current_state
############
# These get called by the parent
############
func process_physics(delta):
move_actor_as_desired(delta)
if has_method('_state_process_physics_' + current_state.name):
call('_state_process_physics_' + current_state.name)
# Shouldn't need a proces function
#func process(delta):
# pass
func process_input(event: InputEvent):
pass
if has_method('_state_process_input_' + current_state.name):
call('_state_process_input_' + current_state.name)
############

View File

@ -1,5 +1,22 @@
extends Movement_StateReceiver
func _ready():
# Lets see if this nutty thing works
var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
state_ref.connect("state_entered", self, "_on_state_entered_idle")
# It works but node order really mattered.
# State machine needed to be processed first probably for ready function.
# good to know!
var fire_a_note:bool = false
# I don't need this right now but I proved it can be done!
func _state_process_physics_idle():
if fire_a_note == true:
print("I got called! (MC)")
fire_a_note = false
func _on_state_entered_idle():
print("Movement State Idle State Entered!")
fire_a_note = true
func _state_process_idle():
print("I got called!")