044 | State - Part 2: Create State System#44
Conversation
|
|
||
| constructor({ scene }: StateSystemProp) { | ||
| if (!scene) throw new Error('scene parameter is missing or invalid'); | ||
|
|
There was a problem hiding this comment.
| constructor() { |
Since the scene is not used within this System, I believe it's best to remove it from both the parameters and the validation. This keeps the code clean and avoids unnecessary dependencies.
| if (!(entities instanceof Map)) { | ||
| throw new Error(`Entities is not a Map: ${typeof entities}`); | ||
| } | ||
|
|
There was a problem hiding this comment.
| if (!(entities instanceof Map)) { | |
| throw new Error(`Entities is not a Map: ${typeof entities}`); | |
| } |
I don't believe adding this validation is necessary, as the system's typing ensure the entities is always valid
| } | ||
|
|
||
| entities.forEach(({ state, input, animation, sprite }) => { | ||
| if (!state || !input || !animation || !sprite?.body) return; |
There was a problem hiding this comment.
| if (!state || !input || !animation || !sprite?.body) return; | |
| if (!state) return; |
As Copilot pointed out, the system only depends on the state. Requiring additional fields would unnecessarily exclude simpler entities that might not need those extra components.
| this.keymapSystem = new KeymapSystem({ scene: this }); | ||
| this.inputSystem = new InputSystem(); | ||
| this.stateSystem = new StateSystem({ scene: this }); | ||
| this.movementSystem = new MovementSystem(); |
There was a problem hiding this comment.
| this.movementSystem = new MovementSystem(); | |
| this.stateSystem = new StateSystem({ scene: this }); |
|
|
||
| update() { | ||
| this.inputSystem.update({ entities: this.entities }); | ||
| this.stateSystem.update({ entities: this.entities }); |
There was a problem hiding this comment.
Wouldn't it be better to call the StateSystem after applying velocity? This ensures the entity's state (like “walking”) is immediately consistent with its movement intent. Running it in this order avoids a one-frame lag between the actual movement and the visual state update.
Information
Describe What Was Done
State Systemresponsible for processing and defining the character's state every frame.Dead Handlerresponsible for defining the correctdeadstate.Detailed Summary (AI Generated)
🤖| Summary
This PR introduces a new
StateSystemin the game's ECS architecture to manage player state transitions and integrates it into theMatchScene. It also includes supporting handlers and types for managing state logic.New System: StateSystem
StateSystemin the fileStateSystem.ts. Key functionalities include:ALIVE_STATE).DeadHandler.isPlayerAlivemethod.New Dead Handler
DeadHandlerinhandlers/dead/DeadHandler.tsto manage actions when the player's state is dead:ALIVE_STATEvalues (e.g.,DEAD,DEAD_NO_HEAD).inputActionandcharacterState.Integration with MatchScene
MatchScene.tsto integrate the newStateSystem:StateSystemininitializeSystems.stateSystem.updateto theupdatelifecycle, enabling player state updates.New Supporting Files
state/types.p.ts: Defines types forStateSystemand its properties.handlers/dead/types.p.ts: Defines type forDeadHandlerproperties.handlers/dead/index.ts: ExportsDeadHandler.state/index.ts: ExportsStateSystem.Index Export Updates
index.tswithin theecs/systemsdirectory to export the newStateSystem.Evidence
⏪️ | Before - No death animation to show
⏩ | After
Gravacao.de.Tela.2026-03-10.212655.mp4
Rollback Plan
Revert from the branch.