diff --git a/src/lib/components/LoadingSpinner.svelte b/src/lib/components/LoadingSpinner.svelte index 9a20317..b00001c 100644 --- a/src/lib/components/LoadingSpinner.svelte +++ b/src/lib/components/LoadingSpinner.svelte @@ -23,7 +23,6 @@ width: var(--size); height: var(--size); box-sizing: border-box; - position: relative; border: 3px solid transparent; border-top-color: var(--color-active-1); border-radius: 50%; diff --git a/src/lib/components/LoadingSpinnerLocal.svelte b/src/lib/components/LoadingSpinnerLocal.svelte new file mode 100644 index 0000000..18051c5 --- /dev/null +++ b/src/lib/components/LoadingSpinnerLocal.svelte @@ -0,0 +1,75 @@ + + +
+ + diff --git a/src/lib/components/consts.ts b/src/lib/components/consts.ts index ec93359..de9f2a5 100644 --- a/src/lib/components/consts.ts +++ b/src/lib/components/consts.ts @@ -1 +1,2 @@ -export const apiBaseUrl = 'https://wip.chellaris.net/api'; \ No newline at end of file +export const apiBaseUrl = 'https://wip.chellaris.net/api'; +export const MACHINE_GROUP_ID = 12; \ No newline at end of file diff --git a/src/lib/stores/ChellarisData.ts b/src/lib/stores/ChellarisData.ts index 0581c6a..088ee33 100644 --- a/src/lib/stores/ChellarisData.ts +++ b/src/lib/stores/ChellarisData.ts @@ -1,7 +1,9 @@ import { writable, type Writable } from "svelte/store"; -import type { ChellarisInfo } from '../types/chellaris'; +import { createBlankChellarisData, type ChellarisData, type ChellarisInfo } from '../types/chellaris'; import { createChellarisInfo } from '../types/chellaris'; const ChellarisDataStore: Writable = writable(createChellarisInfo()); -export default ChellarisDataStore; \ No newline at end of file +export default ChellarisDataStore; + +export const LeanChellarisDataStore: Writable = writable(createBlankChellarisData()); diff --git a/src/lib/types/chellaris.ts b/src/lib/types/chellaris.ts index eef408c..969beea 100644 --- a/src/lib/types/chellaris.ts +++ b/src/lib/types/chellaris.ts @@ -1,9 +1,19 @@ -import type { EmpireEthic, Ethic, Species } from './stellaris'; +import type { EmpireEthic, Ethic, Phenotype } from './stellaris'; export type ChellarisInfo = { games: { [key: number]: ChellarisGame }, // Key is Game Id ethics: { [key: number]: Ethic }, // Key is Ethic Id - species: { [key: number]: Species }, // Key is Species Group Id + phenotypes: { [key: number]: Phenotype }, // Key is Species Group Id +} + +export const createChellarisInfo = (): ChellarisInfo => { + const newChellarisInfo = { + games: {}, + ethics: {}, + phenotypes: {}, + }; + + return newChellarisInfo; } export type ChellarisGame = { @@ -13,39 +23,6 @@ export type ChellarisGame = { empires: { [key: number]: ChellarisEmpire }, // Key is Empire Id } -export type ChellarisGameGroup = { - id: number, - name: string, -} - -export type ChellarisEmpire = { - id: number, - group: number, - game: number, - name: string, - discord_user?: string, - gestalt: boolean, - machine: boolean, - portrait_id: number, // TODO replace with Enum? - portrait_group_id: number, // TODO replace with Enum? - ethics: { [key: number]: EmpireEthic }, -} - -export type ChellarisGameInfo = { - id: number, - name: string -} - -export const createChellarisInfo = (): ChellarisInfo => { - const newChellarisInfo = { - games: [], - ethics: [], - species: [], - }; - - return newChellarisInfo; -} - export const createChellarisGame = (): ChellarisGame => { const newChellarisGame = { id: 1, @@ -57,6 +34,11 @@ export const createChellarisGame = (): ChellarisGame => { return newChellarisGame; } +export type ChellarisGameGroup = { + id: number, + name: string, +} + export const createChellarisGameGroup = (): ChellarisGameGroup => { const newChellarisGameGroup = { id: 1, @@ -66,6 +48,19 @@ export const createChellarisGameGroup = (): ChellarisGameGroup => { return newChellarisGameGroup; } +export type ChellarisEmpire = { + id: number, + group: number, + game: number, + name: string, + discord_user?: string, + gestalt: boolean, + machine: boolean, + portrait_id: number, // TODO replace with Enum? + portrait_group_id: number, // TODO replace with Enum? + ethics: { [key: number]: EmpireEthic }, +} + export const createChellarisEmpire = ( { id, name, discord_user, group_id, game_id, gestalt, portrait_id, portrait_group_id @@ -93,4 +88,42 @@ export const createChellarisEmpire = ( }; return newChellarisEmpire; -} \ No newline at end of file +} + +export const createBlankEmpire = ( + game: number +) => { + const newChellarisEmpire: ChellarisEmpire = { + id: 0, + group: 0, + game: game, + gestalt: false, + machine: false, + portrait_id: 0, + portrait_group_id: 0, + ethics: [], + discord_user: undefined, + name: "" + }; + + return newChellarisEmpire; +} + +export type ChellarisGameInfo = { + id: number, + name: string +} + +export type ChellarisData = { + ethics: { [key: number]: Ethic }, + phenotypes: { [key: number]: Phenotype } +} + +export const createBlankChellarisData = () => { + const newData: ChellarisData = { + ethics: {}, + phenotypes: {} + }; + + return newData; +} diff --git a/src/lib/types/stellaris.ts b/src/lib/types/stellaris.ts index 1f4ac1a..ef3e8f9 100644 --- a/src/lib/types/stellaris.ts +++ b/src/lib/types/stellaris.ts @@ -67,21 +67,21 @@ export class EthicsDataLegacy { export type Ethic = { id: number, display: string, - machine: boolean, + gestalt: boolean, fanatic?: boolean, } export type EmpireEthic = { ethic_id: number, display: string, - machine: boolean, + gestalt: boolean, fanatic?: boolean, } -export type Species = { +export type Phenotype = { id: number, display: string, - portraits: { [key: number]: Portrait }, // Key is Portrait Id + species: { [key: number]: Portrait }, // Key is Portrait Id } export type Portrait = { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 0fbfc81..1b489c8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,22 @@
diff --git a/src/routes/admin/+page.server.ts b/src/routes/admin/+page.server.ts new file mode 100644 index 0000000..c2ec326 --- /dev/null +++ b/src/routes/admin/+page.server.ts @@ -0,0 +1,15 @@ +import { apiBaseUrl } from "$lib/components/consts"; +import { redirect } from "@sveltejs/kit"; + +export async function load({ cookies }) { + const auth = await (await fetch(apiBaseUrl + "/v3/auth", { + headers: { + 'Content-Type': 'application/json', + 'x-api-key': cookies.get("authToken") || "" + } + })).json(); + + if (!auth.admin && !auth.moderator) { + throw redirect(303, '/401'); + } +} diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index ff6c8ad..9c98802 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -1,16 +1,22 @@ @@ -241,129 +259,163 @@
- - {#each Object.values(gameList) as game} - - - {/each} - {#if newGameForm} -
-
- - -
-
- {:else if addingNewGame} -
-
{newGameName}
-
- {:else} - - {/if} -
- - {#if loadingGameData} -
Loading
- {:else} - {#each Object.values(groupList) as group} - - {/if} + {#if loaded} + + {#each Object.values(gameList) as game} + {/each} - {#if newGroupForm} + {#if newGameForm}
-
- - + + +
- {:else if addingNewGroup} + {:else if addingNewGame}
-
{newGroupName}
+
{newGameName}
{:else} {/if} - {/if} -
- -
-
-
Empire Name
-
Discord User
-
-
- {#if loadingGameData} - - {:else} - {#each Object.values(empireList) as empire} - - - {:else} -
-
No Empires Present
+ {/if} + + {/each} + {#if newGroupForm} +
+
+ + +
- {/each} - {/if} + {/if} + + +
+
+
Empire Name
+
Discord User
+
+
+ {#if loadingGameData} + + {:else} + {#each Object.values(empireList) as empire} + + + {:else} +
+
No Empires Present
+
+ {/each} + {#if addingNewEmpire} +
+
{empireData.name}
+
+ {empireData.discord_user || "N/A"} +
+
+ {:else} + + {/if} + {/if} +
-
- - - {#if loadingEmpireData} - Loading... - {:else} - - {/if} - + + + {#if loadingEmpireData || loadingGameData} + + {:else if addingNewEmpire || typeof empireData.group !== 'undefined'} + + {/if} + + {:else} + + + + + + + +
+
+
Empire Name
+
Discord User
+
+
+ +
+
+
+ + + + {/if}
diff --git a/src/routes/admin/+page.ts b/src/routes/admin/+page.ts index b3ece1a..c074a8a 100644 --- a/src/routes/admin/+page.ts +++ b/src/routes/admin/+page.ts @@ -1,29 +1,10 @@ import { apiBaseUrl } from "$lib/components/consts"; import AdminSelectedEmpireStore from "$lib/stores/admin-page/EmpireStore"; import AdminSelectedGameStore from "$lib/stores/admin-page/GameStore"; -import AuthTokenStore from "$lib/stores/AuthTokenStore"; import type { ChellarisGameInfo } from "$lib/types/chellaris"; -import { redirect } from "@sveltejs/kit"; import AdminSelectedGroupStore from '../../lib/stores/admin-page/GroupStore'; export async function load ({ fetch }) { - let authToken = ""; - - AuthTokenStore.subscribe(token => { - authToken = token; - }); - - const auth = await (await fetch(apiBaseUrl + "/v3/auth",{ - headers: { - 'Content-Type': 'application/json', - 'x-api-key': authToken - } - })).json(); - - if (!auth.admin && !auth.moderator) { - throw redirect(303, '/401'); - } - const gameList: { [key: number]: ChellarisGameInfo } = await (await fetch(apiBaseUrl + "/v3/games")).json(); let store: string | null; @@ -56,5 +37,7 @@ export async function load ({ fetch }) { } } - return { games: gameList }; + return { + games: gameList + }; } \ No newline at end of file diff --git a/src/routes/admin/EmpireDetails.svelte b/src/routes/admin/EmpireDetails.svelte index 52fcd88..b5f1ad1 100644 --- a/src/routes/admin/EmpireDetails.svelte +++ b/src/routes/admin/EmpireDetails.svelte @@ -1,49 +1,329 @@ -
- {#if empire} -
- ID: {empire.id} -
-
- Group ID: {empire.group} -
-
- Game ID: {empire.game} -
-
- Gestalt: {empire.gestalt} -
-
- Machine: {empire.machine} -
-
- Portrait ID: {empire.portrait_id} -
-
- Portrait Group ID: {empire.portrait_group_id} -
-
- Name: {empire.name} -
-
- Discord User: {empire.discord_user} -
-
- {#if empire.ethics} - {#each Object.values(empire.ethics) as ethic} - {ethic.ethic_id}, - {/each} +{#if newEmpire && newEmpirePrepared} +
+ ID: {empire.id} +
+
+ Game ID: {empire.game} +
+ + {#each Object.values(groups) as group} + {#if group} + + + + {/if} -
- {:else} - No Empire Selected - {/if} -
+ {/each} + +
+ + +
+ + +
+ + + {#each Object.values($LeanChellarisDataStore.phenotypes[empire.portrait_group_id].species) as species} + {#if species} + + + + + {/if} + {/each} + +
+ + + {#each Object.values(Object.values($LeanChellarisDataStore.phenotypes)) as phenotype} + {#if phenotype} + + + + + {/if} + {/each} + +
+ + +
+ + + + $LeanChellarisDataStore.ethics[selection.ethic_id].display).join(", ")} dropdownId={ethicsDropdownId}> + {#each Object.values($LeanChellarisDataStore.ethics) as ethic} + {#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 if !newEmpire} +
+ {#if empire} +
+ ID: {empire.id} +
+
+ Game ID: {empire.game} +
+ + {#each Object.values(groups) as group} + {#if group} + + + + + {/if} + {/each} + +
+ + +
+ + +
+ + + {#each Object.values($LeanChellarisDataStore.phenotypes[empire.portrait_group_id].species) as species} + {#if species} + + + + + {/if} + {/each} + +
+ + + {#each Object.values(Object.values($LeanChellarisDataStore.phenotypes)) as phenotype} + {#if phenotype} + + + + + {/if} + {/each} + +
+ + +
+ + + (selection.fanatic ? "Fanatic " : "") + $LeanChellarisDataStore.ethics[selection.ethic_id].display).join(", ")} dropdownId={ethicsDropdownId}> + {#each Object.values($LeanChellarisDataStore.ethics) as ethic} + {#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} +
+ + +{/if} diff --git a/src/routes/graphs/excel-style/+page.svelte b/src/routes/graphs/excel-style/+page.svelte index 14b11be..51226a1 100644 --- a/src/routes/graphs/excel-style/+page.svelte +++ b/src/routes/graphs/excel-style/+page.svelte @@ -31,7 +31,7 @@ ethicsData: { [key: number]: { id: number; - machine: boolean; + gestalt: boolean; display: string; regular: number; fanatic: number; @@ -47,7 +47,7 @@ ethicsData: { [key: number]: { id: number; - machine: boolean; + gestalt: boolean; display: string; regular: number; fanatic: number; @@ -67,13 +67,13 @@ Object.values($ChellarisDataStore.ethics).forEach((ethic) => { const newEthicsData: { id: number; - machine: boolean; + gestalt: boolean; display: string; regular: number; fanatic: number; } = { id: ethic.id, - machine: ethic.machine, + gestalt: ethic.gestalt, display: ethic.display, regular: 0, fanatic: 0 @@ -84,60 +84,6 @@ Object.values(selectedGame.empires).forEach((empire) => { console.log(empire); //DEBUG if (empire.group in selectedGameGroupData.selectedGroups) { - newPageData.empireCount = newPageData.empireCount + 1; - - if (empire.gestalt) { - newPageData.gestaltCount.total = newPageData.gestaltCount.total + 1; - - let machine = false; - Object.values(empire.ethics).forEach((ethic) => { - if (ethic.machine) { - machine = true; - } - }); - - if (machine) { - newPageData.gestaltCount.machines = newPageData.gestaltCount.machines + 1; - } - } - - Object.values(empire.ethics).forEach((ethic) => { - const tmpEthicPageData = newPageData.ethicsData[ethic.ethic_id]; - - if (typeof tmpEthicPageData !== 'undefined') { - tmpEthicPageData.display = ethic.display; - if (!ethic.fanatic) { - tmpEthicPageData.regular = tmpEthicPageData.regular + 1; - } else { - tmpEthicPageData.fanatic = tmpEthicPageData.fanatic + 1; - } - - newPageData.ethicsData[ethic.ethic_id] = tmpEthicPageData; - } else { - let newEthicsData: { - id: number; - machine: boolean; - display: string; - regular: number; - fanatic: number; - } = { - id: ethic.ethic_id, - machine: ethic.machine, - display: ethic.display, - regular: 0, - fanatic: 0 - }; - - if (!ethic.fanatic) { - newEthicsData.regular = 1; - } else { - newEthicsData.fanatic = 1; - } - - newPageData.ethicsData[ethic.ethic_id] = newEthicsData; - } - }); - if (typeof newPageData.takenPortraits[empire.portrait_group_id] === 'undefined') { newPageData.takenPortraits[empire.portrait_group_id] = []; } @@ -157,16 +103,63 @@ newPageData.takenPortraits[empire.portrait_group_id] = portraitGroupData; } } + + newPageData.empireCount = newPageData.empireCount + 1; + + if (empire.gestalt) { + newPageData.gestaltCount.total = newPageData.gestaltCount.total + 1; + } + + if (empire.machine) { + newPageData.gestaltCount.machines = newPageData.gestaltCount.machines + 1; + } + + Object.values(empire.ethics).forEach((ethic) => { + const tmpEthicPageData = newPageData.ethicsData[ethic.ethic_id]; + + if (typeof tmpEthicPageData !== 'undefined') { + tmpEthicPageData.display = ethic.display; + if (!ethic.fanatic) { + tmpEthicPageData.regular = tmpEthicPageData.regular + 1; + } else { + tmpEthicPageData.fanatic = tmpEthicPageData.fanatic + 1; + } + + newPageData.ethicsData[ethic.ethic_id] = tmpEthicPageData; + } else { + let newEthicsData: { + id: number; + gestalt: boolean; + display: string; + regular: number; + fanatic: number; + } = { + id: ethic.ethic_id, + gestalt: ethic.gestalt, + display: ethic.display, + regular: 0, + fanatic: 0 + }; + + if (!ethic.fanatic) { + newEthicsData.regular = 1; + } else { + newEthicsData.fanatic = 1; + } + + newPageData.ethicsData[ethic.ethic_id] = newEthicsData; + } + }); } }); // Fill undefined Portrait Info with default information. - for (let i = 0; i < Object.values($ChellarisDataStore.species).length; i++) { + for (let i = 0; i < Object.values($ChellarisDataStore.phenotypes).length; i++) { if (typeof newPageData.takenPortraits[i] === 'undefined') { newPageData.takenPortraits[i] = []; } - for (let ii = 0; ii < Object.values($ChellarisDataStore.species[i].portraits).length; ii++) { + for (let ii = 0; ii < Object.values($ChellarisDataStore.phenotypes[i].species).length; ii++) { if (typeof newPageData.takenPortraits[i][ii] === 'undefined') { newPageData.takenPortraits[i][ii] = [0, []]; } @@ -210,7 +203,7 @@ # Fanatic {#each Object.values(pageData.ethicsData) as ethicData} - {#if ethicData && !ethicData.machine} + {#if ethicData && !ethicData.gestalt} {ethicData.display} {ethicData.regular} @@ -226,11 +219,11 @@

> Machines: {pageData.gestaltCount.machines}

- + {#each Object.values(pageData.ethicsData) as ethicData} - {#if ethicData && ethicData.machine} + {#if ethicData && ethicData.gestalt} @@ -249,11 +242,11 @@ {/each} - {#each Object.values($ChellarisDataStore.species) ?? false as portraitGroup} + {#each Object.values($ChellarisDataStore.phenotypes) ?? false as portraitGroup} {#if portraitGroup} - {#each Object.values(portraitGroup.portraits) ?? false as portrait} + {#each Object.values(portraitGroup.species) ?? false as portrait} {#if portrait}
Machine EthicGestalt Ethic #
{ethicData.display} {ethicData.regular}{index + 1}
{portraitGroup.display}