diff --git a/packages/client/src/phaser/systems/initialize.ts b/packages/client/src/phaser/systems/initialize.ts index 18285b9..8cf208d 100644 --- a/packages/client/src/phaser/systems/initialize.ts +++ b/packages/client/src/phaser/systems/initialize.ts @@ -1,4 +1,4 @@ -import { getComponentValueStrict, setComponent } from "@dojoengine/recs"; +import { getComponentValue, setComponent } from "@dojoengine/recs"; import { PhaserLayer } from ".."; import { zeroEntity } from "../../utils"; import { logDebug } from "../../ui/lib/utils"; @@ -14,7 +14,7 @@ export const initialize = (layer: PhaserLayer) => { }, } = layer; - const playerV = getComponentValueStrict(Player, playerEntity); + const playerV = getComponentValue(Player, playerEntity); logDebug("init player value:", playerV); @@ -23,7 +23,7 @@ export const initialize = (layer: PhaserLayer) => { shouldPlay: false, status: GameStatusEnum.Prepare, currentRound: 1, - currentMatch: playerV.inMatch, + currentMatch: playerV?.inMatch || 0, dangerous: false, homePlayer: BigInt(address), awayPlayer: 1n, diff --git a/packages/client/src/phaser/systems/prepare.ts b/packages/client/src/phaser/systems/prepare.ts index fd7388d..d129380 100644 --- a/packages/client/src/phaser/systems/prepare.ts +++ b/packages/client/src/phaser/systems/prepare.ts @@ -35,12 +35,34 @@ export const prepare = (layer: PhaserLayer) => { }, account: { address }, account, - playerEntity, }, } = layer; const { spawnPiece } = pieceManage(layer); + // listen match update + defineSystemST( + world, + [Has(Player)], + ({ entity, type, value: [v, preV] }) => { + if (!v) { + return; + } + + if (v.player !== BigInt(address)) { + return; + } + + const s = getComponentValueStrict(GameStatus, zeroEntity); + + if (v.inMatch > s.currentMatch) { + updateComponent(GameStatus, zeroEntity, { + currentMatch: v.inMatch, + }); + } + } + ); + // listen whether the match is end defineSystemST( world,