42 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-12-07 10:47:46 +01:00
import { director } from "cc";
import { AppRoot } from "../AppRoot/AppRoot";
import { UserData } from "../Game/Data/UserData";
2022-12-13 18:25:19 +01:00
import { Game, GameResult } from "../Game/Game";
2022-12-07 10:47:46 +01:00
import { delay } from "../Services/Utils/AsyncUtils";
export class GameRunner {
private static instance: GameRunner = new GameRunner();
2022-12-12 09:15:27 +01:00
private isRunning = false;
2022-12-07 10:47:46 +01:00
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {}
public static get Instance(): GameRunner {
return this.instance;
}
2022-12-12 09:15:27 +01:00
public get IsRunning(): boolean {
return this.isRunning;
}
2022-12-07 10:47:46 +01:00
public async playGame(): Promise<void> {
2022-12-12 09:15:27 +01:00
this.isRunning = true;
2022-12-07 10:47:46 +01:00
director.loadScene("Game");
const userData: UserData = AppRoot.Instance.SaveSystem.load();
while (Game.Instance == null) await delay(10);
2022-12-16 12:01:25 +01:00
const result: GameResult = await Game.Instance.playGame(userData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData);
2022-12-13 18:25:19 +01:00
userData.game.goldCoins += result.goldCoins;
if (userData.game.highscore < result.score) {
userData.game.highscore = result.score;
}
2022-12-07 10:47:46 +01:00
AppRoot.Instance.SaveSystem.save(userData);
2022-12-19 15:50:24 +01:00
await delay(1000);
director.loadScene("Menu");
2022-12-12 09:15:27 +01:00
this.isRunning = false;
2022-12-07 10:47:46 +01:00
}
}