瀏覽代碼

Add preamble describing rolls

tags/v0.1.3
bertieb 3 年之前
父節點
當前提交
a879a3df80
共有 1 個文件被更改,包括 24 次插入3 次删除
  1. +24
    -3
      src/ts/frontend.ts

+ 24
- 3
src/ts/frontend.ts 查看文件

@@ -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…
取消
儲存