Skip to content

Commit

Permalink
Merge pull request #20 from Lenni009/dev
Browse files Browse the repository at this point in the history
fix table cols
  • Loading branch information
Lenni009 authored Dec 27, 2023
2 parents d8d7b61 + 2192862 commit 2e2da3a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 0 additions & 1 deletion env.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/output/ChancesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const divTable = computed(() => {

<template>
<div v-if="rewardSearchTerm">
<TextLabel> {{ chancesInputType }}: </TextLabel>
<TextLabel>{{ chancesInputType }}:</TextLabel>
<div
v-if="divTable?.length"
class="chancesTable"
Expand Down
35 changes: 19 additions & 16 deletions src/logic/tableBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import type { DataTable } from "@/types/table";
import type { DataTable } from '@/types/table';

export function buildTable(data: { IDs: string[], chances: string[], rewards: string[] }, productSearchTerm: string): DataTable[] {
export function buildTable(
data: { IDs: string[]; chances: string[]; rewards: string[] },
productSearchTerm: string
): DataTable[] {
const table: DataTable[] = [];
for (let i = 0; i < data.IDs.length; i++) {
const rewardNr = (i + 1).toString();
const rewardNr = i + 1 + '.';
const itemId = data.IDs[i];
const chance = data.chances[i];
const chance = data.chances[i] + '%';
const rewardType = data.rewards[i];

const itemData = {
itemId,
rewardNr,
rewardType,
chance: chance + '%',
rewardNr: rewardNr + '.',
}
itemId,
chance,
};

const isSearchedItem = itemId.toLowerCase() === productSearchTerm?.toLowerCase();
const tableRow: DataTable[] = [];
for (const content of Object.values(itemData)) {
const tableItem: DataTable = {
content,
}
};
if (isSearchedItem) tableItem.htmlClass = 'mark';

tableRow.push(tableItem);
Expand All @@ -32,23 +35,23 @@ export function buildTable(data: { IDs: string[], chances: string[], rewards: st

export function constructData(EXMLSection: XMLDocument | Element, IDs: string[], chances: string[], rewards: string[]) {
const data = {
"IDs": IDs,
"chances": calculateChances(EXMLSection, chances),
"rewards": rewards
}
IDs,
rewards,
chances: calculateChances(EXMLSection, chances),
};
return data;
}

function calculateChances(EXMLSection: XMLDocument | Element, PercentageChances: string[]) {
if (EXMLSection.querySelector('[name="RewardChoice"]')?.getAttribute("value") === 'GiveAll') return PercentageChances;
if (EXMLSection.querySelector('[name="RewardChoice"]')?.getAttribute('value') === 'GiveAll') return PercentageChances;

const calculatedChances: string[] = [];
const chances = PercentageChances.map(Number);

for (const chance of chances) {
const calcChance = chance / (chances.reduce((a, b) => a + b, 0) / 100); // NoSonar this is calculating a percentage
const calcChance = chance / (chances.reduce((a, b) => a + b, 0) / 100); // NoSonar this is calculating a percentage
const decimals = 3;
calculatedChances.push(calcChance.toFixed(decimals));
}
return calculatedChances;
}
}

0 comments on commit 2e2da3a

Please sign in to comment.