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 8a3d079 commit 0dafc04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/client/src/hooks/useChessboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ const useChessboard = () => {
}, [BoardList, PieceInBattleList]);

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

if (!hero) {
return undefined;
}

const creature = getComponentValue(
Creature,
encodeCreatureEntity(hero.creatureId)
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 @@ -84,6 +84,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 0dafc04

Please sign in to comment.