2022-12-20 09:00:47 +00:00
|
|
|
import { Component, director, JsonAsset, _decorator } from "cc";
|
2022-12-16 11:01:25 +00:00
|
|
|
import { GameSettings } from "../Game/Data/GameSettings";
|
|
|
|
import { TranslationData } from "../Game/Data/TranslationData";
|
2022-12-20 09:00:47 +00:00
|
|
|
import { AudioPlayer } from "../Services/AudioPlayer/AudioPlayer";
|
2022-12-07 09:47:46 +00:00
|
|
|
import { SaveSystem } from "./SaveSystem";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass("AppRoot")
|
|
|
|
export class AppRoot extends Component {
|
2022-12-20 09:00:47 +00:00
|
|
|
@property(AudioPlayer) private audio: AudioPlayer;
|
2022-12-16 11:01:25 +00:00
|
|
|
@property(JsonAsset) private settingsAsset: JsonAsset;
|
|
|
|
@property(JsonAsset) private engTranslationAsset: JsonAsset;
|
2022-12-07 09:47:46 +00:00
|
|
|
|
|
|
|
private static instance: AppRoot;
|
|
|
|
private saveSystem: SaveSystem;
|
|
|
|
|
|
|
|
public static get Instance(): AppRoot {
|
|
|
|
return this.instance;
|
|
|
|
}
|
|
|
|
|
2022-12-20 09:00:47 +00:00
|
|
|
public get AudioPlayer(): AudioPlayer {
|
|
|
|
return this.audio;
|
|
|
|
}
|
|
|
|
|
2022-12-07 09:47:46 +00:00
|
|
|
public get SaveSystem(): SaveSystem {
|
|
|
|
return this.saveSystem;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:01:25 +00:00
|
|
|
public get Settings(): GameSettings {
|
|
|
|
return <GameSettings>this.settingsAsset.json;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get TranslationData(): TranslationData {
|
|
|
|
return <TranslationData>this.engTranslationAsset.json;
|
|
|
|
}
|
|
|
|
|
2022-12-07 09:47:46 +00:00
|
|
|
public start(): void {
|
|
|
|
if (AppRoot.Instance == null) {
|
|
|
|
AppRoot.instance = this;
|
|
|
|
director.addPersistRootNode(this.node);
|
|
|
|
this.init();
|
|
|
|
} else {
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private init(): void {
|
|
|
|
this.saveSystem = new SaveSystem();
|
2022-12-20 09:00:47 +00:00
|
|
|
this.audio.init(1, 1);
|
2022-12-07 09:47:46 +00:00
|
|
|
}
|
|
|
|
}
|