Skip to content

Commit

Permalink
check for existence of save state before clearing current state to lo…
Browse files Browse the repository at this point in the history
…ad it
  • Loading branch information
okaybenji committed Jul 9, 2022
1 parent 8ee73bb commit 8add9dd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ let save = (name = 'save') => {
// reapply inputs from saved game
// (optionally accepts a name for the save)
let load = (name = 'save') => {
let save = localStorage.getItem(name);

if (!save) {
println(`Save file not found.`);
return;
}

// if the disk provided is an object rather than a factory function, the game state must be reset by reloading
if (typeof diskFactory !== 'function' && inputs.length) {
println(`You cannot load this disk in the middle of the game. Please reload the browser, then run the **LOAD** command again.`);
Expand All @@ -96,13 +103,6 @@ let load = (name = 'save') => {
inputsPos = 0;
loadDisk();

let save = localStorage.getItem(name);

if (!save) {
println(`Save file not found.`);
return;
}

applyInputs(save);

const line = name.length ? `Game "${name}" was loaded.` : `Game loaded.`;
Expand Down

0 comments on commit 8add9dd

Please sign in to comment.