Files
ResistanceRacing2k97/src/scnSavegameCheck.js
T

87 lines
2.8 KiB
JavaScript
Raw Normal View History

2026-10-23 00:24:27 +02:00
export default class ScnSavegameCheck extends Phaser.Scene {
constructor() {
super("ScnSavegameCheck");
}
init(_data) {
}
create() {
this.cameras.main.setScroll(-this.game.config.width * 0.5, -this.game.config.height * 0.5);
this.cameras.main.setBackgroundColor(0x131313);
//$("#optionbox").show();
this.saveGame = this.getFreshSaveGame();
if (localStorage.getItem(SAVEGAMENAME) === null || localStorage.getItem(SAVEGAMENAME) === "null") {
console.log("creating savegame");
localStorage.setItem(SAVEGAMENAME, JSON.stringify(this.saveGame));
} else {
this.saveGame = JSON.parse(localStorage.getItem(SAVEGAMENAME));
if (this.checkSaveGameInegrity() === false) {
console.warn("found corrupt savegame, generating a new one")
this.saveGame = this.getFreshSaveGame();
localStorage.setItem(SAVEGAMENAME, JSON.stringify(this.saveGame));
}else{
console.log("loaded savegame")
console.log(this.saveGame)
}
}
//this.scene.start("Scn3d", { level: "marketSquareApartements00", params: {lounge: false} });
this.scene.start("Scn3d", { level: "mainMenu", params: null });
}
update(_time, _delta){
}
getFreshSaveGame() {
return {
sound: {
master: OPTIONS.sound.master,
music: OPTIONS.sound.music,
sfx: OPTIONS.sound.sfx,
speech: OPTIONS.sound.speech,
mute: OPTIONS.sound.mute
},
effects: {
screenshake: OPTIONS.effects.screenshake,
shader: OPTIONS.effects.shader,
viewDistWalk: OPTIONS.effects.viewDistWalk,
viewDistShip: OPTIONS.effects.viewDistShip
},
controls: {
mouse: {
sensitivity: 3
},
mobile: false
},
config: {
preferredCam: 0,
collisionRadar: 1,
idealLine: 1,
hideUI: false
},
version: 0.2,
forceFresh: false //uncomment for fresh savegame force
}
}
checkSaveGameInegrity(){
let correct = true;
let save = JSON.parse(localStorage.getItem(SAVEGAMENAME));
let saveKeys = Object.keys(save);
let freshData = this.getFreshSaveGame()
let freshKeys = Object.keys(freshData);
correct = saveKeys.length === freshKeys.length;
if(freshData.forceFresh === true){
return false;
}
return correct;
}
}