Fix NaNs sneaking into the save file

This commit is contained in:
Eevee (Evelyn Woods) 2020-10-21 23:34:59 -06:00
parent 09eb03dad6
commit d03d61516f
2 changed files with 24 additions and 9 deletions

View File

@ -66,11 +66,13 @@ export class StoredGame {
if (meta.error) if (meta.error)
throw meta.error; throw meta.error;
// The editor stores inflated levels at times, so respect that if (meta.stored_level) {
if (meta.stored_level) // The editor stores inflated levels at times, so respect that
return meta.stored_level; return meta.stored_level;
}
// Otherwise, attempt to load the level else {
return this._level_loader(meta.bytes); // Otherwise, attempt to load the level
return this._level_loader(meta.bytes, meta.number);
}
} }
} }

View File

@ -1240,9 +1240,15 @@ class Splash extends PrimaryView {
let score; let score;
let packinfo = conductor.stash.packs[packdef.ident]; let packinfo = conductor.stash.packs[packdef.ident];
if (packinfo && packinfo.total_score !== undefined) { if (packinfo && packinfo.total_score !== undefined) {
// TODO tack on a star if the game is "beaten"? what's that mean? every level if (packinfo.total_score === null) {
// beaten i guess? // Whoops, some NaNs got in here :(
score = packinfo.total_score.toLocaleString(); score = "computing...";
}
else {
// TODO tack on a star if the game is "beaten"? what's that mean? every level
// beaten i guess?
score = packinfo.total_score.toLocaleString();
}
} }
else { else {
score = "unplayed"; score = "unplayed";
@ -1312,7 +1318,7 @@ class Splash extends PrimaryView {
// Bind to "create level" button // Bind to "create level" button
this.root.querySelector('#splash-create-level').addEventListener('click', ev => { this.root.querySelector('#splash-create-level').addEventListener('click', ev => {
let stored_level = new format_base.StoredLevel; let stored_level = new format_base.StoredLevel(1);
stored_level.size_x = 32; stored_level.size_x = 32;
stored_level.size_y = 32; stored_level.size_y = 32;
for (let i = 0; i < 1024; i++) { for (let i = 0; i < 1024; i++) {
@ -1779,6 +1785,13 @@ class Conductor {
if (identifier !== null) { if (identifier !== null) {
// TODO again, enforce something about the shape here // TODO again, enforce something about the shape here
this.current_pack_savefile = JSON.parse(window.localStorage.getItem(STORAGE_PACK_PREFIX + identifier)); this.current_pack_savefile = JSON.parse(window.localStorage.getItem(STORAGE_PACK_PREFIX + identifier));
if (this.current_pack_savefile.total_score === null) {
// Fix some NaNs that slipped in
this.current_pack_savefile.total_score = this.current_pack_savefile.scorecards
.map(scorecard => scorecard ? scorecard.score : 0)
.reduce((a, b) => a + b, 0);
this.save_savefile();
}
} }
if (! this.current_pack_savefile) { if (! this.current_pack_savefile) {
this.current_pack_savefile = { this.current_pack_savefile = {