mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
app root changes
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { Component, director, instantiate, JsonAsset, Prefab, _decorator } from "cc";
|
||||
import { Camera, Component, director, instantiate, JsonAsset, Prefab, _decorator } from "cc";
|
||||
import { GameSettings } from "../Game/Data/GameSettings";
|
||||
import { GameAssets } from "../Game/Data/Assets/GameAssets";
|
||||
import { TranslationData } from "../Game/Data/TranslationData";
|
||||
import { UserData } from "../Game/Data/UserData";
|
||||
import { AudioPlayer } from "../Services/AudioPlayer/AudioPlayer";
|
||||
import { SaveSystem } from "./SaveSystem";
|
||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||
import { OpenCloseAnimator } from "../Utils/OpenCloseAnimator";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("AppRoot")
|
||||
@@ -13,6 +15,9 @@ export class AppRoot extends Component {
|
||||
@property(JsonAsset) private settingsAsset: JsonAsset;
|
||||
@property(JsonAsset) private engTranslationAsset: JsonAsset;
|
||||
@property(Prefab) private gameAssetsPrefab: Prefab;
|
||||
@property(Camera) private mainCamera: Camera;
|
||||
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
|
||||
@property(OpenCloseAnimator) private screenFader: OpenCloseAnimator;
|
||||
|
||||
private static instance: AppRoot;
|
||||
private saveSystem: SaveSystem;
|
||||
@@ -44,6 +49,18 @@ export class AppRoot extends Component {
|
||||
return <TranslationData>this.engTranslationAsset.json;
|
||||
}
|
||||
|
||||
public get ModalWindowManager(): ModalWindowManager {
|
||||
return this.modalWindowManager;
|
||||
}
|
||||
|
||||
public get MainCamera(): Camera {
|
||||
return this.mainCamera;
|
||||
}
|
||||
|
||||
public get ScreenFader(): OpenCloseAnimator {
|
||||
return this.screenFader;
|
||||
}
|
||||
|
||||
public saveUserData(): void {
|
||||
this.saveSystem.save(this.liveUserData);
|
||||
}
|
||||
@@ -54,7 +71,7 @@ export class AppRoot extends Component {
|
||||
director.addPersistRootNode(this.node);
|
||||
this.init();
|
||||
} else {
|
||||
this.destroy();
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,5 +85,8 @@ export class AppRoot extends Component {
|
||||
this.gameAssets.init();
|
||||
|
||||
this.audio.init(this.LiveUserData.soundVolume, this.LiveUserData.musicVolume);
|
||||
|
||||
this.screenFader.init();
|
||||
this.screenFader.node.active = false;
|
||||
}
|
||||
}
|
||||
|
13
assets/Scripts/AppRoot/AppRootUtils.ts
Normal file
13
assets/Scripts/AppRoot/AppRootUtils.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { delay } from "../Services/Utils/AsyncUtils";
|
||||
import { AppRoot } from "./AppRoot";
|
||||
|
||||
export async function requireAppRootAsync(): Promise<void> {
|
||||
console.log("Waiting for app root");
|
||||
while (AppRoot.Instance == null) await delay(10);
|
||||
|
||||
AppRoot.Instance.node.setSiblingIndex(1000); // render on top
|
||||
AppRoot.Instance.node.active = false; // forces engine to reorder by hierarchy
|
||||
AppRoot.Instance.node.active = true;
|
||||
|
||||
console.log("App root ready");
|
||||
}
|
9
assets/Scripts/AppRoot/AppRootUtils.ts.meta
Normal file
9
assets/Scripts/AppRoot/AppRootUtils.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "43cfb543-4c62-4c36-bb28-f307b2e1d280",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
import { Camera, Component, KeyCode, Prefab, Vec2, _decorator } from "cc";
|
||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||
import { Canvas, Component, KeyCode, Vec2, _decorator } from "cc";
|
||||
import { AppRoot } from "../AppRoot/AppRoot";
|
||||
import { requireAppRootAsync } from "../AppRoot/AppRootUtils";
|
||||
import { delay } from "../Services/Utils/AsyncUtils";
|
||||
import { OpenCloseAnimator } from "../Utils/OpenCloseAnimator";
|
||||
import { GameAudioAdapter } from "./Audio/GameAudioAdapter";
|
||||
import { Background } from "./Background/Background";
|
||||
import { MagnetCollisionSystem } from "./Collision/MagnetCollisionSystem";
|
||||
@@ -46,12 +46,10 @@ export class Game extends Component {
|
||||
@property(ProjectileLauncher) private enemyMagicOrbProjectileLauncherComponent: ProjectileLauncher;
|
||||
@property(EnemyManager) private enemyManager: EnemyManager;
|
||||
@property(ItemManager) private itemManager: ItemManager;
|
||||
@property(Camera) private camera: Camera;
|
||||
@property(GameUI) private gameUI: GameUI;
|
||||
@property(Canvas) private gameCanvas: Canvas;
|
||||
@property(Background) private background: Background;
|
||||
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
|
||||
@property(GameAudioAdapter) private gameAudioAdapter: GameAudioAdapter;
|
||||
@property(OpenCloseAnimator) private screenFader: OpenCloseAnimator;
|
||||
|
||||
private playerCollisionSystem: PlayerCollisionSystem;
|
||||
private haloProjectileLauncher: HaloProjectileLauncher;
|
||||
@@ -72,12 +70,12 @@ export class Game extends Component {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
Game.instance = this;
|
||||
public async start(): Promise<void> {
|
||||
this.gamePauser.pause();
|
||||
|
||||
this.screenFader.init();
|
||||
this.screenFader.node.active = true;
|
||||
this.node.active = false; // make sure that nothing is rendered until the app root is ready
|
||||
await requireAppRootAsync();
|
||||
this.node.active = true;
|
||||
Game.instance = this;
|
||||
}
|
||||
|
||||
public async playGame(
|
||||
@@ -86,6 +84,8 @@ export class Game extends Component {
|
||||
translationData: TranslationData,
|
||||
testValues?: TestValues
|
||||
): Promise<GameResult> {
|
||||
this.gameCanvas.cameraComponent = AppRoot.Instance.MainCamera;
|
||||
|
||||
this.gameResult = new GameResult();
|
||||
const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades);
|
||||
|
||||
@@ -154,7 +154,7 @@ export class Game extends Component {
|
||||
this.diagonalProjectileLauncher,
|
||||
settings.upgrades
|
||||
);
|
||||
const modalLauncher = new GameModalLauncher(this.modalWindowManager, this.player, this.gamePauser, upgrader, translationData);
|
||||
const modalLauncher = new GameModalLauncher(AppRoot.Instance.ModalWindowManager, this.player, this.gamePauser, upgrader, translationData);
|
||||
|
||||
this.itemManager.init(this.enemyManager, this.player, this.gameResult, modalLauncher, settings.items);
|
||||
this.gameUI.init(this.player, modalLauncher);
|
||||
@@ -174,7 +174,7 @@ export class Game extends Component {
|
||||
this.haloProjectileLauncher
|
||||
);
|
||||
this.gamePauser.resume();
|
||||
this.screenFader.playClose();
|
||||
AppRoot.Instance.ScreenFader.playClose();
|
||||
|
||||
while (!this.gameResult.hasExitManually && this.player.Health.IsAlive) await delay(100);
|
||||
if (!this.gameResult.hasExitManually) {
|
||||
@@ -207,7 +207,8 @@ export class Game extends Component {
|
||||
this.timeAlive += deltaTime;
|
||||
this.gameUI.updateTimeAlive(this.timeAlive);
|
||||
|
||||
this.camera.node.worldPosition = this.player.node.worldPosition;
|
||||
AppRoot.Instance.MainCamera.node.setWorldPosition(this.player.node.worldPosition);
|
||||
this.gameUI.node.setWorldPosition(this.player.node.worldPosition);
|
||||
}
|
||||
|
||||
private createPlayerData(settings: PlayerSettings, metaUpgrades: MetaUpgrades): PlayerData {
|
||||
|
@@ -1,4 +1,6 @@
|
||||
import { Component, _decorator } from "cc";
|
||||
import { Canvas, Component, _decorator } from "cc";
|
||||
import { AppRoot } from "../AppRoot/AppRoot";
|
||||
import { requireAppRootAsync } from "../AppRoot/AppRootUtils";
|
||||
import { ModalWindowManager } from "../Services/ModalWindowSystem/ModalWindowManager";
|
||||
import { UIButton } from "../Services/UI/Button/UIButton";
|
||||
import { OpenCloseAnimator } from "../Utils/OpenCloseAnimator";
|
||||
@@ -12,24 +14,23 @@ export class Menu extends Component {
|
||||
@property(UIButton) private playBtn: UIButton;
|
||||
@property(UIButton) private upgradeBtn: UIButton;
|
||||
@property(UIButton) private audioSettingsBtn: UIButton;
|
||||
@property(ModalWindowManager) private modalWindowManager: ModalWindowManager;
|
||||
@property(OpenCloseAnimator) private screenFader: OpenCloseAnimator;
|
||||
@property(Canvas) private menuCanvas: Canvas;
|
||||
|
||||
private menuModalLauncher: MenuModalLauncher;
|
||||
|
||||
public async start(): Promise<void> {
|
||||
requireAppRootAsync();
|
||||
this.menuCanvas.cameraComponent = AppRoot.Instance.MainCamera;
|
||||
|
||||
this.playBtn.InteractedEvent.on(this.startGame, this);
|
||||
this.upgradeBtn.InteractedEvent.on(this.openUpgradesWindow, this);
|
||||
this.audioSettingsBtn.InteractedEvent.on(this.openAudioSettingsWindow, this);
|
||||
|
||||
this.menuModalLauncher = new MenuModalLauncher(this.modalWindowManager);
|
||||
|
||||
this.screenFader.init();
|
||||
this.screenFader.node.active = false;
|
||||
this.menuModalLauncher = new MenuModalLauncher(AppRoot.Instance.ModalWindowManager);
|
||||
}
|
||||
|
||||
private startGame(): void {
|
||||
this.screenFader.playOpen();
|
||||
AppRoot.Instance.ScreenFader.playOpen();
|
||||
GameRunner.Instance.playGame();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user