All files / games/mc/src/sections encounters.ts

100% Statements 71/71
80% Branches 8/10
100% Functions 5/5
100% Lines 69/69

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  5x 5x 5x 5x 4x   4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x   4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   4x   5x                                                          
import { convertRatingToStars, createTitle } from "../helper";
 
import { Encounter } from "../@models";
 
export const loadEncounters = (body: HTMLBodyElement, encounters: Encounter[]): void => {
    createTitle("Encounters", body);
 
    // console.table(encounters);
 
    const table = document.createElement("table");
 
    const firstRow = document.createElement("tr");
 
    const scenario = document.createElement("th");
    scenario.innerText = "Scenario";
 
    const module = document.createElement("th");
    module.innerText = "Modular Sets";
 
    const difficulty = document.createElement("th");
    difficulty.innerText = "Difficulty";
 
    const hero1 = document.createElement("th");
    hero1.innerText = "Hero 1";
 
    const hero2 = document.createElement("th");
    hero2.innerText = "Hero 2";
 
    const hero3 = document.createElement("th");
    hero3.innerText = "Hero 3";
 
    const hero4 = document.createElement("th");
    hero4.innerText = "Hero 4";
 
    const rating = document.createElement("th");
    rating.innerText = "Rating";
 
    const result = document.createElement("th");
    result.innerText = "Result";
 
    firstRow.appendChild(scenario);
    firstRow.appendChild(module);
    firstRow.appendChild(difficulty);
    firstRow.appendChild(hero1);
    firstRow.appendChild(hero2);
    firstRow.appendChild(hero3);
    firstRow.appendChild(hero4);
    firstRow.appendChild(rating);
    firstRow.appendChild(result);
 
    table.appendChild(firstRow);
 
    // load encounters
    encounters.forEach((encounter) => {
        const row = document.createElement("tr");
 
        const scenario = document.createElement("td");
        scenario.innerText = encounter.scenario.name;
 
        const module = document.createElement("td");
        module.innerText =
            null != encounter.modularSets ? encounter.modularSets.map((modularSet) => modularSet.name).join(", ") : "";
 
        const difficulty = document.createElement("td");
        difficulty.innerText = encounter.difficulty;
 
        const hero1 = document.createElement("td");
        hero1.innerText = encounter.heroes[0].name;
 
        const hero2 = document.createElement("td");
        hero2.innerText = encounter.heroes[1]?.name || "";
 
        const hero3 = document.createElement("td");
        hero3.innerText = encounter.heroes[2]?.name || "";
 
        const hero4 = document.createElement("td");
        hero4.innerText = encounter.heroes[3]?.name || "";
 
        const ratingScore =
            encounter.modularSets?.map((modularSet) => modularSet.rating).reduce((acc, rating) => (acc += rating), 0) +
            +(encounter.heroes.length === 1)
                ? encounter.scenario.rating_standard_solo
                : encounter.scenario.rating_standard_multi;
 
        const rating = document.createElement("td");
        rating.innerText = convertRatingToStars(ratingScore);
 
        const result = document.createElement("td");
        result.innerText = encounter.result;
 
        row.appendChild(scenario);
        row.appendChild(module);
        row.appendChild(difficulty);
        row.appendChild(hero1);
        row.appendChild(hero2);
        row.appendChild(hero3);
        row.appendChild(hero4);
        row.appendChild(rating);
        row.appendChild(result);
 
        table.appendChild(row);
    });
 
    body.appendChild(table);
};