Skip to content

Commit

Permalink
Config now remembers characters for diff accounts.
Browse files Browse the repository at this point in the history
Map proves to be difficult to interface with JSON, but it works! The last remaining config that needs fixing is the account.
  • Loading branch information
smithcol11 committed Apr 3, 2024
1 parent 65bd7ce commit 5df3b58
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<string, string>
// but this has other problems and implications
const characters: Record<string, string> = {};
configSub.selected_characters?.forEach((value, key) => {
characters[key] = value;
});
const object: Record<string, unknown> = {};
Object.assign(object, configSub);
object.selected_characters = characters;
const json = JSON.stringify(object, null, 4);
xml.send(json);
}
}
1 change: 1 addition & 0 deletions app/src/lib/Launch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$selectedPlay.character?.accountId
);
}
$isConfigDirty = true;
}
// update selected_play
Expand Down

0 comments on commit 5df3b58

Please sign in to comment.