-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.html
638 lines (587 loc) · 31.6 KB
/
debug.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
<!doctype html>
<html lang="en">
<head>
<title>Factini</title>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, user-scalable=no">-->
</head>
<body>
<h1>Factini</h1>
<script src="config.md.js" charset="UTF-8"></script>
<script src="config.assets.md.js" charset="UTF-8"></script>
<script src="config.belts.md.js" charset="UTF-8"></script>
<script src="sprites.md.js" charset="UTF-8"></script>
<script src="quests/bucket_quest.md.js" charset="UTF-8"></script>
<script src="map.md.js" charset="UTF-8"></script>
<script src="options.md.js" charset="UTF-8"></script>
<script src="examples.md.js" charset="UTF-8"></script>
<script>
var queuedAction = '';
var queuedPaste = '';
// Exports
function getPage() { return 'debug.html'; }
function getGameConfig() { return $game_config.value; /*GAME_CONFIG*/ }
function getGameMap() { return $game_map.value /*GAME_MAP*/; }
function getGameOptions() {
console.log('[js] getGameOptions()');
//console.log('[js] getGameOptions(): going to send it this:\n', $game_options.value);
return $game_options.value /*GAME_OPTIONS*/;
}
function setGameOptions(optionStr, onLoad) {
// Note: onLoad is first time Rust passes the options to the UI and again when map is loaded. It is NOT the initial options.md.js fetch, which happens first.
console.log('[js] setGameOptions(', GAME_OPTIONS === optionStr ? 'from options.md.js' : 'from arg', ', onLoad =',onLoad,')');
$game_options.value = optionStr;
$option_bools.innerHTML = '';
let loadMessage = [];
optionStr.trim().split('\n').forEach(s => {
const line = s.trim()[0] === '-' ? s.trim().slice(1) : s.trim();
const [keyy, ...valueParts] = line.split(':');
const key = keyy.trim();
const value = valueParts.join(':').trim();
if (key === 'options_started_from_source') {
if (value === '0') {
loadMessage.push('Options: default');
} else {
loadMessage.push('Options from localStorage: ' + value + ' bytes');
}
}
else if (key === 'initial_map_from_source') {
if (value === '0') {
loadMessage.push('Progress: not found');
} else {
loadMessage.push('Progress from localStorage: ' + value + ' bytes');
}
}
else if (value === 'true' || value === 'false') {
const e = $option_bools.appendChild(document.createElement('label'));
e.className = 'option-label';
const s = e.appendChild(document.createElement('span'));
s.innerHTML = '<span style="color: #ccc;">options.</span>' + key;
const i = e.appendChild(document.createElement('input'));
i.type = 'checkbox';
i.checked = value === 'true';
i.onclick = () => {
console.log('[js] Toggling option', [key], 'to', [!!i.checked]);
$game_options.value = $game_options.value.replace(new RegExp(`- ${key}: (?:true|false)`), `- ${key}: ${Boolean(i.checked)}`);
queuedAction = 'apply_options';
console.log('[js] Stored new options into localStorage');
window.localStorage.setItem('factini.options', $game_options.value);
};
}
});
if (loadMessage.length) $warnings.innerHTML = loadMessage.join('<br/>');
}
function getExamples() { return GAME_EXAMPLES; }
function getAction() { let x = queuedAction; queuedAction = ''; return x; }
function receiveConfigNode(name, pairs) {
//console.log('[js] receiveConfigNode:', name, '->', pairs);
const nodeKinds = new Set;
const nodes = new Map;
pairs.forEach(([key, value], i) => {
switch (key) {
case "kinds": {
value.forEach(name => nodeKinds.add(name));
break;
}
case "nodes": {
console.log('[js] raw nodes:', value);
value.forEach(([raw_name, pairs], j) => {
const node = pairs.reduce((node, [prop, value]) => { node[prop] = value; return node; }, {});
node.parents = [];
node.children = [];
if (node.sprite_config) {
node.sprite_config = node.sprite_config.map(pairs => {
return pairs.reduce((node, [prop, value]) => { node[prop] = value; return node; }, {});
});
}
nodes.set(raw_name, node);
});
break;
}
}
});
nodes.forEach(node => {
if (node.kind === 'Quest') {
node.unlocks_after_by_name.forEach(parentRawName => {
const parent = nodes.get(parentRawName);
node.parents.push(parent.raw_name);
parent.children.push(node.raw_name);
});
}
});
console.log('[js] nodeKinds -->', nodeKinds);
console.log('[js] nodes -->', nodes);
//nodes.forEach(node => {
// if (node.kind === 'Quest') {
// console.log('[js] Quest', node.raw_name, '->', node);
// }
//});
//nodes.forEach(node => {
// if (node.kind === 'Belt') {
// console.log('[js] Belt', node.raw_name, '->', node);
// }
//});
function updateKinds() {
const titles = [];
$config_node_titles.length = 0;
nodeKinds.forEach((name) => {
const option = document.createElement('option');
option.innerText = name;
option.value = name;
titles.push(option);
});
titles.sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
titles.forEach(option => $config_node_titles.appendChild(option));
updateNodes();
}
$config_node_titles.onchange = $config_node_titles.onupdate = updateNodes;
function updateNodes() {
const current = $config_node_titles.children[$config_node_titles.selectedIndex].value;
const cnodes = [];
$config_node_list.length = 0;
nodes.forEach((node, name) => {
if (node.kind === current) {
const option = document.createElement('option');
option.innerText = name;
option.value = name;
cnodes.push(option);
}
});
cnodes.sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
cnodes.forEach(option => $config_node_list.appendChild(option));
showNode();
}
$config_node_list.onchange = $config_node_list.onupdate = showNode;
function showSpritePropField(prop, value) {
document.getElementById('$config_node_' + prop).innerText = value;
document.getElementById('$p_config_node_' + prop).style.display = 'block';
}
function hideSpritePropField(prop) {
document.getElementById('$p_config_node_' + prop).style.display = 'none';
}
function showNode() {
const rawName = $config_node_list.children[$config_node_list.selectedIndex].value;
const node = nodes.get(rawName);
$config_node_index.innerText = node.index;
$config_node_kind.innerText = node.kind;
$config_node_name.innerText = node.name;
$config_node_raw_name.innerText = node.raw_name;
$config_node_frame_offset.innerText = node.frame_offset;
$config_node_frame_delay.innerText = node.frame_delay;
$config_node_frame_looping.innerText = node.looping;
$config_node_loop_delay.innerText = node.loop_delay;
$config_node_loop_backwards.innerText = node.loop_backwards;
$sprite_preview.innerHTML = '(no sprite)';
function showSprite() {
console.log('[js] sprite:', node);
const sprite = node.sprite_config[0] || node;
hideSpritePropField('icon', node.icon);
showSpritePropField('file', sprite.file);
showSpritePropField('file_canvas_cache_index', sprite.file_canvas_cache_index);
showSpritePropField('x', sprite.x);
showSpritePropField('y', sprite.y);
showSpritePropField('w', sprite.w);
showSpritePropField('h', sprite.h);
const tile = createSprite(0);
$sprite_preview.innerHTML = '';
$sprite_preview.appendChild(tile);
}
switch (node.kind) {
case 'Part':
hideSpritePropField('unlocks_after_by_name');
hideSpritePropField('unlocks_after_by_index');
hideSpritePropField('unlocks_todo_by_index');
hideSpritePropField('starting_part_by_name');
hideSpritePropField('starting_part_by_index');
hideSpritePropField('production_target_by_name');
hideSpritePropField('production_target_by_index');
showSpritePropField('pattern_by_index', node.pattern_by_index.join(', '));
showSpritePropField('pattern_by_name', node.pattern_by_name.join(', '));
showSpritePropField('pattern_by_icon', node.pattern_by_icon.join(', '));
showSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds.join(', '));
showSprite();
break;
case 'Quest':
showSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
showSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
showSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
showSpritePropField('starting_part_by_name', node.starting_part_by_name);
showSpritePropField('starting_part_by_index', node.starting_part_by_index);
showSpritePropField('production_target_by_name', node.production_target_by_name);
showSpritePropField('production_target_by_index', node.production_target_by_index);
showSpritePropField('pattern_by_index', node.pattern_by_index);
showSpritePropField('pattern_by_name', node.pattern_by_name.join(', '));
showSpritePropField('pattern_by_icon', node.pattern_by_icon.join(', '));
showSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds.join(', '));
hideSpritePropField('icon');
hideSpritePropField('file');
hideSpritePropField('file_canvas_cache_index');
hideSpritePropField('x');
hideSpritePropField('y');
hideSpritePropField('w');
hideSpritePropField('h');
break;
case 'Supply':
hideSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
hideSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
hideSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
hideSpritePropField('starting_part_by_name', node.starting_part_by_name);
hideSpritePropField('starting_part_by_index', node.starting_part_by_index);
hideSpritePropField('production_target_by_name', node.production_target_by_name);
hideSpritePropField('production_target_by_index', node.production_target_by_index);
hideSpritePropField('pattern_by_index', node.pattern_by_index);
hideSpritePropField('pattern_by_name', node.pattern_by_name);
hideSpritePropField('pattern_by_icon', node.pattern_by_icon);
hideSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds);
showSprite();
break;
case 'Demand':
hideSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
hideSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
hideSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
hideSpritePropField('starting_part_by_name', node.starting_part_by_name);
hideSpritePropField('starting_part_by_index', node.starting_part_by_index);
hideSpritePropField('production_target_by_name', node.production_target_by_name);
hideSpritePropField('production_target_by_index', node.production_target_by_index);
hideSpritePropField('pattern_by_index', node.pattern_by_index);
hideSpritePropField('pattern_by_name', node.pattern_by_name);
hideSpritePropField('pattern_by_icon', node.pattern_by_icon);
hideSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds);
showSprite();
break;
case 'Dock':
hideSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
hideSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
hideSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
hideSpritePropField('starting_part_by_name', node.starting_part_by_name);
hideSpritePropField('starting_part_by_index', node.starting_part_by_index);
hideSpritePropField('production_target_by_name', node.production_target_by_name);
hideSpritePropField('production_target_by_index', node.production_target_by_index);
hideSpritePropField('pattern_by_index', node.pattern_by_index);
hideSpritePropField('pattern_by_name', node.pattern_by_name);
hideSpritePropField('pattern_by_icon', node.pattern_by_icon);
hideSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds);
showSprite();
break;
case 'Machine':
hideSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
hideSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
hideSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
hideSpritePropField('starting_part_by_name', node.starting_part_by_name);
hideSpritePropField('starting_part_by_index', node.starting_part_by_index);
hideSpritePropField('production_target_by_name', node.production_target_by_name);
hideSpritePropField('production_target_by_index', node.production_target_by_index);
hideSpritePropField('pattern_by_index', node.pattern_by_index);
hideSpritePropField('pattern_by_name', node.pattern_by_name);
hideSpritePropField('pattern_by_icon', node.pattern_by_icon);
hideSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds);
showSprite();
break;
case 'Belt':
hideSpritePropField('unlocks_after_by_name', node.unlocks_after_by_name);
hideSpritePropField('unlocks_after_by_index', node.unlocks_after_by_index);
hideSpritePropField('unlocks_todo_by_index', node.unlocks_todo_by_index);
hideSpritePropField('starting_part_by_name', node.starting_part_by_name);
hideSpritePropField('starting_part_by_index', node.starting_part_by_index);
hideSpritePropField('production_target_by_name', node.production_target_by_name);
hideSpritePropField('production_target_by_index', node.production_target_by_index);
hideSpritePropField('pattern_by_index', node.pattern_by_index);
hideSpritePropField('pattern_by_name', node.pattern_by_name);
hideSpritePropField('pattern_by_icon', node.pattern_by_icon);
hideSpritePropField('pattern_unique_kinds', node.pattern_unique_kinds);
showSprite();
break;
}
}
function createSprite(frameIndex) {
const rawName = $config_node_list.children[$config_node_list.selectedIndex].value;
const node = nodes.get(rawName);
const sprite = node.sprite_config[frameIndex];
const finalWidth = 64;
const finalHeight = 64;
const scalex = finalWidth / sprite.w;
const scaley = finalHeight / sprite.h;
// The outer gives a viewport on the inner, scaled, div. Cutting away the overflow.
const outer = document.createElement('div');
// The inner has the image as background with a zoom factor to scale the sprite
const inner = outer.appendChild(document.createElement('img'));
inner.src = sprite.file;
outer.style = `position: relative; width: ${finalWidth}px; height: ${finalHeight}px; overflow: hidden; float: right; border: 1px solid black;`;
inner.style = `position: absolute; left: -${Math.round(scalex * sprite.x)}px; top: -${Math.round(scaley * sprite.y)}px; transform: scale(${scalex}, ${scaley}); transform-origin: top left;`;
return outer;
}
function createNewDraggableTile() {
const tile = createSprite(0);
const wrapper = document.createElementById('div');
wrapper.appendChild(tile);
$sprite_preview.parentNode.insertBefore(wrapper, $sprite_preview);
return tile;
}
updateKinds();
{
// flowchart.fun syntax:
// [Quest_Start] Start; 10x_IngotWhite
// (Quest_Shield)
// (Quest_BlueBottle)
// (Quest_WhiteBook)
// [Quest_Shield] Shield; 10x_ShieldWood
// (Quest_BlueShield)
// [Quest_BlueBottle] BlueBottle; 10x_PotionBlue
// (Quest_BlueShield)
// (Quest_BlueBook)
// [Quest_BlueShield] BlueShield; 10x_ShieldBlue
// (Quest_BookShield)
// [Quest_WhiteBook] WhiteBook; 10x_BookWhite
// (Quest_BlueBook)
// [Quest_BlueBook] BlueBook; 10x_BookBlue
// (Quest_BookShield)
const arr = [];
nodes.forEach(node => {
if (node.kind === 'Quest') {
arr.push(`[${node.raw_name}] ${node.name}; ${node.production_target_by_name.map(([count, qname]) => `${count}x_${qname.split('_')[1]}`).join(' ')}`);
node.production_target_by_name.forEach(([count, name]) => {
node.children.forEach(childName => {
arr.push(`\t(${childName})`);
})
});
}
});
console.log('[js] uncomment next line to print the flowchart.fun code');
//console.log('[js] flowchart.fun code:\n' + arr.join('\n'));
}
updateMermaid(nodes);
nodes.forEach(node => {
if (node.kind !== 'Part') return;
// index: node_index,
// kind:
// name: name.to_string(),
// raw_name: rest.to_string(),
// unlocks_after_by_name: vec!(),
// unlocks_after_by_index: vec!(),
// unlocks_todo_by_index: vec!(),
// starting_part_by_name: vec!(),
// starting_part_by_index: vec!(),
// production_target_by_name: vec!(),
// production_target_by_index: vec!(),
// pattern_by_index: vec!(),
// pattern_by_name: vec!(),
// pattern_by_icon: vec!(),
// pattern_unique_kinds: vec!(),
// icon,
// file: "".to_string(),
// file_canvas_cache_index: 0,
// x: 0.0,
// y: 0.0,
// w: 0.0,
// h: 0.0,
const finalWidth = 64;
const finalHeight = 64;
const scalex = finalWidth / node.sprite_config[0]?.w;
const scaley = finalHeight / node.sprite_config[0]?.h;
// The outer gives a viewport on the inner, scaled, div. Cutting away the overflow.
const outer = $all_parts.appendChild(document.createElement('div'));
outer.title = `${node.raw_name}`;
// The inner has the image as background with a zoom factor to scale the sprite
const inner = outer.appendChild(document.createElement('img'));
inner.src = node.sprite_config[0]?.file;
outer.style = `position: relative; width: ${finalWidth}px; height: ${finalHeight}px; overflow: hidden; float: right; border: 1px solid black;`;
inner.style = `position: absolute; left: -${Math.round(scalex * node.sprite_config[0]?.x)}px; top: -${Math.round(scaley * node.sprite_config[0]?.y)}px; transform: scale(${scalex}, ${scaley}); transform-origin: top left;`;
});
}
function updateMermaid(nodes) {
// mermaid:
// graph TD;
// A-->B;
// A-->C;
// B-->D;
// C-->D;
// B[Line breaks <br />work in<br />decision nodes]
const arr = [
'graph LR'
];
nodes.forEach(node => {
if (node.kind === 'Quest') {
node.children.forEach(childName => {
arr.push(` ${node.raw_name}-->${childName};`);
});
arr.push(`
${node.raw_name}[<span id="$q_${node.raw_name}">
<b>${node.raw_name}</b><br/>
<small><b>Enables:</b></small><br/>
${node.starting_part_by_name.map((qname) => `<span style="cursor:help" title="Components:${nodes.get(qname).pattern_by_name.join(',')||'resource'}">${qname.split('_')[1]}</span>`).join(' <br/> ')}<br/>
<small><b>Targets:</b></small><br/>
${node.production_target_by_name.map(([count, qname]) => `${count}x ${qname.split('_')[1]}`).join(' <br/> ')}
</span>]
`.replace(/\n/g, ''));
}
});
console.log('[js] Note: the mermaid.live code is just text, uncomment to print');
//console.log('[js] mermaid.live code (may need to remove special descs):\n' + arr.join('\n'));
$mermaid.removeAttribute('data-processed'); // :facepalm: not obvious but ok. ht https://stackoverflow.com/questions/73056709/mermaid-in-react-turns-into-plaintext-when-re-rendered
$mermaid.innerHTML = arr.join('\n');
mermaid.init();
}
function onGameMapChange(map) {
$game_map.value = map;
}
function onQuestUpdate(pairs) {
//console.log('(JS) onQuestUpdate():', pairs);
pairs.forEach(([name, value]) => {
const e = document.getElementById(`$q_${name}`);
if (e) {
e.style.backgroundColor = value === 'Active' ? 'yellow' : value === 'Waiting' ? '' : 'lightgreen';
} else {
console.log('Warning: onQuestUpdate():', name, '->', value, 'could not find mermaid node');
}
});
}
function tryFullScreenFromJS() {
// Old browser workaround
// TODO: since this didn't fix it for my ipad, without errors thrown, perhaps we should try harder to manually make the canvas fit the screen instead...
if ($main_game_canvas.webkitRequestFullscreen) $main_game_canvas.webkitRequestFullscreen();
else if ($main_game_canvas.msRequestFullscreen) $main_game_canvas.msRequestFullscreen();
else if ($main_game_canvas .mozRequestFullscreen) $main_game_canvas.mozRequestFullscreen();
else return "failed too";
return "tried but may fail too"; // my ipad won't fullscreen the canvas regardless. Even when trying Sindre's "screenfull" lib.
}
function getLastPaste() {
// When you press ctrl+v the event handler will store the value you pasted and prepare an action for the game to be read it
// Then when the game reads the action it will call this function to retrieve the stored paste value
return queuedPaste || '';
}
function getCurrentPaste() {
// Called from Rust when clicking the "paste" button. Due to unstable api limitations I could not get this to work inside Rust
// so instead I'm just doing it from JS and sending the result back in once there is one. Bit a pingpong but whatever.
// This doesn't work in firefox rn, but it seems firefox only supports clipboard reading through extensions or the paste event.
// This will popup a permission dialog once
try {
navigator.clipboard.readText().then(
s => {
queuedPaste = s;
queuedAction = 'paste';
},
err => {
console.error('(js) getCurrentPaste: failed to navigator.clipboard.readText():', err);
queuedPaste = ''; // This will show the ctrl+v message
queuedAction = 'paste';
}
);
} catch {
console.log('(js) Browser does not support navigator.clipboard :shrug:');
queuedPaste = ''; // This will show the ctrl+v message
queuedAction = 'paste';
}
}
function copyToClipboard(str) {
try {
navigator
.clipboard
.writeText(str)
.then((ok) => console.log('(js) copyToClipboard ok:', ok), (err) => console.log('(js) copyToClipboard err:', err));
return true;
} catch (e) {
console.log('(js) copyToClipboard threw error:', e);
return false;
}
}
</script>
<script type="module">
Error.stackTraceLimit = Infinity;
console.log('(html) start');
import('../pkg/factini.js').then(x => {
console.log('(html) loaded, starting Factini now');
x.default();
}, (e) => console.error(e));
console.log('(html) after import');
window.addEventListener('paste', e => {
// Ironically, this works fine even in firefox. :shrug:
e.preventDefault();
console.log('(js) received paste event with', e.clipboardData?.items?.length, 'items');
e.clipboardData.items[0].getAsString(s => {
queuedPaste = s;
queuedAction = 'paste';
});
});
window.addEventListener('copy', e => {
// Ironically, this works fine even in firefox. :shrug:
e.preventDefault();
console.log('(js) received copy event');
queuedAction = 'copy';
});
</script>
<!-- for flow graphs of the quests -->
<div id="$main_game" style="float: left; clear: both; user-select: none;">padding</div>
<div style="float: right; clear: right; margin-top: 5px;">
Clear local:
<button onclick="window.localStorage.removeItem('factini.options'); $warnings.innerHTML = 'options cleared from localStorage<br/>';">options</button>
<button onclick="window.localStorage.removeItem('factini.lastMap'); $warnings.innerHTML = 'progress cleared from localStorage<br/>';">progress</button>
</div>
<div style="float: right; clear: right; margin-top: 5px;"><hr/>Options:</div>
<div id="$warnings" style="float: right; clear: right; color: red; cursor: pointer;"><br/><br/></div>
<div id="$option_bools"></div>
<style>
.option-label { float: right; clear: right; cursor: pointer; }
.option-label:hover { background-color: yellow; }
</style>
<textarea id="$game_options" style="float: right; clear: right; min-width: 50px; min-height: 50px; width: 300px; height: 100px; margin-top: 5px; margin-right: 5px;" autocomplete="off" spellcheck="false"></textarea>
<script>setGameOptions(GAME_OPTIONS);</script>
<button style="float: right; clear: right; margin-top: 5px; margin-right: 5px;" onclick="queuedAction = 'apply_options';">Apply options</button>
<textarea id="$game_map" style="float: right; clear: right; min-width: 50px; min-height: 50px; width: 400px; height: 300px; margin-top: 5px; margin-right: 5px;" autocomplete="off" spellcheck="false" onClick="this.select();"></textarea>
<script>$game_map.value = GAME_MAP.trim();</script>
<button style="float: right; clear: right; margin-top: 5px; margin-right: 5px;" onclick="queuedAction = 'load_map';">Set as map</button>
<div style="clear: both;">
<div><hr/>Config:</div>
<div>
<div>Quest Tree:</div>
<div style="float: right;">
<textarea id="$game_config" style="min-width: 50px; min-height: 50px; width: 400px; height: 100px; margin-top: 5px; margin-right: 5px;" autocomplete="off" spellcheck="false"></textarea>
<script>$game_config.value = (GAME_CONFIG_MD_DOCS + GAME_CONFIG_ASSETS + GAME_CONFIG_BELTS + CONFIG_BUCKET_QUEST + SPRITE_MAP).trim();</script>
<div id="$sprite_preview"></div>
<div style="margin-bottom: 15px;"><button style="margin-top: 5px; margin-right: 5px;" onclick="queuedAction = 'load_config';">Set as config</button></div>
<div id="$config_editor">
<div id="$config_node_kinds"></div>
<div><select id="$config_node_titles" style="margin-bottom: 5px;"></select></div>
<div><select id="$config_node_list" style="margin-bottom: 5px;"></select></div>
<div id="$config_node_editor" style="text-align: right;">
<style>
.key { font-weight: bold; font-size: 12px; margin: 0 5px 0 5px; }
.value { padding-left: 10px; }
</style>
<div id="$p_config_node_index" style="white-space: pre;"><span class="key">index:</span><span id="$config_node_index" class="value"></span></div>
<div id="$p_config_node_kind" style="white-space: pre;"><span class="key">kind:</span><span id="$config_node_kind" class="value"></span></div>
<div id="$p_config_node_name" style="white-space: pre;"><span class="key">name:</span><span id="$config_node_name" class="value"></span></div>
<div id="$p_config_node_raw_name" style="white-space: pre;"><span class="key">raw_name:</span><span id="$config_node_raw_name" class="value"></span></div>
<div id="$p_config_node_unlocks_after_by_name"><span class="key">unlocks_after_by_name:</span><span id="$config_node_unlocks_after_by_name" class="value"></span></div>
<div id="$p_config_node_unlocks_after_by_index" style="white-space: pre;"><span class="key">unlocks_after_by_index:</span><span id="$config_node_unlocks_after_by_index" class="value"></span></div>
<div id="$p_config_node_unlocks_todo_by_index" style="white-space: pre;"><span class="key">unlocks_todo_by_index:</span><span id="$config_node_unlocks_todo_by_index" class="value"></span></div>
<div id="$p_config_node_starting_part_by_name"><span class="key">starting_part_by_name:</span><span id="$config_node_starting_part_by_name" class="value"></span></div>
<div id="$p_config_node_starting_part_by_index" style="white-space: pre;"><span class="key">starting_part_by_index:</span><span id="$config_node_starting_part_by_index" class="value"></span></div>
<div id="$p_config_node_production_target_by_name"><span class="key">production_target_by_name:</span><span id="$config_node_production_target_by_name" class="value"></span></div>
<div id="$p_config_node_production_target_by_index" style="white-space: pre;"><span class="key">production_target_by_index:</span><span id="$config_node_production_target_by_index" class="value"></span></div>
<div id="$p_config_node_pattern_by_index" style="white-space: pre;"><span class="key">pattern_by_index:</span><span id="$config_node_pattern_by_index" class="value"></span></div>
<div id="$p_config_node_pattern_by_name"><span class="key">pattern_by_name:</span><span id="$config_node_pattern_by_name" class="value"></span></div>
<div id="$p_config_node_pattern_by_icon" style="white-space: pre;"><span class="key">pattern_by_icon:</span><span id="$config_node_pattern_by_icon" class="value"></span></div>
<div id="$p_config_node_pattern_unique_kinds" style="white-space: pre;"><span class="key">pattern_unique_kinds:</span><span id="$config_node_pattern_unique_kinds" class="value"></span></div>
<div id="$p_config_node_icon" style="white-space: pre;"><span class="key">icon:</span><span id="$config_node_icon" class="value"></span></div>
<div id="$p_config_node_file"><span class="key">file:</span><span id="$config_node_file" class="value"></span></div>
<div id="$p_config_node_file_canvas_cache_index" style="white-space: pre;"><span class="key">file_canvas_cache_index:</span><span id="$config_node_file_canvas_cache_index" class="value"></span></div>
<div id="$p_config_node_frame_offset" style="white-space: pre;"><span class="key">frame_offset:</span><span id="$config_node_frame_offset" class="value"></span></div>
<div id="$p_config_node_frame_delay" style="white-space: pre;"><span class="key">frame_delay:</span><span id="$config_node_frame_delay" class="value"></span></div>
<div id="$p_config_node_frame_looping" style="white-space: pre;"><span class="key">looping:</span><span id="$config_node_frame_looping" class="value"></span></div>
<div id="$p_config_node_loop_delay" style="white-space: pre;"><span class="key">loop delay:</span><span id="$config_node_loop_delay" class="value"></span></div>
<div id="$p_config_node_loop_backwards" style="white-space: pre;"><span class="key">loop backwards:</span><span id="$config_node_loop_backwards" class="value"></span></div>
<div id="$p_config_node_x" style="white-space: pre;"><span class="key">x:</span><span id="$config_node_x" class="value"></span></div>
<div id="$p_config_node_y" style="white-space: pre;"><span class="key">y:</span><span id="$config_node_y" class="value"></span></div>
<div id="$p_config_node_w" style="white-space: pre;"><span class="key">w:</span><span id="$config_node_w" class="value"></span></div>
<div id="$p_config_node_h" style="white-space: pre;"><span class="key">h:</span><span id="$config_node_h" class="value"></span></div>
</div>
</div>
</div>
<script src="./lib/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad: false});</script>
<div class="mermaid" id="$mermaid" style="white-space:pre;"></div>
</div>
</div>
<div style="clear: both;" id="$all_parts"></div>
</body>
</html>