Skip to content

Commit

Permalink
Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MycroftKang committed Aug 19, 2024
1 parent da89331 commit 4820647
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/lib/suikaGame/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const SuikaGame = () => {
const [isGameOver, setIsGameOver] = useState<boolean>(false);
const [isShowRank, setIsShowRank] = useState<boolean>(false);
const [loadUserInfo, setLoadUserInfo] = useState<boolean>(false);
const [loadedUserInfo, setLoadedUserInfo] = useState<boolean>(false);

const { clear, createFixedItem } = useMatterJS({ score, setScore, bombItemCount, setBombItemCount, nextItem, setNextItem, isGameOver, setIsGameOver });

Expand Down Expand Up @@ -66,18 +67,21 @@ const SuikaGame = () => {
if (score > Number(bestScore)) {
localStorage.setItem('bestScore', score.toString());
localStorage.setItem('bestScoreUpdatedAt', new Date().getTime().toString());

handleShowRankModal();
}

gameResult?.gameOver(score, bombItemCount);

if (loadUserInfo) {
if (loadedUserInfo) {
gameResult?.send().then(() => { });
} else if (GameResult.isNewUser()) {
} else if (!loadUserInfo && GameResult.isNewUser()) {
setLoadUserInfo(true);
GameResult.loadUserInfo().then(() => {
gameResult?.send().then(() => { });
setLoadedUserInfo(true);
gameResult?.send().then(() => {
if (score > Number(bestScore)) {
handleShowRankModal();
}
});
});
}

Expand Down Expand Up @@ -118,11 +122,12 @@ const SuikaGame = () => {
}

const handleShowRankModal = () => {
if (loadUserInfo) {
if (loadedUserInfo) {
setIsShowRank(true);
} else if (GameResult.isNewUser()) {
} else if (!loadUserInfo && GameResult.isNewUser()) {
setLoadUserInfo(true);
GameResult.loadUserInfo().then(() => {
setLoadedUserInfo(true);
setIsShowRank(true);
});
}
Expand Down

0 comments on commit 4820647

Please sign in to comment.