This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
695 lines (610 loc) · 19.8 KB
/
index.html
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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Printable DCC RPG Monster Cards</title>
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
<!--suppress SpellCheckingInspection, CssReplaceWithShorthandSafely -->
<style>
@media print {
#input {display:none;}
body {
margin: 0 0 0 0;
border: none;
padding: 0 0 0 0;
width: 100vw;
height: 100vh;
}
.output-box {
margin: 0 0 0 0;
border: none;
padding: 0 0 0 0;
box-sizing: border-box;
}
.output-box>h2 {
display: none;
}
#output {
width: 100vw;
height: 100vh;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
border: none;
padding: 0 0 0 0;
}
}
@media screen {
body {
margin: 0 0 0 0;
border: none;
padding: 0 0 0 0;
width: 100vw;
height: 100vh;
}
.output-box {
margin: 1em 1em 1em 1em;
border: 1px solid;
padding: 1em 1em 1em 1em;
display: flow-root;
}
.output-box>h2 {
margin-top: 0;
}
#output {
width: 49em;
height: 70em;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
border: none;
padding: 0 0 0 0;
display: flow-root;
}
}
@page {
display: block;
page-break-after: always;
padding: 0;
}
#input {
margin: 1em 1em 1em 1em;
border: 1px solid;
padding: 1em 1em 1em 1em;
}
.card {
display: block;
float: left;
break-inside: avoid;
width: calc(50%);
margin-left: 0;
margin-right: 0;
padding-left: 1em;
padding-right: 1em;
height: calc(25%);
margin-top: 0;
margin-bottom: 0;
padding-top: 1em;
padding-bottom: 1em;
overflow: hidden;
box-sizing: border-box;
}
.border-yes {
border: 1px gray dashed;
}
.border-no {
border: none;
}
#name {
font-weight: bold;
font-size: 1.2em;
grid-area: a;
width: 100%;
padding-bottom: 0.1em;
}
.label {
font-weight: lighter;
font-size: 0.8em;
margin-right: 0.2em;
display: inline;
}
.label:after {
content: ':';
}
.value {
/*float: left;*/
font-weight: bolder;
font-size: 1em;
margin-top: 0.2em;
margin-right: 0;
margin-left: 0;
margin-bottom: 0;
display: inline;
}
.monster-number {
display: inline-block;
font-size: 0.8em;
}
.monster-info {
display: inline-block;
font-size: 0.8em;
}
.prop {
float: left;
}
.iniaw.prop {
width: 100%;
}
.rktp.prop {
width: 100%;
padding-top: 0.4em;
}
.bw.prop {
width: 100%;
padding-top: 0.4em;
}
.a.prop {
width: 100%;
}
.rw.prop {
width: 100%;
padding-top: 0.4em;
}
.g.prop {
width: 100%;
}
.sp.prop {
width: 100%;
padding-top: 0.1em;
}
.sp.value {
font-size: 0.9em;
}
.ml {
margin-left: 1em;
}
.mr {
margin-right: 1em;
}
.input-box {
border: solid 1px;
padding: 0.2em;
display: flow-root;
}
.output-template {
display: none;
}
#print-button {
font-weight: bold;
background-color: lightblue;
}
.instruction-number {
color: darkred;
font-size: xx-large;
font-weight: bold;
border: darkred double;
display: inline-block;
}
.input-inner-box {
float: left;
}
.instructions-box {
margin-left: 42em;
}
.left-arrow:after {
content: '\2190';
font-size: xx-large;
font-weight: bold;
}
.right-arrow:after {
content: '\2192';
font-size: xx-large;
font-weight: bold;
}
.instruction {
padding: 0.2em;
}
</style>
</head>
<body>
<div id="input">
<h1>
Printable DCC RPG Monster Cards
<span style="font-size: medium">
for the Dungeon Crawl Classics RPG by
<a href="https://goodman-games.com/" target="_blank">Goodman Games</a> (english) /
<a href="https://www.system-matters.de/shop/dungeon-crawl-classics/" target="_blank">System Matters</a> (deutsch)
</span>
</h1>
<form id="input-form">
<div id="input-box-text" class="input-box">
<textarea id="input-text" rows="30" cols="80" class="input-inner-box"
oninput="createCards()">
</textarea>
<div id="input-text-instructions" class="instructions-box">
<div class="instruction">
<i class="right-arrow"></i> <span class="instruction-number">1.</span> Copy monster stats from your DCC RPG adventure PDF</label><br>
(English and German stats are supported. Separate stats by blank lines)
</div>
<div class="instruction">
<i class="left-arrow"></i> <span class="instruction-number">2.</span> Paste the copied monster stats
here (or <label for="input-text">use the</label> <button id="sample-button" type="button" onclick="pasteSampleStats(); createCards()">Sample Stats</button>)
</div>
<div class="instruction">
</div>
<div class="instruction">
(<button id="clear-button" type="button" onclick="clearInputText(); createCards()">Clear</button>
the input text field to start over)
</div>
</div>
</div>
<div class="input-box">
<div id="input-options" class="input-inner-box">
<div>
<input id="draw-border" type="checkbox" onchange="createCards()" checked> <label for="draw-border">Print cutting lines</label>
</div>
<div>
<input id="multiply-cards" type="checkbox" onchange="onMultipleCardsOptionChanged(); createCards()"> <label for="multiply-cards">Print multiple cards when number of monsters is given</label>
</div>
<div>
<input id="random-monster-count" type="checkbox" onchange="createCards()"> <label for="random-monster-count">Use random number of cards for stats with dice roll formula as number</label>
</div>
<div>
<label for="max-cards-per-monster">Max number of cards per monster:</label> <input id="max-cards-per-monster" type="number" value="10" onchange="createCards()">
</div>
<div>
Cards Language:
<input id="cards-language-de" name="cards-language" type="radio" value="de" onchange="createCards()" checked><label for="cards-language-de">German</label>
<input id="cards-language-en" name="cards-language" type="radio" value="en" onchange="createCards()"><label for="cards-language-en">English</label>
</div>
</div>
<div id="input-options-instructions" class="instructions-box">
<i class="left-arrow"></i> <span class="instruction-number">3.</span> Chose the options that match your requirements</label>
</div>
</div>
<div class="input-box">
<div id="input-buttons" class="input-inner-box">
<button id="create-button" type="button" onclick="createCards()">Refresh Cards</button>
<button id="print-button" type="button" onclick="window.print();">Print</button>
</div>
<div id="input-buttons-instructions" class="instructions-box">
<i class="left-arrow"></i> <span class="instruction-number">4.</span> Print with zero margins on A4 or Letter sheets (200g paper recommended)</label>
</div>
</div>
</form>
</div>
<div class="output-box">
<h2>Preview</h2>
<div id="output"></div>
</div>
<script>
const LABELS = {
de: {
INI: 'INI',
AW: 'AW',
A: 'A',
RK: 'RK',
TP: 'TP',
BW: 'BW',
RW: 'RW',
ZAH: 'ZÄH',
REF: 'REF',
WIL: 'WIL',
G: 'AW',
BES: 'BES',
rechtschaffen: 'rechtschaffen',
neutral: 'neutral',
chaotisch: 'chaotisch',
variabel: 'variabel'
},
en: {
INI: 'Init',
AW: 'HD',
A: 'Atk',
RK: 'AC',
TP: 'HP',
BW: 'MV',
RW: 'SV',
ZAH: 'Fort',
REF: 'Ref',
WIL: 'Will',
G: 'AL',
BES: 'SP',
rechtschaffen: 'lawful',
neutral: 'neutral',
chaotisch: 'chaotic',
variabel: 'variable'
}
}
let allCardsTemplate;
let textAreaElement;
let drawBorderCheckbox;
let multiplyCardsCheckbox;
let randomMonsterCountCheckbox;
let maxCardsPerMonsterInputField;
let langRadioDe;
let langRadioEn;
document.addEventListener('DOMContentLoaded', () => {
textAreaElement = document.querySelector('#input-text');
drawBorderCheckbox = document.querySelector('#draw-border');
multiplyCardsCheckbox = document.querySelector('#multiply-cards');
randomMonsterCountCheckbox = document.querySelector('#random-monster-count');
maxCardsPerMonsterInputField = document.querySelector('#max-cards-per-monster');
langRadioDe = document.querySelector('#cards-language-de');
langRadioEn = document.querySelector('#cards-language-en');
onMultipleCardsOptionChanged();
Handlebars.registerHelper('translateDice', function (s, lang) {
switch (lang) {
case 'de':
return s;
case 'en':
return s ? s.replaceAll(/(\d*)(W)(\d)/g, "$1d$3") : '';
default:
return s;
}
});
allCardsTemplate = Handlebars.compile(document.querySelector('#all-cards-template').innerHTML);
Handlebars.registerPartial('cardPartial', document.querySelector('#single-card-template').innerHTML);
console.log("templates compiled");
});
function parseName(text) {
const match = text.match(/^\s*(?<name>[\w\s,äöüÄÖÜß-]*\w)\s*(?:\((?<numberOrInfo>[\w\s/\-,:äöüÄÖÜß]+)\))?\s*:?\s*(?:(?:INI)|(?:Init))\s+(?<ini>[+\-\w()\s]+)\s*[,;]/);
return match && match.groups['name'];
}
function parseNumber(text) {
const match = text.match(/^\s*(?:[\w\s,äöüÄÖÜß-]*\w)\s*\((?<number>[\dWd]+)\)\s*:?\s*(?:(?:INI)|(?:Init))\s+(?<ini>[+\-\w()\s]+)\s*[,;]/);
return match && match.groups['number'];
}
function parseNameInfo(text) {
const match = text.match(/^\s*(?:[\w\s,äöüÄÖÜß-]*\w)\s*\((?<numberOrInfo>[\w\s/\-,:äöüÄÖÜß]+)\)\s*:?\s*(?:(?:INI)|(?:Init))\s+(?<ini>[+\-\w()\s]+)\s*[,;]/);
return match && match.groups['numberOrInfo'];
}
function parseInit(text) {
const match = text.match(/^\s*(?<name>[\w\s,äöüÄÖÜß-]*\w)\s*(?:\((?<numberOrInfo>[\w\s/\-,:äöüÄÖÜß]+)\))?\s*:?\s*(?:(?:INI)|(?:Init))\s+(?<ini>[+\-\w()\s]+)\s*[,;]/);
return match && match.groups['ini'];
}
function parseGenericProp(text, props) {
if (typeof props !== 'string') {
props = props.map(s => '(?:' + s + ')').join('|');
}
const regExp = new RegExp('[,;]\\s*(?:' + props + ')\\s+(?<prop>[^;]+)\\s*[,;]');
const match = text.match(regExp);
return match && fixLinebreaks(match.groups['prop'])
}
function parseSaving(text, rwProp) {
const regExp = new RegExp('[,;]\\s*(RW|SV)'
+ '\\s+(ZÄH|Fort)\\s+(?<zaeh>[^,;]+)\\s*[,;]'
+ '\\s+(REF|Ref)\\s+(?<ref>[^,;]+)\\s*[,;]'
+ '\\s+(WIL|Will)\\s+(?<wil>[^,;]+)\\s*[,;]');
const match = text.match(regExp);
return match && match.groups[rwProp];
}
function parseAlignment(text) {
const match = text.match(/[,;]\s*(G|AL)\s+(?<gesinnung>([RLNCV]|var))\./);
if (match) {
const ges = match.groups['gesinnung'];
switch (ges) {
case 'R': return 'rechtschaffen';
case 'L': return 'rechtschaffen';
case 'N': return 'neutral';
case 'C': return 'chaotisch';
case 'V': return 'variabel';
case 'var': return 'variabel';
}
}
return '?';
}
function unifyDiceRolls(text) {
return text && text.replaceAll(/(\d*)(d)(\d)/g, "$1W$3");
}
function fixLinebreaks(text) {
return text && text.replaceAll(/([a-zäöü])(- )([a-zäöüû]+)/g,
(match, p1, p2, p3) => {
if (p3 === 'und' || p3 === 'and' || p3 === 'oder' || p3 === 'or') {
return match;
} else {
return p1 + p3;
}
});
}
function parseSingleMonsterStat(text) {
if (!text) {
return null;
}
const monsterStat = {
name: parseName(text),
number: parseNumber(text),
info: parseNameInfo(text),
ini: parseInit(text),
a: unifyDiceRolls(parseGenericProp(text, ['A','Atk'])),
dmg: unifyDiceRolls(parseGenericProp(text, ['Dmg'])),
rk: parseGenericProp(text, ['RK','AC']),
tw: unifyDiceRolls(parseGenericProp(text, ['TW','HD'])),
tp: parseGenericProp(text, ['TP','hp', 'HP']),
bw: parseGenericProp(text, ['BW','MV']),
aw: unifyDiceRolls(parseGenericProp(text, ['AW','Act'])),
rw_zaeh: parseSaving(text, 'zaeh'),
rw_ref: parseSaving(text, 'ref'),
rw_wil: parseSaving(text, 'wil'),
gesinnung: parseAlignment(text),
sp: unifyDiceRolls(parseGenericProp(text, ['BES','SP']))
};
return monsterStat.name && monsterStat;
}
function parseMonsterStats(text) {
const parts = text.split(/\.\s*\n/);
return parts.filter(p => !!p.trim()).map(p => parseSingleMonsterStat(p + '.')).filter(ms => !!ms);
}
function multiplyCards(monsterStats, settings) {
const result = [];
for (const monsterStat of monsterStats) {
const number = monsterStat.number;
if (number) {
let num;
if (number.match(/^\d+$/)) {
// plain number
num = number;
} else {
// dice roll?
const match = number.match(/^(?<numDice>\d+)?W(?<diceType>\d+)$/);
if (match) {
const numDice = match.groups['numDice'] || 1;
const diceType = match.groups['diceType'];
if (settings.randomMonsterCount) {
const diceRoll = Math.floor(Math.random() * diceType) + 1;
num = numDice * diceRoll;
console.debug('Random number of ', monsterStat.name, ' (', number, '): ', numDice, 'x', diceRoll, '=', num);
} else {
num = numDice * diceType;
}
}
}
if (num) {
if (settings.maxNumberOfCopies) {
num = Math.min(num, settings.maxNumberOfCopies);
}
for (let i = 0; i < num; i++) {
let s;
if (settings.randomMonsterCount) {
s = `#${i+1} / ${num} (${number})`
} else {
s = `#${i+1} / ${number}`;
}
const copy = {...monsterStat, number: s}
result.push(copy);
}
continue;
}
}
result.push(monsterStat);
}
return result;
}
function renderCards(monsterStats, settings) {
if (settings.multiplyCards) {
monsterStats = multiplyCards(monsterStats, settings);
}
return allCardsTemplate({monsterStats: monsterStats, settings: settings});
}
function createCards() {
console.log("Creating cards...");
const inputText = textAreaElement.value;
const multiplyCards = multiplyCardsCheckbox.checked;
const randomMonsterCount = randomMonsterCountCheckbox.checked;
const maxNumberOfCopies = maxCardsPerMonsterInputField.value;
const drawBorder = !!drawBorderCheckbox.checked;
const lang = langRadioDe.checked ? 'de' : 'en';
const labels = LABELS[lang];
const monsterStats = parseMonsterStats(inputText);
document.querySelector('#output').innerHTML = renderCards(monsterStats, {
multiplyCards,
maxNumberOfCopies,
randomMonsterCount,
drawBorder,
lang,
labels
});
console.log("...finished");
}
function clearInputText() {
document.querySelector('#input-text').value = '';
}
function onMultipleCardsOptionChanged() {
const multiplyCardsChecked = document.querySelector('#multiply-cards').checked;
if (multiplyCardsChecked) {
randomMonsterCountCheckbox.disabled = false;
maxCardsPerMonsterInputField.disabled = false;
} else {
randomMonsterCountCheckbox.disabled = true;
maxCardsPerMonsterInputField.disabled = true;
}
}
function pasteSampleStats() {
document.querySelector('#input-text').value =
'... THE PORTAL UNDER THE STARS ...\n\n' +
'Ssisssuraaaaggg, the immortal demon- snake: Init +0; Atk bite +6 melee; Dmg 1d8; AC 13; HP 20; MV 20’; Act 1d20; SV Fort +8, Ref +4, Will +4; AL L.\n\n' +
'Pile of living bones (7): Init -2; Atk bite +0 melee; Dmg 1d4-1; AC 8; HP 2; MV 5’; Act 1d20; SV Fort +0, Ref -4, Will +1; AL C.\n\n' +
'\n\n' +
'... DAS PORTAL UNTER DEN STERNEN ... \n\n' +
'Kristallstatue (6): INI -2; A Schlag +2 nah (1W4); RK 12; TP 8; BW 3 m; AW 1W20; RW ZÄH -2, REF -2, WIL +0; G N.\n\n' +
'\n\n' +
'... One more ... \n\n' +
'Aua-Monster (2W3): INI +5; A Klaue +7 nah (5W8); RK 23; TP 33; BW fliegen 12 m; AW 3W20; RW ZÄH +1, REF +2, WIL +3; G C.\n\n' +
'\n\n' +
'\n\n' +
'DCC RPG, copyright 2012 Goodman Games, System Matters Verlag. All rights reserved.';
}
</script>
<div class="output-template">
<script id="all-cards-template" type='text/x-handlebars'>
{{#each monsterStats as |monsterStat|}}
{{> cardPartial settings=../settings monster=monsterStat }}
{{/each}}
</script>
</div>
<div class="output-template">
<script id="single-card-template" type='text/x-handlebars'>
<div class="card {{#if settings.drawBorder}}border-yes{{else}}border-no{{/if}}">
<div id="name"><span class="monster-name">{{monster.name}}</span>
{{#if monster.number}}
<span class="monster-number">[{{monster.number}}]</span>
{{else}}
{{#if monster.info}}
<span class="monster-info">({{monster.info}})</span>
{{/if}}
{{/if}}
</div>
<div class="iniaw prop">
<div class="ini label">{{settings.labels.INI}}</div>
<div class="ini value">{{monster.ini}}</div>
<div class="aw label ml">{{settings.labels.AW}}</div>
<div class="aw value">{{translateDice monster.aw settings.lang}}</div>
</div>
<div class="a prop">
<div class="a label">{{settings.labels.A}}</div>
<div class="a value">{{translateDice monster.a settings.lang}}
{{#if monster.dmg}}
({{translateDice monster.dmg settings.lang}})
{{/if}}
</div>
</div>
<div class="rktp prop">
<div class="rk label">{{settings.labels.RK}}</div>
<div class="rk value">{{monster.rk}}</div>
<div class="tp label ml">{{settings.labels.TP}}</div>
<div class="tp value">{{monster.tp}}
{{#if monster.tw}}
({{translateDice monster.tw settings.lang}})
{{/if}}
</div>
</div>
<div class="bw prop">
<div class="bw label">{{settings.labels.BW}}</div>
<div class="bw value">{{monster.bw}}</div>
</div>
<div class="rw prop">
<div class="rw label">{{settings.labels.RW}} {{settings.labels.ZAH}}</div>
<div class="rw value">{{monster.rw_zaeh}}</div>
<div class="rw label ml">{{settings.labels.REF}}</div>
<div class="rw value">{{monster.rw_ref}}</div>
<div class="rw label ml">{{settings.labels.WIL}}</div>
<div class="rw value">{{monster.rw_wil}}</div>
</div>
<div class="g prop">
<div class="g label">{{settings.labels.G}}</div>
<div class="g value">{{lookup settings.labels monster.gesinnung}}</div>
</div>
{{#if monster.sp}}
<div class="sp prop">
<div class="sp label">{{settings.labels.BES}}</div>
<div class="sp value">{{translateDice monster.sp settings.lang}}</div>
</div>
{{/if}}
</div>
</script>
</div>
</body>
</html>