From 3257bded82a61d86b8b8571776f0b8c26b4b38fe Mon Sep 17 00:00:00 2001 From: "Laetitia (O-01-67)" <68935009+O-01-67@users.noreply.github.com> Date: Sun, 5 Mar 2023 14:32:32 -0500 Subject: [PATCH] parse-stringify fallback for no structuredClone to phaseout shortenNulls setting and make it always on --- mods/save_loading.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/mods/save_loading.js b/mods/save_loading.js index e020fb34..8896c030 100644 --- a/mods/save_loading.js +++ b/mods/save_loading.js @@ -6,7 +6,7 @@ function zeroToNull(val) { }; if(!localStorage.slSaveSettings) { - localStorage.setItem("slSaveSettings", '{"shortenNulls":false,"roundTemps":true}'); + localStorage.setItem("slSaveSettings", '{"roundTemps":true}'); }; slSaveSettings = JSON.parse(localStorage.slSaveSettings); @@ -18,7 +18,7 @@ function epsilonRound(num,precision) { function getSimulationState() { var simulationState = { //currentPixels: currentPixels, - pixelMap: structuredClone(pixelMap), + pixelMap: structuredClone ? structuredClone(pixelMap) : JSON.parse(JSON.stringify(pixelMap)), width: width, height: height, pixelSize: pixelSize, @@ -26,18 +26,11 @@ function getSimulationState() { version: 1, enabledMods: localStorage.enabledMods, }; - nulls: if(slSaveSettings.shortenNulls) { - if(!structuredClone) { - alert("Your browser does not support structuredClone, which is needed to shorten nulls to zeroes without corrupting the current pixelMap."); - console.error("shortenNulls: structuredClone not supported"); - break nulls; - }; - for(i = 0; i < simulationState.pixelMap.length; i++) { - var column = simulationState.pixelMap[i]; - for(j = 0; j < column.length; j++) { - if(column[j] === null || typeof(column[j]) === "undefined") { - column[j] = 0; - }; + for(i = 0; i < simulationState.pixelMap.length; i++) { + var column = simulationState.pixelMap[i]; + for(j = 0; j < column.length; j++) { + if(column[j] === null || typeof(column[j]) === "undefined") { + column[j] = 0; }; }; };