Pages affected by Ethics enum renaming

This commit is contained in:
Neshura 2023-08-15 22:51:28 +02:00
parent 716fc71282
commit 84301ecd0a
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
2 changed files with 24 additions and 24 deletions

View file

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { Bar } from 'svelte-chartjs'; import { Bar } from 'svelte-chartjs';
import { Ethics, EthicsDataLegacy } from '$lib/types/stellaris'; import { LegacyEthics, EthicsDataLegacy } from '$lib/types/stellaris';
import { Chart as ChartJS, registerables } from 'chart.js'; import { Chart as ChartJS, registerables } from 'chart.js';
@ -14,7 +14,7 @@
const parseEthicsData = (data: Array<Array<number>>) => { const parseEthicsData = (data: Array<Array<number>>) => {
let parsedEthicsData: Array<EthicsDataLegacy> = new Array<EthicsDataLegacy>(); let parsedEthicsData: Array<EthicsDataLegacy> = new Array<EthicsDataLegacy>();
Object.keys(Ethics).forEach((ethic: number | string) => { Object.keys(LegacyEthics).forEach((ethic: number | string) => {
if (Number.isInteger(Number(ethic))) { if (Number.isInteger(Number(ethic))) {
parsedEthicsData[Number(ethic)] = new EthicsDataLegacy(data[Number(ethic)]); parsedEthicsData[Number(ethic)] = new EthicsDataLegacy(data[Number(ethic)]);
} }
@ -29,12 +29,12 @@
ethicsData.forEach((ethicsData, index) => { ethicsData.forEach((ethicsData, index) => {
sumArray[index] = ethicsData.sum(false); sumArray[index] = ethicsData.sum(false);
labelArray[index] = Ethics[index]; labelArray[index] = LegacyEthics[index];
}); });
let zipped: Array<{ sums: number; labels: string }> = []; let zipped: Array<{ sums: number; labels: string }> = [];
for (let i = 0; i < ethicsData.length; i++) { for (let i = 0; i < ethicsData.length; i++) {
zipped.push({ sums: ethicsData[i].sum(false), labels: Ethics[i] }); zipped.push({ sums: ethicsData[i].sum(false), labels: LegacyEthics[i] });
} }
zipped.sort((a: { sums: number; labels: string }, b: { sums: number; labels: string }) => zipped.sort((a: { sums: number; labels: string }, b: { sums: number; labels: string }) =>
a.sums > b.sums ? -1 : 1 a.sums > b.sums ? -1 : 1

View file

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { writable, type Writable } from "svelte/store"; import { writable, type Writable } from "svelte/store";
import { Radar } from 'svelte-chartjs'; import { Radar } from 'svelte-chartjs';
import { Ethics, EthicsDataLegacy } from '$lib/types/stellaris'; import { LegacyEthics, EthicsDataLegacy } from '$lib/types/stellaris';
import { Chart as ChartJS, registerables } from 'chart.js'; import { Chart as ChartJS, registerables } from 'chart.js';
import ChartDataLabels from 'chartjs-plugin-datalabels'; import ChartDataLabels from 'chartjs-plugin-datalabels';
@ -16,7 +16,7 @@
const parseEthicsData = (data: Array<Array<number>>) => { const parseEthicsData = (data: Array<Array<number>>) => {
let parsedEthicsData: Array<EthicsDataLegacy> = new Array<EthicsDataLegacy>(); let parsedEthicsData: Array<EthicsDataLegacy> = new Array<EthicsDataLegacy>();
Object.keys(Ethics).forEach((ethic: number | string) => { Object.keys(LegacyEthics).forEach((ethic: number | string) => {
if (Number.isInteger(Number(ethic))) { if (Number.isInteger(Number(ethic))) {
parsedEthicsData[Number(ethic)] = new EthicsDataLegacy(data[Number(ethic)]); parsedEthicsData[Number(ethic)] = new EthicsDataLegacy(data[Number(ethic)]);
} }
@ -44,23 +44,23 @@
let sumRegularArray = new Array<number>(); let sumRegularArray = new Array<number>();
const labelsArray = [ const labelsArray = [
Ethics.Egalitarian, LegacyEthics.Egalitarian,
Ethics.Militarist, LegacyEthics.Militarist,
Ethics.Xenophobe, LegacyEthics.Xenophobe,
Ethics.Competitive, LegacyEthics.Competitive,
Ethics.Elitist, LegacyEthics.Elitist,
Ethics.Materialist, LegacyEthics.Materialist,
Ethics.Ecologist, LegacyEthics.Ecologist,
Ethics.Authoritarian, LegacyEthics.Authoritarian,
Ethics.Pacifist, LegacyEthics.Pacifist,
Ethics.Xenophile, LegacyEthics.Xenophile,
Ethics.Cooperative, LegacyEthics.Cooperative,
Ethics.Pluralist, LegacyEthics.Pluralist,
Ethics.Spiritualist, LegacyEthics.Spiritualist,
Ethics.Industrialist LegacyEthics.Industrialist
]; ];
labelsArray.forEach((ethic: Ethics, index: number) => { labelsArray.forEach((ethic: LegacyEthics, index: number) => {
sumTotalArray[index] = ethicsData[ethic].sum(weighted); sumTotalArray[index] = ethicsData[ethic].sum(weighted);
sumRegularArray[index] = ethicsData[ethic].sumRegular(); sumRegularArray[index] = ethicsData[ethic].sumRegular();
}); });
@ -74,7 +74,7 @@
scaleLimit % 2 == 0 ? (scaleLimit = scaleLimit) : (scaleLimit = scaleLimit + 1); scaleLimit % 2 == 0 ? (scaleLimit = scaleLimit) : (scaleLimit = scaleLimit + 1);
const chart_data = { const chart_data = {
labels: labelsArray.map((ethic) => Ethics[ethic]), labels: labelsArray.map((ethic) => LegacyEthics[ethic]),
datasets: [ datasets: [
{ {
label: 'Total Ethics', label: 'Total Ethics',
@ -133,7 +133,7 @@
}; };
function updateChartData() { function updateChartData() {
labelsArray.forEach((ethic: Ethics, index: number) => { labelsArray.forEach((ethic: LegacyEthics, index: number) => {
sumTotalArray[index] = ethicsData[ethic].sum(weighted); sumTotalArray[index] = ethicsData[ethic].sum(weighted);
}); });
@ -158,7 +158,7 @@
<Radar data={chart_data} {options} /> <Radar data={chart_data} {options} />
<label> <label>
<input type="checkbox" bind:checked={weighted} on:change={updateChartData} /> <input type="checkbox" bind:checked={weighted} on:change={updateChartData} />
Use weighted Ethics Use weighted LegacyEthics
</label> </label>
</div> </div>