Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivomo committed Nov 12, 2023
2 parents b689738 + aff02d4 commit eda954c
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 259 deletions.
2 changes: 2 additions & 0 deletions packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,10 @@ export function createSystemCalls(

const submitGem = async () => {
try {
console.log('submitGem', new Date().getTime());
const tx = await worldContract.write.submitGem();
await waitForTransaction(tx);
console.log('submitGem success', new Date().getTime(), tx);
return tx
} catch (error) {
console.log('submitGem', error);
Expand Down
113 changes: 67 additions & 46 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import Map from "@/components/Map";
import UserAvatar from "@/components/UserAvatar";
import Leaderboard from "@/components/Leaderboard";
import { useLocation, useNavigate } from "react-router-dom";
import { message } from 'antd';
import { message, Modal } from 'antd';
import "./styles.scss";
import Rank from "@/components/Rank";
import { CurIdMockData, PlayersMockData, RankMockData, TreasureChestMockData } from "@/mock/data";
import { IPlayer } from "@/components/Player";
import { useMUD } from "@/mud/MUDContext";
import Battle from "@/components/Battle";
import GameContext from '@/context';
import useModal from '@/hooks/useModal';
// import useModal from '@/hooks/useModal';
import TreasureChest from '@/components/TreasureChest';
import UserInfoDialog from '@/components/UserInfoDialog';
import { DELIVERY } from '@/config/map';
Expand Down Expand Up @@ -73,10 +73,14 @@ const Game = () => {

const [percentage, setPercentage] = useState(0);

const [modalVisible, setModalVisible] = useState(false);
const [modalType, setModalType] = useState('');
const [gotBox, setGotBox] = useState(null);

const { account } = network;
const curId = account;

const { Modal, open, close, setContent } = useModal();
// const { Modal, open, close, setContent } = useModal();

const mapDataRef = useRef([]);
const moveInterval = useRef<NodeJS.Timeout>();
Expand Down Expand Up @@ -191,24 +195,9 @@ const Game = () => {
}

const getCollectionsFun = (box: any) => {
setContent(
<div className={'mi-modal-content-wrapper'}>
<div className="mi-modal-content">
Congrats,you got {box.oreBalance} gems!

<div className="mi-treasure-chest-wrapper">
<TreasureChest/>
</div>
</div>
<div className="mi-modal-footer">
<button className="mi-btn" onClick={async () => {
await getCollections(box.id, box.oreBalance, box.treasureBalance);
close();
}}>OK</button>
</div>
</div>
);
open();
setGotBox(box);
setModalType('getCollections');
setModalVisible(true);
}

const boxs = useEntityQuery([Has(BoxList)]).map((entity) => {
Expand Down Expand Up @@ -291,6 +280,8 @@ const Game = () => {
message.error('Waiting for transaction');
return;
}
let txFinished = false;
curPlayer.waiting = true;
let playerLock = getComponentValue(PlayerLocationLock, encodeEntity({ addr: "address" }, { addr: account}))
console.log(playerLock, 'playerLock')
if (playerLock && Number(playerLock.lockTime)) {
Expand All @@ -301,9 +292,10 @@ const Game = () => {
timeout = null
}, 2000);
}
txFinished = true;
curPlayer.waiting = false;
return
}
let txFinished = false;
clearInterval(moveInterval.current);
let pathIndex = 0;
const timeInterval = ~~(1500 / Number(curPlayer.speed))
Expand Down Expand Up @@ -387,8 +379,10 @@ const Game = () => {
const goHomeFun = async () => {
if (!curPlayer.waiting) {
try {
curPlayer.waiting = true;
await goHome();
await joinBattlefield()
curPlayer.waiting = false;
} catch (error) {
console.log(error)
}
Expand All @@ -400,37 +394,44 @@ const Game = () => {
}
}

const closeUserInfoDialog = () => {
if (curPlayer.waiting) {
message.error('Waiting for transaction');
return;
} else {
setUserInfoVisible(false);
}
}

const submitGemFun = async () => {
setUserInfoVisible(true);
try {
goHomeFun()
goHomeFun();
if (curPlayer.oreBalance > 0) {
console.log('submitGem')
setGotBox({oreBalance: curPlayer.oreBalance});
await submitGem();
setContent(
<div className={'mi-modal-content-wrapper'}>
<div className="mi-modal-content">
Congrats,you submitted {curPlayer.oreBalance} gems!

<div className="mi-treasure-chest-wrapper">
<TreasureChest/>
</div>
</div>
<div className="mi-modal-footer">
<button className="mi-btn" onClick={() => {
curPlayer.seasonOreBalance += curPlayer.oreBalance;
curPlayer.oreBalance = 0;
close();
}}>OK</button>
</div>
</div>
);
open();
console.log(curPlayer)
setModalType('submitGem');
setModalVisible(true);
}
} catch (error) {
console.log(error)
}
}

const closeModal = async () => {
if (modalType === 'getCollections') {
await getCollections(gotBox.id, gotBox.oreBalance, gotBox.treasureBalance);
} else if (modalType === 'submitGem') {
curPlayer.oreBalance = 0;
curPlayer.seasonOreBalance = PlayerSeasonData.filter((item) => item.addr.toLocaleLowerCase() == curPlayer.addr.toLocaleLowerCase())[0]?.oreBalance
}
setModalVisible(false);
setGotBox(null);
setModalType('');
}

const setStartBattle = async (player) => {
const paths = bfs(simpleMapData, { x: curPlayer.x, y: curPlayer.y }, {x: player.x, y: player.y}).slice(1);
let res = await battleInvitation(player.addr, formatMovePath(paths));
Expand Down Expand Up @@ -527,13 +528,33 @@ const Game = () => {
}
<UserInfoDialog
visible={userInfoVisible}
onClose={() => {
setUserInfoVisible(false);
}}
onClose={closeUserInfoDialog}
{...userInfoPlayer}
/>

<Modal />
<Modal
visible={modalVisible}
className="mi-modal"
footer={null}
onCancel={() => setModalVisible(false)}
>
<div className={'mi-modal-content-wrapper'}>
<div className="mi-modal-content">
{
modalType === 'submitGem' ? <div className="mi-modal-title">Congrats,you submitted {gotBox?.oreBalance} gems!</div> : null
}
{
modalType === 'getCollections' ? <div className="mi-modal-title">Congrats,you got {gotBox?.oreBalance} gems!</div> : null
}
<div className="mi-treasure-chest-wrapper">
<TreasureChest/>
</div>
</div>
<div className="mi-modal-footer">
<button className="mi-btn" onClick={closeModal}>OK</button>
</div>
</div>
</Modal>
<Leaderboard boxesCount={boxs.length} leaderboard={PlayerSeasonData} />
</div>
</GameContext.Provider>
Expand Down
40 changes: 20 additions & 20 deletions packages/contracts/out/IWorld.sol/IWorld.json
Original file line number Diff line number Diff line change
Expand Up @@ -3912,16 +3912,16 @@
118568,
118556,
71348,
129912,
129821,
129805,
129808,
129860,
173570,
129850,
129839,
129904,
129813,
129797,
129800,
129852,
173562,
129842,
129831,
64435,
127078,
127070,
64393,
64426,
64399,
Expand All @@ -3932,22 +3932,22 @@
"nameLocation": "798:6:169",
"scope": 118826,
"usedErrors": [
127035,
127041,
127043,
127049,
127045,
127051,
127053,
127059,
127065,
127071,
127077,
173539,
173543,
127057,
127063,
127069,
173531,
173535,
173541,
173545,
173549,
173553,
173557,
173561,
173565,
173569
173561
]
}
],
Expand Down
28 changes: 14 additions & 14 deletions packages/contracts/out/Loot.sol/MLoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -1636,34 +1636,34 @@
"id": 119867,
"exportedSymbols": {
"Address": [
131449
131441
],
"Base64": [
118883
],
"Context": [
131471
131463
],
"ERC165": [
131495
131487
],
"ERC721": [
72425
],
"IERC165": [
173776
173768
],
"IERC20": [
71498
],
"IERC721": [
131074
131066
],
"IERC721Metadata": [
131119
131111
],
"IERC721Receiver": [
131092
131084
],
"MLoot": [
119866
Expand All @@ -1672,10 +1672,10 @@
120314
],
"Math": [
132361
132353
],
"SignedMath": [
132466
132458
],
"Strings": [
72654
Expand Down Expand Up @@ -14325,11 +14325,11 @@
119866,
120314,
72425,
131119,
131074,
131495,
173776,
131471,
131111,
131066,
131487,
173768,
131463,
120117
],
"name": "MLoot",
Expand Down
Loading

0 comments on commit eda954c

Please sign in to comment.