Skip to content

Commit

Permalink
fix: page crashes and place back error
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Sep 12, 2023
1 parent 705884b commit f47bae3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
47 changes: 25 additions & 22 deletions packages/client/src/hooks/useChessboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,31 @@ const useChessboard = () => {
}, [BoardList, PieceInBattleList, creatureMap]);

const PiecesList = playerObj?.heroes.map((row, _index: any) => {
try {
const hero = getComponentValueStrict(
Hero,
encodeEntity({ id: "bytes32" }, { id: numberToHex(row, { size: 32 }) })
);
const creature = getComponentValue(
Creature,
encodeCreatureEntity(hero.creatureId)
);

const decodeHeroData = decodeHero(hero.creatureId);

return {
...hero,
...creature,
key: row,
_index,
...decodeHeroData,
image: getHeroImg(hero.creatureId),
maxHealth: creature?.health,
};
} catch (error) {}
const hero = getComponentValue(
Hero,
encodeEntity({ id: "bytes32" }, { id: numberToHex(row, { size: 32 }) })
);

if (!hero) {
return undefined;
}

const creature = getComponentValue(
Creature,
encodeCreatureEntity(hero.creatureId)
);

const decodeHeroData = decodeHero(hero.creatureId);

return {
...hero,
...creature,
key: row,
_index,
...decodeHeroData,
image: getHeroImg(hero.creatureId),
maxHealth: creature?.health,
};
});

const playerListData = currentGame?.players?.map((_player: string) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/ui/Chessboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const Chessboard = ({ setAcHeroFn }: { setAcHeroFn: (any) => void }) => {
});
} else {
PiecesList?.map((item) => {
if (!item) {
return;
}
const position = convertToIndex(item.x, item.y);
newSquares[position] = {
...item,
Expand Down
9 changes: 5 additions & 4 deletions packages/client/src/ui/Synergy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export function useSynergyCount(uniqueCreatureIds: bigint[]) {
};

uniqueCreatureIds.forEach((v) => {
const creatureValue = getComponentValueStrict(
Creature,
encodeCreatureEntity(v)
);
const creatureValue = getComponentValue(Creature, encodeCreatureEntity(v));

if (!creatureValue) {
return;
}

raceSynergy[creatureValue.race as HeroRace] += 1;
classSynergy[creatureValue.class as HeroClass] += 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/systems/PlaceSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract PlaceSystem is System {
function swapInventory(uint256 fromIndex, uint256 toIndex) public onlyWhenGamePreparing {
address player = _msgSender();

uint8 maxIdx = GameConfig.getInventorySlotNum(0) - 1;
uint8 maxIdx = GameConfig.getInventorySlotNum(0);
require(fromIndex < maxIdx, "index out of range");
require(toIndex < maxIdx, "index out of range");

Expand Down

0 comments on commit f47bae3

Please sign in to comment.