From 9fc8d29dbecb7ef07cbc7d2eea9944464c30b1ca Mon Sep 17 00:00:00 2001 From: Tiyo Date: Wed, 1 Nov 2023 14:25:21 +0800 Subject: [PATCH] =?UTF-8?q?uodate:=20=E4=BC=98=E5=8C=96=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E5=AE=9D=E7=AE=B1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/mud/createSystemCalls.ts | 5 ++++- packages/client/src/pages/game/index.tsx | 20 ++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/client/src/mud/createSystemCalls.ts b/packages/client/src/mud/createSystemCalls.ts index d448cb0d..c2489b66 100644 --- a/packages/client/src/mud/createSystemCalls.ts +++ b/packages/client/src/mud/createSystemCalls.ts @@ -3,6 +3,7 @@ import { ClientComponents } from "./createClientComponents"; import { SetupNetworkResult } from "./setupNetwork"; import { singletonEntity, encodeEntity } from "@latticexyz/store-sync/recs"; import { message } from 'antd'; +import { get } from "http"; export type SystemCalls = ReturnType; @@ -10,7 +11,7 @@ export function createSystemCalls( { worldContract, waitForTransaction }: SetupNetworkResult, ClientComponents ) { - const { Counter, Player, LootList1, LootList2 } = ClientComponents; + const { Counter, Player, LootList1, LootList2, BoxList } = ClientComponents; const increment = async () => { const tx = await worldContract.write.increment(); await waitForTransaction(tx); @@ -133,6 +134,7 @@ export function createSystemCalls( try { const tx = await worldContract.write.revealBox([boxId]); await waitForTransaction(tx); + return getComponentValue(BoxList, encodeEntity({ boxId: "uint256" }, { boxId: boxId})); } catch (error) { message.error(error.cause.reason); } @@ -143,6 +145,7 @@ export function createSystemCalls( const tx = await worldContract.write.getCollections([boxId, oreAmount, treasureAmount]); await waitForTransaction(tx); } catch (error) { + console.log('getCollections', error); message.error(error.cause.reason); } } diff --git a/packages/client/src/pages/game/index.tsx b/packages/client/src/pages/game/index.tsx index 2799b864..3b380dd0 100644 --- a/packages/client/src/pages/game/index.tsx +++ b/packages/client/src/pages/game/index.tsx @@ -24,8 +24,7 @@ import { triggerVertexUpdate } from '@/utils/map'; import { bfs, simplifyMapData } from '@/utils/map'; import useMerkel from '@/hooks/useMerkel'; import { ethers } from 'ethers'; - -let boxId = '' +import { get } from "http"; const toObject = (obj) => { return JSON.parse(JSON.stringify(obj, (key, value) => @@ -150,7 +149,7 @@ const Game = () => { } const getCollectionsFun = (box: any) => { - boxId = '' + console.log(box); setContent(
@@ -163,7 +162,6 @@ const Game = () => {
@@ -177,7 +175,7 @@ const Game = () => { const box:any = getComponentValue(BoxList, entity) box.id = id.boxId.toString() return box; - }).filter(e => e.opened == false || (e.opened && (e.oreBalance || e.treasureBalance)));; + }).filter(e => e.opened == false || (e.opened && (e.oreBalance || e.treasureBalance))); const getBalance = async () => { const balance = await network.publicClient.getBalance({ @@ -196,13 +194,6 @@ const Game = () => { getBalance() }, []); - useEffect(() => { - if (boxId) { - const box = boxs.find((item) => item.id === boxId); - getCollectionsFun(box); - } - }, [boxs]); - const finishBattle = (e: any) => { console.log(e); @@ -311,8 +302,9 @@ const Game = () => { console.log(currentBlockNumber, blockNumber, 'currentBlockNumber') if (currentBlockNumber - blockNumber >= 2) { clearInterval(interval) - await revealBox(id) - boxId = id + let boxData = await revealBox(id) + boxData.id = id + getCollectionsFun(boxData); } }, 1000) }