From 5768a15876fa381310fb4049f8cd2a1f0c522619 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 21 Aug 2023 00:48:23 +0200 Subject: [PATCH] Portrait Table --- src/lib/stores/ChellarisData.ts | 7 +- src/lib/types/chellaris.ts | 8 +- src/lib/types/stellaris.ts | 34 +++-- src/routes/graphs/+layout.ts | 30 +++++ src/routes/graphs/excel-style/+page.svelte | 137 ++++++++++++++++----- src/routes/legacy-graphs/PopsPie.svelte | 6 +- src/routes/styles.css | 2 + 7 files changed, 169 insertions(+), 55 deletions(-) diff --git a/src/lib/stores/ChellarisData.ts b/src/lib/stores/ChellarisData.ts index 5b8c659..0581c6a 100644 --- a/src/lib/stores/ChellarisData.ts +++ b/src/lib/stores/ChellarisData.ts @@ -1,10 +1,7 @@ import { writable, type Writable } from "svelte/store"; import type { ChellarisInfo } from '../types/chellaris'; +import { createChellarisInfo } from '../types/chellaris'; -const ChellarisDataStore: Writable = writable({ - games: new Map(), - ethics: [], - portraits: [] -}); +const ChellarisDataStore: Writable = writable(createChellarisInfo()); export default ChellarisDataStore; \ No newline at end of file diff --git a/src/lib/types/chellaris.ts b/src/lib/types/chellaris.ts index 78efdfc..0e31241 100644 --- a/src/lib/types/chellaris.ts +++ b/src/lib/types/chellaris.ts @@ -1,8 +1,8 @@ -import type { Ethic } from './stellaris'; +import type { Ethic, Species } from './stellaris'; export interface ChellarisInfo { games: Map, // Key is Game Id - ethics: Map, // TODO implement - portraits: Array, // TODO implement + ethics: Map, // Key is Ethic Id + species: Map, // Key is Species Group Id } export type ChellarisGame = { @@ -29,7 +29,7 @@ export const createChellarisInfo = (): ChellarisInfo => { const newChellarisInfo = { games: new Map(), ethics: new Map(), - portraits: [] + species: new Map(), }; return newChellarisInfo; diff --git a/src/lib/types/stellaris.ts b/src/lib/types/stellaris.ts index 66a0f1c..d7b4585 100644 --- a/src/lib/types/stellaris.ts +++ b/src/lib/types/stellaris.ts @@ -1,4 +1,4 @@ -export enum Species { +export enum SpeciesLegacy { Humanoid = 0, Mammalian = 1, Reptilian = 2, @@ -31,13 +31,7 @@ export enum LegacyEthics { Industrialist = 13, } -export type Ethic = { - displayName: string, - machine: boolean - fanatic?: boolean, -} - -export enum Scale { +export enum LegacyEthicsScale { normal = 1, fanatic = 2, } @@ -47,8 +41,8 @@ export class EthicsDataLegacy { private data: Array = [0] constructor(data: Array) { - this.data[Scale.normal] = data[0], - this.data[Scale.fanatic] = data[1] + this.data[LegacyEthicsScale.normal] = data[0], + this.data[LegacyEthicsScale.fanatic] = data[1] } sum(weigthed: boolean): number { @@ -66,6 +60,22 @@ export class EthicsDataLegacy { } sumRegular(): number { - return this.data[Scale.normal]; + return this.data[LegacyEthicsScale.normal]; } -} \ No newline at end of file +} + +export type Ethic = { + displayName: string, + machine: boolean, + fanatic?: boolean, +} + +export type Species = { + displayName: string, + portraits: Map, // Key is Portrait Id +} + +export type Portrait = { + imageLink: string, +} + diff --git a/src/routes/graphs/+layout.ts b/src/routes/graphs/+layout.ts index f026545..7e6ad53 100644 --- a/src/routes/graphs/+layout.ts +++ b/src/routes/graphs/+layout.ts @@ -85,6 +85,36 @@ export const load: LayoutLoad = async () => { empireData.ethics.set(empireEthic.ethics_id, tmpEthic); } } + }); + + const portraitGroups: { + id: number, + name: string + }[] = await (await fetch(apiBaseUrl + '/portrait_groups')).json(); + + portraitGroups.sort((a, b) => (a.id < b.id ? -1 : 1)); + + portraitGroups.forEach(portraitGroup => { + const newPortraitGroup = { displayName: portraitGroup.name, portraits: new Map() }; + chellarisData.species.set(portraitGroup.id, newPortraitGroup); + }); + + const portraits: { + id: number, + href: string, + group_id: number + }[] = await (await fetch(apiBaseUrl + '/portraits')).json(); + + portraits.sort((a, b) => (a.id < b.id ? -1 : 1)); + + portraits.forEach(portrait => { + const portraitGroupData = chellarisData.species.get(portrait.group_id); + + if (typeof portraitGroupData !== "undefined") { + const newPortraitData = { imageLink: portrait.href }; + + portraitGroupData.portraits.set(portrait.id, newPortraitData); + } }) ChellarisDataStore.set(chellarisData); diff --git a/src/routes/graphs/excel-style/+page.svelte b/src/routes/graphs/excel-style/+page.svelte index 58cb18a..500aa1d 100644 --- a/src/routes/graphs/excel-style/+page.svelte +++ b/src/routes/graphs/excel-style/+page.svelte @@ -34,10 +34,12 @@ fanatic: number; } >; + takenPortraits: Map>; } = { empireCount: 0, gestaltCount: { total: 0, machines: 0 }, - ethicsData: new Map() + ethicsData: new Map(), + takenPortraits: new Map(), }; // Save Tab to Store @@ -62,22 +64,23 @@ if (typeof tmpGameData !== 'undefined') { const groupEmpires: Map = new Map(); pageData.ethicsData = new Map(); + pageData.takenPortraits = new Map(); pageData.gestaltCount = { total: 0, machines: 0 }; chellarisData.ethics.forEach((ethic, id) => { const newEthicsData: { - machine: boolean; - displayName: string; - regular: number; - fanatic: number; - } = { - machine: ethic.machine, - displayName: ethic.displayName, - regular: 0, - fanatic: 0 - }; + machine: boolean; + displayName: string; + regular: number; + fanatic: number; + } = { + machine: ethic.machine, + displayName: ethic.displayName, + regular: 0, + fanatic: 0 + }; pageData.ethicsData.set(id, newEthicsData); - }) + }); tmpGameData.empires.forEach((empire, index) => { if (selectedGameGroups.includes(empire.group)) { @@ -87,7 +90,7 @@ pageData.gestaltCount.total = pageData.gestaltCount.total + 1; let machine = false; - empire.ethics.forEach(ethic => { + empire.ethics.forEach((ethic) => { if (ethic.machine) { machine = true; } @@ -132,6 +135,25 @@ pageData.ethicsData.set(id, newEthicsData); } }); + + if (!pageData.takenPortraits.has(empire.empire_portrait_group)) { + pageData.takenPortraits.set(empire.empire_portrait_group, new Map()); + } + const portraitGroupData = pageData.takenPortraits.get(empire.empire_portrait_group); + + if (typeof portraitGroupData !== "undefined") { + if (!portraitGroupData.has(empire.empire_portrait)) { + portraitGroupData.set(empire.empire_portrait, 0); + } + + let portraitData = portraitGroupData.get(empire.empire_portrait); + + if (typeof portraitData !== "undefined") { + portraitData = portraitData + 1; + portraitGroupData.set(empire.empire_portrait, portraitData); + pageData.takenPortraits.set(empire.empire_portrait_group, portraitGroupData); + } + } } }); pageData.empireCount = groupEmpires.size; @@ -230,25 +252,34 @@ -
-
-

Portrait 1

-

Portrait 2

-

Portrait 3

+
+
+ + + + {#each Array(18) as _, index (index)} + + {/each} + + {#each chellarisData.species as portraitGroup} + + + {#each portraitGroup[1].portraits as portrait} + + {/each} + + {/each} +
Species{index + 1}
{portraitGroup[1].displayName} + + +
-
-

Portrait 1

-

Portrait 2

-

Portrait 3

-
-
+
diff --git a/src/routes/legacy-graphs/PopsPie.svelte b/src/routes/legacy-graphs/PopsPie.svelte index 4d96372..b82d5ce 100644 --- a/src/routes/legacy-graphs/PopsPie.svelte +++ b/src/routes/legacy-graphs/PopsPie.svelte @@ -1,6 +1,6 @@