Strip out all that state modifier stuff for a new approach.
This commit is contained in:
parent
4fda694182
commit
188bf46a09
|
|
@ -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": "Node",
|
"base": "Object",
|
||||||
"class": "StateModifier",
|
"class": "StateModifier",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/state_modifier.gd"
|
"path": "res://src/state_modifier.gd"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=127 format=2]
|
[gd_scene load_steps=126 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
|
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://src/state_modifier.gd" type="Script" id=9]
|
|
||||||
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
|
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
|
||||||
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
|
||||||
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
|
||||||
|
|
@ -576,14 +575,7 @@ roll_node = NodePath("../roll")
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
move_speed = 90.0
|
move_speed = 90.0
|
||||||
animation_sequence = [ "jump" ]
|
animation_sequence = [ "jump" ]
|
||||||
landing_node = NodePath("landing")
|
landing_node = NodePath("")
|
||||||
|
|
||||||
[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
|
|
||||||
|
|
||||||
[node name="move" parent="movement_state_machine" index="2"]
|
[node name="move" parent="movement_state_machine" index="2"]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
|
@ -599,7 +591,6 @@ animation_sequence = [ "jump" ]
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
attack_node = NodePath("../attack")
|
attack_node = NodePath("../attack")
|
||||||
landing_node = NodePath("../fall/landing")
|
|
||||||
jump_force = 250.0
|
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"]
|
||||||
|
|
@ -609,14 +600,6 @@ jump_node = NodePath("../jump")
|
||||||
idle_node = NodePath("../idle")
|
idle_node = NodePath("../idle")
|
||||||
fall_node = NodePath("../fall")
|
fall_node = NodePath("../fall")
|
||||||
move_node = NodePath("../move")
|
move_node = NodePath("../move")
|
||||||
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
|
|
||||||
|
|
||||||
[node name="hurt" type="Node" parent="movement_state_machine" index="5"]
|
[node name="hurt" type="Node" parent="movement_state_machine" index="5"]
|
||||||
script = ExtResource( 12 )
|
script = ExtResource( 12 )
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ onready var jump_state: State = get_node(jump_node)
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: State = get_node(fall_node)
|
||||||
onready var move_state: State = get_node(move_node)
|
onready var move_state: State = 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)
|
||||||
|
|
||||||
|
|
||||||
var can_fire = true
|
var can_fire = true
|
||||||
|
|
@ -19,7 +19,7 @@ signal do_attack()
|
||||||
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.
|
||||||
modifier_stack_ref.clear()
|
# modifier_stack_ref.clear()
|
||||||
mod_animation_sequence.clear()
|
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)
|
mod_animation_sequence.append_array(animation_sequence)
|
||||||
|
|
@ -94,8 +94,8 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
# force timer reset
|
# force timer reset
|
||||||
weapon_state_modifier.state_timeout.start()
|
# weapon_state_modifier.state_timeout.start()
|
||||||
push_animation_state_modifier(weapon_state_modifier)
|
# push_animation_state_modifier(weapon_state_modifier)
|
||||||
#$"../draw_weapon".state_timeout.start()
|
#$"../draw_weapon".state_timeout.start()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
extends StateAnimatedActor
|
extends StateAnimatedActor
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
modifier_stack_ref.clear()
|
# modifier_stack_ref.clear()
|
||||||
.enter()
|
.enter()
|
||||||
move_component.velocity.x = 0
|
move_component.velocity.x = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ 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: State = get_node(idle_node)
|
||||||
onready var landing_mod: StateModifier = get_node(landing_node)
|
#onready var landing_mod: StateModifier = get_node(landing_node)
|
||||||
|
|
||||||
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:
|
||||||
#print("You're Supposed to be dead!?: ", landing_mod_index)
|
# #print("You're Supposed to be dead!?: ", landing_mod_index)
|
||||||
modifier_stack_ref.remove(landing_mod_index)
|
# modifier_stack_ref.remove(landing_mod_index)
|
||||||
.enter()
|
.enter()
|
||||||
# Jump to fall frame
|
# Jump to fall frame
|
||||||
animations.frame = 5
|
animations.frame = 5
|
||||||
|
|
@ -32,7 +32,7 @@ func process_physics(delta: float) -> State:
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ onready var idle_state: State = get_node(idle_node)
|
||||||
var flash_color = Color.yellow
|
var flash_color = Color.yellow
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
modifier_stack_ref.clear()
|
# modifier_stack_ref.clear()
|
||||||
.enter()
|
.enter()
|
||||||
move_component.velocity.x = 0
|
move_component.velocity.x = 0
|
||||||
#parent.set_hurtbox(false)
|
#parent.set_hurtbox(false)
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,15 @@ export (NodePath) var landing_node
|
||||||
onready var idle_state: State = get_node(idle_node)
|
onready var idle_state: State = get_node(idle_node)
|
||||||
onready var fall_state: State = get_node(fall_node)
|
onready var fall_state: State = get_node(fall_node)
|
||||||
onready var attack_state: State = get_node(attack_node)
|
onready var attack_state: State = get_node(attack_node)
|
||||||
onready var landing_mod: StateModifier = get_node(landing_node)
|
#onready var landing_mod: StateModifier = get_node(landing_node)
|
||||||
|
|
||||||
export var jump_force: float = 200.0
|
export var jump_force: float = 200.0
|
||||||
|
|
||||||
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:
|
||||||
#print("You're Supposed to be dead!?: ", landing_mod_index)
|
# #print("You're Supposed to be dead!?: ", landing_mod_index)
|
||||||
modifier_stack_ref.remove(landing_mod_index)
|
# modifier_stack_ref.remove(landing_mod_index)
|
||||||
# if modifier_stack_ref.has(landing_mod):
|
# if modifier_stack_ref.has(landing_mod):
|
||||||
# print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod))
|
# print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod))
|
||||||
.enter()
|
.enter()
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ signal state_entered()
|
||||||
signal state_exited()
|
signal state_exited()
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
# Declare member variables here. Examples:
|
||||||
var modifier_stack_ref: Array # Well this didn't work
|
#var modifier_stack_ref: Array # Well this didn't work
|
||||||
var state_timeout: Timer
|
var state_timeout: Timer
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ func _ready():
|
||||||
|
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
# animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
|
||||||
mod_animation_sequence.clear()
|
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)
|
mod_animation_sequence.append_array(animation_sequence)
|
||||||
|
|
@ -86,34 +85,34 @@ func enter() -> void:
|
||||||
#modifier_stack_ref = state_modifiers
|
#modifier_stack_ref = state_modifiers
|
||||||
|
|
||||||
# A new attempt at animation modifiers
|
# A new attempt at animation modifiers
|
||||||
if modifier_stack_ref.empty() == false:
|
# if modifier_stack_ref.empty() == false:
|
||||||
print("nope: ")
|
# print("nope: ")
|
||||||
var i = modifier_stack_ref.size() - 1
|
# var i = modifier_stack_ref.size() - 1
|
||||||
##NOTE: i apparently reverse range itteration doesn't work
|
# ##NOTE: i apparently reverse range itteration doesn't work
|
||||||
#for i in range(modifier_stack_ref.size(), 0): # work in reverse
|
# #for i in range(modifier_stack_ref.size(), 0): # work in reverse
|
||||||
while (i >= 0 and modifier_stack_ref[i].modifier_type != "None"):
|
# while (i >= 0 and modifier_stack_ref[i].modifier_type != "None"):
|
||||||
print("Animation Modifier!: ",modifier_stack_ref[i].modifier_type)
|
# print("Animation Modifier!: ",modifier_stack_ref[i].modifier_type)
|
||||||
match modifier_stack_ref[i].modifier_type:
|
# match modifier_stack_ref[i].modifier_type:
|
||||||
"Exit Animation":
|
# "Exit Animation":
|
||||||
mod_animation_sequence.push_front(modifier_stack_ref[i].animation_name)
|
# mod_animation_sequence.push_front(modifier_stack_ref[i].animation_name)
|
||||||
enter_frame = modifier_stack_ref[i].starting_frame
|
# enter_frame = modifier_stack_ref[i].starting_frame
|
||||||
|
#
|
||||||
# Gonna ty and avoid this for now
|
# # Gonna ty and avoid this for now
|
||||||
#modifier_stack_ref.pop_at(i) # we're done with this modifier
|
# #modifier_stack_ref.pop_at(i) # we're done with this modifier
|
||||||
|
#
|
||||||
"Animation Suffix":
|
# "Animation Suffix":
|
||||||
if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name):
|
# if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name):
|
||||||
animation_suffix = modifier_stack_ref[i].animation_name
|
# animation_suffix = modifier_stack_ref[i].animation_name
|
||||||
else:
|
# else:
|
||||||
print("Warning!: Animation suffix that doesn't exist ",
|
# print("Warning!: Animation suffix that doesn't exist ",
|
||||||
mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name)
|
# mod_animation_sequence[animation_index] + modifier_stack_ref[i].animation_name)
|
||||||
"Replace Animation":
|
# "Replace Animation":
|
||||||
#animations.play(modifier_stack_ref[i].animation_name)
|
# #animations.play(modifier_stack_ref[i].animation_name)
|
||||||
#animations.frame = modifier_stack_ref[i].starting_frame
|
# #animations.frame = modifier_stack_ref[i].starting_frame
|
||||||
mod_animation_sequence.clear()
|
# mod_animation_sequence.clear()
|
||||||
mod_animation_sequence.push_back(modifier_stack_ref[i].animation_name)
|
# mod_animation_sequence.push_back(modifier_stack_ref[i].animation_name)
|
||||||
enter_frame = modifier_stack_ref[i].starting_frame
|
# enter_frame = modifier_stack_ref[i].starting_frame
|
||||||
i -= 1
|
# i -= 1
|
||||||
|
|
||||||
|
|
||||||
# if modifier_stack_ref.empty() == false: # a modifier is applied
|
# if modifier_stack_ref.empty() == false: # a modifier is applied
|
||||||
|
|
@ -222,43 +221,44 @@ func push_animation_state_modifier(modifier: StateModifier):
|
||||||
# where different modifier logic can be tested and developed.
|
# where different modifier logic can be tested and developed.
|
||||||
|
|
||||||
# First assure this modifer isn't already there. If it is, maybe I should reset it?
|
# First assure this modifer isn't already there. If it is, maybe I should reset it?
|
||||||
if modifier_stack_ref.has(modifier) == false:
|
# if modifier_stack_ref.has(modifier) == false:
|
||||||
modifier.enter() # call enter function of the modifier
|
# modifier.enter() # call enter function of the modifier
|
||||||
if modifier_stack_ref.size() > 0: # only bother with this if multiple modifers applied
|
# if modifier_stack_ref.size() > 0: # only bother with this if multiple modifers applied
|
||||||
# Get the last modifier in the stack
|
# # Get the last modifier in the stack
|
||||||
var last_modifer: StateModifier = modifier_stack_ref[-1]
|
# var last_modifer: StateModifier = modifier_stack_ref[-1]
|
||||||
# If the modifier at the back and the new one are the same type, we have a problem.
|
# # If the modifier at the back and the new one are the same type, we have a problem.
|
||||||
if last_modifer.modifier_type == modifier.modifier_type and last_modifer.modifier_type != 'None':
|
# if last_modifer.modifier_type == modifier.modifier_type and last_modifer.modifier_type != 'None':
|
||||||
print("WARNING: Multiple same type modifiers applying.")
|
# print("WARNING: Multiple same type modifiers applying.")
|
||||||
# Replace the modifier
|
# # Replace the modifier
|
||||||
modifier_stack_ref.pop_back()
|
# modifier_stack_ref.pop_back()
|
||||||
modifier_stack_ref.push_back(modifier)
|
# modifier_stack_ref.push_back(modifier)
|
||||||
else:
|
# else:
|
||||||
match last_modifer.modifier_type:
|
# match last_modifer.modifier_type:
|
||||||
"None":
|
# "None":
|
||||||
# no special processing, push it to the front of a list
|
# # no special processing, push it to the front of a list
|
||||||
modifier_stack_ref.push_front(modifier)
|
# modifier_stack_ref.push_front(modifier)
|
||||||
"Exit Animation":
|
# "Exit Animation":
|
||||||
if modifier.modifier_type == "Animation Suffix":
|
# if modifier.modifier_type == "Animation Suffix":
|
||||||
# We place this at the back so we can still modify it maybe?
|
# # We place this at the back so we can still modify it maybe?
|
||||||
modifier_stack_ref.push_back(modifier)
|
# modifier_stack_ref.push_back(modifier)
|
||||||
"Animation Suffix":
|
# "Animation Suffix":
|
||||||
if modifier.modifier_type == "Exit Animation":
|
# if modifier.modifier_type == "Exit Animation":
|
||||||
# We have to place this one right before maybe?
|
# # We have to place this one right before maybe?
|
||||||
# Whoops! Forgot to actually do this
|
# # Whoops! Forgot to actually do this
|
||||||
#modifier_stack_ref.push_back(modifier)
|
# #modifier_stack_ref.push_back(modifier)
|
||||||
modifier_stack_ref.insert(modifier_stack_ref.size() - 1, modifier)
|
# modifier_stack_ref.insert(modifier_stack_ref.size() - 1, modifier)
|
||||||
# if last_modifer.animation_name != '': # and if an animation applies
|
## if last_modifer.animation_name != '': # and if an animation applies
|
||||||
# if last_modifer.pre_append_animation == modifier.pre_append_animation: # They're the same type
|
## if last_modifer.pre_append_animation == modifier.pre_append_animation: # They're the same type
|
||||||
# if modifier.pre_append_animation == true and modifier_stack_ref[-1].animation_suffix == true:
|
## if modifier.pre_append_animation == true and modifier_stack_ref[-1].animation_suffix == true:
|
||||||
# modifier.animation_suffix
|
## modifier.animation_suffix
|
||||||
# modifier_stack_ref.push_back(modifier)
|
## modifier_stack_ref.push_back(modifier)
|
||||||
else:
|
# else:
|
||||||
modifier_stack_ref.push_front(modifier)
|
# modifier_stack_ref.push_front(modifier)
|
||||||
|
pass
|
||||||
|
|
||||||
func remove_animation_state_modifiers():
|
func remove_animation_state_modifiers():
|
||||||
for i in modifier_stack_ref.size():
|
# for i in modifier_stack_ref.size():
|
||||||
if modifier_stack_ref[i].modifier_type != "None":
|
# if modifier_stack_ref[i].modifier_type != "None":
|
||||||
#print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation + current_state.animation_suffix)
|
# #print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation + current_state.animation_suffix)
|
||||||
modifier_stack_ref.pop_at(i)
|
# modifier_stack_ref.pop_at(i)
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export (NodePath) var starting_state
|
||||||
export var debug_state_machine: bool = false
|
export var debug_state_machine: bool = false
|
||||||
|
|
||||||
var current_state: State
|
var current_state: State
|
||||||
var state_modifiers: Array
|
#var state_modifiers: Array
|
||||||
|
|
||||||
# Initialize the state machine by giving each child state a reference to the
|
# Initialize the state machine by giving each child state a reference to the
|
||||||
# parent object it belongs to and enter the default starting_state.
|
# parent object it belongs to and enter the default starting_state.
|
||||||
|
|
@ -13,7 +13,7 @@ func init() -> void:
|
||||||
if child is State:
|
if child is State:
|
||||||
if debug_state_machine:
|
if debug_state_machine:
|
||||||
print("Initializing State Node: ", child.name)
|
print("Initializing State Node: ", child.name)
|
||||||
child.modifier_stack_ref = state_modifiers
|
# child.modifier_stack_ref = state_modifiers
|
||||||
if debug_state_machine:
|
if debug_state_machine:
|
||||||
child.debug_state = true
|
child.debug_state = true
|
||||||
|
|
||||||
|
|
@ -27,10 +27,10 @@ func change_state(new_state: State) -> void:
|
||||||
|
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
current_state.enter()
|
current_state.enter()
|
||||||
if(state_modifiers.size() > 0 and debug_state_machine):
|
# if(state_modifiers.size() > 0 and debug_state_machine):
|
||||||
print("Active Modifiers:")
|
# print("Active Modifiers:")
|
||||||
for mods in state_modifiers:
|
# for mods in state_modifiers:
|
||||||
print(mods.name)
|
# print(mods.name)
|
||||||
|
|
||||||
# Pass through functions for the Player to call,
|
# Pass through functions for the Player to call,
|
||||||
# handling state changes as needed.
|
# handling state changes as needed.
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ func change_state(new_state: State) -> void:
|
||||||
|
|
||||||
current_state = new_state
|
current_state = new_state
|
||||||
current_state.enter()
|
current_state.enter()
|
||||||
if(state_modifiers.size() > 0 and debug_state_machine):
|
# if(state_modifiers.size() > 0 and debug_state_machine):
|
||||||
print("Active Modifiers:")
|
# print("Active Modifiers:")
|
||||||
for mods in state_modifiers:
|
# for mods in state_modifiers:
|
||||||
print(mods.name)
|
# print(mods.name)
|
||||||
|
|
||||||
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.)
|
||||||
|
|
@ -35,7 +35,7 @@ func init_animated_actor(parent: KinematicBody2D, animations: AnimatedSprite, mo
|
||||||
child.parent = parent
|
child.parent = parent
|
||||||
child.animations = animations
|
child.animations = animations
|
||||||
child.move_component = move_component
|
child.move_component = move_component
|
||||||
child.modifier_stack_ref = state_modifiers
|
# child.modifier_stack_ref = state_modifiers
|
||||||
if debug_state_machine:
|
if debug_state_machine:
|
||||||
child.debug_state = true
|
child.debug_state = true
|
||||||
|
|
||||||
|
|
@ -49,62 +49,34 @@ func process_frame(delta: float) -> void:
|
||||||
# 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
|
||||||
if state_modifiers[i].state_timeout.time_left == 0 and state_modifiers[i].timeout_seconds !=0:
|
# 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
|
# # Need to do extra stuff if it's an animation based one
|
||||||
if state_modifiers[i].modifier_type == "Animation Suffix":
|
# if state_modifiers[i].modifier_type == "Animation Suffix":
|
||||||
if debug_state_machine:
|
# if debug_state_machine:
|
||||||
print("State Modifier Timeout: ", state_modifiers[i].name, " -> ", state_modifiers[i].animation_name)
|
# print("State Modifier Timeout: ", state_modifiers[i].name, " -> ", state_modifiers[i].animation_name)
|
||||||
# Reset animation suffix
|
# # Reset animation suffix
|
||||||
current_anim_state.animation_suffix = ''
|
# current_anim_state.animation_suffix = ''
|
||||||
# Get the current frame of animation
|
# # Get the current frame of animation
|
||||||
var current_frame = current_anim_state.animations.frame
|
# var current_frame = current_anim_state.animations.frame
|
||||||
|
#
|
||||||
# Set the animation index to the current one
|
# # Set the animation index to the current one
|
||||||
current_anim_state.animation_index = current_anim_state.current_animation_sequence
|
# current_anim_state.animation_index = current_anim_state.current_animation_sequence
|
||||||
#current_anim_state.current_animation_sequence
|
# #current_anim_state.current_animation_sequence
|
||||||
#current_anim_state.animations.play()
|
# #current_anim_state.animations.play()
|
||||||
|
#
|
||||||
current_anim_state.animations.play(
|
# current_anim_state.animations.play(
|
||||||
current_anim_state.mod_animation_sequence[current_anim_state.animation_index])
|
# current_anim_state.mod_animation_sequence[current_anim_state.animation_index])
|
||||||
# Try to set the current frame to the same as before.
|
# # Try to set the current frame to the same as before.
|
||||||
current_anim_state.animations.frames.frames.size() >= current_frame
|
# current_anim_state.animations.frames.frames.size() >= current_frame
|
||||||
current_anim_state.animations.frame = current_frame
|
# current_anim_state.animations.frame = current_frame
|
||||||
|
#
|
||||||
##TODO:
|
# if debug_state_machine:
|
||||||
# no longer needed this way maybe. way to overengineer man.
|
# print("Pop State Modifier: ", state_modifiers[i].name)
|
||||||
# if current_anim_state.animation_sequence.size() >= current_anim_state.mod_animation_sequence.size():
|
# state_modifiers.pop_at(i)
|
||||||
# print("Change sequence!: ", current_anim_state.mod_animation_sequence)
|
|
||||||
# print("Origin sequence!: ", current_state.mod_animation_sequence)
|
|
||||||
# current_anim_state.animations.play(
|
|
||||||
# current_anim_state.mod_animation_sequence[current_anim_state.animation_index])
|
|
||||||
# # Try to set the current frame to the same as before.
|
|
||||||
# current_anim_state.animations.frames.frames.size() >= current_frame
|
|
||||||
# current_anim_state.animations.frame = current_frame
|
|
||||||
# else:
|
|
||||||
# current_anim_state.animations.play(
|
|
||||||
# current_anim_state.animation_sequence[0])
|
|
||||||
|
|
||||||
|
|
||||||
if debug_state_machine:
|
|
||||||
print("Pop State Modifier: ", state_modifiers[i].name)
|
|
||||||
state_modifiers.pop_at(i)
|
|
||||||
|
|
||||||
# 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)
|
var new_state = current_state.process_frame(delta)
|
||||||
if new_state:
|
if new_state:
|
||||||
change_state(new_state)
|
change_state(new_state)
|
||||||
|
|
@ -114,24 +86,17 @@ func _on_AnimatedSprite_animation_finished():
|
||||||
|
|
||||||
##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():
|
||||||
if state_modifiers[i].modifier_type == "Exit Animation":
|
# if state_modifiers[i].modifier_type == "Exit Animation":
|
||||||
#print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation + current_state.animation_suffix)
|
# #print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation + current_state.animation_suffix)
|
||||||
if (state_modifiers[i].animation_name + current_state.animation_suffix) == current_state.animations.animation:
|
# if (state_modifiers[i].animation_name + current_state.animation_suffix) == current_state.animations.animation:
|
||||||
print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation )
|
# print("Time to pop state modifer: ", state_modifiers[i].animation_name, current_state.animation_suffix, " <-> ", current_state.animations.animation )
|
||||||
print(current_state.mod_animation_sequence)
|
# print(current_state.mod_animation_sequence)
|
||||||
state_modifiers.pop_at(i)
|
# state_modifiers.pop_at(i)
|
||||||
current_state.animation_index += 1
|
# current_state.animation_index += 1
|
||||||
break
|
# break
|
||||||
|
|
||||||
|
|
||||||
# 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()
|
|
||||||
##TODO:
|
|
||||||
# consider just stopping the animation and index increment here.
|
|
||||||
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:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class_name StateModifier
|
class_name StateModifier
|
||||||
extends Node
|
extends Object
|
||||||
## 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,6 +10,8 @@ extends Node
|
||||||
##
|
##
|
||||||
## @WIP
|
## @WIP
|
||||||
|
|
||||||
|
enum type {NONE,EXIT_ANIMATION}
|
||||||
|
|
||||||
export var debug_state: bool = false
|
export var debug_state: bool = false
|
||||||
|
|
||||||
export var animation_name: String
|
export var animation_name: String
|
||||||
|
|
@ -59,7 +61,7 @@ func _ready():
|
||||||
state_timeout.wait_time = timeout_seconds
|
state_timeout.wait_time = timeout_seconds
|
||||||
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)
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
if debug_state:
|
if debug_state:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user