61 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-20 10:00:47 +01:00
import { Component, director, JsonAsset, _decorator } from "cc";
2022-12-16 12:01:25 +01:00
import { GameSettings } from "../Game/Data/GameSettings";
import { TranslationData } from "../Game/Data/TranslationData";
2022-12-21 14:08:49 +01:00
import { UserData } from "../Game/Data/UserData";
2022-12-20 10:00:47 +01:00
import { AudioPlayer } from "../Services/AudioPlayer/AudioPlayer";
2022-12-07 10:47:46 +01:00
import { SaveSystem } from "./SaveSystem";
const { ccclass, property } = _decorator;
@ccclass("AppRoot")
export class AppRoot extends Component {
2022-12-20 10:00:47 +01:00
@property(AudioPlayer) private audio: AudioPlayer;
2022-12-16 12:01:25 +01:00
@property(JsonAsset) private settingsAsset: JsonAsset;
@property(JsonAsset) private engTranslationAsset: JsonAsset;
2022-12-07 10:47:46 +01:00
private static instance: AppRoot;
private saveSystem: SaveSystem;
2022-12-21 14:08:49 +01:00
private liveUserData: UserData;
2022-12-07 10:47:46 +01:00
public static get Instance(): AppRoot {
return this.instance;
}
2022-12-20 10:00:47 +01:00
public get AudioPlayer(): AudioPlayer {
return this.audio;
}
2022-12-21 14:08:49 +01:00
public get LiveUserData(): UserData {
return this.liveUserData;
2022-12-07 10:47:46 +01:00
}
2022-12-16 12:01:25 +01:00
public get Settings(): GameSettings {
return <GameSettings>this.settingsAsset.json;
}
public get TranslationData(): TranslationData {
return <TranslationData>this.engTranslationAsset.json;
}
2022-12-21 14:08:49 +01:00
public saveUserData(): void {
this.saveSystem.save(this.liveUserData);
}
2022-12-07 10:47:46 +01: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-21 14:08:49 +01:00
this.liveUserData = this.saveSystem.load();
this.audio.init(this.LiveUserData.soundVolume, this.LiveUserData.musicVolume);
2022-12-07 10:47:46 +01:00
}
}