Skip to content

Commit

Permalink
fix: user info bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivomo committed Oct 24, 2023
1 parent 83060a5 commit c5bab14
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Game = () => {

const [players, setPlayers] = useState(PlayersMockData);
const [targetPlayer, setTargetPlayer] = useState(null);
const [userInfoPlayer, setUserInfoPlayer] = useState();
const [userInfoPlayer, setUserInfoPlayer] = useState<IPlayer>();
const [treasureChest, setTreasureChest] = useState(TreasureChestMockData);
const curId = CurIdMockData;
const curPlayer = players.find((item) => item.id === curId);
Expand All @@ -52,6 +52,7 @@ const Game = () => {
});

const mapDataRef = useRef([]);
const moveInterval = useRef<NodeJS.Timeout>();
const location = useLocation();
const {
username = "",
Expand Down Expand Up @@ -87,17 +88,19 @@ const Game = () => {
}

const movePlayer = (paths, merkelData) => {
clearInterval(moveInterval.current);
let pathIndex = 0;
const interval = setInterval(() => {
moveInterval.current = setInterval(() => {
setVertexCoordinate(triggerVertexUpdate(paths[pathIndex], curPlayer, mapDataRef.current, vertexCoordinate));
updatePlayerPosition(curPlayer, paths[pathIndex]);
pathIndex++;
setPlayers([...players]);
if (pathIndex === paths.length) {
clearInterval(interval);
clearInterval(moveInterval.current);
const target = paths[pathIndex - 1];
const isDelivery = DELIVERY.x === target.x && DELIVERY.y === target.y;
if (isDelivery) {
setUserInfoPlayer(curPlayer);
submitGem();
}
}
Expand Down

0 comments on commit c5bab14

Please sign in to comment.