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 +4 -4
- data/README.md +3 -5
- data/assets/jekyll-dice-tray/dice_tray.js +27 -9
- data/lib/jekyll/dice_tray/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3d407c51d39049511c08f665a5b70a71d0eff1a0ec1522472948ce6350fd670
|
|
4
|
+
data.tar.gz: d2ae3f53ca8018c55bfff796cba3781684076bdeb8ba5bfdc9307c5f3e30c127
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
-
|
|
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
|
-
|
|
12
|
-
-
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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
|
|
201
|
-
if (
|
|
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
|
|
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
|
}
|