From 5df3b5890f139011ce1cdb67883acaed396aa69c Mon Sep 17 00:00:00 2001 From: smithcol11 Date: Tue, 2 Apr 2024 21:44:50 -0700 Subject: [PATCH] Config now remembers characters for diff accounts. Map proves to be difficult to interface with JSON, but it works! The last remaining config that needs fixing is the account. --- app/src/functions.ts | 27 +++++++++++++++++++++++++-- app/src/lib/Launch.svelte | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/functions.ts b/app/src/functions.ts index 05788235..0e4c3cca 100644 --- a/app/src/functions.ts +++ b/app/src/functions.ts @@ -112,7 +112,18 @@ export function urlSearchParams(): void { if (conf) { try { // as above, no need to set configIsDirty - config.set(JSON.parse(conf)); + const parsedConf = JSON.parse(conf); + config.set(parsedConf); + // convert parsed objects into Maps + config.update((data) => { + if (data.selected_game_accounts) { + data.selected_characters = new Map(Object.entries(data.selected_game_accounts)); + delete data.selected_game_accounts; + } else if (data.selected_characters) { + data.selected_characters = new Map(Object.entries(data.selected_characters)); + } + return data; + }); } catch (error: unknown) { err(`Couldn't parse config file: ${error}`, false); } @@ -779,6 +790,18 @@ export function saveConfig() { } }; xml.setRequestHeader('Content-Type', 'application/json'); - xml.send(JSON.stringify(configSub, null, 4)); + + // converting map into something that is compatible for JSON.stringify + // maybe the map should be converted into a Record + // but this has other problems and implications + const characters: Record = {}; + configSub.selected_characters?.forEach((value, key) => { + characters[key] = value; + }); + const object: Record = {}; + Object.assign(object, configSub); + object.selected_characters = characters; + const json = JSON.stringify(object, null, 4); + xml.send(json); } } diff --git a/app/src/lib/Launch.svelte b/app/src/lib/Launch.svelte index 47675874..fcd4f6ea 100644 --- a/app/src/lib/Launch.svelte +++ b/app/src/lib/Launch.svelte @@ -22,6 +22,7 @@ $selectedPlay.character?.accountId ); } + $isConfigDirty = true; } // update selected_play