mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2026-02-14 12:22:42 +00:00
game runner
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user