From 498412fca08baf3fcd96c0b33eccedbf53a016f8 Mon Sep 17 00:00:00 2001 From: bertieb Date: Sat, 20 Feb 2021 14:30:18 +0000 Subject: [PATCH] Add basic frontend (jQuery+Bootstrap) stub --- src/html/index.html | 15 ++++++--------- src/ts/frontend.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 4 ++-- 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/ts/frontend.ts diff --git a/src/html/index.html b/src/html/index.html index b0e19e2..fd9db1f 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -7,16 +7,14 @@ - + + -
-

Asphodice Roller

-

This lets you roll an arbitrary number of Asphodice!

+

Asphodice Roller

+

This lets you roll an arbitrary number of Asphodice. Results will be shown below. Please be patient as the rolls take place in the browser.


@@ -25,10 +23,9 @@ times
- - - + +
diff --git a/src/ts/frontend.ts b/src/ts/frontend.ts new file mode 100644 index 0000000..a4b34c2 --- /dev/null +++ b/src/ts/frontend.ts @@ -0,0 +1,42 @@ +import { RollStats } from "./rollstats" +import { Outcomes } from "./asphodice" + +let rollstats = new RollStats(); + +function getResults():void { + console.log("getting results"); + $("#results").empty(); + rollstats.doRolls(); + $("#results").append(`
`); + $("#results").append(`
`); + $("#results").append(`

+ Rerolled: ${rollstats.rerollCounts.true}
+ Not rerolled: ${rollstats.rerollCounts.false} +

`); + $("#results").append(` + + +
Balance Count Percentage
`); + // + let bc = rollstats.balanceCounts; + let keys = Object.keys(bc); + keys.sort(function(a: string, b: string){return Number(a) - Number(b)}); + //for (let balance in rollstats.balanceCounts) { + for (var i = 0; i < keys.length; i++) { + let tb = $("#balanceTable").find("tbody"); + tb.append(` ${keys[i]} + ${rollstats.balanceCounts[keys[i]]} + ${(rollstats.balanceCounts[keys[i]] / rollstats.numRolls * 100).toFixed(2)} + `); + } + $("#results").append(`
`); + $("#results").append(`
`); +} + + +function setupHandlers(): void { + console.log("adding event handler"); + $("#mainRoll").click(getResults); +} + +document.addEventListener("DOMContentLoaded", setupHandlers); diff --git a/tsconfig.json b/tsconfig.json index 5cf4057..358dd36 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,7 +47,7 @@ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ - "types": [ "node" ], /* Type declaration files to be included in compilation. */ + "types": [ "node", "jquery" ], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ @@ -67,5 +67,5 @@ "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "include": [ "./src/ts/dice.ts", "./src/ts/rollstats.ts" ] + "include": [ "./src/ts/asphodice.ts", "./src/ts/dice.ts", "./src/ts/rollstats.ts" ] }