1
0
Fork 0

Start of data filling

This commit is contained in:
Neshura 2023-06-11 14:24:11 +02:00
parent e637dc1889
commit a78057de8c
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
9 changed files with 184 additions and 87 deletions

View file

@ -1,3 +1,4 @@
import { generateUrl } from '../components/server/fetchers';
// Ethics Data should be stored differently after Game 15, class will stil be needed for compat reasons afterwards
export class EthicsDataG15 {
// Array index determines fanatic or regular, Index value represents number of occurences
@ -5,13 +6,13 @@ export class EthicsDataG15 {
constructor(data: Array<number>) {
this.data[Scale.normal] = data[0],
this.data[Scale.fanatic] = data[1]
this.data[Scale.fanatic] = data[1]
}
sum(weigthed: boolean): number {
let sum = 0;
// skip 0 index since it isn't used
this.data.slice(1,this.data.length).forEach((value, index) => {
this.data.slice(1, this.data.length).forEach((value, index) => {
// Since the index is accessed via scale enum this works, if not weighted override to 1
let factor = index + 1;
if (!weigthed) {
@ -75,3 +76,39 @@ export type GameGroup = {
game_id: number,
name: string
}
export class Empire {
id: number = 0;
group_id: number = 0;
group_game_id: number = 0;
private discord_user: string | undefined;
private empire_name: string | undefined;
gestalt: boolean = false;
empire_portrait_group_id: number = 0;
empire_portrait_id: number = 0;
ethic_ids: number[] = [];
async getEthics() {
let tmpEthics = await fetch(
generateUrl('/empire_ethics', [
{ key: "empires_id", val: this.id },
{ key: "empires_group_id", val: this.group_id },
{ key: "empires_group_game_id", val: this.group_game_id }]
)).then((res) => res.json());
tmpEthics.forEach((empireEthic: { empires_id: number, empires_group_id: number, empires_group_name_id: number, ethics_id: number }) => {
this.ethic_ids.push(empireEthic.ethics_id)
});
}
}
export type Ethic = {
id: number,
name: string,
fanatic: boolean
}
export type GameData = {
info: Game;
groups: GameGroup[];
empires: Empire[];
}