forked from VinMannie/srb2web
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
2176 lines (1929 loc) · 88 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
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
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en-us">
<head>
<!--
@licstart
SONIC ROBO BLAST 2
-----------------------------------------------------------------------------
Copyright (C) 1993-1996 by id Software, Inc.
Copyright (C) 1998-2000 by DooM Legacy Team.
Copyright (C) 1999-2020 by Sonic Team Junior.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
@licend
-->
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="icon" href="assets/srb2.png" sizes="256x256" type="image/png">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<link rel="apple-touch-icon" href="assets/srb2.png">
<meta name="apple-mobile-web-app-title" content="SRB2">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2048-2732.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2732-2048.jpg" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1668-2388.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2388-1668.jpg" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1668-2224.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2224-1668.jpg" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1536-2048.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2048-1536.jpg" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1242-2688.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2688-1242.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1125-2436.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2436-1125.jpg" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-828-1792.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1792-828.jpg" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1242-2208.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-2208-1242.jpg" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-750-1334.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1334-750.jpg" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-640-1136.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="assets/apple-splash-1136-640.jpg" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.3.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.10.1/Sortable.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/mazmazz/idb-keyval@idb-version/dist/idb-keyval-iife.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/es6-promise-pool.min.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-167763417-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-167763417-1');
</script>
<title>Sonic Robo Blast 2</title>
<style>
html, body {
height: 100%;
}
body {
font-family: 'Segoe UI', sans-serif;
margin: 0;
padding: none;
background-color: #000;
background-image:
linear-gradient(90deg, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.80) 10%, rgba(0,0,0,0.80) 90%, rgba(0,0,0,0.25) 100%),
url(assets/background.jpg);
background-size: cover;
background-attachment: fixed;
background-position: center;
color: #ffffff;
}
body.startedMainLoop {
background-image: none;
}
body.startedMainLoop #content {
display: none;
}
a {
color: rgb(107, 161, 255);
}
a:visited {
color: #7f6bd1;
}
@media (min-width: 320px) {
#logo {
width: 120%;
height: auto;
margin: 0 -10%;
}
#systemArguments, #userArguments {
width: 120%;
margin: 0 -10%;
}
}
@media (min-width: 481px) {
#logo {
width: 90%;
height: auto;
}
#systemArguments, #userArguments {
width: 90%;
}
}
@media (min-width: 641px) {
#logo {
width: 60%;
height: auto;
}
#systemArguments, #userArguments {
width: 60%;
}
}
@media (min-width: 1281px) {
#logo {
width: 40%;
height: auto;
}
#systemArguments, #userArguments {
width: 40%;
}
}
#status-cont {
display: inline-block;
font-weight: bold;
text-align: center;
margin: auto 10%;
}
#progress {
height: 20px;
width: 256px;
}
#canvas, #keyCapture {
position: fixed;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
opacity: 0;
}
#keyCapture {
opacity: 0;
background-color: rgba(0,0,0,0);
border: 0;
color: rgba(0,0,0,0);
z-index: -99999;
}
#textForm {
display: flex;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 2.5em;
z-index: -99999;
opacity: 0;
}
#textCapture {
flex-grow: 1;
}
#textSubmit {
width: 6.66em;
}
#content {
width: 100%;
height: 100%;
overflow-y: auto;
text-align: center;
display: grid;
}
button, .button {
width: 160px;
height: 48px;
margin: 0.1em;
background-color: darkgray;
background-image: linear-gradient(black, darkgray);
border: 0.1em gray solid;
border-radius: 2px;
color: white;
font-weight: bold;
text-align: center;
line-height: 2.5em;
display: inline-block;
cursor: default;
}
.blueButton {
background-color: mediumblue;
background-image: linear-gradient(black, mediumblue);
border-color: mediumblue;
}
.yellowButton {
background-color: black;
background-image: linear-gradient(black, white);
border-color: white;
}
.redButton {
background-image: linear-gradient(black, crimson);
border-color: crimson;
}
#startbtn {
background-color: black;
color: white;
background-image: linear-gradient(grey, white);
border: 0.1em black solid;
font-weight: bolder;
font-size: 1.25em;
line-height: normal;
cursor: pointer;
}
#notes {
display: inline-block;
text-align: start;
}
summary {
margin: 0.75em 0;
font-size: 1.2em;
}
#addonFilesTemplate {
display: none;
}
.addonFilesField {
display: inline-block;
width: 100%;
margin: 0.1em 0;
}
#resetbtn {
display: none;
}
.addonFilesField .addonButton {
width: 2.5em;
}
.addonFilesField label,
.addonFilesField input[type=file] {
width: 12.5em;
height: 2.5em;
margin: 0;
cursor: pointer;
}
.addonFilesField input[type=file] {
font-size: 1em;
display: none;
}
.addonFilesField .addonDelete {
width: 2.5em;
height: 2.5em;
margin: 0 0 0 0.1em;
}
#addonButtonAdd {
width: 15.4em;
height: 2.5em;
margin: 0.1em 0;
}
#androidNotice {
display: none;
}
</style>
</head>
<body>
<div id="content">
<div id="status-cont" class="emscripten">
<div id="header">
<p>
<img id="logo" src="assets/srb2logo.png"/>
</p>
</div>
<div id="details">
<p>
<button id="startbtn" onclick="StartLoad()">Play</button>
<span hidden class="emscripten" id="status"></span>
</p>
<progress value="0" max="100" id="progress" hidden=1></progress>
<p>
<button id="resetbtn" class="button" onclick="javascript:window.location.reload()">Cancel</button>
</p>
</div>
<form id="controlsForm" action="javascript:void(0);">
<details id="addons">
<summary>Mods</summary>
<div id="addonFilesContainer">
<div class="addonFilesField" id="addonFilesTemplate">
<input type="file" id="addonFiles" class="button yellowButton"/>
<label for="addonFiles" class="button yellowButton">Load File</label><!--
--><div class="addonButton addonDelete button redButton">-</div>
</div>
</div>
<div id="addonButtonAdd" class="button blueButton">+</div>
<p>
<input type="checkbox" id="addonStartup" checked/>
<label for="addonStartup">Load Mods on Startup</label>
</p>
<details id="addonsHelp">
<summary>Mod Help</summary>
<p>You may load one or more mods here. Drag each mod to change its loading order.</p>
<p>Or, you may load ZIP files. They will be available in the Addons Menu.</p>
<p>To load savegames and gamedata, place them in a folder titled <code>userdata/</code> within the ZIP file. Your stored gamedata will be overwritten.</p>
<p><a href="https://mb.srb2.org/forumdisplay.php?f=116" target="_blank">You may download mods here</a>.</p>
</details>
</details>
<details id="controls">
<summary>Settings</summary>
<p>
<label for="resizeHeight">Resolution</label>
<input type="range" id="resizeHeight" name="resizeHeight" oninput="ShowValue(this, 'p', (elem) => { return elem.value > 800; }, 'Full');"
min="200" max="900" value="200" step="100"/>
<span id="resizeHeightValue"></span>
</p>
<!--<p id="fullscreenRow">
<input type="checkbox" id="fullscreen" checked/>
<label for="fullscreen">Fullscreen</label>
</p>-->
<p>
<input type="checkbox" id="playMusic" checked/>
<label for="playMusic">Play Music</label>
<input type="checkbox" id="playSound" checked/>
<label for="playSound">Play Sounds</label>
</p>
<p>
<input type="checkbox" id="useMouse" checked/>
<label for="useMouse">Use Mouse</label>
</p>
<details id="storageControls">
<summary>Storage</summary>
<button class="yellowButton" onclick="DownloadFS(); return false;">Download User Data</button>
<button class="redButton" onclick="if (confirm('Are you sure? All installed data will be reset!\n\nYour user data will be preserved.')) ResetProgramData(true, _=>alert('Program data reset.')); return false;">Reset Program Data</button>
<button onclick="if (confirm('Are you sure? All your progress will be lost!')) DeleteFS('/home/web_user/.srb2', true, _=>alert('User data deleted.')); return false;">Delete User Data</button>
</details>
<details id="advancedControls">
<summary>Advanced</summary>
<p>
<p>
<label for="drawDistance">Draw Distance</label>
<input type="range" id="drawDistance" name="drawDistance" oninput="ShowValueRange(this, '', DrawDistanceRange);"
min="0" max="10" value="5" step="1"/>
<span id="drawDistanceValue"></span>
</p>
<p>
<input type="checkbox" id="shadow" checked/>
<label for="shadow">Render Shadows</label>
<input type="checkbox" id="midisoundfont" class="nosave"/>
<label for="midisoundfont">Reset Soundfont</label>
</p>
</p>
<p>
<span id="packageVersionRow">
<label for="packageVersion">Version</label>
<select id="packageVersion">
<option value="2.2.4" selected>2.2.4</option>
<option value="2.2.4-lowend">2.2.4-lowend</option>
</select>
</span>
<input type="checkbox" id="lowend"/>
<label for="lowend">Prefer Low-End</label>
</p>
<p>
<label for="userArguments">Command Line</label><br/>
<textarea id="systemArguments" rows="2" readonly></textarea><br/>
<textarea id="userArguments" rows="2" placeholder="Custom Arguments"></textarea>
</p>
</details>
</details>
</form>
<details id="help">
<summary>Help</summary>
<p>Game Notes:</p>
<p id="fullscreenNotice">Toggle fullscreen by pressing F11, which should enter your browser's fullscreen mode.</p>
<p>No online multiplayer: to play netgames, download the PC version at <a href="//www.srb2.org" target="_blank">srb2.org</a>.</p>
<p>Game controllers should work.</p>
<p>If this page crashes, try enabling "Low-End" mode under Settings > Advanced.</p>
<p id="androidNotice">There is a native Android port available on <a href="https://github.com/Jimita/SRB2/releases" target="_blank">GitHub</a>.</p>
</details>
<details id="footer">
<summary>About</summary>
<p>Sonic Robo Blast 2 is a 3D Sonic the Hedgehog fangame inspired by the original Sonic games of the 1990s.</p>
<p>This project allows you to play SRB2 on your web browser, including iPhone and iPad.</p>
<p><a href="https://github.com/mazmazz/SRB2-emscripten/issues">View issues</a> / <a href="https://github.com/mazmazz/SRB2-emscripten">View source</a></p>
<p>Contributors:</p>
<p><a href="https://github.com/mazmazz">mazmazz</a> / <a href="https://github.com/heyjoeway">heyjoeway</a> / <a href="https://github.com/Jimita">Jimita</a></p>
<p>Follow SRB2:</p>
<p><a href="https://www.srb2.org">Website</a> / <a href="https://twitter.com/SonicTeamJr">Twitter</a> / <a href="https://discord.com/invite/pYDXzpX">Discord</a></p>
<p style="font-size:xx-small;">
SRB2 Web Version: 1592091069
</p>
<span id="newVersion"></span>
<p style="font-size:xx-small;">
This software is licensed under GNU General Public License Version 2. See license text at <a href="https://opensource.org/licenses/GPL-2.0" target="_blank">https://opensource.org/licenses/GPL-2.0</a>.
</p>
<p style="font-size:xx-small;">
The <a href="https://musical-artifacts.com/artifacts/400" target="_blank">Florestan Basic GM GS</a> soundfont is created by <a href="http://dev.nando.audio" target="_blank">Nando Florestan</a>.
</p>
<p style="font-size:xx-small;">
Original design and content is copyright 1998-2020 Sonic Team Junior. All non-original material is copyrighted by their respective owners, and no copyright infringement is intended.
</p>
</details>
<div id="copyright">
<p style="font-size:xx-small;">
Sonic Robo Blast 2 and Sonic Team Junior are in no way affiliated with SEGA® or Sonic Team.
</p>
<p style="font-size:xx-small;">
Sonic the Hedgehog is a trademark of SEGA®<br/>
The copyrights of "Sonic the Hedgehog" and all associated characters, names, terms, art, and music thereof belong to SEGA®
</p>
</div>
</div>
</div>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex="-1" style="z-index:-9999;"></canvas>
<textarea id="keyCapture" oncontextmenu="event.preventDefault()" tabindex="-1"></textarea>
<form id="textForm" onsubmit="InjectText();" action="javascript:void(0);" autocomplete="off">
<input id="textCapture" tabindex="-1" placeholder="Console Command" disabled/>
<input id="textSubmit" type="submit" value="Enter"/>
</form>
<script type='text/javascript'>
////////////////////////////////
// UI
////////////////////////////////
var CanvasElement = document.getElementById('canvas');
var StatusElement = document.getElementById('status');
var ProgressElement = document.getElementById('progress');
var ControlsFormElement = document.getElementById('controlsForm');
var PackageVersionElement = document.getElementById('packageVersion');
var AddonFields = 0;
HTMLSelectElement.prototype.contains = function( value ) {
for ( var i = 0, l = this.options.length; i < l; i++ ) {
if ( this.options[i].value == value ) {
return true;
}
}
return false;
};
var URLParams;
var GetSelectedPackageVersion = _ => {
let val = '';
if (PackageVersionElement.selectedIndex > -1) {
val = PackageVersionElement.options[PackageVersionElement.selectedIndex].value;
if (document.getElementById('lowend').checked
&& PackageVersionElement.contains(`${val}-lowend`))
val = `${val}-lowend`;
} else
val = '2.2.4';
return val;
};
var DeleteNode = (node) => {
node.querySelectorAll('*').forEach(n => n.remove());
node.remove();
};
var HideContent = () => {
StatusElement.hidden = false;
ProgressElement.hidden = false;
document.getElementById('startbtn').style.display = "none";
document.getElementById('addons').style.display = "none";
document.getElementById('controls').style.display = "none";
document.getElementById('help').style.display = "none";
document.getElementById('footer').style.display = "none";
document.getElementById('copyright').style.display = "none";
document.getElementById('resetbtn').style.display = "inline-block";
};
var ShowContent = () => {
StatusElement.hidden = true;
ProgressElement.hidden = true;
document.getElementById('startbtn').style.display = "inline-block";
document.getElementById('addons').style.display = "block";
document.getElementById('controls').style.display = "block";
document.getElementById('help').style.display = "block";
document.getElementById('footer').style.display = "block";
document.getElementById('copyright').style.display = "block";
document.getElementById('resetbtn').style.display = "none";
};
var StartLoad = async () => {
PackageVersion = GetSelectedPackageVersion();
SaveFormToStorage(ControlsFormElement);
window.removeEventListener('focus', CheckVersion, false);
await UXInstallProgram(false, PackageVersion); // hides the UI
await GetWasm(PackageVersion);
let scriptSrc = `data/${PackageVersion}/srb2.js`;
let script = document.createElement('script');
script.setAttribute('src',scriptSrc);
document.head.appendChild(script);
document.body.classList.add('calledRun');
};
var DrawDistanceRange = ['256','512','768','1024','1536','2048','3072','4096','6144','8192','Infinite'];
var ShowValueRange = (elem, suffix, rangeValues) => {
document.getElementById(`${elem.id}Value`).innerText = `${rangeValues[elem.value]}${suffix}`;
};
var ShowValue = (elem, suffix, overrideTest, override) => {
if (typeof overrideTest !== 'undefined' && overrideTest(elem))
document.getElementById(`${elem.id}Value`).innerText = override;
else
document.getElementById(`${elem.id}Value`).innerText = `${elem.value}${suffix}`;
};
var SaveFormToStorage = (form) => {
let inputs = form.querySelectorAll('input, textarea, select');
inputs.forEach(input => {
let val = input.type === 'checkbox' ? input.checked
: input.type === 'select-one' ? (input.selectedIndex > -1 ? input.options[input.selectedIndex].value : '')
: input.value
// Don't save the field if it's specified in the URL query string,
// because that's a forced override.
if (input.type !== 'file' && (!URLParams.has(input.id) || URLParams.get(input.id) != val) && !input.classList.contains('nosave'))
localStorage.setItem(`${form.id}_${input.id}`, val);
});
};
var LoadFormFromStorage = (form) => {
let inputs = form.querySelectorAll('input, textarea, select');
inputs.forEach(input => {
let val;
if(URLParams.has(input.id))
val = URLParams.get(input.id);
else
val = localStorage.getItem(`${form.id}_${input.id}`);
if (val !== null && !input.readOnly && input.type !== 'file' && !input.classList.contains('nosave')) {
if (input.type === 'checkbox')
input.checked = (val === "true");
else if (input.type === 'select-one')
for (let i = 0; i < input.length; i++) {
let option = input.options[i];
if (option.value === val) {
input.selectedIndex = i;
break;
}
}
else
input.value = val;
}
});
};
var HandleInput = (e) => {
let val = e.target.type === 'checkbox' ? e.target.checked
: e.target.type === 'select-one' ? (e.target.selectedIndex > -1 ? e.target.options[e.target.selectedIndex].value : '')
: e.target.value
// Don't save the field if it's specified in the URL query string,
// because that's a forced override.
if (e.target.type !== 'file' && (!URLParams.has(e.target.id) || URLParams.get(e.target.id) != val) && !e.target.classList.contains('nosave'))
localStorage.setItem(`${ControlsFormElement.id}_${e.target.id}`, val);
BuildControlArguments();
document.getElementById("systemArguments").value = SystemArgumentsToString();
};
var AddFormEventListeners = (form, event, callback, settings) => {
let inputs = form.querySelectorAll('input, textarea, select');
inputs.forEach(input => input.addEventListener(event, callback, settings));
};
var DeleteAddonField = (elem) => {
DeleteNode(elem);
if (!document.getElementById("addonFilesContainer").querySelectorAll('.addonFilesField:not([id=addonFilesTemplate])').length)
AddAddonField();
};
var HandleDeleteAddon = (e) => {
DeleteAddonField(e.target.parentElement);
BuildControlArguments();
document.getElementById("systemArguments").value = SystemArgumentsToString();
}
var HandleFileInput = (e) => {
if (e.target.files.length) {
let name = e.target.files[0].name;
// truncate name ourselves, because overflow: hidden bugs the layout
if (name.length > 16)
name = `${name.substring(0, 16)}...`;
e.target.parentElement.querySelector('label').innerText = name;
}
};
var AddAddonField = () => {
let newField = document.getElementById("addonFilesTemplate").cloneNode(true);
newField.id = `addonFilesField${AddonFields}`;
newField.querySelector('input[type=file]').id = `addonFiles${AddonFields}`;
newField.querySelector('input[type=file]').addEventListener('input', HandleFileInput, false);
newField.querySelector('input[type=file]').addEventListener('input', HandleInput, false);
newField.querySelector('label').htmlFor = `addonFiles${AddonFields}`;
// iOS file inputs do not emit input events, so let's expose
// the input element itself so the user can see the filename.
if (UserAgentIsiOS()) {
newField.querySelector('label').style.display = 'none';
newField.querySelector('input[type=file]').classList.add('addonButton');
newField.querySelector('input[type=file]').style.display = 'inline-block';
}
newField.querySelector('.addonDelete').addEventListener('click', HandleDeleteAddon, false);
newField.style.display = 'block';
document.getElementById("addonFilesContainer").insertBefore(newField, null);
AddonFields++;
};
var InitializeiOSLanding = () => {
if (UserAgentIsiOS()) {
if (!IsStandalone()) {
document.getElementById("details").innerHTML = "<p style='font-weight: 900;'>To play, add this site to your Home Screen!</p>";
document.getElementById("addons").style.display = "none";
document.getElementById("controls").style.display = "none";
document.getElementById("help").style.display = "none";
document.getElementById("notes").style.display = "none";
return true;
}
}
};
var InitializeFormFields = () => {
URLParams = new URLSearchParams(window.location.search);
LoadFormFromStorage(ControlsFormElement);
// By default, mobile devices should run at 200p.
if (localStorage.getItem('controlsForm_resizeHeight') === null && !UserAgentIsMobile())
document.getElementById('resizeHeight').value = 400;
// iOS devices default to low-end builds. the high-end build does not play
// even on new devices
if (UserAgentIsiOS()) {
document.getElementById('lowend').checked = true;
document.getElementById('lowend').disabled = true;
}
ShowValue(document.getElementById('resizeHeight'), 'p', (elem) => { return elem.value > 800; }, 'Full');
ShowValueRange(document.getElementById('drawDistance'), '', DrawDistanceRange);
AddFormEventListeners(ControlsFormElement, 'input', HandleInput, false);
if (PackageVersionElement.length < 2)
document.getElementById('packageVersionRow').style.display = 'none';
BuildControlArguments();
document.getElementById("systemArguments").value = SystemArgumentsToString();
if (UserAgentIsAndroid())
document.getElementById("androidNotice").style.display = "block";
if (UserAgentIsMobile()) {
if (IsStandalone())
document.getElementById("fullscreenNotice").style.display = "none";
else
document.getElementById("fullscreenNotice").innerText = "To play in fullscreen, try adding this web page to your Home Screen.";
}
if (UserAgentIsiOS() && IsStandalone()) {
document.getElementById("fullscreenRow").style.display = "none";
document.getElementById("fullscreen").checked = true;
}
};
var InitializeAddons = () => {
AddAddonField();
document.getElementById("addonButtonAdd").addEventListener('click', AddAddonField, false);
Sortable.create(document.getElementById('addonFilesContainer'), {
onEnd: () => {
BuildControlArguments();
document.getElementById("systemArguments").value = SystemArgumentsToString();
}
});
};
var InitializeSections = () => {
document.getElementById('addons').open = (localStorage.getItem('addons') === 'true');
document.getElementById('addonsHelp').open = (localStorage.getItem('addonsHelp') === 'true'
|| localStorage.getItem('addonsHelp') === null);
document.getElementById('controls').open = (localStorage.getItem('controls') === 'true');
document.getElementById('advancedControls').open = (localStorage.getItem('advancedControls') === 'true');
document.getElementById('addons').addEventListener('toggle', function(e) {
localStorage.setItem('addons', event.target.open);
}, false);
document.getElementById('addonsHelp').addEventListener('toggle', function(e) {
localStorage.setItem('addonsHelp', event.target.open);
}, false);
document.getElementById('controls').addEventListener('toggle', function(e) {
localStorage.setItem('controls', event.target.open);
}, false);
document.getElementById('advancedControls').addEventListener('toggle', function(e) {
localStorage.setItem('advancedControls', event.target.open);
}, false);
};
window.addEventListener('load', function() {
if (!InitializeiOSLanding()) {
InitializeAddons();
InitializeFormFields();
InitializeSections();
}
}, {once: true});
////////////////////////////////
// Version Check - For PWA
////////////////////////////////
let AuthorUpdateShown = false;
var CheckVersion = async () => {
if (document.body.classList.contains('calledRun'))
return;
try {
////////////////////////////////
// Check Web Version
////////////////////////////////
let response = await fetch("version-shell.txt");
let data = await response.text();
console.log(`SRB2 Web Version: 1592091069`);
if (data.trim() && data.trim() !== "1592091069") {
console.log(`New Web Version Found: ${data}`);
// Don't refresh page more than once in a row.
let updateCount = localStorage.getItem('srb2web_update');
if (IsStandalone() && (!updateCount || !parseInt(updateCount))) {
localStorage.setItem('srb2web_update', (1).toString());
window.location.reload(true);
return;
} else {
if (document.getElementById('newVersion'))
document.getElementById('newVersion').outerHTML = `<p style="font-size:xx-small;">Update Version: <a href="#" onclick="window.location.reload(true);return false;">${data}</a></p>`;
}
}
localStorage.setItem('srb2web_update', (0).toString());
////////////////////////////////
// Check Author Updates
////////////////////////////////
// If this app were to be decentralized, I would still to be able
// to communicate updates. Line 1 is the update ID, everything else
// goes in an alert. Show the alert on two page loads.
// Put new updates in a new filename.
if (!AuthorUpdateShown) {
try {
// get data
let authorUrl = 'https://raw.githubusercontent.com/mazmazz/SRB2-emscripten/emscripten-new/emscripten/author-update.txt';
let authorResponse = await fetch(authorUrl, {mode: 'cors'});
if (!authorResponse.ok)
throw(`Author update check status: ${authorResponse.status}`);
data = await authorResponse.text();
data = data.replace('\r\n','\n');
let linePos = data.indexOf('\n');
// process data
let updateId = data.substr(0, linePos > -1 ? linePos : data.length);
let updateText = data.substr(linePos+1 < data.length ? linePos+1 : data.length, data.length);
if (!updateId.trim() || !updateText.trim())
throw('Invalid author update, updateId or updateText was blank');
// compare against stored info
let updateCount = localStorage.getItem('srb2web_authorUpdate');
updateCount = parseInt(updateCount);
if (!updateCount)
updateCount = 0;
let updateStoredId = localStorage.getItem('srb2web_authorUpdate_id');
if (updateId !== updateStoredId)
updateCount = 0;
// show the update?
if (!AuthorUpdateShown) {
if (updateCount++ < 2) {
AuthorUpdateShown = true; // don't show again for this page load
alert(updateText);
}
}
// store variables
localStorage.setItem('srb2web_authorUpdate_id', updateId);
localStorage.setItem('srb2web_authorUpdate', updateCount.toString());
} catch (err) {
console.log('CheckVersion: author update check', err);
}
}
////////////////////////////////
// Check default program version
////////////////////////////////
// Don't check program version more than once a page load
let updateCount = localStorage.getItem('srb2program_update');
if (!updateCount || !parseInt(updateCount))
response = await fetch("version-package.txt");
else
throw("Already checked program version.");
data = await response.text();
let previousDefaultPackageVersion = localStorage.getItem('srb2program_defaultversion');
console.log(`SRB2 Default Program Version: 2.2.4`);
if (data.trim() && previousDefaultPackageVersion && data.trim() !== previousDefaultPackageVersion) {
console.log(`New Default Program Version Found: ${data}`);
if (PackageVersionElement.length > 1 && confirm(`SRB2 Version ${data} is released! Do you want to switch to the new version?`)) {
for (let i = 0; i < PackageVersionElement.length; i++) {
if (PackageVersionElement.options[i].value === data) {
PackageVersionElement.selectedIndex = i;
SaveFormToStorage(ControlsFormElement);
alert(`The new version will run when you ${UserAgentIsMobile() ? 'tap' : 'click'} "Play".`);
break;
}
}
}
}
localStorage.setItem('srb2program_defaultversion', data.trim());
} catch (err) {
console.log(`Error Checking New Version:`,err);
localStorage.setItem('srb2web_update', (0).toString());
throw err;
}
};
// reset on page load
localStorage.setItem('srb2program_update', (0).toString());
window.addEventListener('load', CheckVersion, {once: true});
window.addEventListener('focus', CheckVersion, false);
////////////////////////////////
// Utilities
////////////////////////////////
var UserAgentIsiOS = () => {
var ua = window.navigator.userAgent;
var iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i) || !!ua.match(/iPod/i);
var webkit = !!ua.match(/WebKit/i);
var iOSSafari = iOS && webkit && !ua.match(/CriOS/i) && !ua.match(/FxiOS/i);
return iOSSafari;
};
var UserAgentIsiPhone = () => /iPhone|iPod/.test(navigator.userAgent);
var IsStandalone = () => (
(window.matchMedia('(display-mode: standalone)').matches) ||
(("standalone" in window.navigator) &&
window.navigator.standalone)
);
// https://stackoverflow.com/a/11381730
var UserAgentIsMobile = () => {
let check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
var UserAgentIsAndroid = () => /Android/.test(navigator.userAgent);
var ResizeDimensions = (x, y, resizeHeight) => {
let portrait = (x < y);
let width = Math.max(x, y);
let height = Math.min(x, y);
let target = Math.max(resizeHeight, (portrait ? 320 : 200)); // BASEVIDHEIGHT
let factor;
if (!resizeHeight)
return {x:x, y:y};
factor = target / height;
if (width * factor < 320) // BASEVIDWIDTH
factor = 320 / width;
width *= factor;
height *= factor;
if (portrait)
{
x = Math.ceil(height);
y = Math.ceil(width);
}
else
{
x = Math.ceil(width);
y = Math.ceil(height);
}
return {x:x, y:y};
};
////////////////////////////////
// Base FS Functions
////////////////////////////////
var GetBasenameFromPath = (path) => path.split('\\').pop().split('/').pop();
var GetDirnameFromPath = (path) => {
let arr = path.split('\\').pop().split('/');
arr.pop();
return arr.join('/');
};
let TypedArrayToBuffer = (array) => array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
// iOS Safari does not implement Blob.arrayBuffer(), so let's
// do it ourselves.
// https://gist.github.com/hanayashiki/8dac237671343e7f0b15de617b0051bd
function MyArrayBuffer () {
// this: File or Blob
return new Promise((resolve) => {
let fr = new FileReader();
fr.onload = () => {
resolve(fr.result);
};
fr.readAsArrayBuffer(this);
})
}
var ImplementArrayBuffer = () => {
if ('File' in self)
File.prototype.arrayBuffer = File.prototype.arrayBuffer || MyArrayBuffer;
if ('Blob' in self)
Blob.prototype.arrayBuffer = Blob.prototype.arrayBuffer || MyArrayBuffer;
};
ImplementArrayBuffer();
var InitializeFS = () => {
FS.mkdirTree('/addons');
FS.symlink('/home/web_user/.srb2', '/addons/.srb2');
FS.symlink('/home/web_user/.srb2', '/addons/userdata');
FS.mount(IDBFS, {}, '/home/web_user');
return (new Promise((resolve, reject) => {
FS.syncfs(true, (err) => {
console.log("SyncFS done");
console.log(err);
resolve();
});
}));
};
var WriteFS = (baseDir, path, data) => {
if (data instanceof ArrayBuffer)
data = new Uint8Array(data);
// split path to base dir and filename
if (path.includes('/') || path.includes('\\'))
baseDir = `${baseDir}/${GetDirnameFromPath(path)}`;
fn = GetBasenameFromPath(path);
// check for symlinks
let parents = '/';
baseDir.split('/').forEach((name) => {