Start of data filling
This commit is contained in:
parent
e637dc1889
commit
a78057de8c
9 changed files with 184 additions and 87 deletions
types
|
@ -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[];
|
||||
}
|
||||
|
|
Reference in a new issue