mirror of
https://github.com/Acamaeda/The-Modding-Tree.git
synced 2025-04-30 13:32:10 +00:00
NaNs are handled
This commit is contained in:
parent
9bfe0fc3d3
commit
de17f38f2f
5 changed files with 55 additions and 9 deletions
|
@ -1,5 +1,7 @@
|
||||||
# The Modding Tree changelog:
|
# The Modding Tree changelog:
|
||||||
|
|
||||||
|
- NaN is now handled more intelligently.
|
||||||
|
|
||||||
### v2.1.4 - 10/25/20
|
### v2.1.4 - 10/25/20
|
||||||
- Added an infobox component. Thank you to thepaperpilot for this contribution!
|
- Added an infobox component. Thank you to thepaperpilot for this contribution!
|
||||||
- Layer type is now optional, and defaults to "none".
|
- Layer type is now optional, and defaults to "none".
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
var player;
|
var player;
|
||||||
var needCanvasUpdate = true;
|
var needCanvasUpdate = true;
|
||||||
var NaNalert = false;
|
|
||||||
var gameEnded = false;
|
var gameEnded = false;
|
||||||
|
|
||||||
// Don't change this
|
// Don't change this
|
||||||
|
@ -319,13 +318,6 @@ function gameLoop(diff) {
|
||||||
if (layers[layer].achievements) updateAchievements(layer)
|
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() {
|
function hardReset() {
|
||||||
|
@ -358,5 +350,6 @@ var interval = setInterval(function() {
|
||||||
if (needCanvasUpdate) resizeCanvas();
|
if (needCanvasUpdate) resizeCanvas();
|
||||||
updateTemp();
|
updateTemp();
|
||||||
gameLoop(diff)
|
gameLoop(diff)
|
||||||
|
fixNaNs()
|
||||||
ticking = false
|
ticking = false
|
||||||
}, 50)
|
}, 50)
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
var layers = {}
|
var layers = {}
|
||||||
|
|
||||||
|
const decimalZero = new Decimal(0)
|
||||||
|
const decimalOne = new Decimal(1)
|
||||||
|
const decimalNaN = new Decimal(NaN)
|
||||||
|
|
||||||
function layerShown(layer){
|
function layerShown(layer){
|
||||||
return layers[layer].layerShown();
|
return layers[layer].layerShown();
|
||||||
}
|
}
|
||||||
|
|
17
js/temp.js
17
js/temp.js
|
@ -1,4 +1,5 @@
|
||||||
var tmp = {}
|
var tmp = {}
|
||||||
|
var NaNalert = false;
|
||||||
|
|
||||||
// Tmp will not call these
|
// Tmp will not call these
|
||||||
var activeFunctions = [
|
var activeFunctions = [
|
||||||
|
@ -88,7 +89,21 @@ function updateTempData(layerData, tmpData) {
|
||||||
updateTempData(layerData[item], tmpData[item])
|
updateTempData(layerData[item], tmpData[item])
|
||||||
}
|
}
|
||||||
else if (isFunction(layerData[item]) && !activeFunctions.includes(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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
js/utils.js
32
js/utils.js
|
@ -241,6 +241,38 @@ function load() {
|
||||||
loadVue();
|
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() {
|
function exportSave() {
|
||||||
let str = btoa(JSON.stringify(player))
|
let str = btoa(JSON.stringify(player))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue