Permanently Fix LocalStorage Problems

This commit is contained in:
Neshura 2024-05-22 23:03:26 +02:00
parent 86cbc1d81d
commit 9a63e033a1
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -22,6 +22,7 @@
import {Inventory} from "$lib/containers.svelte";
import InventoryList from "$lib/components/InventoryList.svelte";
const STORAGE_VERSION = "2";
let i18n = $state(new Localization("en-GB"));
let mounted = $state(false);
@ -50,7 +51,7 @@
let material: CargoMaterial = $state(CargoMaterial.Ore);
$effect(() => {
if (mounted) {
localStorage.setItem("density", JSON.stringify(material.save()));
localStorage.setItem("density", material.save());
}
})
@ -80,7 +81,20 @@
i18n.language = navigator.language;
}
let ret = getFromLocalStorage("ship");
let ret = getFromLocalStorage("version");
if (ret.result) {
console.log(ret);
if (ret.value !== STORAGE_VERSION) {
localStorage.clear();
localStorage.setItem("version", STORAGE_VERSION);
}
}
else {
localStorage.clear();
localStorage.setItem("version", STORAGE_VERSION);
}
ret = getFromLocalStorage("ship");
if (ret.result) {
ship.load(JSON.parse(ret.value));
}
@ -92,7 +106,7 @@
ret = getFromLocalStorage("density");
if (ret.result) {
let parsed = JSON.parse(ret.value);
let parsed = ret.value;
Object.values(CargoMaterial).forEach((cargoMaterial) => {
if (cargoMaterial.name === parsed) {
material = cargoMaterial