From 4df797ccd1ae4925eed3df0521a8b5094ab1be0b Mon Sep 17 00:00:00 2001 From: "R.G. Wood" Date: Fri, 5 Apr 2024 18:50:27 +0100 Subject: [PATCH] Add hideroll attribute --- README.md | 11 ++++++----- index.html | 2 +- src/vellum-random-table.ts | 14 +++++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e43fe10..3915d1a 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,18 @@ Web component for interactive random tables. **[Demo](https://grislyeye.github.io/vellum-random-table/)** -| Attribute | Description | Default | -| --------- | -------------------------------------------------------- | ------- | -| `select` | CSS selector for the container/input to display results. | | -| `preroll` | Load table with pre-rolled result. | `false` | +| Attribute | Description | Default | +| ---------- | -------------------------------------------------------- | ------- | +| `select` | CSS selector for the container/input to display results. | | +| `preroll` | Load table with pre-rolled result. | `false` | +| `hideroll` | Display dice roll in parenthesis after roll. | `false` | ### Examples Simple, one-column table (elements are selected at random with equal weight): ```html - + Random Encounters diff --git a/index.html b/index.html index be3b5a6..b135f39 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@

One-column random table

- + Random Encounters diff --git a/src/vellum-random-table.ts b/src/vellum-random-table.ts index c7fa452..a1292b8 100644 --- a/src/vellum-random-table.ts +++ b/src/vellum-random-table.ts @@ -22,6 +22,9 @@ export class VellumRandomTable extends LitElement { @property({ type: Boolean }) preroll: boolean = false + @property({ type: Boolean }) + hideroll: boolean = false + connectedCallback(): void { super.connectedCallback() @@ -78,8 +81,11 @@ export class VellumRandomTable extends LitElement { if (this.mode == TableMode.FirstColumn) { const selection = this.selection(0) - const result = selection[Math.floor(Math.random() * selection.length)] - this.display(result) + const roll = Math.floor(Math.random() * selection.length) + const result = selection[roll] + + if (!this.hideroll) this.display(`${result} (${roll + 1})`) + else this.display(result) } else if (this.mode == TableMode.TwoColumn) { const ranges = this.ranges(0) const selection = this.selection(1) @@ -90,7 +96,9 @@ export class VellumRandomTable extends LitElement { const index = ranges.findIndex((range) => range.includes(roll)) const result = selection[index] - this.display(`${result} (${roll})`) + + if (!this.hideroll) this.display(`${result} (${roll})`) + else this.display(result) } } }