-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.html
507 lines (449 loc) · 13 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Map vote plugin configuration generator</title>
<style>
*
{
background-color: lightgray;
}
div#main
{
display: flex;
justify-content: space-around;
margin: auto;
}
div.pannel
{
border: black;
border-radius: 15px;
border-style: solid;
padding: 10px;
padding-bottom: 30px;
}
li.rule
{
border: 1px solid black;
border-radius: 10px;
padding: 5px;
margin: 2px;
}
ul.rules
{
margin: 5px;
padding: 2px;
overflow: clip;
overflow-y: scroll;
width: 82ch;
height: 100ch;
border: solid black;
}
ul.nomination_list
{
list-style-type: none;
padding: 2px;
margin-top: 2px;
margin-bottom: 2px;
width: 75ch;
min-height: 5ch;
border: solid black;
}
ul.border_list
{
list-style-type: none;
margin: 5px;
padding: 2px;
overflow: clip;
overflow-y: scroll;
width: 75ch;
height: 10ch;
border: solid black;
}
li.selected
{
background-color: cadetblue;
}
div#info
{
margin: 2%;
}
li.nomination
{
border: 1px solid black;
margin: 5px;
padding: 5px;
}
input.short_input
{
width: 10ch;
}
input.rule_input
{
width: 30ch;
}
.graph_container
{
overflow: hidden;
}
</style>
</head>
<body>
<div id="main">
<div id="left" class="pannel">
<div id="controls">
<button id="save">save</button>
<input type="file" id="load" accept=".json">
</div>
<div id="rules_pannel">
<h3>vote rules:</h3>
<button id="add_rule">add rule</button>
<ul id="rules_list" class="rules"></ul>
</div>
<div id="modes">
<h3>mode strings (case sensitive):</h3>
<ul id="modes_list" class="border_list"></ul>
<input type="text" id="mode_input">
<button id="add_mode">add</button>
<button id="remove_mode">remove</button>
</div>
<div id="addons">
<h3>addon layer strings:</h3>
(not currently implemented)
<ul id="addons_list"></ul>
<input type="text">
<button>add</button>
<button>remove</button>
</div>
<div id="blacklist">
<h3>mode repeat blacklist strings (case sensitive):</h3>
<ul id="blacklist_list" class="border_list"></ul>
<input type="text" id="blacklist_input">
<button id="add_blacklist">add</button>
<button id="remove_blacklist">remove</button>
</div>
</div>
<div id="info">
<button onclick="render_graph()">render graph</button>
<div class="pannel" style="width: 95%;">
<div id="graph_container" class="graph_container"></div>
</div>
<h3>info:</h3>
tool by maskedmonkyman <br>
<h4>warning:</h4>
<p>
this tool is a thin wrapper around
the Squad JS pluggin config schemea. This tool
does <b>NO INPUT VALIDATION</b> and is just a graphical utility.
It is very possible to create broken configs using
this tool. Be sure to check your inputs.
</p>
<h4>notes:</h4>
<ol>
<li>
be sure to always have a "defualt" vote rule.
</li>
<li>
the Any option for modes, will select modes from the
mode strings section so be sure to fill it out.
</li>
<li>
The plugin looks for maps from specific to general so if the
current layer is Yehorivka_RAAS_v1 then the plugin will look for rules: <br>
Yehorivka_RAAS_v1 <br>
Yehorivka_RAAS <br>
Yehorivka <br>
defualt <br>
then load from the first one it finds
</li>
</ol>
</p>
</div>
</div>
<script src="configTool/viz.js"></script>
<script src="configTool/full.render.js"></script>
<script src="configTool/svg-pan-zoom.min.js" type="text/javascript" charset="utf-8"></script>
<script>
"use strict";
//TODO addon layers
const save_button = document.getElementById("save");
const load_button = document.getElementById("load");
//rules
const add_rule_button = document.getElementById("add_rule");
const remove_rule_button = document.getElementById("remove_rule");
const rules_list = document.getElementById("rules_list");
let selected_rule = null;
//mode
const add_mode_button = document.getElementById("add_mode");
const remove_mode_button = document.getElementById("remove_mode");
const mode_input = document.getElementById("mode_input");
const modes_list = document.getElementById("modes_list");
//blacklist
const add_blacklist_button = document.getElementById("add_blacklist");
const remove_blacklist_button = document.getElementById("remove_blacklist");
const blacklist_input = document.getElementById("blacklist_input");
const blacklist_list = document.getElementById("blacklist_list");
let selected_mode = null;
let selected_blacklist_item = null;
let svg_element = null;
function fetch_layer_strings()
{
const wiki_url = "https://raw.githubusercontent.com/Squad-Wiki-Editorial/squad-wiki-pipeline-map-data/master/completed_output/_Current%20Version/finished.json";
let layer_strings = [];
fetch(wiki_url).then(response=>response.json()).then(function(response){
for(const layer of response.Maps)
layer_strings.push(layer.rawName);
});
return layer_strings;
}
function render_graph()
{
const graph = build_graph_string(build_vote_rules());
//let layer_strings = fetch_layer_strings();
var viz = new Viz();
if (svg_element)
svg_element.parentNode.removeChild(svg_element);
viz.renderSVGElement(graph, {"engine" : "circo"})
.then(function(element) {
svg_element = element;
//set svg to the size of it's container
svg_element.setAttribute("width", "100%");
//remove height initially to auto scale
svg_element.removeAttribute("height");
document.getElementById("graph_container").appendChild(svg_element);
let panZoom = svgPanZoom(svg_element, {
zoomEnabled: true,
controlIconsEnabled: true,
fit: false,
center: true
});
//hacky work around for pan zoom so it scale properly
svg_element.setAttribute("height", `${panZoom.getSizes().height}px`)
})
.catch(error => {
// Create a new Viz instance (@see Caveats page for more info)
viz = new Viz();
// Possibly display the error
console.error(error);
});
}
function build_graph_string(vote_rules)
{
let graph = "digraph G \n";
graph += "\{";
let rules = vote_rules.rules;
for(const rule in rules)
{
const nomination = rules[rule];
for (const layer of nomination)
{
graph += `${rule} -> ${layer.map}\n`;
}
}
graph += "\}";
return graph;
}
function build_vote_rules()
{
let vote_rules = {
"modes": [],
"rules": {},
"addon_map_layer_strings": [],
"mode_repeat_blacklist": []
};
for (let mode of modes_list.children)
{
vote_rules.modes.push(mode.innerHTML.trim());
}
for (let blacklist_item of blacklist_list.children)
{
vote_rules.mode_repeat_blacklist.push(blacklist_item.innerHTML.trim());
}
for (let rule_element of rules_list.children)
{
let rule = {
"name": rule_element.rule_string_input.value,
"nominations": []
};
for (let nomination of rule_element.nomination_list.children)
{
rule.nominations.push({
"map": nomination.map_input.value.trim(),
"modes": nomination.mode_input.value.trim().split(',').map(e => e.trim()),
"versions": nomination.verison_input.value.trim().split(',').map(e => e.trim())
});
}
vote_rules.rules[rule.name] = rule.nominations;
}
return vote_rules;
}
add_blacklist_button.onclick = ()=>{
if (blacklist_input.value == "")
return;
add_blacklist_item(blacklist_input.value);
};
add_rule_button.onclick = ()=>{
let rule = build_rule_element();
rules_list.appendChild(rule);
};
add_mode_button.onclick = () => {
if (mode_input.value == "")
return;
add_mode(mode_input.value);
};
function add_mode(mode_string)
{
let mode = document.createElement("li");
mode.innerHTML = mode_string;
modes_list.appendChild(mode);
mode.onclick = () => {
if (selected_mode)
{
selected_mode.classList.remove("selected");
}
selected_mode = mode;
selected_mode.classList.add("selected");
};
}
function add_blacklist_item(blacklist_string)
{
let blacklist_item = document.createElement("li");
blacklist_item.innerHTML = blacklist_string;
blacklist_list.appendChild(blacklist_item);
blacklist_item.onclick = () => {
if (selected_blacklist_item)
{
selected_blacklist_item.classList.remove("selected");
}
selected_blacklist_item = blacklist_item;
selected_blacklist_item.classList.add("selected");
};
}
remove_blacklist_button.onclick = () => {
if (selected_blacklist_item)
{
selected_blacklist_item.parentNode.removeChild(selected_blacklist_item);
selected_blacklist_item = null;
}
};
remove_mode_button.onclick = () => {
if (selected_mode)
{
selected_mode.parentNode.removeChild(selected_mode);
selected_mode = null;
}
};
save_button.onclick = () => {
let vote_rules = build_vote_rules();
var a = document.createElement("a");
a.href = window.URL.createObjectURL(new Blob([JSON.stringify(vote_rules)], {type: "text/plain"}));
a.download = "vote_rules.json";
a.click();
};
load_button.onchange = () => {
let reader = new FileReader();
rules_list.innerHTML = "";
modes_list.innerHTML = "";
reader.addEventListener("load", (event) => {
let vote_rules = JSON.parse(event.target.result);
for (let mode of vote_rules.modes)
add_mode(mode);
for (let blacklist_item of vote_rules.mode_repeat_blacklist)
add_blacklist_item(blacklist_item);
let rules = Object.keys(vote_rules.rules).sort();
for (let rule of rules)
{
let rule_element = build_rule_element();
rule_element.rule_string_input.value = rule;
rules_list.appendChild(rule_element);
for(let nomination of vote_rules.rules[rule])
{
let nomination_element = build_nomination_element(nomination.map, nomination.modes, nomination.versions);
rule_element.nomination_list.appendChild(nomination_element);
}
}
});
reader.readAsText(load_button.files[0]);
};
function build_rule_element()
{
let rule = document.createElement("li");
rule.classList.add("rule");
let label = document.createElement("label");
label.innerHTML = "Rule string: ";
let input = document.createElement("input");
input.setAttribute("type", "text");
input.classList.add("rule_input");
label.appendChild(input);
rule.appendChild(label);
rule["rule_string_input"] = input;
let add_nomination_button = document.createElement("button");
add_nomination_button.innerHTML = "add nomination";
rule.appendChild(add_nomination_button);
let nominations_list = document.createElement("ul");
nominations_list.classList.add("nomination_list");
rule.appendChild(nominations_list);
rule["nomination_list"] = nominations_list;
let delete_button = document.createElement("button");
delete_button.innerHTML = "delete";
rule.appendChild(delete_button);
add_nomination_button.onclick = () => {
nominations_list.appendChild(build_nomination_element());
};
delete_button.onclick = () => {
rule.parentNode.removeChild(rule);
}
return rule;
}
function build_nomination_element(map_string = "", mode_string = "Any", version_string = "Any")
{
let nomination = document.createElement("li");
nomination.classList.add("nomination");
//map field
let map_label = document.createElement("label");
map_label.innerHTML = "Map:";
nomination.appendChild(map_label);
let map_input = document.createElement("input");
map_input.setAttribute("type", "text");
map_input.value = map_string;
map_label.appendChild(map_input);
nomination["map_input"] = map_input;
//mode field
let mode_label = document.createElement("label");
mode_label.innerHTML = "Mode(s):";
nomination.appendChild(mode_label);
let mode_input = document.createElement("input");
mode_input.setAttribute("type", "text");
mode_input.classList.add("short_input");
mode_input.value = mode_string;
mode_label.appendChild(mode_input);
nomination["mode_input"] = mode_input;
//version feild
let version = document.createElement("label");
version.innerHTML = "Version(s):";
nomination.appendChild(version);
let verison_input = document.createElement("input");
verison_input.setAttribute("type", "text");
verison_input.classList.add("short_input");
verison_input.value = version_string;
version.appendChild(verison_input);
nomination["verison_input"] = verison_input;
//delete button
let delete_button = document.createElement("button");
delete_button.innerHTML = "delete";
delete_button.onclick = () => {
nomination.parentNode.removeChild(nomination);
};
nomination.appendChild(delete_button);
return nomination;
}
function main()
{
console.log("hello world");
}
document.addEventListener("DOMContentLoaded", main);
</script>
</body>
</html>