Refactor signal logic

This commit is contained in:
2026-03-15 13:06:21 -05:00
parent 1c95315496
commit 8bcf406576
21 changed files with 234 additions and 223 deletions

View File

@@ -1,22 +1,22 @@
extends Node2D
class_name PlayerSprite
# Signals
signal DrawingBowAnimationFinished
signal FiringArrowAnimationFinished
signal AnimationFinished(animation_name: String)
# Exports
@export var state_machine: PlayerStateMachine
@export var direction_component: FacingDirectionComponent
# OnReady Variables
@onready var full: AnimatedSprite2D = $Full
@onready var base: AnimatedSprite2D = $Base
@onready var hair: AnimatedSprite2D = $Hair
@onready var pants: AnimatedSprite2D = $Pants
@onready var hands: AnimatedSprite2D = $Hands
@onready var shoes: AnimatedSprite2D = $Shoes
var all_parts: Array[AnimatedSprite2D]
var current_animation := "idle-down"
var is_flipped := false
# Private Variables
var _all_parts: Array[AnimatedSprite2D]
var _current_animation := "idle-down"
var _is_flipped := false
# Public Methods
func UpdateSprite() -> void:
@@ -25,37 +25,37 @@ func UpdateSprite() -> void:
var animation := _build_animation_name(current_state, current_direction)
var should_flip := _should_flip_horizontal()
if animation == current_animation and should_flip == is_flipped:
if animation == _current_animation and should_flip == _is_flipped:
return
current_animation = animation
is_flipped = should_flip
_current_animation = animation
_is_flipped = should_flip
for part in all_parts:
for part in _all_parts:
part.animation = animation
part.play()
part.flip_h = should_flip
func OnAnimationFinished() -> void:
if current_animation.begins_with("drawing-bow-"):
if _current_animation.begins_with("drawing-bow-"):
DrawingBowAnimationFinished.emit()
elif current_animation.begins_with("firing-arrow-"):
elif _current_animation.begins_with("firing-arrow-"):
FiringArrowAnimationFinished.emit()
AnimationFinished.emit(current_animation)
AnimationFinished.emit(_current_animation)
func PlaySpecifiedAnimation(animation_name: String) -> void:
current_animation = animation_name
for part in all_parts:
_current_animation = animation_name
for part in _all_parts:
part.animation = animation_name
part.play()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
all_parts = [
full, #base, hair, pants, hands, shoes
_all_parts = [
full
]
UpdateSprite()
@@ -63,8 +63,8 @@ func _ready() -> void:
func _build_animation_name(state: BaseState, direction: Enums.Directions) -> String:
# e.g. "idle-down", "walking-up"
var state_str = state.GetAnimationBaseName().replace("_", "-")
var direction_str = _direction_to_animation_state(direction)
var state_str := state.GetAnimationBaseName().replace("_", "-")
var direction_str := _direction_to_animation_state(direction)
return "%s-%s" % [state_str, direction_str]