Slash-The-Hordes/assets/Scripts/Game/ModalWIndows/GameModalLauncher.ts

55 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

2022-12-21 13:08:49 +00:00
import { MenuModalWindowTypes } from "../../Menu/ModalWindows/MenuModalWindowTypes";
import { Empty } from "../../Menu/ModalWindows/Upgrades/UpgradesModalWindow";
2022-11-25 11:00:09 +00:00
import { ModalWindowManager } from "../../Services/ModalWindowSystem/ModalWindowManager";
2022-12-13 15:58:55 +00:00
import { TranslationData } from "../Data/TranslationData";
2022-12-21 13:08:49 +00:00
import { Game } from "../Game";
2022-11-25 11:00:09 +00:00
import { Pauser } from "../Pauser";
2022-12-13 15:58:55 +00:00
import { LevelUpModalWindowParams } from "../UI/LevelUpWindow/LevelUpModalWindow";
2022-11-28 10:49:16 +00:00
import { Player } from "../Unit/Player/Player";
2022-11-25 11:00:09 +00:00
import { Upgrader } from "../Upgrades/Upgrader";
import { UpgradeType } from "../Upgrades/UpgradeType";
import { GameModalWindowTypes } from "./GameModalWindowTypes";
export class GameModalLauncher {
public constructor(
private modalWindowManager: ModalWindowManager,
private player: Player,
private gamePauser: Pauser,
2022-12-13 15:58:55 +00:00
private upgrader: Upgrader,
private translationData: TranslationData
2022-11-25 11:00:09 +00:00
) {
this.player.Level.LevelUpEvent.on(this.showLevelUpModal, this);
}
private async showLevelUpModal(): Promise<void> {
this.gamePauser.pause();
2022-12-13 15:58:55 +00:00
const skillToUpgrade: UpgradeType = await this.modalWindowManager.showModal<LevelUpModalWindowParams, UpgradeType>(
2022-12-16 10:49:52 +00:00
GameModalWindowTypes.LevelUp,
2022-12-13 15:58:55 +00:00
{ availableUpgrades: Array.from(this.upgrader.getAvailableUpgrades()), translationData: this.translationData }
2022-11-25 11:00:09 +00:00
);
2023-01-02 07:57:59 +00:00
this.upgrader.upgradeSkill(skillToUpgrade);
2022-11-25 11:00:09 +00:00
this.gamePauser.resume();
2023-01-02 07:57:59 +00:00
}
public async showChestModal(): Promise<void> {
this.gamePauser.pause();
const skillToUpgrade: UpgradeType = await this.modalWindowManager.showModal<LevelUpModalWindowParams, UpgradeType>(
GameModalWindowTypes.Chest,
{ availableUpgrades: Array.from(this.upgrader.getAvailableUpgrades()), translationData: this.translationData }
);
2022-11-25 11:00:09 +00:00
this.upgrader.upgradeSkill(skillToUpgrade);
2023-01-02 07:57:59 +00:00
this.gamePauser.resume();
2022-11-25 11:00:09 +00:00
}
2022-12-21 13:08:49 +00:00
public async showPauseModal(): Promise<void> {
this.gamePauser.pause();
const shouldExit = await this.modalWindowManager.showModal<ModalWindowManager, boolean>(GameModalWindowTypes.Pause, this.modalWindowManager);
if (shouldExit) {
Game.Instance.exitGame();
} else {
this.gamePauser.resume();
}
}
2022-11-25 11:00:09 +00:00
}