From 868a77af29f7a03b441adae70802a678055073f7 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Tue, 10 May 2022 20:58:13 -0500 Subject: [PATCH] Saving is now always lz-string. saveEncoding renamed to exportEncoding. exportEncoding only affects exports, and defaults to base64 so it's obfuscated but doesn't have issues with being pasted in discord --- src/components/SavesManager.vue | 4 ++-- src/data/projInfo.json | 2 +- src/game/settings.ts | 14 +------------- src/util/save.ts | 16 +++------------- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/components/SavesManager.vue b/src/components/SavesManager.vue index 940bfc2..bf4d956 100644 --- a/src/components/SavesManager.vue +++ b/src/components/SavesManager.vue @@ -192,9 +192,9 @@ function exportSave(id: string) { saveToExport = save(); } else { saveToExport = JSON.stringify(saves.value[id]); - switch (projInfo.saveEncoding) { + switch (projInfo.exportEncoding) { default: - console.warn(`Unknown save encoding: ${projInfo.saveEncoding}. Defaulting to lz`); + console.warn(`Unknown save encoding: ${projInfo.exportEncoding}. Defaulting to lz`); case "lz": saveToExport = LZString.compressToUTF16(saveToExport); break; diff --git a/src/data/projInfo.json b/src/data/projInfo.json index ad6543d..0356f2a 100644 --- a/src/data/projInfo.json +++ b/src/data/projInfo.json @@ -19,5 +19,5 @@ "maxTickLength": 3600, "offlineLimit": 1, "enablePausing": true, - "saveEncoding": "lz" + "exportEncoding": "base64" } diff --git a/src/game/settings.ts b/src/game/settings.ts index 927c704..9649847 100644 --- a/src/game/settings.ts +++ b/src/game/settings.ts @@ -25,19 +25,7 @@ const state = reactive>({ watch( state, state => { - let stringifiedSettings = JSON.stringify(state); - switch (projInfo.saveEncoding) { - default: - console.warn(`Unknown save encoding: ${projInfo.saveEncoding}. Defaulting to lz`); - case "lz": - stringifiedSettings = LZString.compressToUTF16(stringifiedSettings); - break; - case "base64": - stringifiedSettings = btoa(unescape(encodeURIComponent(stringifiedSettings))); - break; - case "plain": - break; - } + const stringifiedSettings = LZString.compressToUTF16(JSON.stringify(state)); localStorage.setItem(projInfo.id, stringifiedSettings); }, { deep: true } diff --git a/src/util/save.ts b/src/util/save.ts index 6e602e4..58f0c2a 100644 --- a/src/util/save.ts +++ b/src/util/save.ts @@ -25,19 +25,9 @@ export function setupInitialStore(player: Partial = {}): Player { } export function save(playerData?: PlayerData): string { - let stringifiedSave = stringifySave(playerData ?? player[ProxyState]); - switch (projInfo.saveEncoding) { - default: - console.warn(`Unknown save encoding: ${projInfo.saveEncoding}. Defaulting to lz`); - case "lz": - stringifiedSave = LZString.compressToUTF16(stringifiedSave); - break; - case "base64": - stringifiedSave = btoa(unescape(encodeURIComponent(stringifiedSave))); - break; - case "plain": - break; - } + const stringifiedSave = LZString.compressToUTF16( + stringifySave(playerData ?? player[ProxyState]) + ); localStorage.setItem((playerData ?? player[ProxyState]).id, stringifiedSave); return stringifiedSave; }