API Updates

This commit is contained in:
Neshura 2023-09-07 22:04:51 +02:00
parent 5499916e10
commit 00579db8ce
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
12 changed files with 197 additions and 94 deletions

View file

@ -1,4 +0,0 @@
[
"1234",
"5678"
]

View file

@ -1,21 +0,0 @@
import { redirect } from "@sveltejs/kit";
import validAuthTokens from './authTokens.json';
export async function handle({ event, resolve }) {
const cookie = event.cookies.get('authToken');
if (typeof cookie !== 'undefined') {
event.locals.authenticated = validAuthTokens.includes(cookie);
}
else {
event.locals.authenticated = false;
}
if (event.url.pathname.startsWith('/admin')) {
if (!event.locals.authenticated) {
throw redirect(303, '/401');
}
}
return await resolve(event);
}

View file

@ -1,5 +1,5 @@
import { writable, type Writable } from "svelte/store"; import { writable, type Writable } from "svelte/store";
const AdminSelectedGameStore: Writable<number> = writable(0); const AdminSelectedGameStore: Writable<number> = writable(1);
export default AdminSelectedGameStore; export default AdminSelectedGameStore;

View file

@ -1,5 +1,5 @@
import { writable, type Writable } from "svelte/store"; import { writable, type Writable } from "svelte/store";
const AdminSelectedGroupStore: Writable<{ [key: number]: number }> = writable({}); const AdminSelectedGroupStore: Writable<{ [key: number]: { [key: number]: boolean } }> = writable({});
export default AdminSelectedGroupStore; export default AdminSelectedGroupStore;

View file

@ -1,4 +1,4 @@
import type { Ethic, Species } from './stellaris'; import type { EmpireEthic, Ethic, Species } from './stellaris';
export type ChellarisInfo = { export type ChellarisInfo = {
games: { [key: number]: ChellarisGame }, // Key is Game Id games: { [key: number]: ChellarisGame }, // Key is Game Id
@ -20,14 +20,15 @@ export type ChellarisGameGroup = {
export type ChellarisEmpire = { export type ChellarisEmpire = {
id: number, id: number,
gestalt: boolean,
machine: boolean,
group: number, group: number,
empire_portrait: number, // TODO replace with Enum? game: number,
empire_portrait_group: number, // TODO replace with Enum?
name: string, name: string,
discord_user?: string, discord_user?: string,
ethics: { [key: number]: Ethic }, 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 = { export type ChellarisGameInfo = {
@ -47,7 +48,7 @@ export const createChellarisInfo = (): ChellarisInfo => {
export const createChellarisGame = (): ChellarisGame => { export const createChellarisGame = (): ChellarisGame => {
const newChellarisGame = { const newChellarisGame = {
id: 0, id: 1,
name: "", name: "",
groups: [], groups: [],
empires: [], empires: [],
@ -58,7 +59,7 @@ export const createChellarisGame = (): ChellarisGame => {
export const createChellarisGameGroup = (): ChellarisGameGroup => { export const createChellarisGameGroup = (): ChellarisGameGroup => {
const newChellarisGameGroup = { const newChellarisGameGroup = {
id: 0, id: 1,
name: "", name: "",
}; };
@ -67,23 +68,25 @@ export const createChellarisGameGroup = (): ChellarisGameGroup => {
export const createChellarisEmpire = ( export const createChellarisEmpire = (
{ {
id, name, discord_user, group_id, gestalt, empire_portrait_id, empire_portrait_group_id id, name, discord_user, group_id, game_id, gestalt, portrait_id, portrait_group_id
}: { }: {
id: number, id: number,
name: string, name: string,
discord_user?: string, discord_user?: string,
group_id: number, group_id: number,
game_id: number,
gestalt: boolean, gestalt: boolean,
empire_portrait_id: number, portrait_id: number,
empire_portrait_group_id: number, portrait_group_id: number,
}): ChellarisEmpire => { }): ChellarisEmpire => {
const newChellarisEmpire = { const newChellarisEmpire = {
id: id, id: id,
group: group_id,
game: game_id,
gestalt: gestalt, gestalt: gestalt,
machine: false, machine: false,
group: group_id, portrait_id: portrait_id,
empire_portrait: empire_portrait_id, portrait_group_id: portrait_group_id,
empire_portrait_group: empire_portrait_group_id,
ethics: [], ethics: [],
discord_user: discord_user, discord_user: discord_user,
name: name name: name

View file

@ -38,7 +38,7 @@ export enum LegacyEthicsScale {
export class EthicsDataLegacy { export class EthicsDataLegacy {
// Array index determines fanatic or regular, Index value represents number of occurences // Array index determines fanatic or regular, Index value represents number of occurences
private data: Array<number> = [0] private data: Array<number> = [1]
constructor(data: Array<number>) { constructor(data: Array<number>) {
this.data[LegacyEthicsScale.normal] = data[0], this.data[LegacyEthicsScale.normal] = data[0],
@ -66,14 +66,21 @@ export class EthicsDataLegacy {
export type Ethic = { export type Ethic = {
id: number, id: number,
displayName: string, display: string,
machine: boolean,
fanatic?: boolean,
}
export type EmpireEthic = {
ethic_id: number,
display: string,
machine: boolean, machine: boolean,
fanatic?: boolean, fanatic?: boolean,
} }
export type Species = { export type Species = {
id: number, id: number,
displayName: string, display: string,
portraits: { [key: number]: Portrait }, // Key is Portrait Id portraits: { [key: number]: Portrait }, // Key is Portrait Id
} }

View file

@ -31,6 +31,9 @@
// Empire Variables // Empire Variables
let empireList: { [key: number]: ChellarisEmpire } = {}; let empireList: { [key: number]: ChellarisEmpire } = {};
let empireData: ChellarisEmpire;
let loadingEmpireData = true;
const updateGameData = () => { const updateGameData = () => {
fetch(apiBaseUrl + '/v3/game?game_id=' + $AdminSelectedGameStore, { fetch(apiBaseUrl + '/v3/game?game_id=' + $AdminSelectedGameStore, {
@ -39,15 +42,39 @@
'x-api-key': $AuthTokenStore 'x-api-key': $AuthTokenStore
} }
}).then((res) => { }).then((res) => {
res.json().then((data) => { res.json().then((data: {groups: { [key: number]: ChellarisGameGroup}, empires: { [key: number]: ChellarisEmpire}}) => {
console.log(data);
groupList = data.groups; groupList = data.groups;
empireList = data.empires; empireList = {};
Object.values(data.empires).forEach((empire: ChellarisEmpire) => {
if ($AdminSelectedGroupStore[$AdminSelectedGameStore] === undefined) {
$AdminSelectedGroupStore[$AdminSelectedGameStore] = {};
}
if ($AdminSelectedGroupStore[$AdminSelectedGameStore][empire.group]) {
empireList[empire.id] = empire;
}
});
loadingGameData = false; loadingGameData = false;
loadEmpireData();
}); });
}); });
}; };
const loadEmpireData = () => {
fetch(apiBaseUrl + '/v3/empire?game_id=' + $AdminSelectedGameStore + '&empire_id=' + $AdminSelectedEmpireStore[$AdminSelectedGameStore], {
headers: {
'Content-Type': 'application/json',
'x-api-key': $AuthTokenStore
}
}).then((res) => {
res.json().then((data: ChellarisEmpire) => {
empireData = data;
loadingEmpireData = false;
});
});
}
$: { $: {
if (typeof localStorage !== 'undefined') { if (typeof localStorage !== 'undefined') {
localStorage.setItem('adminGameSelection', JSON.stringify($AdminSelectedGameStore)); localStorage.setItem('adminGameSelection', JSON.stringify($AdminSelectedGameStore));
@ -123,8 +150,12 @@
// Group Functions // Group Functions
const setActiveGroup = (group: number) => { const toggleActiveGroup = (group: number) => {
$AdminSelectedGroupStore[$AdminSelectedGameStore] = group; if ($AdminSelectedGroupStore[$AdminSelectedGameStore] === undefined) {
$AdminSelectedGroupStore[$AdminSelectedGameStore] = {};
}
$AdminSelectedGroupStore[$AdminSelectedGameStore][group] = !$AdminSelectedGroupStore[$AdminSelectedGameStore][group];
updateGameData();
}; };
const addGroup = () => { const addGroup = () => {
@ -147,7 +178,7 @@
updateGameData(); updateGameData();
addingNewGroup = false; addingNewGroup = false;
newGroupName = ''; newGroupName = '';
response.json().then((result) => ($AdminSelectedGroupStore[$AdminSelectedGameStore] = result.id)); response.json().then((result) => ($AdminSelectedGroupStore[$AdminSelectedGameStore][result.id] = true));
}); });
}; };
@ -160,8 +191,8 @@
} }
}).then(() => { }).then(() => {
updateGameData(); updateGameData();
if ($AdminSelectedGroupStore[$AdminSelectedGameStore] == group_id) { if ($AdminSelectedGroupStore[$AdminSelectedGameStore][group_id]) {
$AdminSelectedGroupStore[$AdminSelectedGameStore] = Object.values(groupList)[0].id; $AdminSelectedGroupStore[$AdminSelectedGameStore][group_id] = false;
} }
}); });
delete groupList[group_id]; delete groupList[group_id];
@ -171,6 +202,8 @@
// Empire Functions // Empire Functions
const setActiveEmpire = (empireId: number) => { const setActiveEmpire = (empireId: number) => {
loadingEmpireData = true;
loadEmpireData();
$AdminSelectedEmpireStore[$AdminSelectedGameStore] = empireId; $AdminSelectedEmpireStore[$AdminSelectedGameStore] = empireId;
}; };
@ -179,6 +212,23 @@
list2.push(list2.length); list2.push(list2.length);
}; };
const deleteEmpire = (empire: ChellarisEmpire) => {
fetch(apiBaseUrl + '/v3/empire?game_id=' + empire.game + '&group_id=' + empire.group + '&empire_id=' + empire.id, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'x-api-key': $AuthTokenStore
}
}).then(() => {
updateGameData();
if ($AdminSelectedEmpireStore[$AdminSelectedGameStore] == empire.id) {
$AdminSelectedEmpireStore[$AdminSelectedGameStore] = Object.values(empireList)[0].id;
}
});
delete empireList[empire.id];
empireList = empireList;
};
let list2 = new Array(); let list2 = new Array();
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
list2.push(i); list2.push(i);
@ -231,8 +281,8 @@
{#each Object.values(groupList) as group} {#each Object.values(groupList) as group}
<button <button
class="list-card" class="list-card"
class:active={group.id == $AdminSelectedGroupStore[$AdminSelectedGameStore] ? 'active' : ''} class:active={$AdminSelectedGroupStore[$AdminSelectedGameStore] ? $AdminSelectedGroupStore[$AdminSelectedGameStore][group.id] ? 'active' : '' : ''}
on:click={() => setActiveGroup(group.id)} on:click={() => toggleActiveGroup(group.id)}
> >
<div class="card-content">{group.name}</div> <div class="card-content">{group.name}</div>
{#if group.name !== 'N/A'} {#if group.name !== 'N/A'}
@ -289,7 +339,16 @@
<div class="card-content" class:active={empire.id == $AdminSelectedEmpireStore[$AdminSelectedGameStore] ? 'active' : ''}> <div class="card-content" class:active={empire.id == $AdminSelectedEmpireStore[$AdminSelectedGameStore] ? 'active' : ''}>
{empire.discord_user} {empire.discord_user}
</div> </div>
<button class="delete-box" on:click={() => deleteEmpire(empire)}>
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill="none" d="M0 0 24 24 M24 0 0 24" />
</svg>
</button> </button>
</button>
{:else}
<div class="list-card">
<div class="card-content">No Empires Present</div>
</div>
{/each} {/each}
<button class="list-card" on:click={addEmpire}> <button class="list-card" on:click={addEmpire}>
<div class="card-content button">+</div> <div class="card-content button">+</div>
@ -299,7 +358,11 @@
</div> </div>
</List> </List>
<List area="details" listTitle="Empire Details"> <List area="details" listTitle="Empire Details">
<EmpireDetails id={$AdminSelectedEmpireStore[$AdminSelectedGameStore]} /> {#if loadingEmpireData}
Loading...
{:else}
<EmpireDetails empire={empireData} />
{/if}
</List> </List>
</div> </div>

View file

@ -1,10 +1,29 @@
import { apiBaseUrl } from "$lib/components/consts"; import { apiBaseUrl } from "$lib/components/consts";
import AdminSelectedEmpireStore from "$lib/stores/admin-page/EmpireStore"; import AdminSelectedEmpireStore from "$lib/stores/admin-page/EmpireStore";
import AdminSelectedGameStore from "$lib/stores/admin-page/GameStore"; import AdminSelectedGameStore from "$lib/stores/admin-page/GameStore";
import AuthTokenStore from "$lib/stores/AuthTokenStore";
import type { ChellarisGameInfo } from "$lib/types/chellaris"; import type { ChellarisGameInfo } from "$lib/types/chellaris";
import { redirect } from "@sveltejs/kit";
import AdminSelectedGroupStore from '../../lib/stores/admin-page/GroupStore'; import AdminSelectedGroupStore from '../../lib/stores/admin-page/GroupStore';
export async function load ({ fetch }) { 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(); const gameList: { [key: number]: ChellarisGameInfo } = await (await fetch(apiBaseUrl + "/v3/games")).json();
let store: string | null; let store: string | null;

View file

@ -1,11 +1,49 @@
<script lang="ts"> <script lang="ts">
export let id: number; import type { ChellarisEmpire } from '$lib/types/chellaris';
export let empire: ChellarisEmpire;
</script> </script>
<div> <div>
{id} {#if empire}
<div>
ID: {empire.id}
</div>
<div>
Group ID: {empire.group}
</div>
<div>
Game ID: {empire.game}
</div>
<div>
Gestalt: {empire.gestalt}
</div>
<div>
Machine: {empire.machine}
</div>
<div>
Portrait ID: {empire.portrait_id}
</div>
<div>
Portrait Group ID: {empire.portrait_group_id}
</div>
<div>
Name: {empire.name}
</div>
<div>
Discord User: {empire.discord_user}
</div>
<div>
{#if empire.ethics}
{#each Object.values(empire.ethics) as ethic}
{ethic.ethic_id},
{/each}
{/if}
</div>
{:else}
No Empire Selected
{/if}
</div> </div>
<style> <style>
</style> </style>

View file

@ -2,14 +2,12 @@ import ChellarisDataStore from '$lib/stores/ChellarisData';
import SelectedGameStore from '$lib/stores/GameFilter'; import SelectedGameStore from '$lib/stores/GameFilter';
import SelectedGameGroupsStore, { type SelectedChellarisGroups } from "$lib/stores/GameGroupFilter"; import SelectedGameGroupsStore, { type SelectedChellarisGroups } from "$lib/stores/GameGroupFilter";
import GraphsTabStore from '$lib/stores/GraphsTab'; import GraphsTabStore from '$lib/stores/GraphsTab';
import { createChellarisInfo, type ChellarisGame, createChellarisGame, createChellarisGameGroup, createChellarisEmpire } from "$lib/types/chellaris";
import type { LayoutLoad } from "./$types"; import type { LayoutLoad } from "./$types";
import type { Ethic } from '../../lib/types/stellaris';
import type { ChellarisInfo } from '../../lib/types/chellaris'; import type { ChellarisInfo } from '../../lib/types/chellaris';
import { apiBaseUrl } from '$lib/components/consts';
export const load: LayoutLoad = async ({ fetch }) => { export const load: LayoutLoad = async ({ fetch }) => {
let store: string | null; let store: string | null;
const apiBaseUrl = 'https://wip.chellaris.net/api';
// Chellaris Data Code // Chellaris Data Code
const chellarisData: ChellarisInfo = await (await fetch(apiBaseUrl + '/v3/full_view_data')).json(); const chellarisData: ChellarisInfo = await (await fetch(apiBaseUrl + '/v3/full_view_data')).json();
@ -35,7 +33,7 @@ export const load: LayoutLoad = async ({ fetch }) => {
} }
if (typeof gameSelection === 'undefined') { if (typeof gameSelection === 'undefined') {
gameSelection = chellarisData.games[0].id; gameSelection = chellarisData.games[1].id;
} }
// Game Groups Selection // Game Groups Selection
@ -68,7 +66,7 @@ export const load: LayoutLoad = async ({ fetch }) => {
} }
if (typeof gameSelection === 'undefined') { if (typeof gameSelection === 'undefined') {
gameSelection = chellarisData.games[0].id; gameSelection = chellarisData.games[1].id;
} }
SelectedGameStore.set(gameSelection); SelectedGameStore.set(gameSelection);

View file

@ -32,7 +32,7 @@
[key: number]: { [key: number]: {
id: number; id: number;
machine: boolean; machine: boolean;
displayName: string; display: string;
regular: number; regular: number;
fanatic: number; fanatic: number;
}; };
@ -40,8 +40,6 @@
takenPortraits: Array<Array<[number, Array<number>]>>; // <SpeciesGroup, <Portrait, <SumTaken, <GroupsTaken>>>> takenPortraits: Array<Array<[number, Array<number>]>>; // <SpeciesGroup, <Portrait, <SumTaken, <GroupsTaken>>>>
}; };
$: { $: {
console.log('Reran'); // DEBUG
let newPageData: { let newPageData: {
init: boolean; init: boolean;
empireCount: number; empireCount: number;
@ -50,7 +48,7 @@
[key: number]: { [key: number]: {
id: number; id: number;
machine: boolean; machine: boolean;
displayName: string; display: string;
regular: number; regular: number;
fanatic: number; fanatic: number;
}; };
@ -70,13 +68,13 @@
const newEthicsData: { const newEthicsData: {
id: number; id: number;
machine: boolean; machine: boolean;
displayName: string; display: string;
regular: number; regular: number;
fanatic: number; fanatic: number;
} = { } = {
id: ethic.id, id: ethic.id,
machine: ethic.machine, machine: ethic.machine,
displayName: ethic.displayName, display: ethic.display,
regular: 0, regular: 0,
fanatic: 0 fanatic: 0
}; };
@ -84,6 +82,7 @@
}); });
Object.values(selectedGame.empires).forEach((empire) => { Object.values(selectedGame.empires).forEach((empire) => {
console.log(empire); //DEBUG
if (empire.group in selectedGameGroupData.selectedGroups) { if (empire.group in selectedGameGroupData.selectedGroups) {
newPageData.empireCount = newPageData.empireCount + 1; newPageData.empireCount = newPageData.empireCount + 1;
@ -103,28 +102,28 @@
} }
Object.values(empire.ethics).forEach((ethic) => { Object.values(empire.ethics).forEach((ethic) => {
const tmpEthicPageData = newPageData.ethicsData[ethic.id]; const tmpEthicPageData = newPageData.ethicsData[ethic.ethic_id];
if (typeof tmpEthicPageData !== 'undefined') { if (typeof tmpEthicPageData !== 'undefined') {
tmpEthicPageData.displayName = ethic.displayName; tmpEthicPageData.display = ethic.display;
if (!ethic.fanatic) { if (!ethic.fanatic) {
tmpEthicPageData.regular = tmpEthicPageData.regular + 1; tmpEthicPageData.regular = tmpEthicPageData.regular + 1;
} else { } else {
tmpEthicPageData.fanatic = tmpEthicPageData.fanatic + 1; tmpEthicPageData.fanatic = tmpEthicPageData.fanatic + 1;
} }
newPageData.ethicsData[ethic.id] = tmpEthicPageData; newPageData.ethicsData[ethic.ethic_id] = tmpEthicPageData;
} else { } else {
let newEthicsData: { let newEthicsData: {
id: number; id: number;
machine: boolean; machine: boolean;
displayName: string; display: string;
regular: number; regular: number;
fanatic: number; fanatic: number;
} = { } = {
id: ethic.id, id: ethic.ethic_id,
machine: ethic.machine, machine: ethic.machine,
displayName: ethic.displayName, display: ethic.display,
regular: 0, regular: 0,
fanatic: 0 fanatic: 0
}; };
@ -135,27 +134,27 @@
newEthicsData.fanatic = 1; newEthicsData.fanatic = 1;
} }
newPageData.ethicsData[ethic.id] = newEthicsData; newPageData.ethicsData[ethic.ethic_id] = newEthicsData;
} }
}); });
if (typeof newPageData.takenPortraits[empire.empire_portrait_group] === 'undefined') { if (typeof newPageData.takenPortraits[empire.portrait_group_id] === 'undefined') {
newPageData.takenPortraits[empire.empire_portrait_group] = []; newPageData.takenPortraits[empire.portrait_group_id] = [];
} }
const portraitGroupData = newPageData.takenPortraits[empire.empire_portrait_group]; const portraitGroupData = newPageData.takenPortraits[empire.portrait_group_id];
if (typeof portraitGroupData !== 'undefined') { if (typeof portraitGroupData !== 'undefined') {
if (typeof portraitGroupData[empire.empire_portrait] === 'undefined') { if (typeof portraitGroupData[empire.portrait_id] === 'undefined') {
portraitGroupData[empire.empire_portrait] = [0, []]; portraitGroupData[empire.portrait_id] = [0, []];
} }
let portraitData = portraitGroupData[empire.empire_portrait]; let portraitData = portraitGroupData[empire.portrait_id];
if (typeof portraitData !== 'undefined') { if (typeof portraitData !== 'undefined') {
portraitData[0] = portraitData[0] + 1; portraitData[0] = portraitData[0] + 1;
portraitData[1].push(empire.group); portraitData[1].push(empire.group);
portraitGroupData[empire.empire_portrait] = portraitData; portraitGroupData[empire.portrait_id] = portraitData;
newPageData.takenPortraits[empire.empire_portrait_group] = portraitGroupData; newPageData.takenPortraits[empire.portrait_group_id] = portraitGroupData;
} }
} }
} }
@ -178,6 +177,7 @@
} }
pageData = newPageData; pageData = newPageData;
console.log(pageData);
} }
// Save Tab to Store // Save Tab to Store
@ -212,7 +212,7 @@
{#each Object.values(pageData.ethicsData) as ethicData} {#each Object.values(pageData.ethicsData) as ethicData}
{#if ethicData && !ethicData.machine} {#if ethicData && !ethicData.machine}
<tr> <tr>
<td class="table-label">{ethicData.displayName}</td> <td class="table-label">{ethicData.display}</td>
<td>{ethicData.regular}</td> <td>{ethicData.regular}</td>
<td>{ethicData.fanatic}</td> <td>{ethicData.fanatic}</td>
</tr> </tr>
@ -232,7 +232,7 @@
{#each Object.values(pageData.ethicsData) as ethicData} {#each Object.values(pageData.ethicsData) as ethicData}
{#if ethicData && ethicData.machine} {#if ethicData && ethicData.machine}
<tr> <tr>
<td class="table-label">{ethicData.displayName}</td> <td class="table-label">{ethicData.display}</td>
<td>{ethicData.regular}</td> <td>{ethicData.regular}</td>
</tr> </tr>
{/if} {/if}
@ -252,12 +252,12 @@
{#each Object.values($ChellarisDataStore.species) ?? false as portraitGroup} {#each Object.values($ChellarisDataStore.species) ?? false as portraitGroup}
{#if portraitGroup} {#if portraitGroup}
<tr> <tr>
<td>{portraitGroup.displayName}</td> <td>{portraitGroup.display}</td>
{#each Object.values(portraitGroup.portraits) ?? false as portrait} {#each Object.values(portraitGroup.portraits) ?? false as portrait}
{#if portrait} {#if portrait}
<td <td
class="image-box" class="image-box"
style="--color-hovered-portrait: {groupPortraitLimit - pageData.takenPortraits[portraitGroup.id][portrait.id][0] == 0 style="--color-hovered-portrait: {groupPortraitLimit - pageData.takenPortraits[portraitGroup.id][portrait.id][0] <= 0
? 'var(--color-warn-2)' ? 'var(--color-warn-2)'
: groupPortraitLimit - pageData.takenPortraits[portraitGroup.id][portrait.id][0] != groupPortraitLimit : groupPortraitLimit - pageData.takenPortraits[portraitGroup.id][portrait.id][0] != groupPortraitLimit
? 'var(--color-warn-1)' ? 'var(--color-warn-1)'
@ -267,7 +267,7 @@
id={portraitGroup.id + '-' + portrait.id} id={portraitGroup.id + '-' + portrait.id}
type="image" type="image"
src={'../' + portrait.lores} src={'../' + portrait.lores}
alt={portraitGroup.displayName + '-' + portrait.id} alt={portraitGroup.display + '-' + portrait.id}
/> />
<label for={portraitGroup.id + '-' + portrait.id}>{pageData.takenPortraits[portraitGroup.id][portrait.id][0]}/{groupPortraitLimit}</label> <label for={portraitGroup.id + '-' + portrait.id}>{pageData.takenPortraits[portraitGroup.id][portrait.id][0]}/{groupPortraitLimit}</label>
</td> </td>

View file

@ -1,14 +1,14 @@
import { apiBaseUrl } from "$lib/components/consts";
import type { PageLoad } from "../$types"; import type { PageLoad } from "../$types";
export const load: PageLoad = async ({ fetch }) => { export const load: PageLoad = async ({ fetch }) => {
const apiBaseUrl = 'https://www.chellaris.net/api/v1'; const popsRet: { speciesArray: Array<number> } = await (await fetch(apiBaseUrl + '/v1/species')).json();
const popsRet: { speciesArray: Array<number> } = await (await fetch(apiBaseUrl + '/species')).json();
const popsData: Array<number> = popsRet.speciesArray; const popsData: Array<number> = popsRet.speciesArray;
const ethicsRet: { sheetData: Array<Array<number>> } = await (await fetch(apiBaseUrl + '/ethics')).json(); const ethicsRet: { sheetData: Array<Array<number>> } = await (await fetch(apiBaseUrl + '/v1/ethics')).json();
const ethicsData: Array<Array<number>> = ethicsRet.sheetData; const ethicsData: Array<Array<number>> = ethicsRet.sheetData;
const empireRet: { empireCount: number } = await (await fetch(apiBaseUrl + '/empires')).json(); const empireRet: { empireCount: number } = await (await fetch(apiBaseUrl + '/v1/empires')).json();
const empireData: number = empireRet.empireCount; const empireData: number = empireRet.empireCount;
return { popsData, ethicsData, empireData } return { popsData, ethicsData, empireData }