-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost.html
More file actions
3034 lines (2695 loc) · 132 KB
/
Copy pathhost.html
File metadata and controls
3034 lines (2695 loc) · 132 KB
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">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="description" content="Parkoreen - Map Editor & Game">
<title>Parkoreen</title>
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#2d5a27">
<link rel="icon" type="image/png" sizes="32x32" href="assets/png/icons/icon-play-32.png" id="favicon-32">
<link rel="icon" type="image/png" sizes="64x64" href="assets/png/icons/icon-play-64.png" id="favicon-64">
<link rel="apple-touch-icon" href="assets/png/icons/icon-play-128.png">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0">
<style>
/* Page-specific styles */
body.game-active {
overflow: hidden;
}
body.admin-tool-quickkill #game-canvas { cursor: crosshair; }
body.admin-tool-drag #game-canvas { cursor: grab; }
body.admin-tool-drag.admin-dragging #game-canvas { cursor: grabbing; }
body.admin-tool-placeblock #game-canvas { cursor: cell; }
body.admin-tool-erase #game-canvas { cursor: pointer; }
</style>
</head>
<body class="game-active">
<!-- Game Container -->
<div id="game-container">
<div class="game-bg sky"></div>
<canvas id="game-canvas"></canvas>
</div>
<!-- Game HUD (visible during play mode) -->
<div class="game-hud hidden" id="game-hud">
<!-- Leave button -->
<button class="hud-btn" id="hud-leave" style="position: fixed; top: 16px; left: 16px; transform: scaleX(-1);">
<span class="material-symbols-outlined">logout</span>
</button>
<!-- Settings (in-room; mails/admin are on dashboard three-dots menu) -->
<button class="hud-btn" id="hud-settings" style="position: fixed; top: 16px; right: 16px;">
<span class="material-symbols-outlined">settings</span>
</button>
<!-- Chat button -->
<button class="hud-btn" id="hud-chat" style="position: fixed; bottom: 16px; left: 16px;">
<span class="material-symbols-outlined">chat</span>
</button>
<!-- Players button -->
<button class="hud-btn" id="hud-players" style="position: fixed; bottom: 16px; right: 16px;">
<span class="material-symbols-outlined">group</span>
</button>
<!-- Room code display -->
<div id="room-code-display" class="hidden" style="position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.6); padding: 12px 24px; border-radius: 12px; font-family: 'Parkoreen Game', monospace; font-size: 1.5rem; letter-spacing: 6px; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.8); box-shadow: 0 4px 20px rgba(0,0,0,0.5);"></div>
</div>
<!-- Admin Toolbar (visible during play mode for admin role) -->
<div class="toolbar hidden" id="admin-toolbar" style="z-index: 1000;">
<button class="toolbar-btn" data-admin-tool="fly" title="Fly (G)">
<span class="material-symbols-outlined">flight</span>
<span class="toolbar-btn-label">Fly</span>
</button>
<button class="toolbar-btn" data-admin-action="zoom-in" title="Zoom In">
<span class="material-symbols-outlined">zoom_in</span>
<span class="toolbar-btn-label">Zoom In</span>
</button>
<button class="toolbar-btn" data-admin-action="zoom-out" title="Zoom Out">
<span class="material-symbols-outlined">zoom_out</span>
<span class="toolbar-btn-label">Zoom Out</span>
</button>
<button class="toolbar-btn" data-admin-action="toggle-invincibility" title="Invincibility">
<span class="material-symbols-outlined">shield</span>
<span class="toolbar-btn-label">Invincible</span>
</button>
<button class="toolbar-btn" data-admin-action="toggle-touchboxes" title="Show Touchboxes">
<span class="material-symbols-outlined">select_all</span>
<span class="toolbar-btn-label">Touchbox</span>
</button>
<button class="toolbar-btn" data-admin-action="respawn" title="Respawn at Checkpoint">
<span class="material-symbols-outlined">restart_alt</span>
<span class="toolbar-btn-label">Respawn</span>
</button>
<div style="width: 1px; height: 24px; background: rgba(255,255,255,0.15); margin: 0 2px;"></div>
<button class="toolbar-btn" data-admin-tool="quickkill" title="Quick Kill (K)">
<span class="material-symbols-outlined">dangerous</span>
<span class="toolbar-btn-label">Kill (K)</span>
</button>
<button class="toolbar-btn" data-admin-tool="drag" title="Drag Player (M)">
<span class="material-symbols-outlined">drag_indicator</span>
<span class="toolbar-btn-label">Drag</span>
</button>
<button class="toolbar-btn" data-admin-tool="placeblock" title="Place Block">
<span class="material-symbols-outlined">add_box</span>
<span class="toolbar-btn-label">Block</span>
</button>
<button class="toolbar-btn" data-admin-tool="erase" title="Eraser">
<span class="material-symbols-outlined">ink_eraser</span>
<span class="toolbar-btn-label">Erase</span>
</button>
</div>
<!-- Players Panel -->
<div class="players-panel" id="players-panel">
<div class="panel-header">
<span class="panel-title">Players</span>
<button class="btn btn-icon btn-ghost" id="close-players-panel">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<div class="panel-body" id="players-list">
<!-- Players will be listed here -->
</div>
</div>
<!-- Chat Panel -->
<div class="chat-panel" id="chat-panel">
<div style="display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 2px; position: relative;">
<span style="font-size: 0.75rem; color: #888;">Chat</span>
<button class="btn btn-icon btn-ghost" id="chat-settings-btn" title="Chat Settings" style="width: 28px; height: 28px; min-width: 28px; padding: 0;">
<span class="material-symbols-outlined" style="font-size: 16px;">settings</span>
</button>
<div id="chat-settings-dropdown" class="hidden" style="position: absolute; top: 32px; right: 8px; background: rgba(30,30,30,0.95); border-radius: 8px; padding: 10px 14px; z-index: 10; min-width: 180px; box-shadow: 0 4px 16px rgba(0,0,0,0.5);">
<div style="font-size: 0.75rem; color: #aaa; margin-bottom: 6px;">Display names as</div>
<label style="display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: #ddd; cursor: pointer; margin-bottom: 4px;">
<input type="radio" name="chat-name-display" value="displayName" checked> Display Name
</label>
<label style="display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: #ddd; cursor: pointer;">
<input type="radio" name="chat-name-display" value="username"> Username
</label>
</div>
</div>
<div class="chat-messages" id="chat-messages">
<!-- Chat messages will appear here -->
</div>
<div class="chat-input-container">
<input type="text" class="chat-input" id="chat-input" placeholder="Type a message..." maxlength="200">
<button class="chat-send" id="chat-send">
<span class="material-symbols-outlined" style="font-size: 18px;">send</span>
</button>
</div>
</div>
<!-- Loading Screen -->
<div class="loading-overlay" id="loading-overlay">
<div class="loading-content">
<div class="loading-logo">
<img src="assets/png/logo.png" alt="Parkoreen" style="width: 120px; height: 120px; border-radius: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);">
</div>
<h2 class="loading-title">Loading Parkoreen</h2>
<!-- Total Progress (Green) -->
<div class="loading-label" id="loading-label-total">Total Progress</div>
<div class="loading-progress-container">
<div class="loading-progress-bar loading-progress-green" id="loading-progress-total"></div>
</div>
<div class="loading-size" id="loading-size-total"></div>
<!-- Part Progress (Orange) -->
<div class="loading-label" id="loading-label-part" style="margin-top: 16px;">Current: Initializing...</div>
<div class="loading-progress-container">
<div class="loading-progress-bar loading-progress-orange" id="loading-progress-part"></div>
</div>
<div class="loading-size" id="loading-size-part"></div>
<!-- Hints -->
<div class="loading-hint" id="loading-hint"></div>
</div>
</div>
<style>
.loading-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
display: flex;
align-items: center;
justify-content: center;
z-index: 99999;
transition: opacity 0.5s ease;
}
.loading-overlay.hidden {
opacity: 0;
pointer-events: none;
}
.loading-content {
text-align: center;
color: white;
}
.loading-logo {
margin-bottom: 24px;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.loading-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 20px;
color: #4ade80;
}
.loading-label {
font-size: 0.85rem;
color: rgba(255,255,255,0.8);
margin-bottom: 8px;
font-weight: 500;
}
.loading-progress-container {
width: 300px;
height: 12px;
background: rgba(0, 0, 0, 0.4);
border-radius: 6px;
overflow: hidden;
margin: 0 auto 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}
.loading-progress-bar {
height: 100%;
border-radius: 5px;
width: 0%;
background-size: 200% 100%;
animation: shimmer 1.5s ease-in-out infinite;
transition: width 0.15s ease-out;
}
.loading-progress-green {
background: linear-gradient(90deg, #22c55e, #4ade80, #22c55e);
box-shadow: 0 0 10px rgba(74, 222, 128, 0.5), 0 0 20px rgba(74, 222, 128, 0.3);
}
.loading-progress-orange {
background: linear-gradient(90deg, #ea580c, #fb923c, #ea580c);
box-shadow: 0 0 10px rgba(251, 146, 60, 0.5), 0 0 20px rgba(251, 146, 60, 0.3);
}
@keyframes shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
.loading-size {
font-size: 0.75rem;
color: rgba(255,255,255,0.5);
margin-bottom: 4px;
}
.loading-hint {
margin-top: 28px;
padding: 16px 24px;
max-width: 340px;
font-size: 0.85rem;
color: rgba(255,255,255,0.7);
font-style: italic;
line-height: 1.5;
background: rgba(255,255,255,0.05);
border-radius: 8px;
border-left: 3px solid #4ade80;
text-align: left;
opacity: 1;
transition: opacity 0.5s ease;
}
.loading-hint.fade-out {
opacity: 0;
}
</style>
<!-- End Game Screen -->
<div class="end-game-overlay hidden" id="end-game-overlay">
<div class="end-game-modal">
<div class="end-game-trophy">
<span class="material-symbols-outlined">emoji_events</span>
</div>
<h1 class="end-game-title">Level Complete!</h1>
<div class="end-game-time">
<span class="end-game-time-label">Your Time</span>
<span class="end-game-time-value" id="end-game-time">0:00.000</span>
</div>
<div class="end-game-player" id="end-game-player">Player Name</div>
<div class="end-game-actions" id="end-game-actions">
<!-- Buttons will be dynamically set based on mode -->
</div>
</div>
</div>
<!-- Safe wrapper functions with inline fallback (no browser alerts) -->
<script>
function showInlineToast(msg, type) {
var existing = document.getElementById('inline-toast');
if (existing) existing.remove();
var toast = document.createElement('div');
toast.id = 'inline-toast';
toast.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);padding:12px 24px;border-radius:8px;color:#fff;font-weight:500;z-index:99999;animation:fadeIn 0.3s;box-shadow:0 4px 12px rgba(0,0,0,0.3);max-width:90%;text-align:center;';
toast.style.background = type === 'error' ? '#e74c3c' : type === 'success' ? '#27ae60' : '#3498db';
toast.textContent = msg;
document.body.appendChild(toast);
setTimeout(function() { toast.style.opacity = '0'; toast.style.transition = 'opacity 0.3s'; }, 3000);
setTimeout(function() { if (toast.parentNode) toast.remove(); }, 3500);
}
function toastSuccess(msg) {
console.log('[Toast Success]', msg);
try {
if (window.ToastManager && typeof window.ToastManager.show === 'function') {
window.ToastManager.show(msg, 'success');
} else { showInlineToast(msg, 'success'); }
} catch (e) { showInlineToast(msg, 'success'); }
}
function toastError(msg) {
console.log('[Toast Error]', msg);
try {
if (window.ToastManager && typeof window.ToastManager.show === 'function') {
window.ToastManager.show(msg, 'error');
} else { showInlineToast(msg, 'error'); }
} catch (e) { showInlineToast(msg, 'error'); }
}
function loadingShow(msg) {
try {
if (window.LoadingManager && typeof window.LoadingManager.show === 'function') {
window.LoadingManager.show(msg);
}
} catch (e) {}
}
function loadingHide() {
try {
if (window.LoadingManager && typeof window.LoadingManager.hide === 'function') {
window.LoadingManager.hide();
}
} catch (e) {}
}
</script>
<!-- Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="runtime.js?v=20"></script>
<script src="assets/js/style.js?v=11"></script>
<script src="assets/js/plugins.js?v=1"></script>
<script src="assets/js/game.js?v=18"></script>
<!-- Code plugin loader (scripts loaded before editor, see DOMContentLoaded) -->
<script src="assets/plugins/code/js/loader.js?v=1"></script>
<script src="assets/js/exportImport.js?v=12"></script>
<script>
// Global state
let engine;
let editor;
let currentMapId = null;
let currentMode = 'edit'; // 'edit', 'host', 'play'
let isHost = false;
let mapLoadedSuccessfully = false; // Track if map loaded properly to prevent saving corrupted/blank data
let mapDirty = false; // Tracks unsaved editor changes for beforeunload prompt
let adminEditMapSession = false; // Admin UI: load/save any map via /admin/maps (requires ?admin=1 + admin role)
function resolveAdminEditMapSession(params) {
if (params.get('admin') !== '1') return false;
try {
if (typeof window.Settings === 'undefined' || window.Settings.get('roleMode') !== 'admin') {
return false;
}
const u = JSON.parse(localStorage.getItem('parkoreen_user') || '{}');
if (typeof window.isParkoreenAdminUsername === 'function' && !window.isParkoreenAdminUsername(u.username)) {
return false;
}
} catch (e) {
return false;
}
return true;
}
async function fetchMapForEditor(mapId) {
if (adminEditMapSession && typeof window.MapManager.adminGetMap === 'function') {
return window.MapManager.adminGetMap(mapId);
}
return window.MapManager.getMap(mapId);
}
// Show save corrupted popup
function showSaveCorruptedPopup() {
// Create overlay
const overlay = document.createElement('div');
overlay.id = 'save-corrupted-overlay';
overlay.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
display: flex;
align-items: center;
justify-content: center;
z-index: 99999;
`;
const popup = document.createElement('div');
popup.style.cssText = `
background: #1a1a2e;
border: 2px solid #ff4444;
border-radius: 12px;
padding: 32px;
max-width: 400px;
text-align: center;
font-family: 'Parkoreen UI', sans-serif;
`;
popup.innerHTML = `
<div style="font-size: 48px; margin-bottom: 16px;">⚠️</div>
<h2 style="color: #ff4444; margin: 0 0 16px 0; font-size: 24px;">Save Corrupted</h2>
<p style="color: #aaa; margin: 0 0 24px 0; line-height: 1.5;">
The map data could not be loaded. The save file may be corrupted or incompatible.
</p>
<div style="display: flex; gap: 12px; justify-content: center;">
<button id="corrupted-return" style="
padding: 12px 24px;
background: #333;
border: 1px solid #555;
color: #fff;
border-radius: 8px;
cursor: pointer;
font-family: inherit;
font-size: 14px;
">Return to Menu</button>
<button id="corrupted-force" style="
padding: 12px 24px;
background: #ff4444;
border: none;
color: #fff;
border-radius: 8px;
cursor: pointer;
font-family: inherit;
font-size: 14px;
">Force Enter</button>
</div>
`;
overlay.appendChild(popup);
document.body.appendChild(overlay);
// Event listeners
document.getElementById('corrupted-return').addEventListener('click', () => {
window.location.href = 'dashboard/';
});
document.getElementById('corrupted-force').addEventListener('click', () => {
overlay.remove();
mapLoadedSuccessfully = true; // Allow saving now
toastSuccess('Entered with empty map. Changes will be saved.');
});
}
// Helper to change favicon based on mode
function setFavicon(type) {
// type: 'play', 'editor'
const favicon32 = document.getElementById('favicon-32');
const favicon64 = document.getElementById('favicon-64');
if (favicon32) favicon32.href = `assets/png/icons/icon-${type}-32.png`;
if (favicon64) favicon64.href = `assets/png/icons/icon-${type}-64.png`;
}
// Loading hints
const loadingHints = [
"Did you know that if you spam left and right on a checkpoint, you get more jumps?",
"Don't name yourself JimmyQrg, I dare you.",
"I hate the 5 Pantheon. What? I'm not in Hollow Knight? Ah..",
"If you set the spike touchbox to Tip Spike, you can walk through them. Don't fall on them though.",
"Press R to activate the rotate tool. Click and drag to spin objects!",
"Teleportals only work when both ends are connected. Check your Send To and Receive From settings!",
"You can flip objects horizontally in the config panel. Great for symmetrical designs!",
"The eraser tool (Q) can have custom width and height. Big eraser = big destruction.",
"Custom backgrounds can really set the mood. Try uploading your own!",
"Drop Hurt Only spikes are perfect for one-way passages.",
"Zones are invisible during gameplay. Use them for kill zones or special effects!",
"You can adjust the font size in settings. Squint no more!",
"The inspect box in test mode shows all object properties. Debug like a pro!",
"Music keeps playing between editor and test mode. Vibe while you build!",
"Ctrl+Scroll to zoom in editor mode. Ctrl+Shift+Scroll to reset zoom.",
"Text objects pass right through players. Use them for signs and decorations!",
"The loading screen has hints. Oh wait, you're reading one right now...",
"Hosting a game? Share the room code with friends to play together!",
"Your player color is unique to your account. Stand out in multiplayer!",
"Export your map as a .pkrn file to share with others.",
"Import maps from files to play community creations!",
"Gravity can be adjusted in config. Try negative gravity for ceiling runners!",
"Jump height and movement speed are customizable per map.",
"Additional airjump lets you jump even when not touching the ground.",
"Touch controls include a virtual joystick. Great for mobile play!",
"As the host, you can kick players who aren't playing nice.",
"Your best times are displayed when you complete a level. Speed run!",
"Layers help organize complex maps. Use them wisely!",
"Custom music supports MP3 files. Add your favorite tunes!",
"Invalid teleportal connections appear red. Fix them to enable teleportation!",
"Fly mode in test mode lets you explore without restrictions.",
"Ground jumps vs air jumps matter when additional airjump is disabled.",
"Spikes have adjustable touchboxes. Flat, Danger, or Tip - choose wisely!",
"Portal colors can be customized. Color-code your teleport network!",
"This game was made with love, caffeine, and questionable sleep schedules.",
"Sometimes the best parkour is knowing when NOT to jump.",
"Every great map starts with a terrible first draft.",
"If you're stuck, try looking at the problem from a different angle. Literally.",
"The best speedrunners know every pixel. Do you?",
"Fun fact: The developer tested this loading screen way too many times.",
"Remember: Frustration is just delayed satisfaction.",
"Pro tip: Blame the spikes, not yourself.",
"Have you tried turning the gravity off and on again?",
"Your map could be someone's favorite. Keep building!",
"The finish line is just the beginning of another run."
];
let hintInterval = null;
let currentHintIndex = -1;
function getRandomHint() {
let newIndex;
do {
newIndex = Math.floor(Math.random() * loadingHints.length);
} while (newIndex === currentHintIndex && loadingHints.length > 1);
currentHintIndex = newIndex;
return loadingHints[newIndex];
}
function showHint() {
const hintEl = document.getElementById('loading-hint');
if (!hintEl) return;
// Fade out
hintEl.classList.add('fade-out');
setTimeout(() => {
// Change text
hintEl.textContent = '💡 ' + getRandomHint();
// Fade in
hintEl.classList.remove('fade-out');
}, 500);
}
function startHintCycle() {
const hintEl = document.getElementById('loading-hint');
if (!hintEl) return;
// Show first hint immediately (no fade)
hintEl.textContent = '💡 ' + getRandomHint();
// Cycle every 8 seconds
hintInterval = setInterval(showHint, 8000);
}
function stopHintCycle() {
if (hintInterval) {
clearInterval(hintInterval);
hintInterval = null;
}
}
// Resource Loading Manager with accurate progress tracking (dual progress bars)
const resourceLoader = {
// Total progress (green bar) - tracks ALL resources
totalLoaded: 0,
totalSize: 0,
// Part progress (orange bar) - tracks current category
partLoaded: 0,
partSize: 0,
currentPart: '',
// Resource sizes cache (calculated upfront)
resourceSizes: {},
updateTotalUI() {
const progressBar = document.getElementById('loading-progress-total');
const sizeEl = document.getElementById('loading-size-total');
const percent = this.totalSize > 0 ? Math.min(100, (this.totalLoaded / this.totalSize) * 100) : 0;
if (progressBar) {
progressBar.style.width = percent + '%';
}
if (sizeEl) {
const loadedMB = (this.totalLoaded / 1024 / 1024).toFixed(2);
const totalMB = (this.totalSize / 1024 / 1024).toFixed(2);
sizeEl.textContent = `${loadedMB} MB / ${totalMB} MB (${Math.round(percent)}%)`;
}
},
updatePartUI() {
const progressBar = document.getElementById('loading-progress-part');
const labelEl = document.getElementById('loading-label-part');
const sizeEl = document.getElementById('loading-size-part');
if (labelEl) labelEl.textContent = `Current: ${this.currentPart}`;
const percent = this.partSize > 0 ? Math.min(100, (this.partLoaded / this.partSize) * 100) : 0;
if (progressBar) {
progressBar.style.width = percent + '%';
}
if (sizeEl && this.partSize > 0) {
const loadedKB = (this.partLoaded / 1024).toFixed(1);
const totalKB = (this.partSize / 1024).toFixed(1);
sizeEl.textContent = `${loadedKB} KB / ${totalKB} KB (${Math.round(percent)}%)`;
} else if (sizeEl) {
sizeEl.textContent = '';
}
},
startPart(name, resources) {
this.currentPart = name;
this.partLoaded = 0;
// Calculate part size from pre-fetched sizes
this.partSize = resources.reduce((sum, src) => sum + (this.resourceSizes[src] || 0), 0);
this.updatePartUI();
},
async getFileSize(src) {
try {
const res = await fetch(src, { method: 'HEAD' });
return parseInt(res.headers.get('content-length') || '50000');
} catch {
return 50000; // Default estimate
}
},
// Pre-fetch all file sizes to know total upfront
async calculateAllSizes(allResources) {
this.currentPart = 'Calculating...';
this.updatePartUI();
const sizes = await Promise.all(
allResources.map(async (src) => {
const size = await this.getFileSize(src);
this.resourceSizes[src] = size;
return size;
})
);
this.totalSize = sizes.reduce((sum, size) => sum + size, 0);
this.updateTotalUI();
},
async preloadImage(src) {
const size = this.resourceSizes[src] || 50000;
return new Promise((resolve) => {
let resolved = false;
const markLoaded = (img) => {
if (resolved) return;
resolved = true;
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
resolve(img);
};
const img = new Image();
img.onload = () => markLoaded(img);
img.onerror = () => markLoaded(null);
img.src = src;
});
},
async preloadAudio(src) {
const size = this.resourceSizes[src] || 50000;
return new Promise((resolve) => {
let resolved = false;
const markLoaded = (audio) => {
if (resolved) return;
resolved = true;
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
resolve(audio);
};
const audio = new Audio();
audio.addEventListener('canplaythrough', () => markLoaded(audio), { once: true });
audio.onerror = () => markLoaded(null);
// Timeout in case canplaythrough never fires
setTimeout(() => markLoaded(audio), 5000);
audio.src = src;
audio.load();
});
},
// Preload audio and return the Audio object for reuse
async preloadAudioAndReturn(src) {
const size = this.resourceSizes[src] || 50000;
return new Promise((resolve) => {
let resolved = false;
const markLoaded = (audio, success) => {
if (resolved) return;
resolved = true;
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
resolve(success ? audio : null);
};
const audio = new Audio();
audio.addEventListener('canplaythrough', () => markLoaded(audio, true), { once: true });
audio.onerror = () => markLoaded(null, false);
// Timeout - return audio anyway (may still work)
setTimeout(() => markLoaded(audio, true), 5000);
audio.src = src;
audio.load();
});
},
async loadAll(pluginResources = []) {
this.totalLoaded = 0;
this.totalSize = 0;
this.partLoaded = 0;
this.partSize = 0;
this.resourceSizes = {};
this.updateTotalUI();
this.updatePartUI();
// Start hint cycle
startHintCycle();
// Define resources to preload - split into more granular categories
const uiImages = [
'assets/png/logo.png',
'assets/png/cover.png'
];
const gameSprites = [
'assets/svg/spike-64x.svg',
'assets/svg/portal-64x.svg'
];
const sfx = [
'assets/mp3/jump.mp3'
];
const music = [
'assets/mp3/maccary-bay.mp3',
'assets/mp3/reggae-party.mp3'
];
// Step 1: Calculate ALL sizes upfront (core + plugins) so we know the true total
const allResources = [...uiImages, ...gameSprites, ...sfx, ...music, ...pluginResources];
await this.calculateAllSizes(allResources);
// Step 2: Load UI images
this.startPart('Loading UI...', uiImages);
for (const src of uiImages) {
await this.preloadImage(src);
}
// Step 3: Load game sprites
this.startPart('Loading Sprites...', gameSprites);
for (const src of gameSprites) {
await this.preloadImage(src);
}
// Step 4: Load sound effects
this.startPart('Loading SFX...', sfx);
for (const src of sfx) {
await this.preloadAudio(src);
}
// Step 5: Load music
this.startPart('Loading Music...', music);
for (const src of music) {
await this.preloadAudio(src);
}
// Core resources complete - plugins will be loaded next if any
this.currentPart = 'Core resources loaded';
this.updatePartUI();
return true;
},
// Simple status update (for post-resource loading phases)
updateProgress(status) {
const labelEl = document.getElementById('loading-label-part');
if (labelEl) labelEl.textContent = `Current: ${status}`;
// Set part bar to 100% for non-tracked phases
const progressBar = document.getElementById('loading-progress-part');
if (progressBar) progressBar.style.width = '100%';
const sizeEl = document.getElementById('loading-size-part');
if (sizeEl) sizeEl.textContent = '';
},
// Load a script file with progress tracking
async preloadScript(src) {
const size = this.resourceSizes[src] || 50000;
return new Promise((resolve) => {
let resolved = false;
const markLoaded = (success) => {
if (resolved) return;
resolved = true;
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
resolve(success);
};
// Check if script already exists
if (document.querySelector(`script[src="${src}"]`)) {
markLoaded(true);
return;
}
const script = document.createElement('script');
script.src = src;
script.onload = () => markLoaded(true);
script.onerror = () => markLoaded(false);
document.head.appendChild(script);
});
},
// Fetch a script as text with progress tracking
async preloadScriptText(src) {
const size = this.resourceSizes[src] || 10000;
try {
const response = await fetch(src);
const text = response.ok ? await response.text() : null;
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
return text;
} catch (e) {
this.partLoaded += size;
this.totalLoaded += size;
this.updatePartUI();
this.updateTotalUI();
return null;
}
},
// Add more resources to total (for plugins discovered after initial calculation)
async addToTotal(resources) {
for (const src of resources) {
if (!this.resourceSizes[src]) {
const size = await this.getFileSize(src);
this.resourceSizes[src] = size;
this.totalSize += size;
}
}
this.updateTotalUI();
},
hide() {
// Stop hint cycle
stopHintCycle();
const overlay = document.getElementById('loading-overlay');
if (overlay) {
overlay.classList.add('hidden');
setTimeout(() => {
overlay.remove();
}, 500);
}
}
};
document.addEventListener('DOMContentLoaded', async () => {
// Check auth
if (!Auth.requireAuth()) return;
// Code plugin first, then main editor (both stay out of inline game code)
if (typeof window.loadParkoreenCodePluginScripts === 'function') {
await window.loadParkoreenCodePluginScripts();
}
await new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = 'assets/js/editor.js?v=19';
s.onload = () => resolve();
s.onerror = () => reject(new Error('Failed to load editor.js'));
document.head.appendChild(s);
});
// Parse URL params
const params = new URLSearchParams(window.location.search);
currentMapId = params.get('map');
adminEditMapSession = resolveAdminEditMapSession(params);
window.parkoreenEditorMapId = currentMapId || null;
currentMode = params.get('mode') || 'edit';
const roomCode = params.get('room');
// Step 1: Pre-fetch map data to know which plugins need loading
let mapData = null;
let enabledPlugins = [];
if (currentMapId) {
resourceLoader.updateProgress('Fetching map info...');
try {
mapData = await fetchMapForEditor(currentMapId);
// Extract enabled plugins from map data
if (mapData?.data?.plugins?.enabled) {
enabledPlugins = mapData.data.plugins.enabled;
}
} catch (e) {
console.warn('[Preload] Could not fetch map data:', e);
}
} else if (currentMode === 'play' && roomCode) {
// Check session storage for play mode
const gameData = sessionStorage.getItem('parkoreen_game');
if (gameData) {
try {
const data = JSON.parse(gameData);
if (data.mapData?.plugins?.enabled) {
enabledPlugins = data.mapData.plugins.enabled;
}
} catch (e) {
console.warn('[Preload] Could not parse game data:', e);
}
}
}
// Step 2: Discover plugins FIRST to know all resources upfront
let allPluginResources = [];
if (window.PluginManager && enabledPlugins.length > 0) {
resourceLoader.updateProgress('Discovering plugins...');
await window.PluginManager.discoverPlugins();
// Collect all plugin resources to include in initial size calculation
for (const pluginId of enabledPlugins) {
const scriptUrls = window.PluginManager.getPluginScriptUrls(pluginId);
const soundUrls = window.PluginManager.getPluginSoundUrls(pluginId);
allPluginResources.push(...scriptUrls, ...soundUrls);
}
}
// Step 3: Preload core resources (pass plugin resources for accurate total calculation)
resourceLoader.updateProgress('Calculating sizes...');
await resourceLoader.loadAll(allPluginResources);
// Step 4: Load plugins with progress tracking (sizes already calculated)
if (window.PluginManager && enabledPlugins.length > 0) {
for (const pluginId of enabledPlugins) {
const plugin = window.PluginManager.plugins.get(pluginId);
if (!plugin || window.PluginManager.loadedScripts.has(pluginId)) continue;
const scriptUrls = window.PluginManager.getPluginScriptUrls(pluginId);
const soundUrls = window.PluginManager.getPluginSoundUrls(pluginId);
const pluginResources = [...scriptUrls, ...soundUrls];
// Start part tracking for this plugin
resourceLoader.startPart(`Plugin: ${plugin.name || pluginId}`, pluginResources);
try {
// Load library scripts (as script tags)
const libraryScripts = ['skulpt', 'skulptStdlib', 'pythonCompiler'];
for (const scriptName of libraryScripts) {
if (plugin.scripts?.[scriptName]) {
const src = plugin.path + plugin.scripts[scriptName];
await resourceLoader.preloadScript(src);
}
}
// Load text scripts (globals, inject, script)
const scripts = {};
if (plugin.scripts?.globals) {
scripts.globals = await resourceLoader.preloadScriptText(plugin.path + plugin.scripts.globals);
}
if (plugin.scripts?.inject) {
scripts.inject = await resourceLoader.preloadScriptText(plugin.path + plugin.scripts.inject);
}
if (plugin.scripts?.script) {
scripts.script = await resourceLoader.preloadScriptText(plugin.path + plugin.scripts.script);
}
// Load editor script (as script tag)
if (plugin.scripts?.editor) {
await resourceLoader.preloadScript(plugin.path + plugin.scripts.editor);
}
// Store loaded scripts in plugin manager
window.PluginManager.loadedScripts.set(pluginId, scripts);
// Load sounds with progress tracking
// This also stores the audio objects for reuse
if (plugin.sounds) {
const sounds = {};
for (const [name, path] of Object.entries(plugin.sounds)) {
if (Array.isArray(path)) {
sounds[name] = [];
for (const p of path) {
const audio = await resourceLoader.preloadAudioAndReturn(plugin.path + p);
if (audio) {
audio.volume = 1;
sounds[name].push(audio);
}