Skip to content

Commit

Permalink
gameplay: save body and anim indexes in state
Browse files Browse the repository at this point in the history
  • Loading branch information
xesf committed Aug 5, 2023
1 parent d66c46c commit 3b746de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/game/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ export default class Actor {
return;
}
this.props.bodyIndex = index;
if (this.index === 0) {
this.game.getState().hero.bodyIndex = index;
}
this.reloadModel(scene);
}

Expand All @@ -638,6 +641,9 @@ export default class Actor {
return;
}
this.props.animIndex = index;
if (this.index === 0) {
this.game.getState().hero.animIndex = index;
}
if (this.animState.onAnimEnd) {
this.animState.onAnimEnd();
}
Expand Down
4 changes: 4 additions & 0 deletions src/game/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface MagicBallState {
export interface HeroState {
behaviour: number;
prevBehaviour: number;
bodyIndex: number;
animIndex: number;
usingItemId: number;
equippedItemId: number;
inventorySlot: number;
Expand Down Expand Up @@ -74,6 +76,8 @@ export function createGameState(): GameState {
hero: {
behaviour: 0,
prevBehaviour: 0,
bodyIndex: -1,
animIndex: -1,
life: INITIAL_LIFE,
money: 0,
magic: 0,
Expand Down
7 changes: 5 additions & 2 deletions src/game/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ export default class Scene {
return actor;
}

const bodyIndex = getBodyFromGameState(game);
let bodyIndex = getBodyFromGameState(game);
if (bodyIndex === -1) {
bodyIndex = game.getState().hero.bodyIndex;
}

return {
...actor,
entityIndex: game.getState().hero.behaviour,
bodyIndex: bodyIndex !== -1 ? bodyIndex : actor.bodyIndex
bodyIndex: bodyIndex !== -1 ? bodyIndex : actor.bodyIndex,
};
}

Expand Down

0 comments on commit 3b746de

Please sign in to comment.