1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-21 16:13:55 +00:00

NaNs are handled

This commit is contained in:
Acamaeda 2020-10-27 17:41:35 -04:00
parent 9bfe0fc3d3
commit de17f38f2f
5 changed files with 55 additions and 9 deletions

View file

@ -1,5 +1,7 @@
# The Modding Tree changelog:
- NaN is now handled more intelligently.
### v2.1.4 - 10/25/20
- Added an infobox component. Thank you to thepaperpilot for this contribution!
- Layer type is now optional, and defaults to "none".

View file

@ -1,6 +1,5 @@
var player;
var needCanvasUpdate = true;
var NaNalert = false;
var gameEnded = false;
// Don't change this
@ -319,13 +318,6 @@ function gameLoop(diff) {
if (layers[layer].achievements) updateAchievements(layer)
}
if (player.hasNaN&&!NaNalert) {
clearInterval(interval);
player.autosave = false;
NaNalert = true;
alert("We have detected a corruption in your save. Please visit one of the discords in the info panel for help.")
}
}
function hardReset() {
@ -358,5 +350,6 @@ var interval = setInterval(function() {
if (needCanvasUpdate) resizeCanvas();
updateTemp();
gameLoop(diff)
fixNaNs()
ticking = false
}, 50)

View file

@ -1,5 +1,9 @@
var layers = {}
const decimalZero = new Decimal(0)
const decimalOne = new Decimal(1)
const decimalNaN = new Decimal(NaN)
function layerShown(layer){
return layers[layer].layerShown();
}

View file

@ -1,4 +1,5 @@
var tmp = {}
var NaNalert = false;
// Tmp will not call these
var activeFunctions = [
@ -88,7 +89,21 @@ function updateTempData(layerData, tmpData) {
updateTempData(layerData[item], tmpData[item])
}
else if (isFunction(layerData[item]) && !activeFunctions.includes(item)){
Vue.set(tmpData, item, layerData[item]())
let 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 mknow! Would you like to try to auto-fix the save and keep going?")){
NaNalert = true
value = (value !== value ? 0 : decimalZero)
}
else {
clearInterval(interval);
player.autosave = false;
NaNalert = true;
}
}
Vue.set(tmpData, item, value)
}
}
}

View file

@ -241,6 +241,38 @@ function load() {
loadVue();
}
function fixNaNs() {
NaNcheck(player)
}
function NaNcheck(data) {
for (item in data){
if (data[item] == null) {
}
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 mknow! Would you like to try to auto-fix the save and keep going?")){
NaNalert = true
data[item] = (data[item] !== data[item] ? 0 : decimalZero)
}
else {
clearInterval(interval);
player.autosave = false;
NaNalert = true;
}
}
else if (data[item] instanceof Decimal) { // Convert to Decimal
}
else if ((!!data[item]) && (data[item].constructor === Object)) {
NaNcheck(data[item])
}
}
}
function exportSave() {
let str = btoa(JSON.stringify(player))