053 | State - Part 5: Refactor Animation Logic#53
053 | State - Part 5: Refactor Animation Logic#53Pedrohamoura-Git wants to merge 4 commits intofeat/068from
Conversation
…TE constants and update AnimationComponent to remove currentState property
There was a problem hiding this comment.
Pull request overview
This PR continues the ECS “state” refactor by making gameplay systems (movement/animation) respect the entity’s StateComponent, and by aligning sprite-model animation keys with the canonical CHARACTER_STATE constants.
Changes:
- Gate movement intent updates on
state.aliveState === ALIVEinMovementSystem. - Drive animation selection from
state.characterStateinAnimationSystemand removeAnimationComponent.currentState. - Update
CHARACTERS_SPRITES_MODELbase sprite definitions to useCHARACTER_STATE.*constants instead of raw string literals.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/client/src/game/ecs/systems/movement/MovementSystem.ts | Skips movement updates for dead entities by checking state.aliveState. |
| packages/client/src/game/ecs/systems/animation/AnimationSystem.ts | Chooses animation based on state.characterState rather than an animation-local state field. |
| packages/client/src/game/ecs/components/animation/AnimationComponent.ts | Removes currentState from the animation component shape. |
| packages/client/src/game/config/constants/character/sprite-model/characterSpriteModel.ts | Uses CHARACTER_STATE constants for sprite config keys (typed as CharacterState). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
anatfernandes
left a comment
There was a problem hiding this comment.
I believe these changes should not be implemented as they break animations for all other entities. The AnimationSystem was designed to be generic and reusable, coupling it specifically to player states prevents other animated entities from functioning correctly (or forces them to implement unnecessary states just to stay functional).
To fix the player's animations, the individual state handlers should be responsible for updating the animation.currentState. This prevents system-level coupling and ensures all animations remain decoupled and functional.
| entities.forEach(({ input, movement }) => { | ||
| if (!input || !movement) return; | ||
| entities.forEach(({ input, movement, state }) => { | ||
| if (!input || !movement || !state || state.aliveState !== ALIVE_STATE.ALIVE) return; |
There was a problem hiding this comment.
With this additional validation, the MovementSystem becomes restricted once again to moving only players. This prevents other moving entities, such as platforms or projectiles, from functioning correctly. Since this system is designed to be generic and reusable, I recommend removing this check and handling death as a separate concern, perhaps in future tasks focused on respawn and health mechanics.
Information
Describe What Was Done
DEADstate.Detailed Summary (AI Generated)
🤖| Summary
This Pull Request refactors existing game character animation configurations, components, and systems to use standardized state constants. Additionally, it introduces minor updates to corresponding game logic for improved consistency and handling.
Refactor: Standardization of Character State Keys
BASE_CHARACTER_SPRITESincharacterSpriteModel.tsto replace hardcoded animation state keys with dynamic constants imported fromCHARACTER_STATE.'IDLE'→CHARACTER_STATE.IDLE,'RUN'→CHARACTER_STATE.RUN, and others.CHARACTER_STATEfrom the appropriate module to align animation configuration constants across the codebase.Changes to Animation System
AnimationSystem.ts:animation.currentStatewithstate.characterStateto align with the new state management structure.stateproperty exists before updating animation behavior.Changes to Movement System
MovementSystem.ts:state.aliveStateis equal toALIVE_STATE.ALIVE. Entities not marked as alive are skipped during the update process.ALIVE_STATEfrom constants to determine the entity's alive state.Other Updates
currentStateproperty from theAnimationComponentinterface, as the system now relies on the unifiedstate.characterStatefor managing animation states.This refactor enhances the maintainability and readability of the game code by centralizing state definitions and improving consistency in their usage across animation and movement systems. No functional behavior changes were introduced.
Diagrams
📈 | Flowchart - Nothing to show yet
Evidence
⏪️ | Before - No animations
Gravacao.de.Tela.2026-01-31.193506.mp4
⏩ | After - Animations working
State.-.All.animations.working.mp4
Rollback Plan
Revert from the branch.