diff --git a/src/lib/types/chellaris.ts b/src/lib/types/chellaris.ts index 969beea..3d54968 100644 --- a/src/lib/types/chellaris.ts +++ b/src/lib/types/chellaris.ts @@ -101,7 +101,7 @@ export const createBlankEmpire = ( machine: false, portrait_id: 0, portrait_group_id: 0, - ethics: [], + ethics: {}, discord_user: undefined, name: "" }; diff --git a/src/lib/types/stellaris.ts b/src/lib/types/stellaris.ts index ef3e8f9..4889b60 100644 --- a/src/lib/types/stellaris.ts +++ b/src/lib/types/stellaris.ts @@ -68,14 +68,11 @@ export type Ethic = { id: number, display: string, gestalt: boolean, - fanatic?: boolean, } export type EmpireEthic = { ethic_id: number, - display: string, - gestalt: boolean, - fanatic?: boolean, + fanatic: boolean, } export type Phenotype = { diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index 9c98802..c3ec156 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -39,7 +39,6 @@ let empireList: { [key: number]: ChellarisEmpire } = {}; let empireData: ChellarisEmpire; let addingNewEmpire = false; - $: console.log("adding:", addingNewEmpire); let loadingEmpireData = true; const updateGameData = () => { @@ -54,17 +53,19 @@ groupList = data.groups; empireList = {}; Object.values(data.empires).forEach((empire: ChellarisEmpire) => { - if ($AdminSelectedGroupStore[$AdminSelectedGameStore] === undefined) { + if (typeof $AdminSelectedGroupStore[$AdminSelectedGameStore] === 'undefined') { $AdminSelectedGroupStore[$AdminSelectedGameStore] = {}; } - if ($AdminSelectedGroupStore[$AdminSelectedGameStore][empire.group]) { + if (typeof $AdminSelectedGroupStore[$AdminSelectedGameStore][empire.group] !== 'undefined') { empireList[empire.id] = empire; } }); delay(200).then(() => (loadingGameData = false)); delay(200).then(() => (loaded = true)); - loadEmpireData(); + if (typeof $AdminSelectedEmpireStore[$AdminSelectedGameStore] !== 'undefined') { + loadEmpireData(); + } }); }); } @@ -94,7 +95,10 @@ } } - AdminSelectedGameStore.subscribe(() => { + AdminSelectedGameStore.subscribe((game) => { + if (typeof game === 'undefined') { + game = Object.values(gameList)[0].id; + } updateGameData(); loadingGameData = true; }); @@ -217,7 +221,9 @@ const setActiveEmpire = (empireId: number) => { loadingEmpireData = true; $AdminSelectedEmpireStore[$AdminSelectedGameStore] = empireId; - loadEmpireData(); + if (typeof $AdminSelectedEmpireStore[$AdminSelectedGameStore] !== 'undefined') { + loadEmpireData(); + } }; const addEmpire = () => { @@ -228,13 +234,13 @@ list2.push(list2.length); */ }; - const finishAddNewEmpire = (event: { detail: { new_id: number; }; }) => { + const finishAddNewEmpire = (event: { detail: { new_id: number } }) => { $AdminSelectedEmpireStore[$AdminSelectedGameStore] = event.detail.new_id; updateGameData(); }; const deleteEmpire = (empire: ChellarisEmpire) => { - fetch(apiBaseUrl + '/v3/empire?game_id=' + empire.game + '&group_id=' + empire.group + '&empire_id=' + empire.id, { + fetch(apiBaseUrl + '/v3/empire?game_id=' + empire.game + '&empire_id=' + empire.id, { method: 'DELETE', headers: { 'Content-Type': 'application/json', @@ -358,7 +364,7 @@ >
{empire.name}
- {empire.discord_user || "N/A"} + {empire.discord_user || 'N/A'}
+ {#if newEmpireError[0]} +
{newEmpireError[1]}
+ {/if} {:else if !newEmpire}
{#if empire} @@ -299,24 +339,38 @@
- (selection.fanatic ? "Fanatic " : "") + $LeanChellarisDataStore.ethics[selection.ethic_id].display).join(", ")} dropdownId={ethicsDropdownId}> - {#each Object.values($LeanChellarisDataStore.ethics) as ethic} + (selection.fanatic ? 'Fanatic ' : '') + $LeanChellarisDataStore.ethics[selection.ethic_id].display) + .join(', ')} + dropdownId={ethicsDropdownId} + > + {#each Object.values($LeanChellarisDataStore.ethics) as ethic, index} {#if ethic} - + + + {/if} {/each} -
- {#if empire.ethics} - Ethics: - {#each Object.values(empire.ethics) as ethic} - {ethic.fanatic ? ' Fanatic' : ''} {$LeanChellarisDataStore.ethics[ethic.ethic_id].display}, - {/each} - {/if} -
{:else} No Empire Selected {/if} diff --git a/src/routes/graphs/excel-style/+page.svelte b/src/routes/graphs/excel-style/+page.svelte index 51226a1..f53d556 100644 --- a/src/routes/graphs/excel-style/+page.svelte +++ b/src/routes/graphs/excel-style/+page.svelte @@ -118,7 +118,7 @@ const tmpEthicPageData = newPageData.ethicsData[ethic.ethic_id]; if (typeof tmpEthicPageData !== 'undefined') { - tmpEthicPageData.display = ethic.display; + tmpEthicPageData.display = $ChellarisDataStore.ethics[ethic.ethic_id].display; if (!ethic.fanatic) { tmpEthicPageData.regular = tmpEthicPageData.regular + 1; } else { @@ -135,8 +135,8 @@ fanatic: number; } = { id: ethic.ethic_id, - gestalt: ethic.gestalt, - display: ethic.display, + gestalt: $ChellarisDataStore.ethics[ethic.ethic_id].gestalt, + display: $ChellarisDataStore.ethics[ethic.ethic_id].display, regular: 0, fanatic: 0 };