Compare commits

..

2 Commits

Author SHA1 Message Date
f54f49704b Got a modifier signal into animation 2025-03-24 21:14:03 -07:00
591c37dd60 Start of some working animation modifiers applied. 2025-03-23 19:28:18 -07:00
4 changed files with 138 additions and 110 deletions

View File

@ -54,6 +54,37 @@ region = Rect2( 0, 48, 48, 48 )
atlas = SubResource( 145 )
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]
load_path = "res://.import/attack-stab.png-ef2ad659f974ce3d43d446e90b7c2f86.stex"
@ -465,40 +496,37 @@ region = Rect2( 0, 96, 48, 48 )
atlas = SubResource( 18 )
region = Rect2( 48, 96, 48, 48 )
[sub_resource type="StreamTexture" id=151]
load_path = "res://.import/run-shoot.png-04896385acb8306189f1c45bb616220c.stex"
[sub_resource type="AtlasTexture" id=152]
[sub_resource type="AtlasTexture" id=162]
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 )
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 )
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 )
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 )
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 )
region = Rect2( 48, 96, 48, 48 )
[sub_resource type="StreamTexture" id=111]
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]
atlas = SubResource( 111 )
region = Rect2( 0, 0, 48, 48 )
@ -523,14 +551,6 @@ region = Rect2( 48, 48, 48, 48 )
atlas = SubResource( 111 )
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]
load_path = "res://.import/run-crouch.png-13dd70dd30935cf28b601677cc96319e.stex"
@ -574,26 +594,6 @@ region = Rect2( 0, 96, 48, 48 )
atlas = SubResource( 38 )
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]
load_path = "res://.import/walk.png-0d536fc31ef445aa94a97fccd3c71be9.stex"
@ -642,6 +642,11 @@ animations = [ {
"name": "attack-shoot",
"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 ) ],
"loop": false,
"name": "attack-stab",
@ -732,26 +737,21 @@ animations = [ {
"name": "run",
"speed": 13.0
}, {
"frames": [ SubResource( 152 ), SubResource( 153 ), SubResource( 154 ), SubResource( 155 ), SubResource( 156 ), SubResource( 157 ), SubResource( 158 ), SubResource( 152 ) ],
"loop": false,
"frames": [ SubResource( 162 ), SubResource( 152 ), SubResource( 163 ), SubResource( 153 ), SubResource( 154 ), SubResource( 159 ), SubResource( 160 ), SubResource( 161 ) ],
"loop": true,
"name": "run-attack-shoot",
"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,
"name": "run-attack-sword",
"speed": 13.0
}, {
"frames": [ SubResource( 39 ), SubResource( 40 ), SubResource( 41 ), SubResource( 42 ), SubResource( 43 ), SubResource( 44 ), SubResource( 45 ), SubResource( 46 ), SubResource( 47 ), SubResource( 48 ) ],
"loop": true,
"name": "run-crouch",
"name": "run_crouch",
"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 ) ],
"loop": true,
"name": "walk",

View File

@ -1,26 +1,15 @@
class_name AnimatedSprite_StateReceiver
extends AnimatedSprite
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
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
# this just wouldn't work well. Maybe I can try a resource
# export(Array, NodePath) var transition_state_nodes
#TODO: I think these two variables accidentally serve the same purpose
# I think one was intended to be a string of the current animation name.
var animation_index: int = 0
var current_animation_sequence: int = 0
var animation_suffix: String = '';
@ -32,6 +21,8 @@ var previous_state_frame_number : int
var previous_state_name: String
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.
func _ready():
@ -39,6 +30,7 @@ func _ready():
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("modifiers_updated",self,"_on_modifiers_updated")
self.connect("animation_finished",self,"_on_animation_finished")
#set current state since State machine might have set state before this
@ -50,15 +42,10 @@ func _ready():
# Sprites should only have a process function
# but if I have this will the sprite still animate?
func _process(delta):
# Shouldn't need this anymore!
# if current_state.state_timeout != null:
# if current_state.state_timeout.time_left == 0:
# print("You're out of time! I saw it!")
# request_state_change.call_func('idle')
# #play()
# else:
# print("what, no current_state?")
##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.
if has_method('_state_process_' + current_state.name):
call('_state_process_' + current_state.name)
@ -76,28 +63,19 @@ func _on_animation_finished():
current_state.animation_finished = true
# TODO: Allow a way to stop animation even if in a looped sequence
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
# If called, this will attempt to make the most appropriate animation change
# would likely be triggered from an animation sequence finishing or a
# modifier being applied/removed outside of enter/exit transitions.
func change_animation(enter_frame := 0, index := 0, suffix := ''):
## TODO:
# Need to find a way to attempt to keep and transfer the Index or frame
#
# if clear_modifier:
# print("Goodbye Modifiers!")
# modifier = null
# if modifier:
# if modifier.state_timeout and modifier.timeout_seconds == 0:
# modifier = null
if modifier:
#print("hey you got one! -> ", modifier.animation_name)
match modifier.modifier_type:
StateModifier.TYPE.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
# for modifiers
@ -109,6 +87,23 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
animation_suffix = suffix
animation_index = index
current_animation_sequence = animation_index
if modifier:
#TODO: Apply the animation starting frame
#modifier.animation_starting_frame
match modifier.modifier_type:
modifier.TYPE.ANIMATION_SUFFIX:
# Check that this animation actually exists
if frames.has_animation(mod_animation_sequence[animation_index] + '-' + modifier.animation_suffix):
animation_suffix = modifier.animation_suffix
else:
push_warning("Modifier attempting to apply suffix that doesn't exist" +
(mod_animation_sequence[animation_index] + '-' + modifier.animation_suffix))
modifier.TYPE.REPLACE_ANIMATION:
if frames.has_animation(modifier.animation_name):
mod_animation_sequence.clear()
mod_animation_sequence.push_back(modifier.animation_name)
enter_frame = modifier.animation_starting_frame
#var enter_animation = ''
#var enter_frame = 0
# var modifier :StateModifier = current_state.modifier
@ -157,8 +152,13 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
if mod_animation_sequence.size() > 0:
if current_state.debug_state:
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
if enter_frame != 0:
print ("alternate starting frame:", enter_frame)
frame = enter_frame
else:
print("Error! Resolved to empty animation sequence!?")
@ -218,15 +218,15 @@ func change_animation(enter_frame := 0, index := 0, suffix := ''):
# else:
# frame_signal_emitted = false
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.)
if old_state.mod_animation_sequence:
new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence]
new_state.previous_state_frame_number = old_state.animations.frame
new_state.previous_state_name = old_state.name
new_state.previous_speed_multiplier = old_state.speed_multiplier
#animation_name :String, frame_number : int, animation_sequence :Array
return
#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.)
# if old_state.mod_animation_sequence:
# new_state.previous_animation_name = old_state.mod_animation_sequence[old_state.current_animation_sequence]
# new_state.previous_state_frame_number = old_state.animations.frame
# new_state.previous_state_name = old_state.name
# new_state.previous_speed_multiplier = old_state.speed_multiplier
# #animation_name :String, frame_number : int, animation_sequence :Array
# return
# Handle state change from subscribed state machine.
#From signal state_changed(old_state_name, new_state)
@ -247,3 +247,20 @@ func _on_state_change(old_state_name:String, new_state :State):
push_warning("Received non animated Actor 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
signal state_changed(old_state_name, new_state)
signal modifiers_updated(modifier_type, modifier_eventid)
var current_state: State
var state_modifiers: Array
@ -61,6 +61,7 @@ func _physics_process(delta):
merge_modifiers()
func merge_modifiers():
merged_animation_state_modifiers.reset()
for m in state_modifiers:
if m is StateModifierAnimatedActor:
#print(m.name)
@ -77,6 +78,7 @@ func change_state(new_state: State) -> void:
current_state = new_state
current_state.enter()
# Seems like I don't have to do this every state change!
# if(state_modifiers.size() > 0):
# print("Active Modifiers:")
# for mods in state_modifiers:
@ -110,6 +112,11 @@ func handle_modifier_events(eventID :int):
if eventID == StateModifier.EVENT_ID.ACTIVATED:
print ("A mod activated! Which one though?")
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.
## Pass through functions for the Player to call,

View File

@ -11,12 +11,16 @@ func _ready():
state_ref.connect("state_exited", self, "_on_state_exited_attack_sword")
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)
attack_sword.animation_name = 'PoopenStein'
attack_sword.animation_suffix = '-attack_sword'
#attack_sword.animation_name = 'PoopenStein'
attack_sword.animation_suffix = '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!
#func _state_process_idle():
# print("I got called!")
@ -41,10 +45,10 @@ func _ready():
# frame = 2
# stop()
func _on_state_change_idle():
change_animation()
if previous_state_name == 'attack_sword':
animation = 'idle-attack-sword'
#func _on_state_change_idle():
# change_animation()
# if previous_state_name == 'attack_sword':
# animation = 'idle-attack-sword'
func _on_state_change_fall():
change_animation()