More state modifier work. Repeating old mistakes.
This commit is contained in:
parent
d9b5d27855
commit
c544a924c3
|
|
@ -9,6 +9,9 @@ export var callable_state_machine :NodePath
|
|||
|
||||
onready var current_state = StateAnimatedActor.new()
|
||||
|
||||
#var state_machine_modifiers: Array
|
||||
var modifier: StateModifierAnimatedActor
|
||||
|
||||
#var animation_finished: bool = false
|
||||
var request_state_change: FuncRef
|
||||
var add_state_modifier: FuncRef
|
||||
|
|
@ -41,6 +44,8 @@ func _ready():
|
|||
#set current state since State machine might have set state before this
|
||||
# processed
|
||||
current_state = get_node(callable_state_machine).current_state
|
||||
#state_machine_modifiers = get_node(callable_state_machine).state_modifiers
|
||||
modifier = get_node(callable_state_machine).merged_animation_state_modifiers
|
||||
|
||||
# Sprites should only have a process function
|
||||
# but if I have this will the sprite still animate?
|
||||
|
|
@ -88,8 +93,8 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
|||
# if modifier.state_timeout and modifier.timeout_seconds == 0:
|
||||
# modifier = null
|
||||
|
||||
if current_state.modifier:
|
||||
print("hey you got one! -> ", current_state.modifier.name)
|
||||
if modifier:
|
||||
print("hey you got one! -> ", modifier.name)
|
||||
|
||||
# By Default, we build an animation sequence off of this state's before checking
|
||||
# for modifiers
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ signal state_exited()
|
|||
var state_timeout: Timer
|
||||
var state_ready: bool = true
|
||||
|
||||
var modifier: StateModifier
|
||||
|
||||
export var name: String
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
|
@ -57,7 +55,6 @@ func enter() -> void:
|
|||
|
||||
func exit() -> void:
|
||||
emit_signal("state_exited")
|
||||
modifier = null
|
||||
return
|
||||
|
||||
# Disable to test whether actually needed.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ signal state_changed(old_state_name, new_state)
|
|||
|
||||
var current_state: State
|
||||
var state_modifiers: Array
|
||||
onready var merged_animation_state_modifiers :StateModifierAnimatedActor = StateModifierAnimatedActor.new()
|
||||
|
||||
export var starting_state_name = 'default'
|
||||
export(Array,Resource) var states
|
||||
|
|
@ -53,6 +54,18 @@ func _ready():
|
|||
push_error("State machine cannot find starting state: " + starting_state_name)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if(state_modifiers.size() > 0):
|
||||
merged_animation_state_modifiers.reset()
|
||||
merged_animation_state_modifiers.animation_name = 'floopy doo,'
|
||||
merge_modifiers()
|
||||
|
||||
func merge_modifiers():
|
||||
for m in state_modifiers:
|
||||
if m is StateModifierAnimatedActor:
|
||||
#print(m.name)
|
||||
m.merge_StateModifierAnimatedActor(merged_animation_state_modifiers)
|
||||
|
||||
# Change to the new state by first calling any exit logic on the current state.
|
||||
func change_state(new_state: State) -> void:
|
||||
var current_state_name :String
|
||||
|
|
@ -63,12 +76,12 @@ func change_state(new_state: State) -> void:
|
|||
current_state = new_state
|
||||
current_state.enter()
|
||||
|
||||
if(state_modifiers.size() > 0):
|
||||
print("Active Modifiers:")
|
||||
for mods in state_modifiers:
|
||||
if mods is AnimationStateModifier:
|
||||
print(mods.name, "asm")
|
||||
current_state.modifier = mods #mods.copy_AnimationStateModifier(AnimationStateModifier.new())
|
||||
# if(state_modifiers.size() > 0):
|
||||
# print("Active Modifiers:")
|
||||
# for mods in state_modifiers:
|
||||
# if mods is StateModifierAnimatedActor:
|
||||
# print(mods.name, " <- asm")
|
||||
|
||||
|
||||
emit_signal("state_changed",current_state_name,current_state)
|
||||
|
||||
|
|
|
|||
|
|
@ -82,10 +82,15 @@ func setup(modifier_name:String, type = TYPE.NONE,_timeout_seconds : float = 0):
|
|||
timeout.one_shot = true
|
||||
timeout.autostart = false
|
||||
|
||||
func reset():
|
||||
name = ''
|
||||
modifier_type = TYPE.NONE
|
||||
|
||||
func copy(_copy_state: StateModifier):
|
||||
_copy_state.name = name
|
||||
_copy_state.modifier_type = modifier_type
|
||||
|
||||
|
||||
func merge(_copy_state: StateModifier):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,55 @@
|
|||
class_name AnimationStateModifier
|
||||
class_name StateModifierAnimatedActor
|
||||
extends StateModifier
|
||||
|
||||
|
||||
## Animation modifier variables
|
||||
## The name of the animation that could be applied and starting frame
|
||||
var animation_name: String = ''
|
||||
var animation_suffix: String = ''
|
||||
var animation_starting_frame: int = 0
|
||||
var animation_speed: float
|
||||
|
||||
func copy_AnimationStateModifier(_copy_state: AnimationStateModifier):
|
||||
var horizontal_speed: float = 0
|
||||
var horizontal_acceleration: float = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
var horizontal_speed_offset: float = 0
|
||||
## Applies only if offset applies
|
||||
var horizontal_speed_offset_acceleration: float = 0
|
||||
var jerk_factor: float = 0
|
||||
|
||||
var gravity: int = 0
|
||||
|
||||
func reset():
|
||||
.reset()
|
||||
animation_name = ''
|
||||
animation_suffix = ''
|
||||
animation_starting_frame = 0
|
||||
|
||||
horizontal_speed = 0
|
||||
horizontal_acceleration = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
horizontal_speed_offset = 0
|
||||
## Applies only if offset applies
|
||||
horizontal_speed_offset_acceleration = 0
|
||||
jerk_factor = 0
|
||||
|
||||
func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
|
||||
.copy(_copy_state)
|
||||
_copy_state.animation_name = animation_name
|
||||
_copy_state.animation_starting_frame = animation_starting_frame
|
||||
_copy_state.animation_speed = animation_speed
|
||||
|
||||
#TODO: finish these
|
||||
_copy_state.horizontal_speed = horizontal_speed
|
||||
_copy_state.horizontal_acceleration = horizontal_acceleration
|
||||
|
||||
func merge_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
|
||||
.merge(_copy_state)
|
||||
_copy_state.animation_name += animation_name
|
||||
|
||||
#_copy_state.animation_starting_frame = animation_starting_frame
|
||||
#_copy_state.animation_speed = animation_speed
|
||||
|
||||
|
||||
# This is probably not necessary just access properties directly
|
||||
#func animation_mod_setup( anim_name:String = ''):
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
class_name MovementStateModifier
|
||||
extends StateModifier
|
||||
|
||||
|
||||
var horizontal_speed: float = 0
|
||||
var horizontal_acceleration: float = 0
|
||||
## Movement Speed Offsets (Positive or Negative)
|
||||
var horizontal_speed_offset: float = 0
|
||||
## Applies only if offset applies
|
||||
var horizontal_speed_offset_acceleration: float = 0
|
||||
var jerk_factor: float = 0
|
||||
|
||||
var gravity: int = 0
|
||||
|
||||
|
|
@ -19,11 +19,6 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://lib/classes/animated_sprite_state_receiver.gd"
|
||||
}, {
|
||||
"base": "StateModifier",
|
||||
"class": "AnimationStateModifier",
|
||||
"language": "GDScript",
|
||||
"path": "res://lib/classes/state_modifier_animation.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "DEPR_ModifierProperties",
|
||||
"language": "GDScript",
|
||||
|
|
@ -74,11 +69,6 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://src/classes/movement_component.gd"
|
||||
}, {
|
||||
"base": "StateModifier",
|
||||
"class": "MovementStateModifier",
|
||||
"language": "GDScript",
|
||||
"path": "res://lib/classes/state_modifier_movement.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "Movement_StateReceiver",
|
||||
"language": "GDScript",
|
||||
|
|
@ -108,11 +98,15 @@ _global_script_classes=[ {
|
|||
"class": "StateModifier",
|
||||
"language": "GDScript",
|
||||
"path": "res://lib/classes/state_modifier.gd"
|
||||
}, {
|
||||
"base": "StateModifier",
|
||||
"class": "StateModifierAnimatedActor",
|
||||
"language": "GDScript",
|
||||
"path": "res://lib/classes/state_modifier_animation.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"Actor": "",
|
||||
"AnimatedSprite_StateReceiver": "",
|
||||
"AnimationStateModifier": "",
|
||||
"DEPR_ModifierProperties": "",
|
||||
"DumbOldStateModifier": "",
|
||||
"GitAPI": "",
|
||||
|
|
@ -123,13 +117,13 @@ _global_script_class_icons={
|
|||
"Level": "",
|
||||
"Modifier_Receiver": "",
|
||||
"MovementComponent": "",
|
||||
"MovementStateModifier": "",
|
||||
"Movement_StateReceiver": "",
|
||||
"State": "",
|
||||
"StateAnimatedActor": "",
|
||||
"StateMachine": "",
|
||||
"StateMachineAnimatedActor": "",
|
||||
"StateModifier": ""
|
||||
"StateModifier": "",
|
||||
"StateModifierAnimatedActor": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
extends AnimatedSprite_StateReceiver
|
||||
|
||||
var attack_sword: AnimationStateModifier
|
||||
var attack_sword: StateModifierAnimatedActor
|
||||
|
||||
func _ready():
|
||||
# Lets see if this nutty thing works
|
||||
|
|
@ -10,9 +10,10 @@ func _ready():
|
|||
state_ref = get_node(callable_state_machine).get_state_reference('attack_sword')
|
||||
state_ref.connect("state_exited", self, "_on_state_exited_attack_sword")
|
||||
|
||||
attack_sword = AnimationStateModifier.new()
|
||||
attack_sword = StateModifierAnimatedActor.new()
|
||||
attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,5.0)
|
||||
add_child(attack_sword.timeout)
|
||||
attack_sword.animation_name = 'PoopenStein'
|
||||
add_state_modifier.call_func(attack_sword)
|
||||
|
||||
# I don't need this right now but I proved it can be done!
|
||||
|
|
@ -52,4 +53,5 @@ func _on_state_change_fall():
|
|||
func _on_state_exited_attack_sword():
|
||||
print("you just swung your sword, you should get a modifier.")
|
||||
attack_sword.timeout.start()
|
||||
print ("you has merged as? :" ,modifier.animation_name)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user