More state modifier fixes. Still getting crashes.
This commit is contained in:
parent
438edc8e70
commit
87eba39116
|
|
@ -98,6 +98,10 @@ region = Rect2( 1920, 0, 240, 160 )
|
|||
atlas = SubResource( 90 )
|
||||
region = Rect2( 2160, 0, 240, 160 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=163]
|
||||
atlas = SubResource( 90 )
|
||||
region = Rect2( 480, 160, 240, 160 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=112]
|
||||
atlas = SubResource( 90 )
|
||||
region = Rect2( 1920, 160, 240, 160 )
|
||||
|
|
@ -302,10 +306,6 @@ region = Rect2( 0, 160, 240, 160 )
|
|||
atlas = SubResource( 90 )
|
||||
region = Rect2( 240, 160, 240, 160 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=163]
|
||||
atlas = SubResource( 90 )
|
||||
region = Rect2( 480, 160, 240, 160 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=164]
|
||||
atlas = SubResource( 90 )
|
||||
region = Rect2( 0, 1280, 240, 160 )
|
||||
|
|
@ -427,6 +427,11 @@ animations = [ {
|
|||
"name": "idle",
|
||||
"speed": 10.0
|
||||
}, {
|
||||
"frames": [ SubResource( 163 ) ],
|
||||
"loop": true,
|
||||
"name": "idle_shoot",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ SubResource( 112 ), SubResource( 113 ), SubResource( 114 ), SubResource( 115 ), SubResource( 113 ), SubResource( 116 ), SubResource( 117 ), SubResource( 118 ) ],
|
||||
"loop": false,
|
||||
"name": "jump",
|
||||
|
|
@ -489,8 +494,8 @@ player_number = 1
|
|||
[node name="AnimatedSprite" parent="." index="0"]
|
||||
position = Vector2( -1, -51 )
|
||||
frames = SubResource( 190 )
|
||||
animation = "idle"
|
||||
frame = 11
|
||||
animation = "idle_shoot"
|
||||
frame = 0
|
||||
flip_h = false
|
||||
__meta__ = {
|
||||
"_aseprite_wizard_config_": {
|
||||
|
|
@ -521,10 +526,12 @@ attack_node = NodePath("../attack")
|
|||
[node name="fall" parent="movement_state_machine" index="1"]
|
||||
script = ExtResource( 6 )
|
||||
animation_sequence = [ "jump" ]
|
||||
landing_node = NodePath("landing")
|
||||
|
||||
[node name="landing" type="Node" parent="movement_state_machine/fall" index="0"]
|
||||
script = ExtResource( 9 )
|
||||
animation_name = "jump"
|
||||
modifier_type = "Exit Animation"
|
||||
starting_frame = 6
|
||||
pre_append_animation = true
|
||||
|
||||
|
|
@ -553,6 +560,7 @@ draw_weapon_node = NodePath("draw_weapon")
|
|||
[node name="draw_weapon" type="Node" parent="movement_state_machine/attack" index="0"]
|
||||
script = ExtResource( 9 )
|
||||
animation_name = "_shoot"
|
||||
modifier_type = "Animation Suffix"
|
||||
timeout_seconds = 2.2
|
||||
animation_suffix = true
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
extends StateAnimatedActor
|
||||
|
||||
export (NodePath) var idle_node
|
||||
export (NodePath) var landing_node
|
||||
|
||||
onready var idle_state: State = get_node(idle_node)
|
||||
onready var landing_mod: StateModifier = get_node(landing_node)
|
||||
|
||||
func enter() -> void:
|
||||
.enter()
|
||||
|
|
@ -26,6 +28,7 @@ func process_physics(delta: float) -> State:
|
|||
|
||||
func exit() -> void:
|
||||
.exit()
|
||||
$"../landing".enter()
|
||||
modifier_stack_ref.push_front($"../landing")
|
||||
push_animation_state_modifier(landing_mod)
|
||||
# $"../landing".enter()
|
||||
# modifier_stack_ref.push_front($"../landing")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -59,38 +59,79 @@ func _ready():
|
|||
func enter() -> void:
|
||||
# animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
||||
mod_animation_sequence.clear()
|
||||
mod_animation_sequence = animation_sequence.duplicate(true)
|
||||
#mod_animation_sequence = animation_sequence.duplicate(true)
|
||||
mod_animation_sequence.append_array(animation_sequence)
|
||||
# Reset animation suffix in case there isn't one
|
||||
animation_suffix = ''
|
||||
animation_index = 0
|
||||
current_animation_sequence = 0
|
||||
#var enter_animation = ''
|
||||
var enter_frame = 0
|
||||
|
||||
if debug_state:
|
||||
print(parent.name, " entering State: ", self.name)
|
||||
move_component.current_movement_state = self.name
|
||||
emit_signal("state_entered")
|
||||
#modifier_stack_ref = state_modifiers
|
||||
if modifier_stack_ref.empty() == false: # a modifier is applied
|
||||
if modifier_stack_ref[-1].animation_name != '': # the first one has an animation
|
||||
if modifier_stack_ref[-1].animation_suffix: # it's a suffix type
|
||||
if mod_animation_sequence.size() > 0: # the current animation is multipart (sequence > 0)
|
||||
animation_index = 0
|
||||
current_animation_sequence = 0
|
||||
# Guess I don't need this one anymore
|
||||
#if animations.frames.get_animation_names().has(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||
if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||
|
||||
# A new attempt at animation modifiers
|
||||
if modifier_stack_ref.empty() == false:
|
||||
print("nope: ")
|
||||
var i = modifier_stack_ref.size() - 1
|
||||
##NOTE: i apparently reverse range itteration doesn't work
|
||||
#for i in range(modifier_stack_ref.size(), 0): # work in reverse
|
||||
while (i >= 0 and modifier_stack_ref[i].modifier_type != "None"):
|
||||
print("Animation Modifier!: ",modifier_stack_ref[i].modifier_type)
|
||||
match modifier_stack_ref[i].modifier_type:
|
||||
"Exit Animation":
|
||||
mod_animation_sequence.push_front(modifier_stack_ref[i].animation_name)
|
||||
enter_frame = modifier_stack_ref[i].starting_frame
|
||||
|
||||
# Gonna ty and avoid this for now
|
||||
#modifier_stack_ref.pop_at(i) # we're done with this modifier
|
||||
|
||||
"Animation Suffix":
|
||||
if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name):
|
||||
animation_suffix = modifier_stack_ref[-1].animation_name
|
||||
elif modifier_stack_ref[-1].pre_append_animation == true: # it's a pre-append type
|
||||
#animation_sequence.size()
|
||||
print ("DEBUG: A prepend animation")
|
||||
#mod_animation_sequence = animation_sequence
|
||||
mod_animation_sequence.push_front(modifier_stack_ref[-1].animation_name)
|
||||
else:
|
||||
animations.play(modifier_stack_ref[-1].animation_name)
|
||||
animations.frame = modifier_stack_ref[-1].starting_frame
|
||||
return
|
||||
else:
|
||||
print("Warning!: Animation suffix that doesn't exist ",
|
||||
mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name)
|
||||
"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_stack_ref[i].animation_name)
|
||||
enter_frame = modifier_stack_ref[i].starting_frame
|
||||
i -= 1
|
||||
|
||||
|
||||
# if modifier_stack_ref.empty() == false: # a modifier is applied
|
||||
# if modifier_stack_ref[-1].animation_name != '': # the first one has an animation
|
||||
# if modifier_stack_ref[-1].animation_suffix: # it's a suffix type
|
||||
# if mod_animation_sequence.size() > 0: # the current animation is multipart (sequence > 0)
|
||||
# animation_index = 0
|
||||
# current_animation_sequence = 0
|
||||
# # Guess I don't need this one anymore
|
||||
# #if animations.frames.get_animation_names().has(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||
# if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name):
|
||||
# animation_suffix = modifier_stack_ref[-1].animation_name
|
||||
# elif modifier_stack_ref[-1].pre_append_animation == true: # it's a pre-append type
|
||||
# #animation_sequence.size()
|
||||
# print ("DEBUG: A prepend animation")
|
||||
# #mod_animation_sequence = animation_sequence
|
||||
# mod_animation_sequence.push_front(modifier_stack_ref[-1].animation_name)
|
||||
# else:
|
||||
# animations.play(modifier_stack_ref[-1].animation_name)
|
||||
# animations.frame = modifier_stack_ref[-1].starting_frame
|
||||
# return
|
||||
|
||||
if mod_animation_sequence.size() > 0:
|
||||
animation_index = 0
|
||||
current_animation_sequence = 0
|
||||
animations.play(mod_animation_sequence[animation_index] + animation_suffix)
|
||||
return
|
||||
#TODO: maybe check current animatio has this frame
|
||||
animations.frame = enter_frame
|
||||
else:
|
||||
print("Error! Resolved to empty animation sequence!?")
|
||||
return
|
||||
|
||||
func exit() -> void:
|
||||
emit_signal("state_exited")
|
||||
|
|
@ -108,7 +149,8 @@ func process_frame(_delta: float) -> State:
|
|||
##TODO: Add a safety check here.
|
||||
animations.play(mod_animation_sequence[animation_index] + animation_suffix)
|
||||
if debug_state:
|
||||
print("An animation sequence: ", animations.animation , animation_index)
|
||||
print("An animation sequence: ", mod_animation_sequence[animation_index - 1], " -> ",
|
||||
animations.animation , " (", animation_index, ")")
|
||||
current_animation_sequence = animation_index
|
||||
# We have no more sequence animations and the current one doesn't loop
|
||||
# we do this to prevent the default idle animation from playing.
|
||||
|
|
@ -181,4 +223,6 @@ func push_animation_state_modifier(modifier: StateModifier):
|
|||
# if modifier.pre_append_animation == true and modifier_stack_ref[-1].animation_suffix == true:
|
||||
# modifier.animation_suffix
|
||||
# modifier_stack_ref.push_back(modifier)
|
||||
else:
|
||||
modifier_stack_ref.push_front(modifier)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,38 +24,62 @@ func process_frame(delta: float) -> void:
|
|||
# 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
|
||||
# states to be that complex.
|
||||
var current_anim_state :StateAnimatedActor = current_state
|
||||
if state_modifiers.empty() == false:
|
||||
for i in range(state_modifiers.size()):
|
||||
# if this modifer is a timer based one
|
||||
if state_modifiers[i].state_timeout.time_left == 0 and state_modifiers[i].timeout_seconds !=0:
|
||||
|
||||
# Need to do extra stuff if it's an animation based one
|
||||
if state_modifiers[i].modifier_type == "Animation Suffix":
|
||||
# Reset animation suffix
|
||||
current_anim_state.animation_suffix = ''
|
||||
var current_frame = current_anim_state.animations.frame
|
||||
current_anim_state.animation_index = current_anim_state.current_animation_sequence
|
||||
#current_anim_state.current_animation_sequence
|
||||
#current_anim_state.animations.play()
|
||||
if current_anim_state.animation_sequence.size() >= current_anim_state.current_animation_sequence:
|
||||
current_anim_state.animations.play(
|
||||
current_state.animation_sequence[current_anim_state.current_animation_sequence])
|
||||
current_anim_state.animations.frames.frames.size() >= current_frame
|
||||
current_anim_state.animations.frame = current_frame
|
||||
else:
|
||||
current_anim_state.animations.play(
|
||||
current_state.animation_sequence[0])
|
||||
|
||||
|
||||
if debug_state_machine:
|
||||
print("Pop State Modifier: ", state_modifiers[i].name)
|
||||
state_modifiers.pop_at(i)
|
||||
|
||||
# for i in state_modifiers:
|
||||
# # if this modifer is a timer based one
|
||||
# if i.state_timeout.time_left == 0 and i.timeout_seconds !=0:
|
||||
# if debug_state_machine:
|
||||
# print("Pop State Modifier: ", i.name)
|
||||
|
||||
if state_modifiers[-1].state_timeout.time_left == 0 and state_modifiers[-1].pre_append_animation == false:
|
||||
if debug_state_machine:
|
||||
print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||
state_modifiers.pop_back()
|
||||
# Reset animation suffix
|
||||
current_state.animation_suffix = ''
|
||||
var current_frame = current_state.animations.frame
|
||||
#current_state.animations.play(current_state.animation_sequence[current_state.animation_index])
|
||||
#TODO: Bodge to fix crash
|
||||
current_state.animation_index = 0
|
||||
current_state.current_animation_sequence = 0
|
||||
current_state.animations.play(current_state.animation_sequence[0])
|
||||
current_state.animations.frame = current_frame;
|
||||
# if state_modifiers[-1].state_timeout.time_left == 0 and state_modifiers[-1].pre_append_animation == false:
|
||||
# if debug_state_machine:
|
||||
# print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||
# state_modifiers.pop_back()
|
||||
# # Reset animation suffix
|
||||
# current_state.animation_suffix = ''
|
||||
# var current_frame = current_state.animations.frame
|
||||
# #current_state.animations.play(current_state.animation_sequence[current_state.animation_index])
|
||||
# #TODO: Bodge to fix crash
|
||||
# current_state.animation_index = 0
|
||||
# current_state.current_animation_sequence = 0
|
||||
# current_state.animations.play(current_state.animation_sequence[0])
|
||||
# current_state.animations.frame = current_frame;
|
||||
var new_state = current_state.process_frame(delta)
|
||||
if new_state:
|
||||
change_state(new_state)
|
||||
|
||||
|
||||
func _on_AnimatedSprite_animation_finished():
|
||||
if state_modifiers.empty() == false:
|
||||
if state_modifiers[-1].pre_append_animation == true:
|
||||
if debug_state_machine:
|
||||
print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||
state_modifiers.pop_back()
|
||||
for i in state_modifiers.size():
|
||||
if state_modifiers[i].animation_name == current_state.animations.animation:
|
||||
state_modifiers.pop_at(i)
|
||||
|
||||
# if state_modifiers.empty() == false:
|
||||
# if state_modifiers[-1].pre_append_animation == true:
|
||||
# if debug_state_machine:
|
||||
# print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||
# state_modifiers.pop_back()
|
||||
if current_state.animations.frames.get_animation_loop(
|
||||
current_state.animations.animation) == false:
|
||||
if current_state.animation_sequence.size() > 0:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user