Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 6x 6x 6x 6x 21x 21x 21x 6x 6x 26x 26x 26x 6x 6x 15x 15x 15x 15x 5x 5x 5x 5x 5x 5x 5x 5x 5x 15x 15x 6x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 6x 6x 6x 33x 33x 33x 33x 33x 46x 46x 46x 46x 46x 33x 6x 6x 23x 6x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 3x 5x 8x 6x | import {
DifficultyEnum,
Hero,
isHero,
isModularSet,
isPack,
isScenario,
ModularSet,
Pack,
ResultEnum,
Scenario,
} from "./@models";
export const createTitle = (title: string, body: HTMLBodyElement): void => {
const header = document.createElement("h2");
header.innerText = title;
body.appendChild(header);
};
export const createSubTitle = (title: string, body: HTMLBodyElement): void => {
const header = document.createElement("h3");
header.innerText = title;
body.appendChild(header);
};I
export const createSection = (
title: string,
data: Hero[] | Scenario[] | ModularSet[] | Pack[],
body: HTMLBodyElement,
): void => {
createSubTitle(title, body);
const section = document.createElement("section");
I
const list = document.createElement("ul");
data.forEach((item: Hero | Scenario | ModularSet | Pack) => {
const element = document.createElement("li");
const data = document.createElement("data");
data.innerText = `${item.name}`;
let dataAttribute = "";
if (isHeroOrModularSetOrScenario(item)) {
dataAttribute = `Pack : ${item.pack.name}`;
if (isModularSet(item)) {
dataAttribute = `${dataAttribute}, rating: ${item.rating}`;
}
if (isScenario(item)) {
dataAttribute = `${dataAttribute}, rating standard solo: ${item.rating_standard_solo}, rating standard multi: ${item.rating_standard_multi}`;
}
} else {
if (isPack(item)) {
dataAttribute = item.releaseDate;
}
}
data.setAttribute("value", dataAttribute);
element.appendChild(data);
list.appendChild(element);
});
section.appendChild(list);
Ibody.appendChild(section);
};
export const createStatsTable = (
data: Map<string, number>,
source: Hero[] | Scenario[],
wins: Map<string, number>,
body: HTMLBodyElement,
): void I=> {
const table = document.createElement("table");
source.forEach((item: Hero | Scenario) => {
const itemLine = document.createElement("tr");
const itemName = document.createElement("td");
const itemCount = document.createElement("td");
const itemRate = document.createElement("td");
const gameNumber = (data.has(item.name) ? data.get(item.name) : 0) as number;
const winRate = (
gameNumber !== 0 ? ((wins.has(item.name) ? (wins.get(item.name) as number) : 0) / gameNumber) * 100 : 0
) as number;
itemName.innerText = item.name;
itemCount.innerText = gameNumber.toString();
I itemRate.innerText = ` (${winRate.toFixed(0).toString()} %) `;
itemLine.appendChild(itemName);
iItemLine.appendChild(itemCount);
itemLine.appendChild(itemRate);
tIable.appendChild(itemLine);
});
body.IappendChild(table);
};
export coInst createSelectElement = (
defaultValue: DifficultyEnum | Hero | ModularSet | ResultEnum | Scenario | null,
source: DifficultyEnum[] | ResultEnum[] | string[],
multiIple = false,
): HTMLSelectElement => {
const selectElement = document.createElement("select");
constI selectOption = document.createElement("option");
if (true === multiple) {
sIelectElement.setAttribute("multiple", "true");
}
selectElement.appendChild(selectOption);
for (const item in source) {
cIonst option = document.createElement("option");
option.value = source[item];
option.innerText = source[item];
if (
null !== defaultValue &&
((isHeroOrModularSetOrScenario(defaultValue) && defaultValue.name === source[item]) ||
(!isHeroOrModularSetOrScenario(defaultValue) && defaultValue === source[item]))
) {
option.selected = true;
}
selectElement.appendChild(option);
}
return selectElement;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isHeroOrModularSetOrScenario = (value: any): value is Hero | ModularSet | Scenario => {
return isHero(value) || isModularSet(value) || isScenario(value);
};
export const convertRatingToStars = (rating: number): string => {
let stars = 0;
if (28 <= rating) {
stars = 5;
} else if (24 <= rating) {
stars = 4.5;
} else if (20 <= rating) {
stars = 4;
} else if (16 <= rating) {
stars = 3.5;
} else if (12 <= rating) {
stars = 3;
} else if (9 <= rating) {
stars = 2.5;
} else if (5 <= rating) {
stars = 2;
} else if (1 <= rating) {
stars = 1.5;
} else if (-4 <= rating) {
stars = 1;
} else if (-7 <= rating) {
stars = 0.5;
}
return `⭐`.repeat(stars * 2);
};
|