mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
game runner
This commit is contained in:
34
assets/Scripts/AppRoot/AppRoot.ts
Normal file
34
assets/Scripts/AppRoot/AppRoot.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { _decorator, Component, Node, director, AudioSource } from "cc";
|
||||
import { SaveSystem } from "./SaveSystem";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("AppRoot")
|
||||
export class AppRoot extends Component {
|
||||
@property(AudioSource) private soundSource: AudioSource;
|
||||
@property(AudioSource) private musicSource: AudioSource;
|
||||
|
||||
private static instance: AppRoot;
|
||||
private saveSystem: SaveSystem;
|
||||
|
||||
public static get Instance(): AppRoot {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public get SaveSystem(): SaveSystem {
|
||||
return this.saveSystem;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
9
assets/Scripts/AppRoot/AppRoot.ts.meta
Normal file
9
assets/Scripts/AppRoot/AppRoot.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4943d4af-b7d1-41bc-b8b3-2751e114ece0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
21
assets/Scripts/AppRoot/SaveSystem.ts
Normal file
21
assets/Scripts/AppRoot/SaveSystem.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { sys } from "cc";
|
||||
import { UserData } from "../Game/Data/UserData";
|
||||
|
||||
export class SaveSystem {
|
||||
private userDataIdentifier = "user-data";
|
||||
public save(userData: UserData): void {
|
||||
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
||||
}
|
||||
|
||||
public load(): UserData {
|
||||
const data: string = sys.localStorage.getItem(this.userDataIdentifier);
|
||||
|
||||
if (!data) return new UserData();
|
||||
|
||||
try {
|
||||
return <UserData>JSON.parse(data);
|
||||
} catch (error) {
|
||||
return new UserData();
|
||||
}
|
||||
}
|
||||
}
|
9
assets/Scripts/AppRoot/SaveSystem.ts.meta
Normal file
9
assets/Scripts/AppRoot/SaveSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ed50cd4b-21fa-4acc-9fee-92abaf3e2134",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user