states again.
This commit is contained in:
parent
188bf46a09
commit
0203076676
|
|
@ -69,7 +69,7 @@ _global_script_classes=[ {
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/state_machine_animated_actor.gd"
|
"path": "res://src/state_machine_animated_actor.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Object",
|
"base": "Reference",
|
||||||
"class": "StateModifier",
|
"class": "StateModifier",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/state_modifier.gd"
|
"path": "res://src/state_modifier.gd"
|
||||||
|
|
|
||||||
|
|
@ -562,8 +562,12 @@ script = ExtResource( 2 )
|
||||||
player_number = 1
|
player_number = 1
|
||||||
interactable_node = NodePath("../Interactable_Receiver")
|
interactable_node = NodePath("../Interactable_Receiver")
|
||||||
|
|
||||||
|
[node name="movement_state_machine" parent="." index="3"]
|
||||||
|
debug_state_machine = true
|
||||||
|
|
||||||
[node name="idle" parent="movement_state_machine" index="0"]
|
[node name="idle" parent="movement_state_machine" index="0"]
|
||||||
script = ExtResource( 4 )
|
script = ExtResource( 4 )
|
||||||
|
debug_state = true
|
||||||
move_speed = 1.0
|
move_speed = 1.0
|
||||||
animation_sequence = [ "idle" ]
|
animation_sequence = [ "idle" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
|
|
@ -573,12 +577,14 @@ roll_node = NodePath("../roll")
|
||||||
|
|
||||||
[node name="fall" parent="movement_state_machine" index="1"]
|
[node name="fall" parent="movement_state_machine" index="1"]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
debug_state = true
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
animation_sequence = [ "jump" ]
|
animation_sequence = [ "jump" ]
|
||||||
landing_node = NodePath("")
|
landing_node = NodePath("")
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="2"]
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
debug_state = true
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
animation_sequence = [ "step", "run" ]
|
animation_sequence = [ "step", "run" ]
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ onready var move_state: State = get_node(move_node)
|
||||||
var can_fire = true
|
var can_fire = true
|
||||||
signal do_attack()
|
signal do_attack()
|
||||||
|
|
||||||
|
var draw_weapon_modifier: StateModifier
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
#.enter()
|
#.enter()
|
||||||
##TODO: Turn this to clear only the animation modifiers.
|
##TODO: Turn this to clear only the animation modifiers.
|
||||||
|
|
@ -54,6 +56,19 @@ func enter() -> void:
|
||||||
animations.frame = previous_state_frame_number
|
animations.frame = previous_state_frame_number
|
||||||
_:
|
_:
|
||||||
print("Warning!: Attack state encountered unhandled prev animation: ", previous_animation_name)
|
print("Warning!: Attack state encountered unhandled prev animation: ", previous_animation_name)
|
||||||
|
|
||||||
|
draw_weapon_modifier = StateModifier.new()
|
||||||
|
var mod_timer :Timer = draw_weapon_modifier.ready( "idle_shoot" , draw_weapon_modifier.TYPE.ANIMATION_SUFFIX, 2.0)
|
||||||
|
add_child(mod_timer)
|
||||||
|
# connect()
|
||||||
|
mod_timer.connect("timeout", draw_weapon_modifier, "_on_Timer_timeout")
|
||||||
|
mod_timer.connect("timeout", self, "_on_Timer_timeout")
|
||||||
|
draw_weapon_modifier.state_timeout.start()
|
||||||
|
#mod_timer.connect("timeout",)
|
||||||
|
|
||||||
|
func _on_Timer_timeout():
|
||||||
|
print("Oh Crap! I this worked too!")
|
||||||
|
animations.stop()
|
||||||
|
|
||||||
func process_frame(delta: float) -> State:
|
func process_frame(delta: float) -> State:
|
||||||
# if animations.frame == 2:
|
# if animations.frame == 2:
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,20 @@ extends StateAnimatedActor
|
||||||
export (NodePath) var idle_node
|
export (NodePath) var idle_node
|
||||||
export (NodePath) var landing_node
|
export (NodePath) var landing_node
|
||||||
|
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: StateAnimatedActor = get_node(idle_node)
|
||||||
#onready var landing_mod: StateModifier = get_node(landing_node)
|
#onready var landing_mod: StateModifier = get_node(landing_node)
|
||||||
|
|
||||||
|
var landing_modifier: StateModifier
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
landing_modifier= StateModifier.new()
|
||||||
|
#add_child(modifier)
|
||||||
|
#modifier.init_ref()
|
||||||
|
landing_modifier.ready( "jump" , landing_modifier.TYPE.EXIT_ANIMATION)
|
||||||
|
landing_modifier.starting_frame = 6
|
||||||
|
#print("ready! MOD")
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
# var landing_mod_index = modifier_stack_ref.rfind(landing_mod)
|
# var landing_mod_index = modifier_stack_ref.rfind(landing_mod)
|
||||||
# if landing_mod_index != -1:
|
# if landing_mod_index != -1:
|
||||||
|
|
@ -26,13 +37,15 @@ func process_physics(delta: float) -> State:
|
||||||
parent.transform.x.x = move_component.get_movement_direction()
|
parent.transform.x.x = move_component.get_movement_direction()
|
||||||
|
|
||||||
if parent.is_on_floor():
|
if parent.is_on_floor():
|
||||||
|
print("DO you even!?: ", landing_modifier.animation_name)
|
||||||
|
#modifier.reference()
|
||||||
|
idle_state.modifier = landing_modifier
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func exit() -> void:
|
#func exit() -> void:
|
||||||
.exit()
|
# .exit()
|
||||||
# push_animation_state_modifier(landing_mod)
|
## push_animation_state_modifier(landing_mod)
|
||||||
# $"../landing".enter()
|
## $"../landing".enter()
|
||||||
# modifier_stack_ref.push_front($"../landing")
|
## modifier_stack_ref.push_front($"../landing")
|
||||||
return
|
# return
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ signal frame_reached(state_name, animation_name, frame_number)
|
||||||
export(Dictionary) var emitter_frame_subscriptions
|
export(Dictionary) var emitter_frame_subscriptions
|
||||||
var frame_signal_emitted: bool = false
|
var frame_signal_emitted: bool = false
|
||||||
|
|
||||||
|
var animation_finished: bool = false
|
||||||
|
|
||||||
|
var transition_state: StateAnimatedActor
|
||||||
|
|
||||||
# this just wouldn't work well. Maybe I can try a resource
|
# this just wouldn't work well. Maybe I can try a resource
|
||||||
# export(Array, NodePath) var transition_state_nodes
|
# export(Array, NodePath) var transition_state_nodes
|
||||||
|
|
||||||
|
|
@ -52,6 +56,8 @@ var previous_state_frame_number : int
|
||||||
var previous_state_name: String
|
var previous_state_name: String
|
||||||
var previous_speed_multiplier: float
|
var previous_speed_multiplier: float
|
||||||
|
|
||||||
|
var modifier: StateModifier
|
||||||
|
|
||||||
#var animation_sequence_timer: Timer
|
#var animation_sequence_timer: Timer
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,6 +71,8 @@ func _ready():
|
||||||
state_timeout.one_shot = true
|
state_timeout.one_shot = true
|
||||||
state_timeout.autostart = false
|
state_timeout.autostart = false
|
||||||
add_child(state_timeout)
|
add_child(state_timeout)
|
||||||
|
|
||||||
|
#modifier = StateModifier.new()
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
|
|
@ -83,6 +91,13 @@ func enter() -> void:
|
||||||
move_component.current_movement_state = self.name
|
move_component.current_movement_state = self.name
|
||||||
emit_signal("state_entered")
|
emit_signal("state_entered")
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
|
|
||||||
|
if modifier != null:
|
||||||
|
if modifier.modifier_type == modifier.TYPE.EXIT_ANIMATION:
|
||||||
|
#print("OHHH Modifier Applies! ", modifier.animation_name)
|
||||||
|
mod_animation_sequence.push_front(modifier.animation_name)
|
||||||
|
enter_frame = modifier.starting_frame
|
||||||
|
|
||||||
|
|
||||||
# A new attempt at animation modifiers
|
# A new attempt at animation modifiers
|
||||||
# if modifier_stack_ref.empty() == false:
|
# if modifier_stack_ref.empty() == false:
|
||||||
|
|
@ -148,8 +163,20 @@ func enter() -> void:
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
emit_signal("state_exited")
|
emit_signal("state_exited")
|
||||||
# animations.disconnect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
# animations.disconnect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
||||||
|
#modifier = null
|
||||||
return
|
return
|
||||||
|
|
||||||
|
func transfer_modifiers(exiting_state_modifier : StateModifier):
|
||||||
|
if modifier == null: # We have no existing modifier applied.
|
||||||
|
match exiting_state_modifier.modifier_type:
|
||||||
|
exiting_state_modifier.TYPE.ANIMATION_SUFFIX:
|
||||||
|
print("Transferring Animation Suffix")
|
||||||
|
modifier = exiting_state_modifier
|
||||||
|
exiting_state_modifier.TYPE.EXIT_ANIMATION:
|
||||||
|
print("Exit Animation: well this was useless.")
|
||||||
|
else:
|
||||||
|
print("Insert modifier merge function here...")
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ func change_state(new_state: State) -> void:
|
||||||
# Set parameters for information
|
# Set parameters for information
|
||||||
if new_state is StateAnimatedActor and current_state is StateAnimatedActor:
|
if new_state is StateAnimatedActor and current_state is StateAnimatedActor:
|
||||||
set_previous_animation( current_state, new_state)
|
set_previous_animation( current_state, new_state)
|
||||||
|
if current_state.modifier: # Current state has a modifier
|
||||||
|
new_state.transfer_modifiers(current_state.modifier)
|
||||||
|
current_state.modifier = null
|
||||||
|
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
current_state.enter()
|
current_state.enter()
|
||||||
|
|
@ -48,7 +51,7 @@ func process_frame(delta: float) -> void:
|
||||||
# If the modifier is no longer valid, pop it from the stack.
|
# If the modifier is no longer valid, pop it from the stack.
|
||||||
# We could iterate through a whole list of states but I'm not sure i want
|
# We could iterate through a whole list of states but I'm not sure i want
|
||||||
# states to be that complex.
|
# states to be that complex.
|
||||||
var current_anim_state :StateAnimatedActor = current_state
|
# var current_anim_state :StateAnimatedActor = current_state
|
||||||
# if state_modifiers.empty() == false:
|
# if state_modifiers.empty() == false:
|
||||||
# for i in range(state_modifiers.size()):
|
# for i in range(state_modifiers.size()):
|
||||||
# # if this modifer is a timer based one
|
# # if this modifer is a timer based one
|
||||||
|
|
@ -83,7 +86,8 @@ func process_frame(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_AnimatedSprite_animation_finished():
|
func _on_AnimatedSprite_animation_finished():
|
||||||
|
# if debug_state_machine:
|
||||||
|
# print("Stop!!!!!")
|
||||||
##TODO:
|
##TODO:
|
||||||
# It's hard to pop an exit animation off when it's stacked with another kind of animation.
|
# It's hard to pop an exit animation off when it's stacked with another kind of animation.
|
||||||
# for i in state_modifiers.size():
|
# for i in state_modifiers.size():
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class_name StateModifier
|
class_name StateModifier
|
||||||
extends Object
|
extends Reference
|
||||||
## State modification
|
## State modification
|
||||||
##
|
##
|
||||||
## A state modifier doesn't have any direct control of a game object.
|
## A state modifier doesn't have any direct control of a game object.
|
||||||
|
|
@ -10,7 +10,7 @@ extends Object
|
||||||
##
|
##
|
||||||
## @WIP
|
## @WIP
|
||||||
|
|
||||||
enum type {NONE,EXIT_ANIMATION}
|
enum TYPE {NONE,EXIT_ANIMATION, ANIMATION_SUFFIX, REPLACE_ANIMATION}
|
||||||
|
|
||||||
export var debug_state: bool = false
|
export var debug_state: bool = false
|
||||||
|
|
||||||
|
|
@ -19,26 +19,23 @@ export var animation_name: String
|
||||||
## Modification Type
|
## Modification Type
|
||||||
## if an animation is specified, the default behavior will be just to override
|
## if an animation is specified, the default behavior will be just to override
|
||||||
## the state animation. Or perform a 'Replace Animation'
|
## the state animation. Or perform a 'Replace Animation'
|
||||||
export(String, "None",
|
var modifier_type = TYPE.NONE
|
||||||
"Exit Animation",
|
|
||||||
"Animation Suffix",
|
|
||||||
"Replace Animation") var modifier_type = "None"
|
|
||||||
|
|
||||||
export var starting_frame: int = 0
|
var starting_frame: int = 0
|
||||||
|
|
||||||
# Move Speed in Pixels Per Second
|
# Move Speed in Pixels Per Second
|
||||||
# These should only apply if Modification Type Set to None.
|
# These should only apply if Modification Type Set to None.
|
||||||
# (But I'm not sure if I like that model.)
|
# (But I'm not sure if I like that model.)
|
||||||
export var move_speed: float
|
var move_speed: float
|
||||||
export var move_speed_modifier: float = 0
|
var move_speed_modifier: float = 0
|
||||||
export var move_speed_modifier_decay: float = 0
|
var move_speed_modifier_decay: float = 0
|
||||||
|
|
||||||
export var timeout_seconds: float = 0.0
|
var timeout_seconds: float = 0.0
|
||||||
|
|
||||||
# Attempting to use this as an animation suffix that can linger after
|
# Attempting to use this as an animation suffix that can linger after
|
||||||
# state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc.
|
# state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc.
|
||||||
export var animation_suffix: bool = false
|
var animation_suffix: bool = false
|
||||||
export var pre_append_animation: bool = false
|
var pre_append_animation: bool = false
|
||||||
|
|
||||||
# not sure if I can do the array thing from state change. Maybe?
|
# not sure if I can do the array thing from state change. Maybe?
|
||||||
# disabling this sequencing for now.
|
# disabling this sequencing for now.
|
||||||
|
|
@ -52,21 +49,34 @@ var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
|
||||||
var state_timeout: Timer
|
var state_timeout: Timer
|
||||||
|
|
||||||
func _ready():
|
#func copy_modifier() -> StateModifier:
|
||||||
|
# var new_modifier = StateModifier.new()
|
||||||
|
# new_modifier.ready(animation_name, modifier_type, timeout_seconds)
|
||||||
|
#
|
||||||
|
# return StateModifier.new()
|
||||||
|
|
||||||
|
func ready(anim_name:String = '', type = TYPE.NONE, timeout : float = 0) -> Timer:
|
||||||
# If somebody forgot to specify the type
|
# If somebody forgot to specify the type
|
||||||
if animation_name != '' and modifier_type == "None":
|
if anim_name != '' and type == TYPE.NONE:
|
||||||
modifier_type = "Replace Animation"
|
modifier_type = TYPE.REPLACE_ANIMATION
|
||||||
state_timeout = Timer.new()
|
animation_name = anim_name
|
||||||
if timeout_seconds > 0:
|
modifier_type = type
|
||||||
state_timeout.wait_time = timeout_seconds
|
if timeout > 0:
|
||||||
state_timeout.one_shot = true
|
state_timeout = Timer.new()
|
||||||
state_timeout.autostart = false
|
state_timeout.wait_time = timeout
|
||||||
|
state_timeout.one_shot = true
|
||||||
|
state_timeout.autostart = false
|
||||||
|
return state_timeout
|
||||||
#add_child(state_timeout)
|
#add_child(state_timeout)
|
||||||
|
return null
|
||||||
|
|
||||||
|
func _on_Timer_timeout():
|
||||||
|
print("Oh Crap! I can't beleive it worked")
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
if debug_state:
|
if debug_state:
|
||||||
print("Apply State Modifier: ", self.name)
|
print("Apply State Modifier: ", self.name)
|
||||||
state_timeout.start()
|
# state_timeout.start()
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user