This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromptrun.html
892 lines (793 loc) · 21.4 KB
/
promptrun.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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Adventure Prompt Runner</title>
<style>
body {
Font-family: serif;
Font-size: 14pt;
Color: black;
Background-color: tan;
Margin: 0;
Padding: 0;
}
h1, h2 { Font-family: sans-serif; }
.book {
Display: table;
Width: 100%;
Border-spacing: 1em;
}
.page-frame {
Display: table-cell;
Width: 50%;
Margin: 1em;
Padding: 1em;
Line-height: 1.5em;
/*Text-align: justify;*/
Background-color: white;
Box-shadow: 0.5ex 0.5ex 0.5ex saddlebrown;
}
#toolbar {
Padding: 1ex;
Text-align: right;
Color: white;
Background-color: black;
Font-weight: bold;
Font-family: sans-serif;
Font-size: 12pt;
}
#toolbar label { Float: left; Margin: 1ex; }
.page-content p { Text-indent: 3ex; }
.title-page p, .edition-notice p { Text-indent: 0; }
p.ending {
Text-indent: 0;
Text-align: center;
Font-weight: bold;
}
.title-page { Text-align: center; }
button {
Font-family: sans-serif;
Font-weight: bold;
Font-size: 12pt;
Color: white;
Background-color: saddlebrown;
Padding: 0.5ex 1em;
Margin: 0.5ex;
Border-radius: 1em;
/*Width: 6em;*/
}
button:disabled { Opacity: 0.5; }
.status-line, dt {
Background-color: black;
Color: white;
Font-weight: bold;
Font-family: monospace;
Font-size: 12pt;
Padding-left: 1ex;
Padding-right: 1ex;
}
dd { Margin-left: 1em; }
dd ul { padding-left: 1em; }
.status-line { Text-align: right; }
.status-line span { Text-indent: 0; }
</style>
</head>
<body role="document">
<div id="toolbar" role="toolbar">
<label>
Pick a story file from your computer:
<input type="file" id="local-file" accept="application/json">
</label>
<button type="button" id="save-button" disabled>save</button>
<!--<button type="button" id="wait-button" disabled>wait</button>-->
<!--<button type="button" id="undo-button" disabled>undo</button>-->
<button type="button" id="restart-button" disabled>restart</button>
</div>
<div class="book" role="main">
<div class="page-frame">
<div id="verso-page" class="page-content" aria-live="polite">
<div role="contentinfo">
<p>Welcome to Adventure Prompt 1.0b, from 6 April 2018, a system for making
and playing interactive fiction. This is the runner, or interpreter —
the half that lets you play story files. You should be able to get samples
from the same place where you found this. Look for files with the
<code>.json</code> extension.
<p>To create your own adventures, look for the tools that should be
available from the same source.
</div>
</div>
</div>
<div class="page-frame">
<div id="recto-page" class="page-content" aria-live="polite">
<div class="title-page">
<h1>Adventure Prompt</h1>
<p>an interactive fiction engine
<p>by
<p><b>Felix Pleşoianu</b>
</div>
</div>
</div>
</div>
<script>
var game_text = "{}";
var game_data = null;
var verso;
var recto;
var wait_button, undo_button, restart_button, save_button;
function say(page, content) {
if (typeof content === "string")
page.appendChild(document.createTextNode(content));
else
page.appendChild(content);
}
function tag(name, content) {
var t = document.createElement(name);
if (content !== undefined) {
if (typeof content === "string")
t.innerHTML = content;
else
t.appendChild(content);
}
return t;
}
function title_page(metadata) {
var page = tag("div");
page.className = "title-page";
say(page, tag("h1", metadata.title));
say(page, tag("p", metadata.subtitle));
say(page, tag("p", "by"));
say(page, tag("p", tag("b", metadata.author)));
var start = tag("button", "Turn the page");
start.type = "button";
start.addEventListener("click", start_game, false);
say(page, tag("p", start));
return page;
}
function edition_notice(metadata) {
var page = tag("div");
page.className = "edition-notice";
page.setAttribute("aria-role", "contentinfo");
say(page, tag("div", tag("b", metadata.title)));
say(page, tag("div", metadata.subtitle));
say(page, tag("p", metadata.author + "<br>" + metadata.date));
say(page, tag("p", metadata.genre));
say(page, tag("p", metadata.blurb));
say(page, tag("p", metadata.license));
say(page, tag("p", metadata.ifid));
say(page, tag("small", "Made with Adventure Prompt"));
return page;
}
function status_line() {
var line = tag("p");
line.className = "status-line";
line.setAttribute("role", "status");
if (game_data.config.use_score) {
var score = tag("span");
score.id = "score";
score.style.float = "left";
say(score, " Score: " + game_data.meta.score
+ "/" + (game_data.config.max_score || "?"));
say(line, score);
}
say(line, "Moves: " + game_data.meta.turns);
return line;
}
function refresh_view(verso_msg, recto_msg) {
verso.innerHTML = "";
say(verso, status_line());
if (verso_msg)
say(verso, verso_msg);
look();
recto.innerHTML = "";
if (recto_msg)
say(recto, recto_msg);
say(recto, carried_objects());
}
function carried_objects() {
var list = tag("dl");
say(list, tag("dt", game_data.objects.hero.name));
say(list, tag("dd", game_data.objects.hero.description));
var inventory = find_objects_in("hero");
var non_spells = filter_objects(inventory,
function (obj) { return obj.type !== "spell"; });
var spells = filter_objects(inventory,
function (obj) { return obj.type === "spell"; });
say(list, tag("dt", "You are carrying:"));
if (count_keys(non_spells) > 0)
say(list, tag("dd", object_list(non_spells)));
else
say(list, tag("dd", "Nothing."));
if (game_data.config.use_spells) {
say(list, tag("dt", "Spells you know:"));
if (count_keys(spells) > 0)
say(list, tag("dd", object_list(spells)));
else
say(list, tag("dd", "None yet."));
}
if (game_data.config.use_breakdown) {
say(list, tag("dt", "Score breakdown:"));
say(list, tag("dd", score_breakdown()));
}
return list;
}
// Avoid creating an discarding an array as with Object.keys(obj).length.
function count_keys(obj) {
var count = 0;
for (var i in obj) count++;
return count;
}
function filter_objects(group, filter) {
var kept = {};
for (var i in group)
if (filter(group[i]))
kept[i] = group[i];
return kept;
}
function score_breakdown() {
var list = tag("ul");
for (var i in game_data.objects) {
var obj = game_data.objects[i];
if (obj.score && obj.visited)
say(list, tag("li", explain_score(i, obj)));
}
return list;
}
function explain_score(obj_id, obj) {
switch (obj.type) {
case "room": return obj.score
+ " points for visiting "
+ obj.name;
case "exit": return obj.score
+ " points for going "
+ obj.name + " from "
+ game_data.objects[obj_id.location].name;
case "scenery": return obj.score
+ " points for entering the "
+ obj.name;
case "thing": return obj.score
+ " points for picking up the "
+ obj.name;
case "vehicle": return obj.score
+ " points for getting on the "
+ obj.name;
case "text": return obj.score
+ " points for reading the "
+ obj.name;
case "action": return obj.score
+ " points for getting to "
+ obj.name + " the "
+ game_data.objects[obj_id.location].name;
case "spell": return obj.score
+ " points for learning "
+ obj.name;
}
}
function room_here() {
var me = game_data.objects.hero;
var here = game_data.objects[me.location];
if (here.type === "vehicle")
return here.location;
else
return me.location;
}
function room_has_light(room_id) {
if (!game_data.objects[room_id].dark)
return true;
var obj = find_objects_in("hero");
for (var i in obj)
if (obj[i].light)
return true;
var obj = find_objects_in(room_id);
for (var i in obj)
if (obj[i].light)
return true;
return false;
}
function find_objects_in(loc) {
var found = {};
for (var i in game_data.objects) {
var obj = game_data.objects[i];
if (obj.location !== loc)
continue;
else if (obj.type === "exit" || obj.type === "action")
continue;
else
found[i] = obj;
}
return found;
}
function object_list(group) {
var list = tag("ul");
for (var i in group) {
var item = tag("li", group[i].name);
var actions = object_actions(i, group[i]);
for (var j in actions)
say(item, actions[j]);
say(list, item);
}
return list;
}
function object_actions(obj_id, obj) {
var list = [];
switch (obj.type) {
case "thing":
list.push(action_button(
"look", obj_id, handle_look_at));
if (obj.location === "hero")
list.push(action_button(
"drop", obj_id, handle_drop));
else
list.push(action_button(
"take", obj_id, handle_take));
break;
case "scenery":
list.push(action_button(
"look", obj_id, handle_look_at));
if (obj.link) {
list.push(exit_button(
"enter", obj_id, "hero"));
}
break;
case "vehicle":
list.push(action_button(
"look", obj_id, handle_look_at));
if (game_data.objects.hero.location === obj_id)
list.push(action_button(
"get off", obj_id, handle_get_off));
else
list.push(action_button(
"get on", obj_id, handle_get_on));
break;
case "text":
list.push(action_button(
"read", obj_id, handle_read));
break;
case "spell":
if (obj.location === "hero")
list.push(action_button(
"cast", obj_id, handle_cast));
else
list.push(action_button(
"learn", obj_id, handle_learn));
}
for (i in game_data.objects) {
var obj2 = game_data.objects[i];
if (obj2.location === obj_id && obj2.type === "action")
if (!obj2.dark)
list.push(action_button(
obj2.name, i, handle_action));
}
return list;
}
function action_button(label, obj_id, handler) {
var button = document.createElement("button");
button.type = "button";
button.setAttribute("data-target", obj_id);
button.innerHTML = label;
button.addEventListener("click", handler, false);
return button;
}
function exit_button(label, obj_id, actor_id) {
var button = action_button(label, obj_id, handle_exit);
button.setAttribute("data-actor", actor_id);
return button;
}
function handle_look_at() {
game_data.meta.turns++;
var obj_id = this.getAttribute("data-target");
if (room_has_light(room_here()))
refresh_view(null, object_description(obj_id));
else
refresh_view(null, "It's too dark to see much at all.");
}
function object_description(obj_id) {
var obj = game_data.objects[obj_id];
var desc = tag("div");
if (!obj.visited && obj.initial)
say(desc, tag("p", obj.initial));
else if (obj.description) {
say(desc, tag("p", obj.description));
} else {
say(desc, tag("p", "You see nothing special."));
}
var content = find_objects_in(obj_id);
var non_topics = filter_objects(content,
function (obj) { return obj.type !== "topic"; });
var topics = filter_objects(content,
function (obj) { return obj.type === "topic"; });
say(desc, object_list(non_topics));
if (count_keys(topics) > 0) {
say(desc, "Learn about: ");
for (var i in topics)
say(desc, action_button(
topics[i].name, i, handle_topic));
}
return desc;
}
function handle_take() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
if (pass_lock("hero", obj.lock)) {
score_object(obj_id);
obj.location = "hero";
obj.visited = true;
if (obj.success)
var msg = tag("p", obj.success);
else
var msg = tag("p", "Taken.");
} else if (obj.failure) {
var msg = tag("p", obj.failure);
} else {
var msg = tag("p", "You can't seem to pick that up.");
}
game_data.meta.turns++;
refresh_view(null, msg);
}
function handle_drop() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
var room_id = game_data.objects.hero.location;
var here = game_data.objects[room_id];
if (obj.sticky) {
if (obj.nodrop)
var msg = tag("p", obj.nodrop);
else
var msg = tag("p",
"You try to drop that, but can't seem to.");
} else if (here.sticky) {
if (here.nodrop)
var msg = tag("p", here.nodrop);
else
var msg = tag("p",
"You try to drop that, but can't seem to.");
} else {
if (here.link)
obj.location = here.link;
else
obj.location = room_id;
if (obj.drop)
var msg = tag("p", obj.drop);
else
var msg = tag("p", "Dropped.");
if (here.drop)
say(msg, " " + here.drop);
}
game_data.meta.turns++;
refresh_view(null, msg);
}
function handle_get_on() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
if (pass_lock("hero", obj.lock)) {
score_object(obj_id);
game_data.objects.hero.location = obj_id;
obj.visited = true;
if (obj.success)
var msg = tag("p", obj.success);
else
var msg = tag("p",
"You get on the " + obj.name + ".");
} else if (obj.failure) {
var msg = tag("p", obj.failure);
} else {
var msg = tag("p",
"You can't seem to get on the " + obj.name + ".");
}
game_data.meta.turns++;
refresh_view(null, msg);
}
function handle_get_off() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
game_data.objects.hero.location = obj.location;
game_data.meta.turns++;
refresh_view(null, tag("p", "You get off the " + obj.name + "."));
}
function handle_read() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
game_data.meta.turns++;
if (room_has_light(room_here())) {
score_object(obj_id);
obj.visited = true;
if (obj.link)
game_data.objects[obj.link].dark = false;
var msg = tag("div", tag("p", obj.description));
say(msg, success_message(obj));
} else {
var msg = tag("p", "It's too dark in here to read.");
}
refresh_view(null, msg);
if (obj.ending)
end_game();
}
function handle_action() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
game_data.meta.turns++;
if (pass_lock("hero", obj.lock)) {
score_object(obj_id);
obj.visited = true;
if (obj.link) {
var target = game_data.objects[obj.link];
target.dark = !target.dark;
}
if (!obj.sticky)
obj.dark = true;
var msg = tag("p", success_message(obj));
} else {
var msg = tag("p", obj.failure);
}
refresh_view(null, msg);
}
function handle_learn() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
score_object(obj_id);
obj.location = "hero";
obj.visited = true;
game_data.meta.turns++;
refresh_view(null, "You seem to have learned a new spell!");
}
function handle_cast() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
if (pass_lock("hero", obj.lock)) {
if (obj.link) {
var target = game_data.objects[obj.link];
if (target.type === "room") {
score_object(obj.link);
game_data.objects.hero.location = obj.link;
} else {
target.location = room_here();
}
}
obj.visited = true;
var msg = tag("p", success_message(obj));
} else {
var msg = tag("p", obj.failure);
}
game_data.meta.turns++;
refresh_view(null, msg);
}
function handle_topic() {
var obj_id = this.getAttribute("data-target");
var obj = game_data.objects[obj_id];
if (pass_lock("hero", obj.lock)) {
score_object(obj_id);
obj.visited = true;
if (obj.link)
game_data.objects[obj.link].dark = false;
var msg = object_description(obj_id);
} else {
var msg = tag("p", obj.failure);
}
game_data.meta.turns++;
refresh_view(null, msg);
}
function look() {
var obj = game_data.objects;
var me = obj.hero;
var room_id = me.location
var here = obj[room_id];
if (here.type === "vehicle") {
var vehicle_msg = " (on the " + here.name + ")";
room_id = here.location
here = obj[room_id];
} else {
var vehicle_msg = "";
}
say(verso, tag("div", tag("b", here.name + vehicle_msg)));
if (room_has_light(room_here())) {
score_object(room_id);
if (!here.visited && here.initial)
say(verso, tag("p", here.initial));
else
say(verso, tag("p", here.description));
here.visited = true;
document.getElementById("score").innerText =
" Score: " + game_data.meta.score
+ "/" + (game_data.config.max_score || "?");
say(verso, success_message(here));
var obj = find_objects_in(room_id);
delete obj.hero;
if (count_keys(obj) > 0) {
say(verso, tag("div", tag("b", "You see:")));
say(verso, object_list(obj));
}
} else {
if (here.failure)
say(verso, here.failure);
else
say(verso, "It's too dark to see much at all.");
}
if (!here.ending)
say(verso, exit_list(me.location));
}
function success_message(obj) {
if (obj.ending) {
if (obj.success)
var succ = tag("p", "*** " + obj.success + " ***");
else
var succ = tag("p", "*** The End ***");
succ.className = "ending";
return succ;
} else {
return tag("p", obj.success);
}
}
function exit_list(room_id) {
var list = tag("div", tag("b", "Which way now?"));
say(list, tag("br"));
var obj = game_data.objects;
if (obj[room_id].type === "vehicle") {
var actor = room_id;
room_id = obj[room_id].location;
} else {
var actor = "hero";
}
var is_dark = !room_has_light(room_id);
for (var i in obj) {
if (obj[i].location !== room_id)
continue;
else if (obj[i].type !== "exit")
continue;
else if (obj[i].dark)
continue;
else if (is_dark && !obj[i].light)
continue;
var btn = exit_button(obj[i].name, i, actor);
if (!obj[i].visited && obj[i].initial)
btn.title = obj[i].initial;
else if (obj[i].description)
btn.title = obj[i].description;
say(list, btn);
}
return list;
}
function handle_exit() {
var exit_id = this.getAttribute("data-target");
var actor_id = this.getAttribute("data-actor");
var exit_obj = game_data.objects[exit_id];
var actor = game_data.objects[actor_id];
if (exit_obj.visited && exit_obj.sticky) {
pass_through(exit_obj, actor);
} else if (pass_lock(actor_id, exit_obj.lock)) {
pass_through(exit_obj, actor);
} else {
var msg = tag("p", exit_obj.failure);
say(verso, msg);
msg.scrollIntoView();
}
}
function pass_lock(actor_id, lock) {
if (lock === undefined) {
return true;
} else if (typeof lock === "string") {
var key_id = lock.substr(1);
var key = game_data.objects[key_id];
switch (lock[0]) {
case "+": return key.location === actor_id;
case "-": return key.location !== actor_id;
case "?": return key_id === actor_id;
case "!": return key_id !== actor_id;
case "@": return key.visited;
case "^": return !key.visited;
case "#": return !key.dark;
case "~": return key.dark;
default: throw new Error("Bad lock type: " + lock[0]);
}
} else {
throw new Error("Bad lock: " + lock.toString());
}
}
function pass_through(exit_obj, actor) {
actor.location = exit_obj.link;
exit_obj.visited = true;
game_data.meta.turns++;
refresh_view(tag("p", success_message(exit_obj)));
if (exit_obj.ending || game_data.objects[exit_obj.link].ending)
end_game();
}
function score_object(obj_id) {
var obj = game_data.objects[obj_id];
if (obj.score && !obj.visited)
game_data.meta.score += obj.score | 0;
}
function start_game() {
game_data.meta.turns = 0;
game_data.meta.score = 0;
refresh_view(tag("p", game_data.config.banner));
//wait_button.disabled = false;
restart_button.disabled = false;
save_button.disabled = false;
}
function end_game() {
var buttons = document.getElementsByTagName("button");
for (var i in buttons)
buttons[i].disabled = true;
document.getElementById("save-button").disabled = false;
document.getElementById("restart-button").disabled = false;
}
function show_metadata() {
verso.innerHTML = "";
say(verso, edition_notice(game_data.meta));
recto.innerHTML = "";
say(recto, title_page(game_data.meta));
if (game_data.meta.title)
document.title =
game_data.meta.title;
if (game_data.meta.language) {
verso.lang = game_data.meta.language;
recto.lang = game_data.meta.language;
}
}
window.addEventListener("load", function () {
"use strict";
verso = document.getElementById("verso-page");
recto = document.getElementById("recto-page");
//wait_button = document.getElementById("wait-button");
//undo_button = document.getElementById("undo-button");
restart_button = document.getElementById("restart-button");
save_button = document.getElementById("save-button");
// Firefox "helpfully" remembers the wrong state on page reload.
restart_button.disabled = true;
save_button.disabled = true;
var input = document.getElementById("local-file");
input.addEventListener("change", function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function () {
try {
game_text = reader.result;
game_data = JSON.parse(reader.result);
if (game_data.meta.turns !== undefined) {
game_data.meta.turns |= 0;
game_data.meta.score |= 0;
refresh_view();
restart_button.disabled = false;
save_button.disabled = false;
} else {
if (game_data.config.max_score)
game_data.config.max_score |= 0;
show_metadata();
}
} catch (e) {
console.log(e);
alert("Can't load story file. See console.");
}
};
reader.readAsText(file);
}, false);
save_button.addEventListener("click", function () {
if (window.File !== undefined) {
var save_data = JSON.stringify(game_data);
var save_file = new File([save_data], "save.json", {
"type": "application/octet-stream"
});
var url = URL.createObjectURL(save_file);
window.location.assign(url);
URL.revokeObjectURL(url);
} else {
alert("Can't save game in this browser, sorry.");
}
}, false);
/*wait_button.addEventListener("click", function () {
game_data.meta.turns++;
refresh_view(tag("p", "You wait. Time passes..."));
}, false);
undo_button.addEventListener("click", function () {
}, false);*/
restart_button.addEventListener("click", function () {
game_data = JSON.parse(game_text);
show_metadata();
}, false);
if (game_data) {
game_text = JSON.stringify(game_data);
show_metadata();
}
}, false);
</script>
</body>
</html>