Browse Source

Add preamble describing rolls

tags/v0.1.3
bertieb 3 years ago
parent
commit
a879a3df80
1 changed files with 24 additions and 3 deletions
  1. +24
    -3
      src/ts/frontend.ts

+ 24
- 3
src/ts/frontend.ts View File

@@ -250,16 +250,39 @@ function generateTables(rollstats: RollStats): void {

}

/**
* For pretty-printing. See https://stackoverflow.com/a/2901298
*/
function numberWithCommas(x:number): string {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

/**
* Give some info on the dice used to generate these results
*/

function describeRolls(rollstats: RollStats): string {
let output = subTitle("Description");
output += `<p>There were <strong>${rollstats.numDice}</strong> Asphodice rolled <strong>${numberWithCommas(rollstats.numRolls)}</strong> times.</p>`;
return output;
}

function getResults():void {
console.log("getting results");
// Disable 'roll' button (TODO: multiple sets of rolls)
$("#mainRoll").prop("disabled", true);
console.log("Getting results..."); // TODO: progress bar when we have multiple sets of rolls

$("#results").empty();
rollstats.doRolls();

$("#results").append(`<div class="card my-4">`);
let resultsCard = $("#results").find("div.card");
resultsCard.append(`<div class="card-body">`);
let resultsCardBody = $("#results").find("div.card-body");


resultsCardBody.append(bigTitle("Asphodice Results"));
resultsCardBody.append(describeRolls(rollstats));
resultsCardBody.append(rerollReport(rollstats));
resultsCardBody.append(outcomesReport(rollstats));
resultsCardBody.append(outcomeBalancesReport(rollstats));
@@ -277,12 +300,10 @@ function getResults():void {

// Charts
generateCharts(rollstats);

}


function setupHandlers(): void {
console.log("adding event handler");
$("#mainRoll").click(getResults);
}



Loading…
Cancel
Save