Skip to content

Commit

Permalink
🐛 FIX catch localStorage error
Browse files Browse the repository at this point in the history
  • Loading branch information
pixel-fabian committed Apr 3, 2022
1 parent 856b494 commit a4161af
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/js/game.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/js/objects/saveGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ export default class SaveGame {
}

save() {
localStorage.setItem('highscores', JSON.stringify(this.aHighscores));
try {
localStorage.setItem('highscores', JSON.stringify(this.aHighscores));
} catch {
console.warn('Saving to local storage failed!');
}
}

load() {
if (JSON.parse(localStorage.getItem('highscores'))) {
this.aHighscores = JSON.parse(localStorage.getItem('highscores'));
try {
if (JSON.parse(localStorage.getItem('highscores'))) {
this.aHighscores = JSON.parse(localStorage.getItem('highscores'));
}
} catch {
console.warn('Loading from local storage failed!');
}
}
}
2 changes: 1 addition & 1 deletion src/js/scenes/sceneCredits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class SceneCredits extends Phaser.Scene {

create(): void {
this.add.image(0, 0, TEXTURES.MENU_BG).setOrigin(0, 0).setScale(8);
new Window(this, 'Credits.txt', {}, SCENES.MENU);
new Window(this, 'credits.txt', {}, SCENES.MENU);

// add text
const screenCenterX = this.scale.width / 2;
Expand Down
2 changes: 1 addition & 1 deletion src/js/scenes/sceneHighscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class SceneHighscore extends Phaser.Scene {

create(): void {
this.add.image(0, 0, TEXTURES.MENU_BG).setOrigin(0, 0).setScale(8);
new Window(this, 'Highscore.txt', {}, SCENES.MENU);
new Window(this, 'highscore.txt', {}, SCENES.MENU);

const screenCenterX = this.scale.width / 2;
this.add
Expand Down

0 comments on commit a4161af

Please sign in to comment.