2024-02-13 23:42:11 +00:00
|
|
|
import BattleScene from "./battle-scene";
|
2024-02-14 15:44:55 +00:00
|
|
|
import AwaitableUiHandler from "./ui/awaitable-ui-handler";
|
|
|
|
import { Mode } from "./ui/ui";
|
2024-04-29 16:33:18 +00:00
|
|
|
import i18next from './plugins/i18n';
|
2024-02-13 23:42:11 +00:00
|
|
|
|
|
|
|
export enum Tutorial {
|
|
|
|
Intro = "INTRO",
|
2024-02-14 15:44:55 +00:00
|
|
|
Access_Menu = "ACCESS_MENU",
|
2024-02-13 23:42:11 +00:00
|
|
|
Menu = "MENU",
|
|
|
|
Starter_Select = "STARTER_SELECT",
|
2024-04-02 02:50:00 +00:00
|
|
|
Pokerus = "POKERUS",
|
2024-05-01 03:02:16 +00:00
|
|
|
Stat_Change = "STAT_CHANGE",
|
2024-02-13 23:42:11 +00:00
|
|
|
Select_Item = "SELECT_ITEM",
|
2024-02-14 15:44:55 +00:00
|
|
|
Egg_Gacha = "EGG_GACHA"
|
2024-02-13 23:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const tutorialHandlers = {
|
|
|
|
[Tutorial.Intro]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:intro"), null, () => resolve(), null, true);
|
2024-02-13 23:42:11 +00:00
|
|
|
});
|
|
|
|
},
|
2024-02-14 15:44:55 +00:00
|
|
|
[Tutorial.Access_Menu]: (scene: BattleScene) => {
|
2024-02-13 23:42:11 +00:00
|
|
|
return new Promise<void>(resolve => {
|
|
|
|
if (scene.enableTouchControls)
|
|
|
|
return resolve();
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.showFieldOverlay(1000).then(() => scene.ui.showText(i18next.t("tutorial:accessMenu"), null, () => scene.hideFieldOverlay(1000).then(() => resolve()), null, true));
|
2024-02-14 15:44:55 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
[Tutorial.Menu]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
|
|
|
scene.gameData.saveTutorialFlag(Tutorial.Access_Menu, true);
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:menu"), null, () => scene.ui.showText('', null, () => resolve()), null, true);
|
2024-02-13 23:42:11 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
[Tutorial.Starter_Select]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:starterSelect"), null, () => scene.ui.showText('', null, () => resolve()), null, true);
|
2024-02-14 15:44:55 +00:00
|
|
|
});
|
|
|
|
},
|
2024-04-02 02:50:00 +00:00
|
|
|
[Tutorial.Pokerus]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:pokerus"), null, () => scene.ui.showText('', null, () => resolve()), null, true);
|
2024-04-02 02:50:00 +00:00
|
|
|
});
|
|
|
|
},
|
2024-05-01 03:02:16 +00:00
|
|
|
[Tutorial.Stat_Change]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
|
|
|
scene.showFieldOverlay(1000).then(() => scene.ui.showText(i18next.t("tutorial:statChange"), null, () => scene.ui.showText('', null, () => scene.hideFieldOverlay(1000).then(() => resolve())), null, true));
|
|
|
|
});
|
|
|
|
},
|
2024-02-14 15:44:55 +00:00
|
|
|
[Tutorial.Select_Item]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
|
|
|
scene.ui.setModeWithoutClear(Mode.MESSAGE).then(() => {
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:selectItem"), null, () => scene.ui.showText('', null, () => scene.ui.setModeWithoutClear(Mode.MODIFIER_SELECT).then(() => resolve())), null, true);
|
2024-02-14 15:44:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[Tutorial.Egg_Gacha]: (scene: BattleScene) => {
|
|
|
|
return new Promise<void>(resolve => {
|
2024-04-29 16:33:18 +00:00
|
|
|
scene.ui.showText(i18next.t("tutorial:eggGacha"), null, () => scene.ui.showText('', null, () => resolve()), null, true);
|
2024-02-13 23:42:11 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export function handleTutorial(scene: BattleScene, tutorial: Tutorial): Promise<boolean> {
|
|
|
|
return new Promise<boolean>(resolve => {
|
|
|
|
if (!scene.enableTutorials)
|
|
|
|
return resolve(false);
|
|
|
|
|
|
|
|
if (scene.gameData.getTutorialFlags()[tutorial])
|
|
|
|
return resolve(false);
|
|
|
|
|
2024-02-14 15:44:55 +00:00
|
|
|
const handler = scene.ui.getHandler();
|
|
|
|
if (handler instanceof AwaitableUiHandler)
|
|
|
|
handler.tutorialActive = true;
|
2024-02-13 23:42:11 +00:00
|
|
|
tutorialHandlers[tutorial](scene).then(() => {
|
|
|
|
scene.gameData.saveTutorialFlag(tutorial, true);
|
2024-02-14 15:44:55 +00:00
|
|
|
if (handler instanceof AwaitableUiHandler)
|
|
|
|
handler.tutorialActive = false;
|
2024-02-13 23:42:11 +00:00
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
2024-04-29 16:33:18 +00:00
|
|
|
}
|