Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: page crashes and place back error #176

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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