Change to Ethics Enum
This commit is contained in:
parent
b427d07b2e
commit
053b0366f8
3 changed files with 66 additions and 130 deletions
types
|
@ -1,111 +1,52 @@
|
|||
import { element } from 'prop-types';
|
||||
export namespace Ethics {
|
||||
|
||||
class eth_template {
|
||||
protected key: string = "";
|
||||
private data: Array<{type: Scale, value: number}> = []
|
||||
|
||||
constructor(data: Array<{type: Scale, value: number}>) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
sum(weigthed: boolean): number {
|
||||
let sum = 0;
|
||||
this.data.forEach((element) => {
|
||||
if (weigthed) {
|
||||
sum = sum + element.value * element.type;
|
||||
}
|
||||
else {
|
||||
sum = sum + element.value * 1;
|
||||
}
|
||||
});
|
||||
return sum;
|
||||
}
|
||||
|
||||
sumRegular(): number {
|
||||
let sum = 0;
|
||||
this.data.forEach((element) => {
|
||||
if (element.type == Scale.normal) {
|
||||
sum = sum + element.value;
|
||||
}
|
||||
});
|
||||
return sum;
|
||||
}
|
||||
|
||||
entries(): number {
|
||||
let sum = 0;
|
||||
this.data.forEach((element) => {
|
||||
sum = sum + element.value;
|
||||
});
|
||||
return sum;
|
||||
}
|
||||
|
||||
getKey(): string {
|
||||
return this.key
|
||||
}
|
||||
// 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],
|
||||
this.data[Scale.fanatic] = data[1]
|
||||
}
|
||||
|
||||
export class ega extends eth_template {
|
||||
protected key = "Egalitarian";
|
||||
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) => {
|
||||
// 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;
|
||||
}
|
||||
|
||||
export class aut extends eth_template {
|
||||
protected key = "Authoritarian";
|
||||
sumRegular(): number {
|
||||
return this.data[Scale.normal];
|
||||
}
|
||||
}
|
||||
|
||||
export class mil extends eth_template {
|
||||
protected key = "Militarist";
|
||||
}
|
||||
|
||||
export class pac extends eth_template {
|
||||
protected key = "Pacifist";
|
||||
}
|
||||
|
||||
export class pho extends eth_template {
|
||||
protected key = "Xenophobe";
|
||||
}
|
||||
|
||||
export class phi extends eth_template {
|
||||
protected key = "Xenophile";
|
||||
}
|
||||
|
||||
export class com extends eth_template {
|
||||
protected key = "Competitive";
|
||||
}
|
||||
|
||||
export class coo extends eth_template {
|
||||
protected key = "Cooperative";
|
||||
}
|
||||
|
||||
export class eli extends eth_template {
|
||||
protected key = "Elitist";
|
||||
}
|
||||
|
||||
export class plu extends eth_template {
|
||||
protected key = "Pluralist";
|
||||
}
|
||||
|
||||
export class mat extends eth_template {
|
||||
protected key = "Materialist";
|
||||
}
|
||||
|
||||
export class spi extends eth_template {
|
||||
protected key = "Spiritualist";
|
||||
}
|
||||
|
||||
export class eco extends eth_template {
|
||||
protected key = "Ecologist";
|
||||
}
|
||||
|
||||
export class ind extends eth_template {
|
||||
protected key = "Industrialist";
|
||||
}
|
||||
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,
|
||||
}
|
||||
|
||||
export enum Scale {
|
||||
normal = 1,
|
||||
fanatic = 2
|
||||
fanatic = 2,
|
||||
}
|
||||
|
||||
export enum Species {
|
||||
|
@ -121,5 +62,5 @@ export enum Species {
|
|||
Necroid = 9,
|
||||
Aquatic = 10,
|
||||
Toxoid = 11,
|
||||
Machine = 12
|
||||
Machine = 12,
|
||||
}
|
||||
|
|
Reference in a new issue