mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
save system
This commit is contained in:
parent
537c5c2855
commit
93ae069aba
@ -2,7 +2,7 @@ import { sys } from "cc";
|
|||||||
import { UserData } from "../Game/Data/UserData";
|
import { UserData } from "../Game/Data/UserData";
|
||||||
|
|
||||||
export class SaveSystem {
|
export class SaveSystem {
|
||||||
private userDataIdentifier = "user-data";
|
private userDataIdentifier = "user-dat";
|
||||||
public save(userData: UserData): void {
|
public save(userData: UserData): void {
|
||||||
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
sys.localStorage.setItem(this.userDataIdentifier, JSON.stringify(userData));
|
||||||
}
|
}
|
||||||
@ -13,6 +13,7 @@ export class SaveSystem {
|
|||||||
if (!data) return new UserData();
|
if (!data) return new UserData();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// TODO: the data can be corrupted if we introduce a new field in UserData
|
||||||
return <UserData>JSON.parse(data);
|
return <UserData>JSON.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new UserData();
|
return new UserData();
|
||||||
|
Loading…
Reference in New Issue
Block a user