Skip to content

Commit

Permalink
fix: PlayersData undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Dec 15, 2023
1 parent 8cf1e87 commit 288705b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/client/public/assets/img/meme/E21.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/client/public/assets/img/meme/E4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 26 additions & 10 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import discordImg from '@/assets/img/discord.png';
import { TALK_MAIN } from '@/config/talk';
import { getClient } from '../../utils/client';
import { getUserPublicProfileRequest } from '@web3mq/client';
import { delay } from '../../utils/delay'

const toObject = (obj) => {
return JSON.parse(JSON.stringify(obj, (key, value) =>
Expand Down Expand Up @@ -77,9 +78,13 @@ const Game = () => {

const mapDataRef = useRef([]);

const playerList = useRef([])

// getMUDTables();
// mud bug, if syncProgress not 100, it will return a decimals less 1.
let percentage = 0
// let percentage = 0
const [percentage, setPercentage] = useState(0);


const GlobalConfigData = useStore((state: any) => {
const records = Object.values(state.getRecords(tables.GlobalConfig));
Expand Down Expand Up @@ -161,6 +166,8 @@ const Game = () => {
})
});

playerList.current = PlayersData

const curPlayer = PlayersData.find((player: any) => player.addr.toLocaleLowerCase() == account.toLocaleLowerCase());
if (curPlayer && curPlayer.state == 0 && percentage == 100) {
navigate('/');
Expand Down Expand Up @@ -220,10 +227,7 @@ const Game = () => {
setBattleId(battle.id)
}
setStartBattleData(true);
}

percentage = 100

}
const getCollectionsFun = async (box: any) => {
setGotBox(box);
setModalType('getCollections');
Expand All @@ -248,9 +252,20 @@ const Game = () => {
setRenderMapData(csv);
mapDataRef.current = csv;
});
getBalance()
getBalance();
}, []);

useEffect(() => {
const setP = async () => {
await delay(400)
setPercentage(100);
}
if (GlobalConfigData.length && percentage < 100) {
setP()
}

}, [GlobalConfigData]);

const [clientData, setClientData] = useState(null)


Expand All @@ -264,10 +279,11 @@ const Game = () => {
// });
// console.log(userData)

let playerIndex = PlayersData.findIndex((item) => item.addr.toLocaleLowerCase() == network.account.toLocaleLowerCase())
let player = PlayersData[playerIndex]
player.lastMsg = msg.content
PlayersData[playerIndex] = player
let playerIndex = playerList.current.findIndex((item) => item.addr.toLocaleLowerCase() == network.account.toLocaleLowerCase())
let player = playerList.current[playerIndex]
console.log(player, playerList.current)
if (player) player.lastMsg = msg.content
playerList.current[playerIndex] = player
}

const sendMsg = async (msg) => {
Expand Down

0 comments on commit 288705b

Please sign in to comment.