save system

This commit is contained in:
Martin 2022-12-14 09:17:11 +01:00
parent 537c5c2855
commit 93ae069aba

View File

@ -2,7 +2,7 @@ import { sys } from "cc";
import { UserData } from "../Game/Data/UserData";
export class SaveSystem {
private userDataIdentifier = "user-data";
private userDataIdentifier = "user-dat";
public save(userData: UserData): void {
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
}
@ -13,6 +13,7 @@ export class SaveSystem {
if (!data) return new UserData();
try {
// TODO: the data can be corrupted if we introduce a new field in UserData
return <UserData>JSON.parse(data);
} catch (error) {
return new UserData();