What am I even doing.
This commit is contained in:
parent
0203076676
commit
aef17c3d81
|
|
@ -601,7 +601,6 @@ jump_force = 250.0
|
||||||
|
|
||||||
[node name="attack" type="Node" parent="movement_state_machine" index="4"]
|
[node name="attack" type="Node" parent="movement_state_machine" index="4"]
|
||||||
script = ExtResource( 10 )
|
script = ExtResource( 10 )
|
||||||
timeout_seconds = 2.0
|
|
||||||
jump_node = NodePath("../jump")
|
jump_node = NodePath("../jump")
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ export (NodePath) var fall_node
|
||||||
export (NodePath) var move_node
|
export (NodePath) var move_node
|
||||||
export (NodePath) var draw_weapon_node
|
export (NodePath) var draw_weapon_node
|
||||||
|
|
||||||
onready var jump_state: State = get_node(jump_node)
|
onready var jump_state: StateAnimatedActor = get_node(jump_node)
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: StateAnimatedActor = get_node(idle_node)
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: StateAnimatedActor = get_node(fall_node)
|
||||||
onready var move_state: State = get_node(move_node)
|
onready var move_state: StateAnimatedActor = get_node(move_node)
|
||||||
#onready var weapon_state_modifier: StateModifier = get_node(draw_weapon_node)
|
#onready var weapon_state_modifier: StateModifier = get_node(draw_weapon_node)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,7 +37,6 @@ 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")
|
||||||
|
|
||||||
state_timeout.start()
|
|
||||||
can_fire = true
|
can_fire = true
|
||||||
# if modifier_stack_ref.has($"../draw_weapon") == false:
|
# if modifier_stack_ref.has($"../draw_weapon") == false:
|
||||||
# $"../draw_weapon".enter()
|
# $"../draw_weapon".enter()
|
||||||
|
|
@ -58,23 +57,31 @@ func enter() -> void:
|
||||||
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()
|
draw_weapon_modifier = StateModifier.new()
|
||||||
var mod_timer :Timer = draw_weapon_modifier.ready( "idle_shoot" , draw_weapon_modifier.TYPE.ANIMATION_SUFFIX, 2.0)
|
var mod_timer :Timer = draw_weapon_modifier.ready( "_shoot" , draw_weapon_modifier.TYPE.ANIMATION_SUFFIX, 2.0)
|
||||||
add_child(mod_timer)
|
add_child(mod_timer)
|
||||||
# connect()
|
|
||||||
mod_timer.connect("timeout", draw_weapon_modifier, "_on_Timer_timeout")
|
# An example where the modifier is left to alert on a timeout
|
||||||
mod_timer.connect("timeout", self, "_on_Timer_timeout")
|
#mod_timer.connect("timeout", draw_weapon_modifier, "_on_Timer_timeout")
|
||||||
draw_weapon_modifier.state_timeout.start()
|
# An example where the current node subscribes
|
||||||
#mod_timer.connect("timeout",)
|
#mod_timer.connect("timeout", self, "_on_Timer_timeout")
|
||||||
|
|
||||||
|
animation_finished = false
|
||||||
|
|
||||||
func _on_Timer_timeout():
|
func _on_Timer_timeout():
|
||||||
print("Oh Crap! I this worked too!")
|
print("Modifier Timeout from attack! Forcing animation recall")
|
||||||
animations.stop()
|
#animations.stop()
|
||||||
|
|
||||||
func process_frame(delta: float) -> State:
|
func process_frame(delta: float) -> State:
|
||||||
|
if animation_finished:
|
||||||
|
print("WTF!?!! Finish already!")
|
||||||
|
draw_weapon_modifier.state_timeout.start()
|
||||||
|
modifier = draw_weapon_modifier
|
||||||
|
return idle_state
|
||||||
|
.process_frame(delta)
|
||||||
# if animations.frame == 2:
|
# if animations.frame == 2:
|
||||||
# animations.stop()
|
# animations.stop()
|
||||||
if state_timeout.time_left == 0 and animations.animation == "shoot":
|
# if state_timeout.time_left == 0 and animations.animation == "shoot":
|
||||||
return idle_state
|
# return idle_state
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,6 +100,9 @@ func process_physics(delta: float) -> State:
|
||||||
return idle_state
|
return idle_state
|
||||||
|
|
||||||
if previous_state_name == "idle" and move_component.velocity.x != 0.0:
|
if previous_state_name == "idle" and move_component.velocity.x != 0.0:
|
||||||
|
draw_weapon_modifier.state_timeout.start()
|
||||||
|
move_state.modifier = draw_weapon_modifier
|
||||||
|
#draw_weapon_modifier.transfer_owner(move_state)
|
||||||
return move_state
|
return move_state
|
||||||
|
|
||||||
if move_component.get_movement_direction() != 0.0:
|
if move_component.get_movement_direction() != 0.0:
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,65 @@ func _ready():
|
||||||
|
|
||||||
#modifier = StateModifier.new()
|
#modifier = StateModifier.new()
|
||||||
|
|
||||||
|
# If called, this will attempt to make the most appropriate animation change
|
||||||
|
# would likely be triggered from an animation sequence finishing or a
|
||||||
|
# modifier being applied/removed outside of enter/exit transitions.
|
||||||
|
func update_animation(enter_frame := 0, index := 0, suffix := ''):
|
||||||
|
## TODO:
|
||||||
|
# Need to find a way to attempt to keep and transfer the Index or frame
|
||||||
|
#
|
||||||
|
# if clear_modifier:
|
||||||
|
# print("Goodbye Modifiers!")
|
||||||
|
# modifier = null
|
||||||
|
# if modifier:
|
||||||
|
# if modifier.state_timeout and modifier.timeout_seconds == 0:
|
||||||
|
# modifier = null
|
||||||
|
|
||||||
|
# By Default, we build an animation sequence off of this state's before checking
|
||||||
|
# for modifiers
|
||||||
|
mod_animation_sequence.clear()
|
||||||
|
mod_animation_sequence.append_array(animation_sequence)
|
||||||
|
# Reset animation suffix in case there isn't one
|
||||||
|
animation_suffix = suffix
|
||||||
|
animation_index = index
|
||||||
|
current_animation_sequence = animation_index
|
||||||
|
#var enter_animation = ''
|
||||||
|
#var enter_frame = 0
|
||||||
|
|
||||||
|
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
|
||||||
|
match modifier.modifier_type:
|
||||||
|
modifier.TYPE.EXIT_ANIMATION:
|
||||||
|
mod_animation_sequence.push_front(modifier.animation_name)
|
||||||
|
enter_frame = modifier.starting_frame
|
||||||
|
|
||||||
|
modifier.TYPE.ANIMATION_SUFFIX:
|
||||||
|
if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier.animation_name):
|
||||||
|
animation_suffix = modifier.animation_name
|
||||||
|
else:
|
||||||
|
print("Warning!: Modifier attempting to apply suffix that doesn't exist ",
|
||||||
|
mod_animation_sequence[animation_index] + modifier.animation_name)
|
||||||
|
|
||||||
|
modifier.TYPE.REPLACE_ANIMATION:
|
||||||
|
#animations.play(modifier_stack_ref[i].animation_name)
|
||||||
|
#animations.frame = modifier_stack_ref[i].starting_frame
|
||||||
|
mod_animation_sequence.clear()
|
||||||
|
mod_animation_sequence.push_back(modifier.animation_name)
|
||||||
|
enter_frame = modifier.starting_frame
|
||||||
|
|
||||||
|
if mod_animation_sequence.size() > 0:
|
||||||
|
if debug_state:
|
||||||
|
print("Starting Animation: " , mod_animation_sequence[animation_index] + animation_suffix)
|
||||||
|
animations.play(mod_animation_sequence[animation_index] + animation_suffix)
|
||||||
|
#TODO: maybe check current animatio has this frame
|
||||||
|
animations.frame = enter_frame
|
||||||
|
else:
|
||||||
|
print("Error! Resolved to empty animation sequence!?")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
mod_animation_sequence.clear()
|
mod_animation_sequence.clear()
|
||||||
|
|
@ -93,10 +152,38 @@ func enter() -> void:
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
|
|
||||||
if modifier != null:
|
if modifier != null:
|
||||||
if modifier.modifier_type == modifier.TYPE.EXIT_ANIMATION:
|
# if modifier.modifier_type == modifier.TYPE.EXIT_ANIMATION:
|
||||||
#print("OHHH Modifier Applies! ", modifier.animation_name)
|
# #print("OHHH Modifier Applies! ", modifier.animation_name)
|
||||||
mod_animation_sequence.push_front(modifier.animation_name)
|
# mod_animation_sequence.push_front(modifier.animation_name)
|
||||||
enter_frame = modifier.starting_frame
|
# enter_frame = modifier.starting_frame
|
||||||
|
match modifier.modifier_type:
|
||||||
|
modifier.TYPE.EXIT_ANIMATION:
|
||||||
|
mod_animation_sequence.push_front(modifier.animation_name)
|
||||||
|
enter_frame = modifier.starting_frame
|
||||||
|
|
||||||
|
modifier.TYPE.ANIMATION_SUFFIX:
|
||||||
|
if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier.animation_name):
|
||||||
|
animation_suffix = modifier.animation_name
|
||||||
|
else:
|
||||||
|
print("Warning!: Modifier attempting to apply suffix that doesn't exist ",
|
||||||
|
mod_animation_sequence[animation_index] + modifier.animation_name)
|
||||||
|
|
||||||
|
modifier.TYPE.REPLACE_ANIMATION:
|
||||||
|
#animations.play(modifier_stack_ref[i].animation_name)
|
||||||
|
#animations.frame = modifier_stack_ref[i].starting_frame
|
||||||
|
mod_animation_sequence.clear()
|
||||||
|
mod_animation_sequence.push_back(modifier.animation_name)
|
||||||
|
enter_frame = modifier.starting_frame
|
||||||
|
|
||||||
|
if mod_animation_sequence.size() > 0:
|
||||||
|
if debug_state:
|
||||||
|
print("Starting Animation: " , mod_animation_sequence[animation_index] + animation_suffix)
|
||||||
|
animations.play(mod_animation_sequence[animation_index] + animation_suffix)
|
||||||
|
#TODO: maybe check current animatio has this frame
|
||||||
|
animations.frame = enter_frame
|
||||||
|
else:
|
||||||
|
print("Error! Resolved to empty animation sequence!?")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
# A new attempt at animation modifiers
|
# A new attempt at animation modifiers
|
||||||
|
|
@ -181,6 +268,14 @@ func process_input(_event: InputEvent) -> State:
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func process_frame(_delta: float) -> State:
|
func process_frame(_delta: float) -> State:
|
||||||
|
|
||||||
|
if modifier != null:
|
||||||
|
if modifier.state_timeout and modifier.state_timeout.time_left == 0:
|
||||||
|
print("Expired Modifier, updating animation.")
|
||||||
|
modifier = null
|
||||||
|
update_animation()
|
||||||
|
|
||||||
|
|
||||||
#if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
#if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
||||||
if mod_animation_sequence.size() > animation_index and current_animation_sequence != animation_index:
|
if mod_animation_sequence.size() > animation_index and current_animation_sequence != animation_index:
|
||||||
#TODO: why was I doing this
|
#TODO: why was I doing this
|
||||||
|
|
@ -192,11 +287,13 @@ func process_frame(_delta: float) -> State:
|
||||||
print("An animation sequence: ", mod_animation_sequence[animation_index - 1], " -> ",
|
print("An animation sequence: ", mod_animation_sequence[animation_index - 1], " -> ",
|
||||||
animations.animation , " (", animation_index, ")")
|
animations.animation , " (", animation_index, ")")
|
||||||
current_animation_sequence = animation_index
|
current_animation_sequence = animation_index
|
||||||
|
|
||||||
# We have no more sequence animations and the current one doesn't loop
|
# We have no more sequence animations and the current one doesn't loop
|
||||||
# we do this to prevent the default idle animation from playing.
|
# we do this to prevent the default idle animation from playing.
|
||||||
if animation_index >= mod_animation_sequence.size() and animations.frames.get_animation_loop(
|
if animation_index >= mod_animation_sequence.size() and animations.frames.get_animation_loop(
|
||||||
animations.animation) == false:
|
animations.animation) == false:
|
||||||
animations.stop()
|
animations.stop()
|
||||||
|
animation_finished = true
|
||||||
|
|
||||||
# Singal based frame call.
|
# Singal based frame call.
|
||||||
if emitter_frame_subscriptions.has(animations.frame):
|
if emitter_frame_subscriptions.has(animations.frame):
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ func process_frame(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_AnimatedSprite_animation_finished():
|
func _on_AnimatedSprite_animation_finished():
|
||||||
# if debug_state_machine:
|
if debug_state_machine:
|
||||||
# print("Stop!!!!!")
|
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():
|
||||||
|
|
@ -100,7 +100,8 @@ func _on_AnimatedSprite_animation_finished():
|
||||||
# current_state.animation_index += 1
|
# current_state.animation_index += 1
|
||||||
# break
|
# break
|
||||||
|
|
||||||
|
if current_state is StateAnimatedActor:
|
||||||
|
current_state.animation_finished = true
|
||||||
if current_state.animations.frames.get_animation_loop(
|
if current_state.animations.frames.get_animation_loop(
|
||||||
current_state.animations.animation) == false:
|
current_state.animations.animation) == false:
|
||||||
if current_state.animation_sequence.size() > 0:
|
if current_state.animation_sequence.size() > 0:
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ 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.
|
||||||
var animation_suffix: bool = false
|
#var animation_suffix: bool = false
|
||||||
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.
|
||||||
|
|
@ -49,18 +49,24 @@ var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
|
||||||
var state_timeout: Timer
|
var state_timeout: Timer
|
||||||
|
|
||||||
|
# Meant to be called on timeout or other counters this modifier may have.
|
||||||
|
# Should be updated whenever modifier owner transfers
|
||||||
|
var state_call_function: FuncRef
|
||||||
|
|
||||||
#func copy_modifier() -> StateModifier:
|
#func copy_modifier() -> StateModifier:
|
||||||
# var new_modifier = StateModifier.new()
|
# var new_modifier = StateModifier.new()
|
||||||
# new_modifier.ready(animation_name, modifier_type, timeout_seconds)
|
# new_modifier.ready(animation_name, modifier_type, timeout_seconds)
|
||||||
#
|
#
|
||||||
# return StateModifier.new()
|
# return StateModifier.new()
|
||||||
|
|
||||||
func ready(anim_name:String = '', type = TYPE.NONE, timeout : float = 0) -> Timer:
|
func ready(anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
|
||||||
# If somebody forgot to specify the type
|
# If somebody forgot to specify the type
|
||||||
if anim_name != '' and type == TYPE.NONE:
|
if anim_name != '' and type == TYPE.NONE:
|
||||||
modifier_type = TYPE.REPLACE_ANIMATION
|
modifier_type = TYPE.REPLACE_ANIMATION
|
||||||
animation_name = anim_name
|
animation_name = anim_name
|
||||||
modifier_type = type
|
modifier_type = type
|
||||||
|
# if parent != null and function_name != "":
|
||||||
|
# state_call_function = funcref(parent, function_name)
|
||||||
if timeout > 0:
|
if timeout > 0:
|
||||||
state_timeout = Timer.new()
|
state_timeout = Timer.new()
|
||||||
state_timeout.wait_time = timeout
|
state_timeout.wait_time = timeout
|
||||||
|
|
@ -70,8 +76,19 @@ func ready(anim_name:String = '', type = TYPE.NONE, timeout : float = 0) -> Time
|
||||||
#add_child(state_timeout)
|
#add_child(state_timeout)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
func transfer_owner(parent:Node):
|
||||||
|
print("Modifier owner will now be: ", parent.name)
|
||||||
|
state_call_function = funcref(parent, 'update_animation')
|
||||||
|
|
||||||
func _on_Timer_timeout():
|
func _on_Timer_timeout():
|
||||||
print("Oh Crap! I can't beleive it worked")
|
print("Oh Crap! I can't beleive it worked")
|
||||||
|
if state_call_function:
|
||||||
|
if state_call_function.is_valid():
|
||||||
|
state_call_function.call_func()
|
||||||
|
else:
|
||||||
|
print("Warning! Modifier timed out with no callback to alert.")
|
||||||
|
else:
|
||||||
|
print("Warning! no function applies.")
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
if debug_state:
|
if debug_state:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user