From a1d11ccf2b916ff85ae52d4bb34152cb6f21255d Mon Sep 17 00:00:00 2001 From: Harley White Date: Thu, 17 Jun 2021 11:51:40 -0400 Subject: [PATCH] Various fixes --- changelog.md | 5 +++++ js/Demo/demoMod.js | 2 +- js/game.js | 24 +++++------------------- js/utils/save.js | 10 ++++++++-- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index 734741b..1c9ce4e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,13 @@ # The Modding Tree changelog: +# v2.6.4 - 6/17/21 +- The game now autosaves before closing, if autosave is on. (Thank you to thepaperpilot for this!) +- More Anti-NaN safety. +- canReset now works properly for non-custom layers. - Fixed baseAmount being set to 0 even when a layer resets nothing. - Fixed centering on tooltips. - Changed some default values on startup to prevent potential issues. +- Cleaned up resetting. # v2.6.3 - 6/11/21 - Added better support for using multiple layer files and similar. See modFiles in modInfo. diff --git a/js/Demo/demoMod.js b/js/Demo/demoMod.js index 6699f96..4257d46 100644 --- a/js/Demo/demoMod.js +++ b/js/Demo/demoMod.js @@ -13,7 +13,7 @@ let modInfo = { // Set your version in num and name let VERSION = { - num: "2.6.3", + num: "2.6.4", name: "Fixed Reality", } diff --git a/js/game.js b/js/game.js index 955a3dc..68e3580 100644 --- a/js/game.js +++ b/js/game.js @@ -4,7 +4,7 @@ var gameEnded = false; // Don't change this const TMT_VERSION = { - tmtNum: "2.6.3", + tmtNum: "2.6.4", tmtName: "Fixed Reality" } @@ -145,29 +145,14 @@ function layerDataReset(layer, keep = []) { if (player[layer][keep[thing]] !== undefined) storedData[keep[thing]] = player[layer][keep[thing]] } - Vue.set(player[layer], "buyables", getStartBuyables(layer)) - Vue.set(player[layer], "clickables", getStartClickables(layer)) - Vue.set(player[layer], "challenges", getStartChallenges(layer)) layOver(player[layer], getStartLayerData(layer)) - player[layer].upgrades = [] - player[layer].milestones = [] - player[layer].achievements = [] - player[layer].challenges = getStartChallenges(layer) - resetBuyables(layer) - if (layers[layer].clickables && !player[layer].clickables) - player[layer].clickables = getStartClickables(layer) for (thing in storedData) { player[layer][thing] =storedData[thing] } } -function resetBuyables(layer){ - if (layers[layer].buyables) - player[layer].buyables = getStartBuyables(layer) - player[layer].spentOnBuyables = decimalZero -} function addPoints(layer, gain) { @@ -184,15 +169,16 @@ function doReset(layer, force=false) { if (tmp[layer].type == "none") return let row = tmp[layer].row if (!force) { + + if (tmp[layer].canReset === false) return; + if (tmp[layer].baseAmount.lt(tmp[layer].requires)) return; let gain = tmp[layer].resetGain if (tmp[layer].type=="static") { if (tmp[layer].baseAmount.lt(tmp[layer].nextAt)) return; gain =(tmp[layer].canBuyMax ? gain : 1) } - if (tmp[layer].type=="custom") { - if (!tmp[layer].canReset) return; - } + if (layers[layer].onPrestige) run(layers[layer].onPrestige, layers[layer], gain) diff --git a/js/utils/save.js b/js/utils/save.js index 845f503..597cdd1 100644 --- a/js/utils/save.js +++ b/js/utils/save.js @@ -243,13 +243,13 @@ function NaNcheck(data) { } 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); NaNalert = true; + alert("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.") return } } - else if (data[item] instanceof Decimal) { // Convert to Decimal + else if (data[item] instanceof Decimal) { } else if ((!!data[item]) && (data[item].constructor === Object)) { NaNcheck(data[item]); @@ -313,3 +313,9 @@ var saveInterval = setInterval(function () { if (options.autosave) save(); }, 5000); + +window.onbeforeunload = () => { + if (player.autosave) { + save(); + } +}; \ No newline at end of file