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
|
||||
|
||||
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
|
||||
# for modifiers
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ func merge_modifiers():
|
|||
for m in state_modifiers:
|
||||
if m is StateModifierAnimatedActor:
|
||||
#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.
|
||||
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:
|
||||
if state_modifiers.has(_state_modifier) == false:
|
||||
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())
|
||||
|
||||
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.
|
||||
## Pass through functions for the Player to call,
|
||||
## handling state changes as needed.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,18 @@ extends Reference
|
|||
##
|
||||
## @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
|
||||
|
||||
|
|
@ -22,7 +33,10 @@ var debug: bool = false
|
|||
var modifier_type = TYPE.NONE
|
||||
|
||||
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
|
||||
# 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.one_shot = true
|
||||
timeout.autostart = false
|
||||
timeout.connect("timeout",self,"deactivate")
|
||||
|
||||
func reset():
|
||||
name = ''
|
||||
|
|
@ -91,9 +106,19 @@ func copy(_copy_state: StateModifier):
|
|||
_copy_state.modifier_type = modifier_type
|
||||
|
||||
|
||||
func merge(_copy_state: StateModifier):
|
||||
func merge(_merge_from_modifier: StateModifier):
|
||||
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:
|
||||
# name = modifier_name
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
class_name StateModifierAnimatedActor
|
||||
extends StateModifier
|
||||
|
||||
|
||||
## Animation modifier variables
|
||||
## The name of the animation that could be applied and starting frame
|
||||
var animation_name: String = ''
|
||||
|
|
@ -43,10 +42,28 @@ func copy_StateModifierAnimatedActor(_copy_state: StateModifierAnimatedActor):
|
|||
_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
|
||||
func merge_StateModifierAnimatedActor(_merge_from_modifier: StateModifierAnimatedActor):
|
||||
.merge(_merge_from_modifier)
|
||||
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_speed = animation_speed
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ func _ready():
|
|||
attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,5.0)
|
||||
add_child(attack_sword.timeout)
|
||||
attack_sword.animation_name = 'PoopenStein'
|
||||
attack_sword.animation_suffix = '-attack_sword'
|
||||
add_state_modifier.call_func(attack_sword)
|
||||
|
||||
# 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():
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user