Got a modifier signal into animation

This commit is contained in:
Dustin 2025-03-24 21:14:03 -07:00
parent 591c37dd60
commit f54f49704b
4 changed files with 110 additions and 69 deletions

View File

@ -54,6 +54,37 @@ region = Rect2( 0, 48, 48, 48 )
atlas = SubResource( 145 ) atlas = SubResource( 145 )
region = Rect2( 48, 48, 48, 48 ) region = Rect2( 48, 48, 48, 48 )
[sub_resource type="StreamTexture" id=151]
load_path = "res://.import/run-shoot.png-04896385acb8306189f1c45bb616220c.stex"
[sub_resource type="AtlasTexture" id=152]
atlas = SubResource( 151 )
region = Rect2( 0, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=153]
atlas = SubResource( 151 )
region = Rect2( 48, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=154]
atlas = SubResource( 151 )
region = Rect2( 96, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=155]
atlas = SubResource( 151 )
region = Rect2( 144, 0, 48, 48 )
[sub_resource type="AtlasTexture" id=156]
atlas = SubResource( 151 )
region = Rect2( 0, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=157]
atlas = SubResource( 151 )
region = Rect2( 48, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=158]
atlas = SubResource( 151 )
region = Rect2( 96, 48, 48, 48 )
[sub_resource type="StreamTexture" id=133] [sub_resource type="StreamTexture" id=133]
load_path = "res://.import/attack-stab.png-ef2ad659f974ce3d43d446e90b7c2f86.stex" load_path = "res://.import/attack-stab.png-ef2ad659f974ce3d43d446e90b7c2f86.stex"
@ -465,40 +496,37 @@ region = Rect2( 0, 96, 48, 48 )
atlas = SubResource( 18 ) atlas = SubResource( 18 )
region = Rect2( 48, 96, 48, 48 ) region = Rect2( 48, 96, 48, 48 )
[sub_resource type="StreamTexture" id=151] [sub_resource type="AtlasTexture" id=162]
load_path = "res://.import/run-shoot.png-04896385acb8306189f1c45bb616220c.stex"
[sub_resource type="AtlasTexture" id=152]
atlas = SubResource( 151 ) atlas = SubResource( 151 )
region = Rect2( 0, 0, 48, 48 ) region = Rect2( 96, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=153] [sub_resource type="AtlasTexture" id=163]
atlas = SubResource( 151 ) atlas = SubResource( 151 )
region = Rect2( 48, 0, 48, 48 ) region = Rect2( 144, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=154] [sub_resource type="AtlasTexture" id=159]
atlas = SubResource( 151 ) atlas = SubResource( 151 )
region = Rect2( 96, 0, 48, 48 ) region = Rect2( 144, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=155] [sub_resource type="AtlasTexture" id=160]
atlas = SubResource( 151 ) atlas = SubResource( 151 )
region = Rect2( 144, 0, 48, 48 ) region = Rect2( 0, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=156] [sub_resource type="AtlasTexture" id=161]
atlas = SubResource( 151 ) atlas = SubResource( 151 )
region = Rect2( 0, 48, 48, 48 ) region = Rect2( 48, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=157]
atlas = SubResource( 151 )
region = Rect2( 48, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=158]
atlas = SubResource( 151 )
region = Rect2( 96, 48, 48, 48 )
[sub_resource type="StreamTexture" id=111] [sub_resource type="StreamTexture" id=111]
load_path = "res://.import/run-sword.png-6e6a5a9983f4110cdd5e02e00d67da69.stex" load_path = "res://.import/run-sword.png-6e6a5a9983f4110cdd5e02e00d67da69.stex"
[sub_resource type="AtlasTexture" id=118]
atlas = SubResource( 111 )
region = Rect2( 0, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=119]
atlas = SubResource( 111 )
region = Rect2( 48, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=112] [sub_resource type="AtlasTexture" id=112]
atlas = SubResource( 111 ) atlas = SubResource( 111 )
region = Rect2( 0, 0, 48, 48 ) region = Rect2( 0, 0, 48, 48 )
@ -523,14 +551,6 @@ region = Rect2( 48, 48, 48, 48 )
atlas = SubResource( 111 ) atlas = SubResource( 111 )
region = Rect2( 96, 48, 48, 48 ) region = Rect2( 96, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=118]
atlas = SubResource( 111 )
region = Rect2( 0, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=119]
atlas = SubResource( 111 )
region = Rect2( 48, 96, 48, 48 )
[sub_resource type="StreamTexture" id=38] [sub_resource type="StreamTexture" id=38]
load_path = "res://.import/run-crouch.png-13dd70dd30935cf28b601677cc96319e.stex" load_path = "res://.import/run-crouch.png-13dd70dd30935cf28b601677cc96319e.stex"
@ -574,26 +594,6 @@ region = Rect2( 0, 96, 48, 48 )
atlas = SubResource( 38 ) atlas = SubResource( 38 )
region = Rect2( 48, 96, 48, 48 ) region = Rect2( 48, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=159]
atlas = SubResource( 151 )
region = Rect2( 144, 48, 48, 48 )
[sub_resource type="AtlasTexture" id=160]
atlas = SubResource( 151 )
region = Rect2( 0, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=161]
atlas = SubResource( 151 )
region = Rect2( 48, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=162]
atlas = SubResource( 151 )
region = Rect2( 96, 96, 48, 48 )
[sub_resource type="AtlasTexture" id=163]
atlas = SubResource( 151 )
region = Rect2( 144, 96, 48, 48 )
[sub_resource type="StreamTexture" id=124] [sub_resource type="StreamTexture" id=124]
load_path = "res://.import/walk.png-0d536fc31ef445aa94a97fccd3c71be9.stex" load_path = "res://.import/walk.png-0d536fc31ef445aa94a97fccd3c71be9.stex"
@ -642,6 +642,11 @@ animations = [ {
"name": "attack-shoot", "name": "attack-shoot",
"speed": 15.0 "speed": 15.0
}, { }, {
"frames": [ SubResource( 152 ), SubResource( 153 ), SubResource( 154 ), SubResource( 155 ), SubResource( 156 ), SubResource( 157 ), SubResource( 158 ), SubResource( 152 ) ],
"loop": false,
"name": "attack-shoot-run",
"speed": 13.0
}, {
"frames": [ SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 136 ), SubResource( 137 ), SubResource( 138 ), SubResource( 139 ) ], "frames": [ SubResource( 134 ), SubResource( 135 ), SubResource( 136 ), SubResource( 136 ), SubResource( 137 ), SubResource( 138 ), SubResource( 139 ) ],
"loop": false, "loop": false,
"name": "attack-stab", "name": "attack-stab",
@ -732,26 +737,21 @@ animations = [ {
"name": "run", "name": "run",
"speed": 13.0 "speed": 13.0
}, { }, {
"frames": [ SubResource( 152 ), SubResource( 153 ), SubResource( 154 ), SubResource( 155 ), SubResource( 156 ), SubResource( 157 ), SubResource( 158 ), SubResource( 152 ) ], "frames": [ SubResource( 162 ), SubResource( 152 ), SubResource( 163 ), SubResource( 153 ), SubResource( 154 ), SubResource( 159 ), SubResource( 160 ), SubResource( 161 ) ],
"loop": false, "loop": true,
"name": "run-attack-shoot", "name": "run-attack-shoot",
"speed": 13.0 "speed": 13.0
}, { }, {
"frames": [ SubResource( 112 ), SubResource( 113 ), SubResource( 114 ), SubResource( 115 ), SubResource( 116 ), SubResource( 117 ), SubResource( 118 ), SubResource( 119 ) ], "frames": [ SubResource( 118 ), SubResource( 119 ), SubResource( 112 ), SubResource( 113 ), SubResource( 114 ), SubResource( 115 ), SubResource( 116 ), SubResource( 117 ) ],
"loop": true, "loop": true,
"name": "run-attack-sword", "name": "run-attack-sword",
"speed": 13.0 "speed": 13.0
}, { }, {
"frames": [ SubResource( 39 ), SubResource( 40 ), SubResource( 41 ), SubResource( 42 ), SubResource( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ) ], "frames": [ SubResource( 39 ), SubResource( 40 ), SubResource( 41 ), SubResource( 42 ), SubResource( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ) ],
"loop": true, "loop": true,
"name": "run-crouch", "name": "run_crouch",
"speed": 10.0 "speed": 10.0
}, { }, {
"frames": [ SubResource( 153 ), SubResource( 154 ), SubResource( 159 ), SubResource( 160 ), SubResource( 161 ), SubResource( 162 ), SubResource( 152 ), SubResource( 163 ) ],
"loop": true,
"name": "run-shoot",
"speed": 13.0
}, {
"frames": [ SubResource( 125 ), SubResource( 126 ), SubResource( 127 ), SubResource( 128 ), SubResource( 129 ), SubResource( 130 ), SubResource( 131 ), SubResource( 132 ) ], "frames": [ SubResource( 125 ), SubResource( 126 ), SubResource( 127 ), SubResource( 128 ), SubResource( 129 ), SubResource( 130 ), SubResource( 131 ), SubResource( 132 ) ],
"loop": true, "loop": true,
"name": "walk", "name": "walk",

View File

@ -21,12 +21,16 @@ var previous_state_frame_number : int
var previous_state_name: String var previous_state_name: String
var previous_speed_multiplier: float var previous_speed_multiplier: float
var _frame_switch_tracker := -1
var _index_tracker := -1
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state') request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
add_state_modifier = funcref(get_node(callable_state_machine),'push_state_modifier') add_state_modifier = funcref(get_node(callable_state_machine),'push_state_modifier')
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change") get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
get_node(callable_state_machine).connect("modifiers_updated",self,"_on_modifiers_updated")
self.connect("animation_finished",self,"_on_animation_finished") self.connect("animation_finished",self,"_on_animation_finished")
#set current state since State machine might have set state before this #set current state since State machine might have set state before this
@ -38,6 +42,10 @@ func _ready():
# Sprites should only have a process function # Sprites should only have a process function
# but if I have this will the sprite still animate? # but if I have this will the sprite still animate?
func _process(delta): func _process(delta):
##TODO: Put in to try to buffer animation switches on frame change
if _frame_switch_tracker != -1 and frame == _frame_switch_tracker:
print ("time to switch", _frame_switch_tracker)
change_animation(_frame_switch_tracker, _index_tracker)
# Not sure what should be called first here. # Not sure what should be called first here.
if has_method('_state_process_' + current_state.name): if has_method('_state_process_' + current_state.name):
call('_state_process_' + current_state.name) call('_state_process_' + current_state.name)
@ -61,13 +69,14 @@ func _on_animation_finished():
func change_animation(enter_frame := 0, index := 0, suffix := ''): func change_animation(enter_frame := 0, index := 0, suffix := ''):
## TODO: ## TODO:
# Need to find a way to attempt to keep and transfer the Index or frame # Need to find a way to attempt to keep and transfer the Index or frame
if modifier: if modifier:
#print("hey you got one! -> ", modifier.animation_name) #print("hey you got one! -> ", modifier.animation_name)
match modifier.modifier_type: match modifier.modifier_type:
StateModifier.TYPE.ANIMATION_SUFFIX: StateModifier.TYPE.ANIMATION_SUFFIX:
print("hey you got one! -> ", modifier.animation_suffix) print("hey you got one! -> ", modifier.animation_suffix)
_frame_switch_tracker = -1
_index_tracker = -1
# 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
var animation_sequence = current_state.animation_sequence var animation_sequence = current_state.animation_sequence
@ -85,11 +94,11 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
match modifier.modifier_type: match modifier.modifier_type:
modifier.TYPE.ANIMATION_SUFFIX: modifier.TYPE.ANIMATION_SUFFIX:
# Check that this animation actually exists # Check that this animation actually exists
if frames.has_animation(mod_animation_sequence[animation_index] + modifier.animation_suffix): if frames.has_animation(mod_animation_sequence[animation_index] + '-' + modifier.animation_suffix):
animation_suffix = modifier.animation_suffix animation_suffix = modifier.animation_suffix
else: else:
push_warning("Modifier attempting to apply suffix that doesn't exist" + push_warning("Modifier attempting to apply suffix that doesn't exist" +
(mod_animation_sequence[animation_index] + modifier.animation_suffix)) (mod_animation_sequence[animation_index] + '-' + modifier.animation_suffix))
modifier.TYPE.REPLACE_ANIMATION: modifier.TYPE.REPLACE_ANIMATION:
if frames.has_animation(modifier.animation_name): if frames.has_animation(modifier.animation_name):
mod_animation_sequence.clear() mod_animation_sequence.clear()
@ -143,9 +152,14 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
if mod_animation_sequence.size() > 0: if mod_animation_sequence.size() > 0:
if current_state.debug_state: if current_state.debug_state:
print("Starting Animation: " , mod_animation_sequence[animation_index] + animation_suffix) print("Starting Animation: " , mod_animation_sequence[animation_index] + animation_suffix)
play(mod_animation_sequence[animation_index] + animation_suffix) if animation_suffix != '':
play(mod_animation_sequence[animation_index] + '-' + animation_suffix)
else:
play(mod_animation_sequence[animation_index])
#TODO: maybe check current animatio has this frame #TODO: maybe check current animatio has this frame
frame = enter_frame if enter_frame != 0:
print ("alternate starting frame:", enter_frame)
frame = enter_frame
else: else:
print("Error! Resolved to empty animation sequence!?") print("Error! Resolved to empty animation sequence!?")
return return
@ -232,4 +246,21 @@ func _on_state_change(old_state_name:String, new_state :State):
else: else:
push_warning("Received non animated Actor state.") push_warning("Received non animated Actor state.")
#current_state = new_state #current_state = new_state
func _on_modifiers_updated(_modifier_type :int, _modifier_action :int):
##TODO: There's so many things I could maybe do here but lets target the
## current use case.
if _modifier_type == StateModifierAnimatedActor.TYPE.ANIMATION_SUFFIX:
print("A: ", animation, " F: ", frame, " -Modifier Changed Signal")
# Wait for frame to finish before doing anything.
#yield(self, "frame_changed")
if _modifier_action == StateModifierAnimatedActor.EVENT_ID.DEACTIVATED:
if frame != 0 and frame != frames.get_frame_count(animation):
print ("lets change the animation suffix frame:", frame)
var current_frame = frame
#yield(self, "frame_changed")
#while current_frame == frame:
# print("waiting...")
#change_animation(frame + 1 ,animation_index)
_frame_switch_tracker = frame + 1
_index_tracker = animation_index

View File

@ -8,7 +8,7 @@ export var debug_state_machine: bool = false
#var starting_state: State #var starting_state: State
signal state_changed(old_state_name, new_state) signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid)
var current_state: State var current_state: State
var state_modifiers: Array var state_modifiers: Array
@ -61,6 +61,7 @@ func _physics_process(delta):
merge_modifiers() merge_modifiers()
func merge_modifiers(): func merge_modifiers():
merged_animation_state_modifiers.reset()
for m in state_modifiers: for m in state_modifiers:
if m is StateModifierAnimatedActor: if m is StateModifierAnimatedActor:
#print(m.name) #print(m.name)
@ -111,6 +112,11 @@ func handle_modifier_events(eventID :int):
if eventID == StateModifier.EVENT_ID.ACTIVATED: if eventID == StateModifier.EVENT_ID.ACTIVATED:
print ("A mod activated! Which one though?") print ("A mod activated! Which one though?")
merge_modifiers() merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
elif eventID == StateModifier.EVENT_ID.DEACTIVATED:
merge_modifiers()
emit_signal("modifiers_updated",merged_animation_state_modifiers.modifier_type, eventID)
# 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,

View File

@ -11,11 +11,15 @@ func _ready():
state_ref.connect("state_exited", self, "_on_state_exited_attack_sword") state_ref.connect("state_exited", self, "_on_state_exited_attack_sword")
attack_sword = StateModifierAnimatedActor.new() attack_sword = StateModifierAnimatedActor.new()
attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,5.0) attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,2.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' attack_sword.animation_suffix = 'attack-sword'
add_state_modifier.call_func(attack_sword) add_state_modifier.call_func(attack_sword)
# Testing
#speed_scale = .1
# 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!
#func _state_process_idle(): #func _state_process_idle():