State Machine cleanup

This commit is contained in:
Dustin 2025-04-20 22:15:51 -07:00
parent d8a5107739
commit 5fffb666d6
4 changed files with 14 additions and 39 deletions

View File

@ -54,7 +54,7 @@ func _on_state_change(old_state_name:String, new_state :State):
else:
if default_shape_when_no_state_function:
if debug_component:
print ("Returning to default collision shape")
print (get_path(), " Returning to default collision shape")
if shape is RectangleShape2D:
shape.extents = default_shape.extents
transform = default_transform

View File

@ -29,7 +29,6 @@ export var name: String
func setup():
# Only add timout node if timer value was specified.
if(timeout_seconds > 0.0):
print("init timer...")
state_timeout = Timer.new()
state_timeout.wait_time = timeout_seconds
state_timeout.one_shot = true
@ -48,7 +47,8 @@ func enter() -> void:
if debug_state:
print("Got call to enter state ", name)
if state_timeout != null:
print(name, "-Starting Timer")
if debug_state:
print(name, "-Starting Timer")
state_timeout.start()
emit_signal("state_entered")
return

View File

@ -25,12 +25,13 @@ var states_index :Dictionary
# print ("init state machine.")
func _ready():
print ("ready state machine.")
if debug_state_machine:
print (get_path(), " - ready state machine.")
for s in states:
print ("sname: ", s.name)
var this_state = s
if this_state is State:
print("Adding state ", this_state.name)
if debug_state_machine:
print("Adding state ", this_state.name)
#check for empty state name
if this_state.name != '':
#check for unique state name
@ -48,7 +49,7 @@ func _ready():
else:
push_error("Multiple states with same name in: ")
else:
print("State missing name in: " )
push_error("State missing name in: " + str(get_path()) )
if states_index.has(starting_state_name):
change_state(states_index[starting_state_name])
@ -80,17 +81,6 @@ func change_state(new_state: State) -> void:
current_state = new_state
current_state.enter()
#puppet puppet_change_state(new_state: State) -> void:
# pass
# Seems like I don't have to do this every state change!
# if(state_modifiers.size() > 0):
# print("Active Modifiers:")
# for mods in state_modifiers:
# if mods is StateModifierAnimatedActor:
# print(mods.name, " <- asm")
emit_signal("state_changed",current_state_name,current_state)
puppet func puppet_change_to_known_state(new_state_name: String) -> void:
@ -121,7 +111,6 @@ func change_to_known_state(new_state_name: String) -> void:
# return false
func get_state_reference(state_name: String) -> State:
print ("what you want? ", state_name)
if states_index.has(state_name):
return states_index[state_name]
return null
@ -130,30 +119,16 @@ func push_state_modifier(_state_modifier: StateModifier) -> void:
if state_modifiers.has(_state_modifier) == false:
state_modifiers.push_front(_state_modifier)
_state_modifier.connect("modifier_event",self,"handle_modifier_events")
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
if debug_state_machine:
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
func handle_modifier_events(eventID :int):
if eventID == StateModifier.EVENT_ID.ACTIVATED:
print ("A mod activated! Which one though?")
if debug_state_machine:
print ("A mod activated! Which one though?")
merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
elif eventID == StateModifier.EVENT_ID.DEACTIVATED:
merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
# Disable to test whether actually needed.
## Pass through functions for the Player to call,
## handling state changes as needed.
#func process_physics(delta: float) -> void:
# change_to_known_state( current_state.process_physics(delta) )
#
#func process_input(event: InputEvent) -> void:
# var new_state = current_state.process_input(event)
# if new_state:
# change_state(new_state)
#
#func process_frame(delta: float) -> void:
# var new_state = current_state.process_frame(delta)
# if new_state:
# change_state(new_state)

View File

@ -9,7 +9,7 @@ signal health_depleted()
func take_damage(damage_amount :int):
if damage_amount < 0:
print("ERROR: Only positive numbers in health component functions.")
push_error("Only positive numbers in health component functions.")
health -= damage_amount
if health <= 0:
@ -18,7 +18,7 @@ func take_damage(damage_amount :int):
func heal(heal_amount :int):
if heal_amount < 0:
print("ERROR: Only positive numbers in health component functions.")
push_error("ERROR: Only positive numbers in health component functions.")
return
health += heal_amount