-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
288 lines (250 loc) · 9.92 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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2E561F2422"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-2E561F2422');
</script>
<!--
************************************************
The script above is for google analytics.
You'll want to remove that if you use this page.
************************************************
-->
<title>BotC Random Generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="data/townsfolk.js"></script>
<script src="data/outsider.js"></script>
<script src="data/minion.js"></script>
<script src="data/demon.js"></script>
<script src="data/script_adjective.js"></script>
<script src="data/script_noun.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rubik&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@400;500&display=swap">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Blood on the Clocktower:<br>Random Generator</h1>
<p>
<input id="createTownsfolk" type="button" value="Townsfolk" onclick="createCharacter('Townsfolk')">
<input id="createOutsider" type="button" value="Outsider" onclick="createCharacter('Outsider')">
<input id="createMinion" type="button" value="Minion" onclick="createCharacter('Minion')">
<input id="createDemon" type="button" value="Demon" onclick="createCharacter('Demon')">
<span id="diamond">◆</span>
<input id="createScript" type="button" value="Script" onclick="createScript()">
</p>
<div id="content">
<p id="name"></p>
<p id="description"></p>
</div>
<div id="script">
</div>
<p id="copyCharacter"><input type="button" value="Copy" onclick="copyCharacter()"></p>
<p id="copyScript"><input type="button" value="Reorder & Copy" onclick="copyScript()"></p>
<p id="footer">
Data by <a href="https://www.reddit.com/user/DrewHancock">Drew</a>.
<a href="https://github.com/Robson/BotC-Generator">Code</a> by <a href="https://robson.plus">Robson</a>.
<br>
Not affiliated with or endorsed by The Pandemonium Institute.
</p>
<script>
var character = '';
var fullScript = [];
var scriptName = '';
var version = 0;
d3.select('#content').style('display', 'none');
d3.select('#copyCharacter').style('display', 'none');
d3.select('#copyScript').style('display', 'none');
d3.select('#script').style('display', 'none');
d3.select('#footer').style('display', 'none');
scriptAdjectives = scriptAdjectives.trim().split('\n');
scriptNouns = scriptNouns.trim().split('\n');
function randomItemFromArray(arr) {
return arr[~~(Math.random() * arr.length)];
}
function getLibraryForRole(role) {
switch (role.toLowerCase()) {
case 'townsfolk': return townsfolk;
case 'outsider': return outsider;
case 'minion': return minion;
case 'demon': return demon;
}
}
function createCharacter(role) {
var library = getLibraryForRole(role);
var name = createName(library);
var description = resolveRandomText(createDescription(library));
character = name + ': ' + simplifyDescription(description);
d3.select('#name').html(name);
d3.select('#description').html(description);
d3.select('#content').style('display', null);
d3.select('#script').style('display', 'none');
d3.select('#copyCharacter').style('display', null);
d3.select('#copyScript').style('display', 'none');
d3.select('#footer').style('display', null);
d3.selectAll('input').classed('selected', false);
d3.select('#create' + role).classed('selected', true);
}
function createName(library) {
var name = randomItemFromArray(library.adjective) + ' ' + randomItemFromArray(library.noun);
name = name.replace('- ', '-');
return name;
}
function createDescription(library) {
var description = randomItemFromArray(library.frequency) + '<br/>';
var style = randomItemFromArray(library.styles);
for (var item of style) {
description += randomItemFromArray(item) + '<br/>';
}
if (library.hasOwnProperty('extraChance') &&
library.hasOwnProperty('extraEffects')) {
if (Math.random() <= library.extraChance) {
description += randomItemFromArray(library.extraEffects);
}
}
return description;
}
function simplifyDescription(description) {
while (description.includes('<br/>')) {
description = description.replace('<br/>', ' ');
}
return description;
}
function copyCharacter() {
navigator.clipboard.writeText(character);
alert('Character copied to the clipboard!');
return;
}
function createScript() {
d3.select('#content').style('display', 'none');
d3.select('#script').style('display', null);
d3.select('#copyCharacter').style('display', 'none');
d3.select('#copyScript').style('display', null);
d3.select('#footer').style('display', null);
d3.selectAll('input').classed('selected', false);
d3.select('#createScript').classed('selected', true);
version = 0;
makeRandomScriptName();
fullScript = [];
addRowsForRole(13, 'Townsfolk', 'Townsfolk');
addRowsForRole( 4, 'Outsider', 'Outsiders');
addRowsForRole( 4, 'Minion', 'Minions');
addRowsForRole( 4, 'Demon', 'Demons');
fullScript = fullScript.sort((a, b) => a.description > b.description);
fullScript = fullScript.sort((a, b) => a.role.length < b.role.length);
outputScript();
}
function makeRandomScriptName() {
var connections = [
'of',
'and',
'by',
'with'
];
var patterns = [
'The {adjective} {noun}',
'{noun} {connection} the {noun}',
'{noun} {connection} the {adjective} {noun}',
'{adjective} {noun} {connection} the {noun}'
];
var pattern = randomItemFromArray(patterns);
scriptName = pattern
.replace('{connection}', randomItemFromArray(connections))
.replace('{adjective}', randomItemFromArray(scriptAdjectives))
.replace('{adjective}', randomItemFromArray(scriptAdjectives))
.replace('{adjective}', randomItemFromArray(scriptAdjectives))
.replace('{noun}', randomItemFromArray(scriptNouns))
.replace('{noun}', randomItemFromArray(scriptNouns))
.replace('{noun}', randomItemFromArray(scriptNouns));
}
function hasDuplication(name, description, arr) {
return arr.some(a => a.name == name) || arr.some(a => a.description == description);
}
function createCharacterFromLibrary(library, existing) {
var name = '', description = '';
do {
name = createName(library);
description = resolveRandomText(simplifyDescription(createDescription(library)));
} while (hasDuplication(name, description, fullScript) || hasDuplication(name, description, existing));
return { name: name, description: description };
}
function resolveRandomText(text) {
while (text.includes('{') && text.includes('}')) {
var start = text.indexOf('{');
var end = text.indexOf('}');
var potentialItems = text.substr(start+1, (end-start)-1).split(';');
var chosenItem = randomItemFromArray(potentialItems);
text = text.substr(0, start) + chosenItem + text.substr(end+1, text.length);
}
return text;
}
function addRowsForRole(amount, role, title) {
var library = getLibraryForRole(role);
var chars = [];
for (var a = 0; a < amount; a++) {
chars.push(createCharacterFromLibrary(library, chars));
}
for (var char of chars) {
fullScript.push({ role: role, name: char.name, description: char.description });
}
}
function rerole(index) {
var library = getLibraryForRole(fullScript[index].role);
var next = createCharacterFromLibrary(library, []);
fullScript[index].name = next.name;
fullScript[index].description = next.description;
version++;
outputScript();
}
function outputScript() {
d3.selectAll('#script *').remove();
d3.select('#script').append('h2').html(scriptName).append('span').attr('id', 'version').html('v1.' + version);
var script = d3.select('#script').append('table');
var previousRole = '';
for (var index in fullScript) {
var line = fullScript[index];
if (line.role != previousRole) {
script
.append('tr')
.classed('header', true)
.append('td')
.attr('colspan', 3)
.html(line.role + (line.role == 'Townsfolk' ? '' : 's'));
previousRole = line.role;
}
var row = script.append('tr');
row.append('td').html("🎲").classed('dice', true).attr('onclick', 'rerole(' + index + ')').attr('title', 'Remove this character and create a new one.');
row.append('th').html(line.name);
row.append('td').html(line.description);
}
}
function copyScript() {
fullScript = fullScript.sort((a, b) => a.description > b.description);
fullScript = fullScript.sort((a, b) => a.role.length < b.role.length);
outputScript();
var output = '== ' + scriptName + ' v1.' + version + ' ==\r\n';
var previousRole = '';
for (var index in fullScript) {
var line = fullScript[index];
if (line.role != previousRole) {
output += '\r\n=== ' + line.role + (line.role == 'Townsfolk' ? '' : 's') + ' ===\r\n';
previousRole = line.role;
}
output += '*' + line.name + '*: ' + line.description + '\r\n';
}
navigator.clipboard.writeText(output);
alert('Script copied to the clipboard!');
return;
}
</script>
</body>
</html>