State modifier merge and signals. They mostly work.
This commit is contained in:
parent
c544a924c3
commit
a09be453da
|
|
@ -94,7 +94,10 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
|
||||||
# modifier = null
|
# modifier = null
|
||||||
|
|
||||||
if modifier:
|
if modifier:
|
||||||
print("hey you got one! -> ", modifier.name)
|
#print("hey you got one! -> ", modifier.animation_name)
|
||||||
|
match modifier.modifier_type:
|
||||||
|
StateModifier.TYPE.ANIMATION_SUFFIX:
|
||||||
|
print("hey you got one! -> ", modifier.animation_suffix)
|
||||||
|
|
||||||
# By Default, we build an animation sequence off of this state's before checking
|
# By Default, we build an animation sequence off of this state's before checking
|
||||||
# for modifiers
|
# for modifiers
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ func merge_modifiers():
|
||||||
for m in state_modifiers:
|
for m in state_modifiers:
|
||||||
if m is StateModifierAnimatedActor:
|
if m is StateModifierAnimatedActor:
|
||||||
#print(m.name)
|
#print(m.name)
|
||||||
m.merge_StateModifierAnimatedActor(merged_animation_state_modifiers)
|
if m.is_active:
|
||||||
|
merged_animation_state_modifiers.merge_StateModifierAnimatedActor(m)
|
||||||
|
|
||||||
# Change to the new state by first calling any exit logic on the current state.
|
# Change to the new state by first calling any exit logic on the current state.
|
||||||
func change_state(new_state: State) -> void:
|
func change_state(new_state: State) -> void:
|
||||||
|
|
@ -102,8 +103,14 @@ func get_state_reference(state_name: String) -> State:
|
||||||
func push_state_modifier(_state_modifier: StateModifier) -> void:
|
func push_state_modifier(_state_modifier: StateModifier) -> void:
|
||||||
if state_modifiers.has(_state_modifier) == false:
|
if state_modifiers.has(_state_modifier) == false:
|
||||||
state_modifiers.push_front(_state_modifier)
|
state_modifiers.push_front(_state_modifier)
|
||||||
|
_state_modifier.connect("modifier_event",self,"handle_modifier_events")
|
||||||
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
|
print("Add State Modifier: ", _state_modifier.name, " now size ", state_modifiers.size())
|
||||||
|
|
||||||
|
func handle_modifier_events(eventID :int):
|
||||||
|
if eventID == StateModifier.EVENT_ID.ACTIVATED:
|
||||||
|
print ("A mod activated! Which one though?")
|
||||||
|
merge_modifiers()
|
||||||
|
|
||||||
# Disable to test whether actually needed.
|
# Disable to test whether actually needed.
|
||||||
## 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.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,18 @@ extends Reference
|
||||||
##
|
##
|
||||||
## @WIP
|
## @WIP
|
||||||
|
|
||||||
enum TYPE {NONE,EXIT_ANIMATION, ANIMATION_SUFFIX, REPLACE_ANIMATION}
|
# Used for mutually exclusive modifiers to aid merging
|
||||||
|
enum TYPE {
|
||||||
|
NONE, # Usually just a physics modifier
|
||||||
|
EXIT_ANIMATION, # Adds an animation at the end? Not really sure anymore
|
||||||
|
ANIMATION_SUFFIX, # Adds an animation suffix to aid slightly modified animations
|
||||||
|
REPLACE_ANIMATION # Completely replaces a state animation.
|
||||||
|
}
|
||||||
|
|
||||||
|
enum EVENT_ID {
|
||||||
|
ACTIVATED,
|
||||||
|
DEACTIVATED
|
||||||
|
}
|
||||||
|
|
||||||
var debug: bool = false
|
var debug: bool = false
|
||||||
|
|
||||||
|
|
@ -22,7 +33,10 @@ var debug: bool = false
|
||||||
var modifier_type = TYPE.NONE
|
var modifier_type = TYPE.NONE
|
||||||
|
|
||||||
var name :String = ''
|
var name :String = ''
|
||||||
var ready :bool = false
|
#var ready :bool = false
|
||||||
|
var is_active: bool = false
|
||||||
|
|
||||||
|
signal modifier_event(event_id )
|
||||||
|
|
||||||
# Move Speed in Pixels Per Second
|
# Move Speed in Pixels Per Second
|
||||||
# These should only apply if Modification Type Set to None.
|
# These should only apply if Modification Type Set to None.
|
||||||
|
|
@ -81,6 +95,7 @@ func setup(modifier_name:String, type = TYPE.NONE,_timeout_seconds : float = 0):
|
||||||
timeout.wait_time = _timeout_seconds
|
timeout.wait_time = _timeout_seconds
|
||||||
timeout.one_shot = true
|
timeout.one_shot = true
|
||||||
timeout.autostart = false
|
timeout.autostart = false
|
||||||
|
timeout.connect("timeout",self,"deactivate")
|
||||||
|
|
||||||
func reset():
|
func reset():
|
||||||
name = ''
|
name = ''
|
||||||
|
|
@ -91,9 +106,19 @@ func copy(_copy_state: StateModifier):
|
||||||
_copy_state.modifier_type = modifier_type
|
_copy_state.modifier_type = modifier_type
|
||||||
|
|
||||||
|
|
||||||
func merge(_copy_state: StateModifier):
|
func merge(_merge_from_modifier: StateModifier):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func activate():
|
||||||
|
is_active = true
|
||||||
|
if timeout != null:
|
||||||
|
timeout.start()
|
||||||
|
emit_signal("modifier_event",EVENT_ID.ACTIVATED)
|
||||||
|
|
||||||
|
func deactivate():
|
||||||
|
is_active = false
|
||||||
|
print(name," <- Got call to deactivate.")
|
||||||
|
emit_signal("modifier_event",EVENT_ID.DEACTIVATED)
|
||||||
|
|
||||||
#func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
|
#func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
|
||||||
# name = modifier_name
|
# name = modifier_name
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
class_name StateModifierAnimatedActor
|
class_name StateModifierAnimatedActor
|
||||||
extends StateModifier
|
extends StateModifier
|
||||||
|
|
||||||
|
|
||||||
## Animation modifier variables
|
## Animation modifier variables
|
||||||
## The name of the animation that could be applied and starting frame
|
## The name of the animation that could be applied and starting frame
|
||||||
var animation_name: String = ''
|
var animation_name: String = ''
|
||||||
|
|
@ -43,10 +42,28 @@ func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
|
||||||
_copy_state.horizontal_speed = horizontal_speed
|
_copy_state.horizontal_speed = horizontal_speed
|
||||||
_copy_state.horizontal_acceleration = horizontal_acceleration
|
_copy_state.horizontal_acceleration = horizontal_acceleration
|
||||||
|
|
||||||
func merge_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
|
func merge_StateModifierAnimatedActor(_merge_from_modifier: StateModifierAnimatedActor):
|
||||||
.merge(_copy_state)
|
.merge(_merge_from_modifier)
|
||||||
_copy_state.animation_name += animation_name
|
if modifier_type == TYPE.NONE and _merge_from_modifier.modifier_type != TYPE.NONE:
|
||||||
|
modifier_type = _merge_from_modifier.modifier_type
|
||||||
|
|
||||||
|
#_copy_state.animation_name += animation_name
|
||||||
|
match _merge_from_modifier.modifier_type:
|
||||||
|
TYPE.ANIMATION_SUFFIX:
|
||||||
|
# Attempt to seemlessly transition animations.
|
||||||
|
if _merge_from_modifier.animation_suffix != '':
|
||||||
|
animation_suffix = _merge_from_modifier.animation_suffix
|
||||||
|
TYPE.REPLACE_ANIMATION:
|
||||||
|
if _merge_from_modifier.animation_name != '':
|
||||||
|
animation_name = _merge_from_modifier.animation_name
|
||||||
|
_: # None
|
||||||
|
#print ('physics?')
|
||||||
|
horizontal_speed += _merge_from_modifier.horizontal_speed
|
||||||
|
horizontal_acceleration += _merge_from_modifier.horizontal_acceleration
|
||||||
|
horizontal_speed_offset += _merge_from_modifier.horizontal_speed_offset
|
||||||
|
horizontal_speed_offset_acceleration += _merge_from_modifier.horizontal_speed_offset_acceleration
|
||||||
|
|
||||||
|
|
||||||
#_copy_state.animation_starting_frame = animation_starting_frame
|
#_copy_state.animation_starting_frame = animation_starting_frame
|
||||||
#_copy_state.animation_speed = animation_speed
|
#_copy_state.animation_speed = animation_speed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +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'
|
||||||
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!
|
||||||
|
|
@ -52,6 +53,7 @@ func _on_state_change_fall():
|
||||||
|
|
||||||
func _on_state_exited_attack_sword():
|
func _on_state_exited_attack_sword():
|
||||||
print("you just swung your sword, you should get a modifier.")
|
print("you just swung your sword, you should get a modifier.")
|
||||||
attack_sword.timeout.start()
|
#attack_sword.timeout.start()
|
||||||
|
attack_sword.activate()
|
||||||
print ("you has merged as? :" ,modifier.animation_name)
|
print ("you has merged as? :" ,modifier.animation_name)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user