diff --git a/assets/Media/Prefabs/AppRoot.prefab b/assets/Media/Prefabs/AppRoot.prefab index fccf0f7..05f46fa 100644 --- a/assets/Media/Prefabs/AppRoot.prefab +++ b/assets/Media/Prefabs/AppRoot.prefab @@ -66,6 +66,14 @@ "__prefab": { "__id__": 3 }, + "settingsAsset": { + "__uuid__": "4a156ee8-535e-4443-8bf5-8b979a08d232", + "__expectedType__": "cc.JsonAsset" + }, + "engTranslationAsset": { + "__uuid__": "7d43843c-0765-427c-9161-2fd9030369c8", + "__expectedType__": "cc.JsonAsset" + }, "_id": "" }, { diff --git a/assets/Scripts/AppRoot/AppRoot.ts b/assets/Scripts/AppRoot/AppRoot.ts index 1ab42c6..236922d 100644 --- a/assets/Scripts/AppRoot/AppRoot.ts +++ b/assets/Scripts/AppRoot/AppRoot.ts @@ -1,4 +1,6 @@ -import { _decorator, Component, Node, director, AudioSource } from "cc"; +import { _decorator, Component, Node, director, AudioSource, JsonAsset } from "cc"; +import { GameSettings } from "../Game/Data/GameSettings"; +import { TranslationData } from "../Game/Data/TranslationData"; import { SaveSystem } from "./SaveSystem"; const { ccclass, property } = _decorator; @@ -6,6 +8,8 @@ const { ccclass, property } = _decorator; export class AppRoot extends Component { @property(AudioSource) private soundSource: AudioSource; @property(AudioSource) private musicSource: AudioSource; + @property(JsonAsset) private settingsAsset: JsonAsset; + @property(JsonAsset) private engTranslationAsset: JsonAsset; private static instance: AppRoot; private saveSystem: SaveSystem; @@ -18,6 +22,14 @@ export class AppRoot extends Component { return this.saveSystem; } + public get Settings(): GameSettings { + return this.settingsAsset.json; + } + + public get TranslationData(): TranslationData { + return this.engTranslationAsset.json; + } + public start(): void { if (AppRoot.Instance == null) { AppRoot.instance = this; diff --git a/assets/Scripts/Game/Game.ts b/assets/Scripts/Game/Game.ts index 3224abf..64ddef4 100644 --- a/assets/Scripts/Game/Game.ts +++ b/assets/Scripts/Game/Game.ts @@ -37,8 +37,6 @@ export class Game extends Component { @property(GameUI) private gameUI: GameUI; @property(Background) private background: Background; @property(ModalWindowManager) private modalWindowManager: ModalWindowManager; - @property(JsonAsset) private settingsAsset: JsonAsset; - @property(JsonAsset) private translationAsset: JsonAsset; private playerCollisionSystem: PlayerCollisionSystem; private haloProjectileLauncher: HaloProjectileLauncher; @@ -59,9 +57,7 @@ export class Game extends Component { this.gamePauser.pause(); } - public async playGame(userData: UserData): Promise { - const translationData = this.translationAsset.json; - const settings = this.settingsAsset.json; + public async playGame(userData: UserData, settings: GameSettings, translationData: TranslationData): Promise { const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades); this.virtualJoystic.init(); diff --git a/assets/Scripts/Game/TestGameRunner.ts b/assets/Scripts/Game/TestGameRunner.ts index 22824b8..669e8db 100644 --- a/assets/Scripts/Game/TestGameRunner.ts +++ b/assets/Scripts/Game/TestGameRunner.ts @@ -1,4 +1,5 @@ -import { CCInteger, Component, _decorator } from "cc"; +import { approx, CCInteger, Component, _decorator } from "cc"; +import { AppRoot } from "../AppRoot/AppRoot"; import { GameRunner } from "../Menu/GameRunner"; import { delay } from "../Services/Utils/AsyncUtils"; import { UserData } from "./Data/UserData"; @@ -20,7 +21,7 @@ export class TestGameRunner extends Component { } public async playTestGameAsync(): Promise { - while (Game.Instance == null) await delay(100); + while (Game.Instance == null || AppRoot.Instance == null) await delay(100); const testUserData = new UserData(); testUserData.game.metaUpgrades.maxHpLevel = this.maxHpLevel; @@ -29,6 +30,6 @@ export class TestGameRunner extends Component { testUserData.game.metaUpgrades.movementSpeedLevel = this.movementSpeedLevel; testUserData.game.metaUpgrades.xpGathererLevel = this.xpGathererLevel; testUserData.game.metaUpgrades.goldGathererLevel = this.goldGathererLevel; - Game.Instance.playGame(testUserData); + Game.Instance.playGame(testUserData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData); } } diff --git a/assets/Scripts/Menu/GameRunner.ts b/assets/Scripts/Menu/GameRunner.ts index 883aa95..04ed22c 100644 --- a/assets/Scripts/Menu/GameRunner.ts +++ b/assets/Scripts/Menu/GameRunner.ts @@ -25,7 +25,7 @@ export class GameRunner { director.loadScene("Game"); const userData: UserData = AppRoot.Instance.SaveSystem.load(); while (Game.Instance == null) await delay(10); - const result: GameResult = await Game.Instance.playGame(userData); + const result: GameResult = await Game.Instance.playGame(userData, AppRoot.Instance.Settings, AppRoot.Instance.TranslationData); userData.game.goldCoins += result.goldCoins; if (userData.game.highscore < result.score) {