Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pages/games/SnackGame/game/SnackGameBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const SnackGameBase = ({ replaceErrorHandler }: Props) => {
const handleStreak = async (streak: StreakWithMeta, isGolden: boolean) => {
cumulativeStreaks = [...cumulativeStreaks, streak];

if (isGolden || streak.isFever) {
if (isGolden) {
session = await handleStreaksMove();
}
return session!;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/games/SnackGame/game/popup/PausePopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class PausePopup extends BasePopup {
try {
this.setButtonsEnabled(false);
await this.handleGameEnd();
this.setButtonsEnabled(true);
} catch (error) {
this.app.setError(error);
}
Expand All @@ -50,6 +51,7 @@ export class PausePopup extends BasePopup {
try {
this.setButtonsEnabled(false);
await this.handleGameResume();
this.setButtonsEnabled(true);
this.app.dismissPopup();
} catch (error) {
this.app.setError(error);
Expand Down
9 changes: 7 additions & 2 deletions src/pages/games/SnackGame/game/screen/BizGameScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SNACK_TYPE,
SnackGameMode,
Streak,
StreakWithMeta,
snackGameGetConfig,
} from '../snackGame/SnackGameUtil';
import { BeforeGameStart } from '../ui/BeforeGameStart';
Expand Down Expand Up @@ -55,7 +56,7 @@ export class BizGameScreen extends Container implements AppScreen {
private app: SnackgameApplication,
private getCurrentMode: () => SnackGameMode,
private handleStreak: (
streak: Streak,
streak: StreakWithMeta,
isGolden: boolean,
) => Promise<SnackGameVerify | SnackGameBizVerify>,
private handleGameStart: () => Promise<SnackGameStart | SnackGameBizStart>,
Expand Down Expand Up @@ -94,6 +95,7 @@ export class BizGameScreen extends Container implements AppScreen {
this.snackGame.onPop = this.onPop.bind(this);
this.snackGame.onStreak = (data: Snack[]) => {
let isGolden = false;
const occurredAt = new Date().toISOString();

const streak = data.reduce((acc: Streak, snack) => {
if (snack.type === SNACK_TYPE.GOLDEN) isGolden = true;
Expand All @@ -103,7 +105,10 @@ export class BizGameScreen extends Container implements AppScreen {
return acc;
}, []);

return this.handleStreak(streak, isGolden);
return this.handleStreak(
{ coordinates: streak, isFever: false, occurredAt },
isGolden,
);
};
this.snackGame.onSnackGameBoardReset =
this.onSnackGameBoardReset.bind(this);
Expand Down
27 changes: 20 additions & 7 deletions src/pages/games/SnackGame/game/screen/GameScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gsap from 'gsap';
import { Container, Rectangle, Ticker } from 'pixi.js';

import { ItemBar } from '@pages/games/SnackGame/game/ui/ItemBar';
import { ItemResponse } from '@utils/types/item.type';
import { ItemResponse, ItemType } from '@utils/types/item.type';

import { AppScreen, AppScreenConstructor } from './appScreen';
import { SnackgameApplication } from './SnackgameApplication';
Expand Down Expand Up @@ -114,15 +114,15 @@ export class GameScreen extends Container implements AppScreen {
);
};
this.snackGame.onBomb = (position: SnackGamePosition, data: Snack[]) => {
this.snackGame.setSelectedItem(null);
this.itemBar.setItemsLocked(false);
let isGolden = false;

data.forEach((snack) => {
if (snack.type === SNACK_TYPE.GOLDEN) isGolden = true;
});

return this.itemHandlers.bomb(position, isGolden);
const result = this.itemHandlers.bomb(position, isGolden);
this.releaseItem();
return result;
};
this.snackGame.onSnackGameBoardReset =
this.onSnackGameBoardReset.bind(this);
Expand All @@ -149,11 +149,12 @@ export class GameScreen extends Container implements AppScreen {
return {
...item,
onUse: async (type) => {
this.snackGame.setSelectedItem(type);
this.selectItem(type);

if (type === 'FEVER_TIME') {
await this.itemHandlers.fever();
this.feverTimer.start(30, () => {
this.snackGame.setSelectedItem(null);
this.releaseItem();
});
}
Comment on lines 154 to 159
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

itemHandlers.fever() 호출이 실패할 경우를 대비한 에러 처리가 필요합니다. 현재 구현에서는 await된 프로미스가 reject되면 unhandled promise rejection이 발생할 수 있습니다. 또한, 에러가 발생하면 아이템이 선택된 상태로 잠겨있게 되어 사용자가 다른 행동을 할 수 없게 됩니다.

try...catch 블록을 추가하여 에러를 처리하고, 에러 발생 시 releaseItem()을 호출하여 아이템 선택을 해제하는 것이 좋습니다.

            if (type === 'FEVER_TIME') {
              try {
                await this.itemHandlers.fever();
                this.feverTimer.start(30, () => {
                  this.releaseItem();
                });
              } catch (error) {
                this.app.setError(error);
                this.releaseItem();
              }
            }

},
Expand Down Expand Up @@ -185,14 +186,26 @@ export class GameScreen extends Container implements AppScreen {
gsap.killTweensOf(this.timer.scale);
}

/** 화면 업테이트, 하위 컴포넌트의 update함수를 모두 실행합니다. */
/** 화면 업데이트, 하위 컴포넌트의 update함수를 모두 실행합니다. */
public update(time: Ticker) {
this.snackGame.update(time.deltaMS);
this.timer.updateTime(this.snackGame.timer.getTimeRemaining());
this.feverTimer.update(time.deltaMS);
this.score.setScore(this.snackGame.stats.getScore());
}

/** 아이템 선택 */
private selectItem(type: ItemType) {
this.snackGame.setSelectedItem(type);
this.itemBar.setItemsLocked(true);
}

/** 아이템 선택 해제 */
private releaseItem() {
this.snackGame.setSelectedItem(null);
this.itemBar.setItemsLocked(false);
}

private onSnackGameBoardReset() {
for (const snack of this.snackGame.board.snacks) {
this.vfx?.animationBeforeStart(snack);
Expand Down
6 changes: 3 additions & 3 deletions src/pages/games/SnackgameBiz/SnackGameBizBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { LobbyScreen } from '../SnackGame/game/screen/LobbyScreen';
import { SnackgameApplication } from '../SnackGame/game/screen/SnackgameApplication';
import {
SnackGameMode,
Streak,
StreakWithMeta,
} from '../SnackGame/game/snackGame/SnackGameUtil';

type Props = {
Expand Down Expand Up @@ -68,7 +68,7 @@ const SnackGameBizBase = ({ replaceErrorHandler }: Props) => {
// 게임 진행 관련 functions
let session: SnackGameBizDefaultResponse | undefined;
let sessionMode: SnackGameMode | undefined;
let cumulativeStreaks: Streak[] = [];
let cumulativeStreaks: StreakWithMeta[] = [];

const handleGameStart = async () => {
session = await gameApi.start();
Expand All @@ -85,7 +85,7 @@ const SnackGameBizBase = ({ replaceErrorHandler }: Props) => {
};

// TODO: 지금은 인자로 숫자를 사용하지만, '스트릭' VO를 만들어 사용하면 더 좋겠네요.
const handleStreak = async (streak: Streak, isGolden: boolean) => {
const handleStreak = async (streak: StreakWithMeta, isGolden: boolean) => {
cumulativeStreaks = [...cumulativeStreaks, streak];

if (isGolden) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/games/SnackgameBiz/util/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

import { Streak } from '@pages/games/SnackGame/game/snackGame/SnackGameUtil';
import { StreakWithMeta } from '@pages/games/SnackGame/game/snackGame/SnackGameUtil';

import {
SnackGameBizDefaultResponse,
Expand Down Expand Up @@ -39,7 +39,7 @@ export const createGameApiClient = () => {
},
verifyStreaks: async (
sessionId: number,
streaks: Streak[],
streaks: StreakWithMeta[],
): Promise<SnackGameBizVerify> => {
const { data } = await api.post(
`/games/${GAME_ID}/${sessionId}/streaks`,
Expand Down
Loading