1
0
Fork 0
This repository has been archived on 2023-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
chellaris-galaxy-political-.../types/stellaris.ts

115 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-06-11 12:24:11 +00:00
import { generateUrl } from '../components/server/fetchers';
2023-06-03 01:01:38 +00:00
// 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
private data: Array<number> = [0]
constructor(data: Array<number>) {
this.data[Scale.normal] = data[0],
2023-06-11 12:24:11 +00:00
this.data[Scale.fanatic] = data[1]
2023-05-31 22:10:59 +00:00
}
2023-06-03 01:01:38 +00:00
sum(weigthed: boolean): number {
let sum = 0;
// skip 0 index since it isn't used
2023-06-11 12:24:11 +00:00
this.data.slice(1, this.data.length).forEach((value, index) => {
2023-06-03 01:01:38 +00:00
// Since the index is accessed via scale enum this works, if not weighted override to 1
let factor = index + 1;
if (!weigthed) {
factor = 1;
}
sum = sum + value * factor;
});
return sum;
2023-05-31 22:10:59 +00:00
}
2023-06-03 01:01:38 +00:00
sumRegular(): number {
return this.data[Scale.normal];
2023-05-31 22:10:59 +00:00
}
2023-06-03 01:01:38 +00:00
}
2023-05-31 22:10:59 +00:00
2023-06-03 01:01:38 +00:00
export enum Ethics {
Egalitarian = 0,
Authoritarian = 1,
Militarist = 2,
Pacifist = 3,
Xenophobe = 4,
Xenophile = 5,
Competitive = 6,
Cooperative = 7,
Elitist = 8,
Pluralist = 9,
Materialist = 10,
Spiritualist = 11,
Ecologist = 12,
Industrialist = 13,
2023-05-31 22:10:59 +00:00
}
export enum Scale {
normal = 1,
2023-06-03 01:01:38 +00:00
fanatic = 2,
2023-05-31 22:10:59 +00:00
}
2023-06-01 23:06:04 +00:00
export enum Species {
Humanoid = 0,
Mammalian = 1,
Reptilian = 2,
Avian = 3,
Arthropod = 4,
Molluscoid = 5,
Fungoid = 6,
Plantoid = 7,
Lithoid = 8,
Necroid = 9,
Aquatic = 10,
Toxoid = 11,
2023-06-03 01:01:38 +00:00
Machine = 12,
2023-06-01 23:06:04 +00:00
}
export type Game = {
id: number,
name: string
}
export type GameGroup = {
id: number,
game_id: number,
name: string
}
2023-06-11 12:24:11 +00:00
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[];
}