From a285c0820e8fb7d56f3e8472e79e8d9480e4e5a2 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 14 Aug 2023 22:31:16 +0200 Subject: [PATCH] Added partial Sign Up Info in excel style --- src/lib/types/chellaris.ts | 38 ++++- src/routes/graphs/+layout.ts | 27 +++- src/routes/graphs/excel-style/+page.svelte | 160 +++++++++++++++------ 3 files changed, 176 insertions(+), 49 deletions(-) diff --git a/src/lib/types/chellaris.ts b/src/lib/types/chellaris.ts index 269245e..eedd056 100644 --- a/src/lib/types/chellaris.ts +++ b/src/lib/types/chellaris.ts @@ -1,19 +1,27 @@ export interface ChellarisInfo { - games: Map, + games: Map, // Key is Game Id ethics: Array, // TODO implement portraits: Array, // TODO implement } export type ChellarisGame = { name: string, - groups: Map, - empires: Array, // TODO implement + groups: Map, // Key is Group Id + empires: Map, // Key is Empire Id } export type ChellarisGameGroup = { name: string, } +export type ChellarisEmpire = { + gestalt: boolean, + group: number, + empire_portrait: number, // TODO replace with Enum? + empire_portrait_group: number, // TODO replace with Enum? + discord_user?: string, +} + export const createChellarisInfo = (): ChellarisInfo => { const newChellarisInfo = { games: new Map(), @@ -28,7 +36,7 @@ export const createChellarisGame = (): ChellarisGame => { const newChellarisGame = { name: "", groups: new Map(), - empires: [], + empires: new Map(), }; return newChellarisGame; @@ -40,4 +48,26 @@ export const createChellarisGameGroup = (): ChellarisGameGroup => { }; return newChellarisGameGroup; +} + +export const createChellarisEmpire = ( + { + id, discord_user, group_id, gestalt, empire_portrait_id, empire_portrait_group_id, group_game_id + }: { + id: number, + discord_user?: string, + group_id: number, + gestalt: boolean, + empire_portrait_id: number, + empire_portrait_group_id: number, + group_game_id: number + }): ChellarisEmpire => { + const newChellarisEmpire = { + gestalt: gestalt, + group: group_id, + empire_portrait: empire_portrait_id, + empire_portrait_group: empire_portrait_group_id, + }; + + return newChellarisEmpire; } \ No newline at end of file diff --git a/src/routes/graphs/+layout.ts b/src/routes/graphs/+layout.ts index 5e0ecc1..3c5805f 100644 --- a/src/routes/graphs/+layout.ts +++ b/src/routes/graphs/+layout.ts @@ -1,7 +1,7 @@ import type { PageLoad } from "../$types"; import ChellarisDataStore from '$lib/stores/ChellarisData'; import SelectedGameStore from '$lib/stores/GameFilter'; -import { type ChellarisInfo, type ChellarisGame, type ChellarisGameGroup, createChellarisInfo, createChellarisGameGroup, createChellarisGame } from '../../lib/types/chellaris'; +import { type ChellarisInfo, type ChellarisGame, type ChellarisGameGroup, createChellarisInfo, createChellarisGameGroup, createChellarisGame, createChellarisEmpire } from '../../lib/types/chellaris'; import SelectedGameGroupsStore from "$lib/stores/GameGroupFilter"; import GraphsTabStore from '$lib/stores/GraphsTab'; @@ -34,6 +34,26 @@ export const load: PageLoad = async () => { } }) + const empires: { + id: number, + discord_user?: string, + group_id: number, + gestalt: boolean, + empire_portrait_id: number, + empire_portrait_group_id: number, + group_game_id: number}[] = await (await fetch(apiBaseUrl + '/empires')).json(); + + empires.sort((a, b) => (a.id < b.id ? -1 : 1)); + empires.forEach(empire => { + const gameData = chellarisData.games.get(empire.group_game_id); + + if (typeof gameData !== "undefined") { + const newEmpire = createChellarisEmpire(empire); + gameData.empires.set(empire.id, newEmpire); + } + }); + + console.log(chellarisData); //DEBUG ChellarisDataStore.set(chellarisData); // Local Storage Code @@ -57,11 +77,12 @@ export const load: PageLoad = async () => { store = localStorage.getItem('gameGroupSelection'); if (typeof store == 'string') { + let selectedGameGroups: Array = []; const gameGroupSelectionMap = new Map>(JSON.parse(store)); const tmp = gameGroupSelectionMap.get(selectedGame); - let selectedGameGroups: Array = []; + if (typeof tmp !== 'undefined') { - selectedGameGroups = [...tmp.values()]; + selectedGameGroups = tmp; } else { const tmpGameData = chellarisData.games.get(selectedGame); // If this fails an empty array is precisely what we want diff --git a/src/routes/graphs/excel-style/+page.svelte b/src/routes/graphs/excel-style/+page.svelte index cb3517a..ce531b1 100644 --- a/src/routes/graphs/excel-style/+page.svelte +++ b/src/routes/graphs/excel-style/+page.svelte @@ -1,19 +1,30 @@