Start of some working animation modifiers applied.
This commit is contained in:
parent
a09be453da
commit
591c37dd60
|
|
@ -1,26 +1,15 @@
|
||||||
class_name AnimatedSprite_StateReceiver
|
class_name AnimatedSprite_StateReceiver
|
||||||
extends AnimatedSprite
|
extends AnimatedSprite
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
export var callable_state_machine :NodePath
|
export var callable_state_machine :NodePath
|
||||||
|
|
||||||
onready var current_state = StateAnimatedActor.new()
|
onready var current_state = StateAnimatedActor.new()
|
||||||
|
|
||||||
#var state_machine_modifiers: Array
|
|
||||||
var modifier: StateModifierAnimatedActor
|
var modifier: StateModifierAnimatedActor
|
||||||
|
|
||||||
#var animation_finished: bool = false
|
|
||||||
var request_state_change: FuncRef
|
var request_state_change: FuncRef
|
||||||
var add_state_modifier: FuncRef
|
var add_state_modifier: FuncRef
|
||||||
|
|
||||||
# this just wouldn't work well. Maybe I can try a resource
|
|
||||||
# export(Array, NodePath) var transition_state_nodes
|
|
||||||
|
|
||||||
#TODO: I think these two variables accidentally serve the same purpose
|
|
||||||
# I think one was intended to be a string of the current animation name.
|
|
||||||
var animation_index: int = 0
|
var animation_index: int = 0
|
||||||
var current_animation_sequence: int = 0
|
var current_animation_sequence: int = 0
|
||||||
var animation_suffix: String = '';
|
var animation_suffix: String = '';
|
||||||
|
|
@ -32,7 +21,6 @@ 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
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
|
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
|
||||||
|
|
@ -50,15 +38,6 @@ func _ready():
|
||||||
# Sprites should only have a process function
|
# Sprites should only have a process function
|
||||||
# but if I have this will the sprite still animate?
|
# but if I have this will the sprite still animate?
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
# Shouldn't need this anymore!
|
|
||||||
# if current_state.state_timeout != null:
|
|
||||||
# if current_state.state_timeout.time_left == 0:
|
|
||||||
# print("You're out of time! I saw it!")
|
|
||||||
# request_state_change.call_func('idle')
|
|
||||||
# #play()
|
|
||||||
# else:
|
|
||||||
# print("what, no current_state?")
|
|
||||||
|
|
||||||
# Not sure what should be called first here.
|
# Not sure what should be called first here.
|
||||||
if has_method('_state_process_' + current_state.name):
|
if has_method('_state_process_' + current_state.name):
|
||||||
call('_state_process_' + current_state.name)
|
call('_state_process_' + current_state.name)
|
||||||
|
|
@ -76,22 +55,12 @@ func _on_animation_finished():
|
||||||
current_state.animation_finished = true
|
current_state.animation_finished = true
|
||||||
# TODO: Allow a way to stop animation even if in a looped sequence
|
# TODO: Allow a way to stop animation even if in a looped sequence
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
# If called, this will attempt to make the most appropriate animation change
|
# If called, this will attempt to make the most appropriate animation change
|
||||||
# would likely be triggered from an animation sequence finishing or a
|
# would likely be triggered from an animation sequence finishing or a
|
||||||
# modifier being applied/removed outside of enter/exit transitions.
|
# modifier being applied/removed outside of enter/exit transitions.
|
||||||
func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
||||||
## TODO:
|
## TODO:
|
||||||
# Need to find a way to attempt to keep and transfer the Index or frame
|
# 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
|
|
||||||
|
|
||||||
if modifier:
|
if modifier:
|
||||||
#print("hey you got one! -> ", modifier.animation_name)
|
#print("hey you got one! -> ", modifier.animation_name)
|
||||||
|
|
@ -109,6 +78,23 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
||||||
animation_suffix = suffix
|
animation_suffix = suffix
|
||||||
animation_index = index
|
animation_index = index
|
||||||
current_animation_sequence = animation_index
|
current_animation_sequence = animation_index
|
||||||
|
|
||||||
|
if modifier:
|
||||||
|
#TODO: Apply the animation starting frame
|
||||||
|
#modifier.animation_starting_frame
|
||||||
|
match modifier.modifier_type:
|
||||||
|
modifier.TYPE.ANIMATION_SUFFIX:
|
||||||
|
# Check that this animation actually exists
|
||||||
|
if frames.has_animation(mod_animation_sequence[animation_index] + modifier.animation_suffix):
|
||||||
|
animation_suffix = modifier.animation_suffix
|
||||||
|
else:
|
||||||
|
push_warning("Modifier attempting to apply suffix that doesn't exist" +
|
||||||
|
(mod_animation_sequence[animation_index] + modifier.animation_suffix))
|
||||||
|
modifier.TYPE.REPLACE_ANIMATION:
|
||||||
|
if frames.has_animation(modifier.animation_name):
|
||||||
|
mod_animation_sequence.clear()
|
||||||
|
mod_animation_sequence.push_back(modifier.animation_name)
|
||||||
|
enter_frame = modifier.animation_starting_frame
|
||||||
#var enter_animation = ''
|
#var enter_animation = ''
|
||||||
#var enter_frame = 0
|
#var enter_frame = 0
|
||||||
# var modifier :StateModifier = current_state.modifier
|
# var modifier :StateModifier = current_state.modifier
|
||||||
|
|
@ -218,15 +204,15 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
||||||
# else:
|
# else:
|
||||||
# frame_signal_emitted = false
|
# frame_signal_emitted = false
|
||||||
|
|
||||||
func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnimatedActor ) -> void:
|
#func set_previous_animation( old_state: StateAnimatedActor, new_state: StateAnimatedActor ) -> void:
|
||||||
# added this to help prevent nul index crashes. (Usually because of signal based state changes.)
|
# # added this to help prevent nul index crashes. (Usually because of signal based state changes.)
|
||||||
if old_state.mod_animation_sequence:
|
# if old_state.mod_animation_sequence:
|
||||||
new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence]
|
# new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence]
|
||||||
new_state.previous_state_frame_number = old_state.animations.frame
|
# new_state.previous_state_frame_number = old_state.animations.frame
|
||||||
new_state.previous_state_name = old_state.name
|
# new_state.previous_state_name = old_state.name
|
||||||
new_state.previous_speed_multiplier = old_state.speed_multiplier
|
# new_state.previous_speed_multiplier = old_state.speed_multiplier
|
||||||
#animation_name :String, frame_number : int, animation_sequence :Array
|
# #animation_name :String, frame_number : int, animation_sequence :Array
|
||||||
return
|
# return
|
||||||
|
|
||||||
# Handle state change from subscribed state machine.
|
# Handle state change from subscribed state machine.
|
||||||
#From signal state_changed(old_state_name, new_state)
|
#From signal state_changed(old_state_name, new_state)
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ func change_state(new_state: State) -> void:
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
current_state.enter()
|
current_state.enter()
|
||||||
|
|
||||||
|
# Seems like I don't have to do this every state change!
|
||||||
# if(state_modifiers.size() > 0):
|
# if(state_modifiers.size() > 0):
|
||||||
# print("Active Modifiers:")
|
# print("Active Modifiers:")
|
||||||
# for mods in state_modifiers:
|
# for mods in state_modifiers:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ func _ready():
|
||||||
attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,5.0)
|
attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,5.0)
|
||||||
add_child(attack_sword.timeout)
|
add_child(attack_sword.timeout)
|
||||||
attack_sword.animation_name = 'PoopenStein'
|
attack_sword.animation_name = 'PoopenStein'
|
||||||
attack_sword.animation_suffix = '-attack_sword'
|
attack_sword.animation_suffix = '-attack-sword'
|
||||||
add_state_modifier.call_func(attack_sword)
|
add_state_modifier.call_func(attack_sword)
|
||||||
|
|
||||||
# I don't need this right now but I proved it can be done!
|
# I don't need this right now but I proved it can be done!
|
||||||
|
|
@ -41,10 +41,10 @@ func _ready():
|
||||||
# frame = 2
|
# frame = 2
|
||||||
# stop()
|
# stop()
|
||||||
|
|
||||||
func _on_state_change_idle():
|
#func _on_state_change_idle():
|
||||||
change_animation()
|
# change_animation()
|
||||||
if previous_state_name == 'attack_sword':
|
# if previous_state_name == 'attack_sword':
|
||||||
animation = 'idle-attack-sword'
|
# animation = 'idle-attack-sword'
|
||||||
|
|
||||||
func _on_state_change_fall():
|
func _on_state_change_fall():
|
||||||
change_animation()
|
change_animation()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user