-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_roller.html
More file actions
631 lines (580 loc) · 24.9 KB
/
Copy pathexample_roller.html
File metadata and controls
631 lines (580 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice Roller Test</title>
<style>
body {
font-family: system-ui, sans-serif;
max-width: 600px;
margin: 2rem auto;
padding: 50vh 1rem 0 1rem;
}
#dice-tray {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 50vh;
background: #000;
}
#slow-indicator {
position: fixed;
bottom: calc(50vh + 8px);
right: 8px;
color: #fff;
font-weight: bold;
font-size: 28px;
text-shadow: 1px 1px 2px #666, -1px -1px 2px #666;
opacity: 0;
transition: opacity 0.1s;
}
#slow-indicator.visible {
opacity: 1;
}
h1 {
margin-top: 0;
}
h2 {
margin-top: 1rem;
margin-bottom: 0;
font-size: 1.2em;
}
p {
margin: 0 0 1rem;
line-height: 1.4;
}
code {
background: #f0f0f0;
padding: 0.1rem 0.3rem;
border-radius: 3px;
font-size: 0.9em;
}
.roll {
display: inline-block;
padding: 0.25rem 0.5rem;
margin: 0.25rem;
background: #e0e0e0;
border-radius: 4px;
cursor: pointer;
}
.roll:hover {
background: #d0d0d0;
}
#debug-controls button,
#debug-controls select,
#debug-controls label {
display: inline-block;
padding: 0.25rem 0.5rem;
margin: 0.25rem;
background: #e0e0e0;
border: none;
border-radius: 4px;
font: inherit;
}
#debug-controls button {
cursor: pointer;
}
#debug-controls button:hover {
background: #d0d0d0;
}
#result-modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #333;
color: #fff;
padding: 2rem 3rem;
border-radius: 8px;
font-size: 3rem;
font-weight: bold;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
cursor: pointer;
}
#result-modal.visible {
opacity: 1;
pointer-events: auto;
}
#result-modal .notation {
font-size: 1rem;
font-weight: normal;
opacity: 0.7;
}
#result-modal .dice {
font-size: 1.5rem;
font-weight: normal;
margin: 0.5rem 0;
}
</style>
</head>
<body>
<h1>Dice Roller</h1>
<div id="dice-tray"></div>
<div id="slow-indicator">too many dice</div>
<div id="result-modal">
<div class="notation"></div>
<div class="dice"></div>
<div class="total"></div>
</div>
<div>
<strong>Debug visuals: </strong>
<div id="debug-controls"></div>
</div>
<span class="roll" data-roll="3d4 3d6 3d8 3d10 3d12 3d20">all the dice</span>
<span class="roll" data-roll="red:1d6 green:1d6 yellow:1d6 blue:1d6 orange:1d6 purple:1d6 cyan:1d6 magenta:1d6 lime:1d6 teal:1d6 brown:1d6 maroon:1d6 olive:1d6 navy:1d6 grey:1d6">all the colours</span>
<span class="roll" data-roll="acid:1d6 bludgeoning:1d6 cold:1d6 fire:1d6 force:1d6 lightning:1d6 necrotic:1d6 piercing:1d6 poison:1d6 psychic:1d6 radiant:1d6 slashing:1d6 thunder:1d6">all the damage</span>
<form class="roll">
<input type="text" placeholder="e.g. 2d20kh1+5" required>
<button type="submit">Roll</button>
</form>
<h2>Basic Dice</h2>
<p>The standard seven polyhedrals, plus a coin flip (1d2). Write as
<code>NdS</code> where N is the number of dice and S is the number of
sides.</p>
<span class="roll" data-roll="1d2">coin flip</span>
<span class="roll">1d4</span>
<span class="roll">1d6</span>
<span class="roll">1d8</span>
<span class="roll">1d10</span>
<span class="roll">1d12</span>
<span class="roll">1d20</span>
<span class="roll">1d100</span>
<span class="roll" data-roll="str:3d6 dex:3d6 con:3d6 int:3d6 wis:3d6 cha:3d6">old-skool character gen</span>
<h2>Bonuses</h2>
<p>Add or subtract a fixed value with <code>+N</code> or <code>-N</code>
at the end of the expression.</p>
<span class="roll">1d20+5</span>
<span class="roll">1d20-1</span>
<span class="roll">2d6+3</span>
<h2>Keep Highest / Lowest</h2>
<p>Roll extra dice and keep only some. Use <code>khN</code> to keep the
highest N dice, or <code>klN</code> to keep the lowest N. This is how
advantage and disadvantage work in 5e.</p>
<span class="roll" data-roll="2d20kh1">advantage</span>
<span class="roll" data-roll="2d20kl1">disadvantage</span>
<span class="roll">2d20kh1+5</span>
<span class="roll">2d20kl1-1</span>
<h2>Drop Highest / Lowest</h2>
<p>Roll extra dice and discard some. Use <code>dlN</code> to drop the
lowest N dice, or <code>dhN</code> to drop the highest N.</p>
<span class="roll" data-roll="4d6dl1">one ability score</span>
<span class="roll" data-roll="red:4d6dl1 orange:4d6dl1 yellow:4d6dl1 green:4d6dl1 blue:4d6dl1 purple:4d6dl1">roll all six at once</span>
<span class="roll" data-roll="red:5d6dl2 orange:5d6dl2 yellow:5d6dl2 green:5d6dl2 blue:5d6dl2 purple:5d6dl2">Brennan Lee Mulligan style</span>
<span class="roll" data-roll="str:4d6dl1 dex:4d6dl1 con:4d6dl1 int:4d6dl1 wis:4d6dl1 cha:4d6dl1">roll preassigned</span>
<span class="roll">5d6dl2</span>
<span class="roll">4d6dh1</span>
<h2>Reroll Below (Once)</h2>
<p>Use <code>rbN</code> to reroll any dice that land below N, but only
once per die. This is the Halfling Luck trait, rerolling natural 1s only the first time.</p>
<span class="roll" data-roll="1d20rb2">halfling luck</span>
<span class="roll" data-roll="2d6rb3">great weapon fighting</span>
<span class="roll">1d20rb2</span>
<h2>Reroll Below (Multiple)</h2>
<p>Use <code>rmN</code> to keep rerolling dice below N until all dice show
at least N. Unlike <code>rb</code>, this continues until the condition
is satisfied.</p>
<span class="roll" data-roll="1d20rm10">keep rerolling below 10</span>
<span class="roll" data-roll="12d6rm3">reroll all 1s and 2s</span>
<span class="roll">2d6rm3</span>
<h2>Minimum Value</h2>
<p>Use <code>mN</code> to treat any die result below N as if it were N.
This is how Reliable Talent works — you can't roll below 10.</p>
<span class="roll" data-roll="1d20m10">reliable talent</span>
<span class="roll" data-roll="1d20m10+11">reliable talent +11</span>
<span class="roll">1d20m10</span>
<h2>Reroll Minimum Total</h2>
<p>Use <code>rmtN</code> to reroll all dice if the total (after other
modifiers) is below N. Useful for ability score generation where you
want to guarantee a minimum result.</p>
<span class="roll" data-roll="4d6dl1rmt6">ability score (min 6)</span>
<span class="roll" data-roll="str:4d6dl1rmt10 dex:4d6dl1rmt10 con:4d6dl1rmt10 int:4d6dl1rmt10 wis:4d6dl1rmt10 cha:4d6dl1rmt10">above average character</span>
<span class="roll">3d6rmt10</span>
<h2>Constraints</h2>
<p>Use <code>label:rmtN</code> to reroll all dice with that label if their
combined total is below N. Use <code>*:rmtN</code> to constrain the total
of all dice.</p>
<span class="roll" data-roll="str:4d6dl1 dex:4d6dl1 con:4d6dl1 int:4d6dl1 wis:4d6dl1 cha:4d6dl1 *:rmt70">Matt Mercer style</span>
<span class="roll" data-roll="fire:20d6 bludgeoning:20d6 *:rmt140">above average meteor swarm</span>
<span class="roll">3d6 3d8 *:rmt24</span>
<h2>Labels</h2>
<p>Prefix an expression with <code>label:</code> to group dice by damage
type or other category. Separate multiple expressions with spaces.</p>
<span class="roll" data-roll="fire:8d6">fireball</span>
<span class="roll" data-roll="fire:4d6 radiant:4d6">flame strike</span>
<span class="roll" data-roll="bludgeoning:2d8 cold:4d6">ice storm</span>
<span class="roll">fire:2d6</span>
<span class="roll">slashing:1d8+3 fire:1d6</span>
<h2>Complex Examples</h2>
<p>Combine modifiers for advanced rolls. Modifiers are applied left to
right before the bonus, so ordering matters.</p>
<span class="roll">4d6rb3kh1</span>
<span class="roll">4d6kh1rb3</span>
<span class="roll">fire:3d10rm8+2 cold:2d20kh1rb15 force:1d12m10-1</span>
<script src="dist/dice-roller.js"></script>
<script>
var tray = DiceRoller.tray('#dice-tray', { seed: 1 });
var modal = document.getElementById('result-modal');
var diceTrayEl = document.getElementById('dice-tray');
var debugControlsEl = document.getElementById('debug-controls');
var slowIndicator = document.getElementById('slow-indicator');
// Debug die state
var debugDie = null;
var splash = null;
var autoRotate = true;
var targetFace = 0;
var animationStart = 0;
var pausing = true;
var dragging = false;
var lastDragEnd = 0;
var startQuaternion = null;
var targetQuaternion = null;
var ROTATE_DURATION = 2000;
var PAUSE_DURATION = 1000;
var RESUME_DELAY = 2000;
var textureStyle = 'standard';
var textureClasses = {
debug: {
4: DiceRoller.D4DebugTexture,
6: DiceRoller.D6DebugTexture,
8: DiceRoller.D8DebugTexture,
10: DiceRoller.D10DebugTexture,
12: DiceRoller.D12DebugTexture,
20: DiceRoller.D20DebugTexture,
100: DiceRoller.DPercentileDebugTexture
},
standard: {
4: DiceRoller.D4Texture,
6: DiceRoller.D6Texture,
8: DiceRoller.D8Texture,
10: DiceRoller.D10Texture,
12: DiceRoller.D12Texture,
20: DiceRoller.D20Texture,
100: DiceRoller.DPercentileTexture
},
kintsugi: {
4: DiceRoller.D4KintsugiTexture,
6: DiceRoller.D6KintsugiTexture,
8: DiceRoller.D8KintsugiTexture,
10: DiceRoller.D10KintsugiTexture,
12: DiceRoller.D12KintsugiTexture,
20: DiceRoller.D20KintsugiTexture,
100: DiceRoller.DPercentileKintsugiTexture
},
pride: {
4: DiceRoller.D4PrideTexture,
6: DiceRoller.D6PrideTexture,
8: DiceRoller.D8PrideTexture,
10: DiceRoller.D10PrideTexture,
12: DiceRoller.D12PrideTexture,
20: DiceRoller.D20PrideTexture,
100: DiceRoller.DPercentilePrideTexture
},
nightsky: {
4: DiceRoller.D4NightSkyTexture,
6: DiceRoller.D6NightSkyTexture,
8: DiceRoller.D8NightSkyTexture,
10: DiceRoller.D10NightSkyTexture,
12: DiceRoller.D12NightSkyTexture,
20: DiceRoller.D20NightSkyTexture,
100: DiceRoller.DPercentileNightSkyTexture
}
};
function createDebugTexture(sides) {
var TextureClass = textureClasses[textureStyle][sides];
if (textureStyle === 'kintsugi' || textureStyle === 'nightsky') {
return new TextureClass({ seed: tray.physicsTray.seed || 1 });
}
return new TextureClass();
}
var dieCreators = {
2: function() { return DiceRoller.createD2(1); },
4: function() { return DiceRoller.createD4(1, createDebugTexture(4)); },
6: function() { return DiceRoller.createD6(1, createDebugTexture(6)); },
8: function() { return DiceRoller.createD8(1, createDebugTexture(8)); },
10: function() { return DiceRoller.createD10(1, createDebugTexture(10)); },
12: function() { return DiceRoller.createD12(1, createDebugTexture(12)); },
20: function() { return DiceRoller.createD20(1, createDebugTexture(20)); },
100: function() { return DiceRoller.createPercentile(1, createDebugTexture(100)); }
};
function createDebugDie(sides) {
if (tray.physicsTray.simulation) {
tray.physicsTray.simulation.cancel();
}
DiceRoller.removeDice(tray.physicsTray, tray);
debugDie = null;
return dieCreators[sides]().then(function(die) {
debugDie = die;
die.mesh.position.y = 1;
// size camera so bounding sphere fits at any rotation
var radius = die.physics.body.shapes[0].boundingSphereRadius;
var aspect = diceTrayEl.clientWidth / diceTrayEl.clientHeight;
var size = radius * Math.sqrt(Math.max(aspect, 1 / aspect));
DiceRoller.setCameraSize(tray, size * 1.05);
targetQuaternion = die.defaultOrientation();
if (targetQuaternion) {
die.mesh.quaternion.copy(targetQuaternion);
}
targetFace = 0;
pausing = true;
animationStart = performance.now();
tray.scene.add(die.mesh);
tray.physicsTray.dice.push(die);
if (!splash) {
splash = document.createElement('div');
splash.style.cssText = 'position:absolute;top:8px;right:8px;font-size:24px;font-weight:bold;color:#fff;opacity:0.7;font-family:system-ui,sans-serif;pointer-events:none;';
diceTrayEl.appendChild(splash);
}
updateFaceSelect();
});
}
function updateDebugDie() {
// Check if die was removed by a roll
if (debugDie && !tray.physicsTray.dice.includes(debugDie)) {
debugDie = null;
if (splash) {
splash.remove();
splash = null;
}
return;
}
if (!debugDie) return;
var mesh = debugDie.mesh;
var q = mesh.quaternion;
debugDie.physics.body.quaternion.set(q.x, q.y, q.z, q.w);
if (splash) {
splash.textContent = String(debugDie.physics.readFace());
}
if (dragging) return;
var now = performance.now();
if (autoRotate && lastDragEnd > 0 && now - lastDragEnd < RESUME_DELAY) {
targetFace = debugDie.physics.readFace();
targetQuaternion = null;
pausing = true;
animationStart = now;
return;
}
var elapsed = now - animationStart;
if (pausing) {
if (autoRotate && elapsed >= PAUSE_DURATION) {
var faceValues = debugDie.physics.faces.map(function(f) { return f.value; }).filter(function(v) { return v > 0; }).sort(function(a, b) { return a - b; });
var currentIndex = faceValues.indexOf(targetFace);
var nextIndex = (currentIndex + 1) % faceValues.length;
targetFace = faceValues[nextIndex];
startQuaternion = mesh.quaternion.clone();
targetQuaternion = debugDie.orientToFace(targetFace);
animationStart = now;
pausing = false;
}
} else {
if (startQuaternion && targetQuaternion) {
var t = Math.min(elapsed / ROTATE_DURATION, 1);
var eased = t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
mesh.quaternion.copy(startQuaternion).slerp(targetQuaternion, eased);
if (t >= 1) {
mesh.quaternion.copy(targetQuaternion);
pausing = true;
animationStart = now;
}
}
}
}
// Drag interaction
var lastX = 0, lastY = 0;
diceTrayEl.addEventListener('mousedown', function(e) {
if (!debugDie) return;
dragging = true;
startQuaternion = null;
targetQuaternion = null;
autoRotate = false;
if (autoRotateCheckbox) autoRotateCheckbox.checked = false;
lastX = e.clientX;
lastY = e.clientY;
});
window.addEventListener('mousemove', function(e) {
if (!dragging || !debugDie) return;
var deltaX = e.clientX - lastX;
var deltaY = e.clientY - lastY;
var rotZ = new DiceRoller.THREE.Quaternion().setFromAxisAngle(new DiceRoller.THREE.Vector3(0, 0, 1), -deltaX * 0.01);
var rotX = new DiceRoller.THREE.Quaternion().setFromAxisAngle(new DiceRoller.THREE.Vector3(1, 0, 0), deltaY * 0.01);
debugDie.mesh.quaternion.premultiply(rotZ).premultiply(rotX);
lastX = e.clientX;
lastY = e.clientY;
});
window.addEventListener('mouseup', function() {
if (dragging) {
dragging = false;
lastDragEnd = performance.now();
}
});
// Debug controls - die type buttons
[2, 4, 6, 8, 10, 12, 20, 100].forEach(function(sides) {
var btn = document.createElement('button');
btn.textContent = sides === 100 ? 'd%' : 'd' + sides;
btn.addEventListener('click', function() {
createDebugDie(sides);
});
debugControlsEl.appendChild(btn);
});
// Face select dropdown
var faceSelect = document.createElement('select');
faceSelect.addEventListener('change', function(e) {
if (!debugDie) return;
var face = Number(e.target.value);
startQuaternion = debugDie.mesh.quaternion.clone();
targetQuaternion = debugDie.orientToFace(face);
targetFace = face;
animationStart = performance.now();
pausing = false;
});
debugControlsEl.appendChild(faceSelect);
function updateFaceSelect() {
if (!debugDie) return;
faceSelect.innerHTML = '';
var faceValues = debugDie.physics.faces.map(function(f) { return f.value; }).filter(function(v) { return v > 0; }).sort(function(a, b) { return a - b; });
faceValues.forEach(function(value) {
var option = document.createElement('option');
option.value = String(value);
option.textContent = debugDie.getFaceLabel(value);
faceSelect.appendChild(option);
});
faceSelect.value = String(targetFace || faceValues[0]);
}
// Auto-rotate checkbox
var autoRotateLabel = document.createElement('label');
var autoRotateCheckbox = document.createElement('input');
autoRotateCheckbox.type = 'checkbox';
autoRotateCheckbox.checked = autoRotate;
autoRotateCheckbox.addEventListener('change', function(e) {
autoRotate = e.target.checked;
if (autoRotate && debugDie) {
targetFace = 0;
pausing = true;
animationStart = performance.now();
}
});
autoRotateLabel.appendChild(autoRotateCheckbox);
autoRotateLabel.appendChild(document.createTextNode(' Auto-rotate'));
debugControlsEl.appendChild(autoRotateLabel);
var textureSelect = document.createElement('select');
var textureOptions = [
{ value: 'debug', label: 'Debug' },
{ value: 'standard', label: 'Standard' },
{ value: 'kintsugi', label: 'Kintsugi' },
{ value: 'pride', label: 'Pride' },
{ value: 'nightsky', label: 'Night Sky' }
];
textureOptions.forEach(function(opt) {
var option = document.createElement('option');
option.value = opt.value;
option.textContent = opt.label;
textureSelect.appendChild(option);
});
textureSelect.value = textureStyle;
DiceRoller.texture(textureStyle);
textureSelect.addEventListener('change', function(e) {
textureStyle = e.target.value;
DiceRoller.texture(textureStyle);
if (debugDie) {
var sides;
if (debugDie instanceof DiceRoller.DPercentile) {
sides = 100;
} else if (debugDie instanceof DiceRoller.D2) {
sides = 2;
} else {
sides = debugDie.physics.faces.length;
}
createDebugDie(sides);
}
});
debugControlsEl.appendChild(textureSelect);
var overrideColoursLabel = document.createElement('label');
var overrideColoursCheckbox = document.createElement('input');
overrideColoursCheckbox.type = 'checkbox';
overrideColoursCheckbox.checked = false;
overrideColoursCheckbox.addEventListener('change', function(e) {
DiceRoller.texture(textureStyle, { asColours: e.target.checked });
});
overrideColoursLabel.appendChild(overrideColoursCheckbox);
overrideColoursLabel.appendChild(document.createTextNode(' Override colours'));
debugControlsEl.appendChild(overrideColoursLabel);
var overrideDamageLabel = document.createElement('label');
var overrideDamageCheckbox = document.createElement('input');
overrideDamageCheckbox.type = 'checkbox';
overrideDamageCheckbox.checked = false;
overrideDamageCheckbox.addEventListener('change', function(e) {
DiceRoller.texture(textureStyle, { asDamage: e.target.checked });
});
overrideDamageLabel.appendChild(overrideDamageCheckbox);
overrideDamageLabel.appendChild(document.createTextNode(' Override damage'));
debugControlsEl.appendChild(overrideDamageLabel);
// Result modal
function hideModal() {
modal.classList.remove('visible');
}
function showResult(result) {
console.log(JSON.stringify(result));
if (result.expressions.length === 0) return;
var groupsByLabel = {};
var bonusByLabel = {};
var labelOrder = [];
for (var i = 0; i < result.expressions.length; i++) {
var expr = result.expressions[i];
var label = expr.label || '';
var lastDice = null;
var bonus = 0;
for (var j = 0; j < expr.steps.length; j++) {
var key = Object.keys(expr.steps[j])[0];
var values = expr.steps[j][key];
if (Array.isArray(values)) {
lastDice = values;
} else if (key === 'bonus') {
bonus = values;
}
}
if (lastDice !== null) {
if (!groupsByLabel[label]) {
groupsByLabel[label] = [];
bonusByLabel[label] = 0;
labelOrder.push(label);
}
groupsByLabel[label] = groupsByLabel[label].concat(lastDice);
bonusByLabel[label] += bonus;
}
}
var diceHtml = labelOrder.map(function(label) {
var dice = groupsByLabel[label];
var bonus = bonusByLabel[label];
var diceStr = dice.join('+');
if (bonus > 0) {
diceStr += '+' + bonus;
} else if (bonus < 0) {
diceStr += bonus;
}
var total = dice.reduce(function(sum, v) { return sum + v; }, 0) + bonus;
return label ? label + ': ' + diceStr + ' = ' + total : diceStr;
}).join('<br>');
modal.querySelector('.notation').textContent = result.notation;
modal.querySelector('.dice').innerHTML = diceHtml;
modal.querySelector('.total').textContent = result.total;
modal.classList.add('visible');
}
modal.addEventListener('click', hideModal);
DiceRoller.onRoll(showResult);
DiceRoller.bind('.roll');
var lastSlow = false;
tray.onUpdate = function() {
updateDebugDie();
var slow = tray.physicsTray.isDropping;
if (slow !== lastSlow) {
slowIndicator.classList.toggle('visible', slow);
lastSlow = slow;
}
};
createDebugDie(12);
</script>
</body>
</html>