jekyll-dice-tray 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c1d6ec0bd75b534e1e9065d50c819cb075cfc38f730123263387edf464af7d6
4
- data.tar.gz: a4c84f2d04c3459cb7c7ee1aadfc650fecdbeb24fbc8dc0ffbe7edd77831218b
3
+ metadata.gz: d3d407c51d39049511c08f665a5b70a71d0eff1a0ec1522472948ce6350fd670
4
+ data.tar.gz: d2ae3f53ca8018c55bfff796cba3781684076bdeb8ba5bfdc9307c5f3e30c127
5
5
  SHA512:
6
- metadata.gz: 851289f4145e40ee533165363dee941f88f9ac816a3038a09e79e450485219f1963a0d47e63749ef413f0b1476e732f708ec84ea647a46eb7ffc26ff1725a59c
7
- data.tar.gz: 5cc132b97b1af190917d1d7c6b7c0134b3968f54e8e02e32f468c5e411ccca0aced928d7ef951873a10c5a443efd09010bb73cde7b8f3fbcb5b289f307dd9f6b
6
+ metadata.gz: e30263b41fc804cb82a2f6ba76a0697bd31e0e6d5ace3550a94fb6d41d20a25eec1c2db6e65048ea94b549b3137de4a079dc57c7c9f6209b6b841d5b20723ac4
7
+ data.tar.gz: 843991fe95b1a12b60550fc6bc462ea547b46e23b740eda47fe3a454dda4d0e34c4757d7ba8f2f3ae68989814c551b3011fbb571b7f022ab1dd404a4f28942fe
data/README.md CHANGED
@@ -4,12 +4,10 @@ A Jekyll plugin gem that:
4
4
 
5
5
  - Adds an overlay dice tray that accepts dice rolling input
6
6
  - Recognizes dice expressions in rendered pages like `d4`, `1d6`, `1d20+1` and turns them into clickable links that roll in the tray
7
- - Recognizes THAC0-style bracket modifiers like `THAC0 18 [+1]` or `18 [+1]` in a THAC0 table row/column; the `+1` inside the brackets is clickable and rolls `d20+1` (other `[+n]` text is left alone)
8
- - Recognizes chance notation like `2-in-6` (roll a d6; 1–2 succeed in green, higher results fail in red)
9
- - Clicking a lookup-table die in the header row (e.g. `1d12`) rolls and shows the matching encounter row
7
+ - Clicking a lookup-table die in the header row (e.g. `1d12`) rolls and shows the matching row
10
8
  - Persists input history, result history, minimize status
11
- - `/help` - help
12
- - `/clear` - clears results and input history
9
+
10
+ https://github.com/user-attachments/assets/6ef8d788-a1ee-49d4-ab26-f63899bb4a10
13
11
 
14
12
  ## Install
15
13
 
@@ -172,13 +172,26 @@
172
172
  return table.querySelector("tr");
173
173
  }
174
174
 
175
- function firstColumnNumber(row) {
175
+ function parseFirstColumnEntry(text) {
176
+ if (!text) return null;
177
+ var normalized = text.replace(/[\u2013\u2014]/g, "-");
178
+ if (/^\d+$/.test(normalized)) {
179
+ return { kind: "exact", value: parseInt(normalized, 10) };
180
+ }
181
+ var rangeMatch = normalized.match(/^(\d+)\s*-\s*(\d+)$/);
182
+ if (rangeMatch) {
183
+ var min = parseInt(rangeMatch[1], 10);
184
+ var max = parseInt(rangeMatch[2], 10);
185
+ if (min <= max) return { kind: "range", min: min, max: max };
186
+ }
187
+ return null;
188
+ }
189
+
190
+ function firstColumnEntry(row) {
176
191
  if (!row) return null;
177
192
  var cell = row.querySelector("td, th");
178
193
  if (!cell) return null;
179
- var text = normalizeCellText(cell);
180
- if (!/^\d+$/.test(text)) return null;
181
- return parseInt(text, 10);
194
+ return parseFirstColumnEntry(normalizeCellText(cell));
182
195
  }
183
196
 
184
197
  function isLookupTable(table, headerRow) {
@@ -187,20 +200,25 @@
187
200
  var matches = 0;
188
201
  for (var i = 0; i < rows.length; i++) {
189
202
  if (rows[i] === headerRow) continue;
190
- if (firstColumnNumber(rows[i]) !== null) matches++;
203
+ if (firstColumnEntry(rows[i]) !== null) matches++;
191
204
  }
192
205
  return matches >= 2;
193
206
  }
194
207
 
195
208
  function findLookupRow(table, headerRow, rollTotal) {
196
209
  var rows = table.querySelectorAll("tr");
210
+ var rangeRow = null;
197
211
  for (var i = 0; i < rows.length; i++) {
198
212
  var row = rows[i];
199
213
  if (row === headerRow) continue;
200
- var n = firstColumnNumber(row);
201
- if (n !== null && n === rollTotal) return row;
214
+ var entry = firstColumnEntry(row);
215
+ if (!entry) continue;
216
+ if (entry.kind === "exact" && entry.value === rollTotal) return row;
217
+ if (entry.kind === "range" && !rangeRow && rollTotal >= entry.min && rollTotal <= entry.max) {
218
+ rangeRow = row;
219
+ }
202
220
  }
203
- return null;
221
+ return rangeRow;
204
222
  }
205
223
 
206
224
  function getLookupTableContext(anchor, rollTotal) {
@@ -534,7 +552,7 @@
534
552
  function showHelp() {
535
553
  addSystemEntry(
536
554
  "Usage: 1d6, d4, 2d8+1, 2-in-6",
537
- "Click linked dice like 1d20+5, chance like 2-in-6 (roll d6, 1-2 succeed), or bracket modifiers like [+1] (rolls d20+1). Clicking a table die (e.g. 1d12) shows the matching row. Commands: /help, /clear",
555
+ "Click linked dice like 1d20+5, chance like 2-in-6 (roll d6, 1-2 succeed), or bracket modifiers like [+1] (rolls d20+1). Clicking a table die (e.g. 1d12) shows the matching row (first column: single number or range like 3-12). Commands: /help, /clear",
538
556
  nowTime()
539
557
  );
540
558
  }
@@ -1,6 +1,6 @@
1
1
  module Jekyll
2
2
  module DiceTray
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-dice-tray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun