parse-stringify fallback for no structuredClone

to phaseout shortenNulls setting and make it always on
This commit is contained in:
Laetitia (O-01-67) 2023-03-05 14:32:32 -05:00 committed by GitHub
parent 83046dc20f
commit 3257bded82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 14 deletions

View File

@ -6,7 +6,7 @@ function zeroToNull(val) {
}; };
if(!localStorage.slSaveSettings) { if(!localStorage.slSaveSettings) {
localStorage.setItem("slSaveSettings", '{"shortenNulls":false,"roundTemps":true}'); localStorage.setItem("slSaveSettings", '{"roundTemps":true}');
}; };
slSaveSettings = JSON.parse(localStorage.slSaveSettings); slSaveSettings = JSON.parse(localStorage.slSaveSettings);
@ -18,7 +18,7 @@ function epsilonRound(num,precision) {
function getSimulationState() { function getSimulationState() {
var simulationState = { var simulationState = {
//currentPixels: currentPixels, //currentPixels: currentPixels,
pixelMap: structuredClone(pixelMap), pixelMap: structuredClone ? structuredClone(pixelMap) : JSON.parse(JSON.stringify(pixelMap)),
width: width, width: width,
height: height, height: height,
pixelSize: pixelSize, pixelSize: pixelSize,
@ -26,12 +26,6 @@ function getSimulationState() {
version: 1, version: 1,
enabledMods: localStorage.enabledMods, 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++) { for(i = 0; i < simulationState.pixelMap.length; i++) {
var column = simulationState.pixelMap[i]; var column = simulationState.pixelMap[i];
for(j = 0; j < column.length; j++) { for(j = 0; j < column.length; j++) {
@ -40,7 +34,6 @@ function getSimulationState() {
}; };
}; };
}; };
};
if(slSaveSettings.roundTemps) { if(slSaveSettings.roundTemps) {
for(i = 0; i < simulationState.pixelMap.length; i++) { for(i = 0; i < simulationState.pixelMap.length; i++) {
var column = simulationState.pixelMap[i]; var column = simulationState.pixelMap[i];