From b123b19ca5d1874b9a7e1b5e2d6bece84b032c2a Mon Sep 17 00:00:00 2001 From: Harley White Date: Wed, 2 Jun 2021 17:39:19 -0400 Subject: [PATCH] Fixed NaN checks --- changelog.md | 5 +++-- js/technical/temp.js | 34 +++++++++++++++++++++++++++------- js/utils/save.js | 13 ++++++------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index 10a78e5..004b0a0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,12 @@ # The Modding Tree changelog: +- Fixed issues with NaN checking. Saves should never break now unless something really unusual happens. - Fixed demo.html - You can now use "this" in tabFormat! -- The prestige/sec display now shows decimals. -- resetsNothing now works immediately on a reset that enables it. - Added onComplete for milestones. - Added addBuyables. +- The prestige/sec display now shows decimals. +- resetsNothing now works immediately on a reset that enables it. - Fixed challenges with no currencyDisplayName using "points" instead of the mod's pointsName. - inChallenge no longer can return undefined. diff --git a/js/technical/temp.js b/js/technical/temp.js index ed2d4b0..399618f 100644 --- a/js/technical/temp.js +++ b/js/technical/temp.js @@ -84,6 +84,7 @@ function setupTempData(layerData, tmpData, funcsData) { } } + function updateTemp() { if (tmp === undefined) setupTemp() @@ -91,16 +92,34 @@ function updateTemp() { updateTempData(layers, tmp, funcs) for (layer in layers){ + let problem = "" tmp[layer].resetGain = getResetGain(layer) + if (checkDecimalNaN(tmp[layer].resetGain)) + problem = "resetGain" tmp[layer].nextAt = getNextAt(layer) + if (checkDecimalNaN(tmp[layer].nextAt)) + problem = "nextAt" tmp[layer].nextAtDisp = getNextAt(layer, true) tmp[layer].canReset = canReset(layer) tmp[layer].trueGlowColor = tmp[layer].glowColor tmp[layer].notify = shouldNotify(layer) tmp[layer].prestigeNotify = prestigeNotify(layer) + if (problem && !NaNalert) { + confirm("Invalid value found in temp." + layer + "." + problem + ". Please let the creator of this mod know! You can refresh the page, and you will be un-NaNed.") + clearInterval(interval); + NaNalert = true; + return + } + } tmp.pointGen = getPointGen() + if (checkDecimalNaN(tmp.pointGen) && !NaNalert) { + confirm("Invalid value found in temp.pointGen. Please let the creator of this mod know! You can refresh the page, and you will be un-NaNed.") + clearInterval(interval); + NaNalert = true; + return + } tmp.displayThings = [] for (thing in displayThings){ let text = displayThings[thing] @@ -123,15 +142,12 @@ function updateTempData(layerData, tmpData, funcsData, useThis) { if (useThis !== undefined) value = layerData[item].bind(useThis)() else value = layerData[item]() - if (value !== value || value === decimalNaN){ - if (NaNalert === true || confirm ("Invalid value found in tmp, named '" + item + "'. Please let the creator of this mod know! Would you like to try to auto-fix the save and keep going?")){ - NaNalert = true - value = (value !== value ? 0 : decimalZero) - } - else { + if (value !== value || checkDecimalNaN(value)){ + if (!NaNalert) { + confirm("Invalid value found in tmp, named '" + item + "'. Please let the creator of this mod know! You can refresh the page, and you will be un-NaNed.") clearInterval(interval); - player.autosave = false; NaNalert = true; + return } } Vue.set(tmpData, item, value) @@ -171,4 +187,8 @@ function setupBuyables(layer) { } } } +} + +function checkDecimalNaN(x) { + return (x instanceof Decimal) && !x.eq(x) } \ No newline at end of file diff --git a/js/utils/save.js b/js/utils/save.js index cc3a24b..0892a33 100644 --- a/js/utils/save.js +++ b/js/utils/save.js @@ -1,5 +1,6 @@ // ************ Save stuff ************ function save() { + if (NaNalert) return localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(player))))); } function startPlayerBase() { @@ -228,15 +229,12 @@ function NaNcheck(data) { else if (Array.isArray(data[item])) { NaNcheck(data[item]); } - else if (data[item] !== data[item] || data[item] === decimalNaN) { - if (NaNalert === true || confirm("Invalid value found in player, named '" + item + "'. Please let the creator of this mod know! Would you like to try to auto-fix the save and keep going?")) { - NaNalert = true; - data[item] = (data[item] !== data[item] ? 0 : decimalZero); - } - else { + else if (data[item] !== data[item] || checkDecimalNaN(data[item])) { + if (!NaNalert) { + confirm("Invalid value found in player, named '" + item + "'. Please let the creator of this mod know! You can refresh the page, and you will be un-NaNed.") clearInterval(interval); - player.autosave = false; NaNalert = true; + return } } else if (data[item] instanceof Decimal) { // Convert to Decimal @@ -247,6 +245,7 @@ function NaNcheck(data) { } } function exportSave() { + if (NaNalert) return let str = btoa(JSON.stringify(player)); const el = document.createElement("textarea");