-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSPRITE STUDIO.html
More file actions
2388 lines (2094 loc) · 112 KB
/
Copy pathSPRITE STUDIO.html
File metadata and controls
2388 lines (2094 loc) · 112 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">
<title>Fighter Studio & Real-Time Arena (Ultimate Edition)</title>
<style>
/* =====================================================================
1. CSS STYLING & THEMES
===================================================================== */
:root {
--bg-dark: #0a0b10;
--bg-panel: #13151f;
--bg-card: #1c1f2e;
--bg-active: #272c40;
--accent: #ff4757;
--accent-hover: #ff6b81;
--text-main: #f1f2f6;
--text-muted: #8b92a5;
--border: #2a3045;
--highlight: #2ed573;
--gold: #ffa502;
--blue: #1e90ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: monospace, sans-serif; user-select: none; }
body { background: var(--bg-dark); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
header {
background: var(--bg-panel);
border-bottom: 1px solid var(--border);
padding: 6px 14px;
display: flex;
justify-content: space-between;
align-items: center;
z-index: 30;
}
.title-group { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.title-group span.badge {
background: #2ed57322; color: var(--highlight); border: 1px solid var(--highlight);
padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; letter-spacing: 1px;
}
.view-tabs { display: flex; gap: 4px; background: #0c0d14; padding: 3px; border-radius: 6px; }
.view-tab {
background: transparent; border: none; color: var(--text-muted); padding: 5px 12px;
border-radius: 4px; cursor: pointer; font-size: 0.75rem; font-weight: bold; transition: 0.15s;
}
.view-tab.active { background: var(--accent); color: #fff; }
.char-input {
background: var(--bg-card); border: 1px solid var(--border); color: #fff;
padding: 4px 8px; border-radius: 4px; font-size: 0.8rem; width: 110px;
}
.btn {
background: var(--accent); color: #fff; border: none; padding: 5px 10px;
border-radius: 4px; cursor: pointer; font-size: 0.75rem; font-weight: bold;
display: inline-flex; align-items: center; gap: 4px;
}
.btn:hover { background: var(--accent-hover); }
.btn-sec { background: var(--bg-card); border: 1px solid var(--border); color: #fff; }
.btn-sec:hover { background: #2f3549; }
.btn-green { background: var(--highlight); color: #000; }
.btn-green:hover { background: #7bed9f; }
.btn-gold { background: var(--gold); color: #000; }
.btn-gold:hover { background: #eccc68; }
/* Workspace */
.workspace { display: flex; flex: 1; overflow: hidden; position: relative; }
.view-container { display: flex; flex: 1; width: 100%; height: 100%; position: absolute; left: 0; top: 0; }
.hidden { display: none !important; }
/* Moves Sidebar */
.moves-sidebar {
width: 250px; background: var(--bg-panel); border-right: 1px solid var(--border);
display: flex; flex-direction: column; overflow-y: auto; padding: 6px; gap: 4px;
}
.sidebar-title {
font-size: 0.7rem; color: var(--text-muted); font-weight: bold; padding: 4px 8px;
display: flex; justify-content: space-between; align-items: center; text-transform: uppercase;
}
.move-row {
background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px;
padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.move-row.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.move-header { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: bold; }
.frame-strip { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 2px; }
.frame-pill {
width: 26px; height: 26px; background: #0e1017; border: 1px dashed var(--border);
border-radius: 3px; display: flex; align-items: center; justify-content: center;
font-size: 0.65rem; color: var(--text-muted); cursor: pointer; flex-shrink: 0;
}
.frame-pill.assigned { border-style: solid; border-color: var(--highlight); color: var(--highlight); background: #2ed57315; }
.frame-pill.active { border-color: var(--accent); border-width: 2px; color: #fff; font-weight: bold; }
/* Slicer Viewport */
.canvas-viewport {
flex: 1; background: #07080c; position: relative; overflow: hidden; cursor: crosshair;
}
canvas#sheetCanvas { position: absolute; left: 0; top: 0; }
.viewport-hud {
position: absolute; bottom: 10px; left: 10px; background: rgba(19, 21, 31, 0.92);
border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px;
display: flex; gap: 8px; align-items: center; font-size: 0.72rem; z-index: 10;
}
/* Tools Sidebar */
.tools-sidebar {
width: 290px; background: var(--bg-panel); border-left: 1px solid var(--border);
padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; font-size: 0.75rem;
}
.tool-card {
background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.tool-card header {
background: transparent; border-bottom: 1px solid var(--border); padding: 0 0 4px 0;
font-size: 0.75rem; color: var(--gold); font-weight: bold;
}
/* Arena Viewport */
.stage-viewport {
flex: 1; background: #000; position: relative; display: flex;
justify-content: center; align-items: center; overflow: hidden;
}
canvas#stageCanvas {
background: linear-gradient(to bottom, #11141e 0%, #202434 72%, #485460 72%, #1e272e 100%);
box-shadow: 0 0 30px rgba(0,0,0,0.9);
image-rendering: pixelated;
}
.hud-health {
position: absolute; top: 16px; left: 20px; right: 20px; display: flex;
justify-content: space-between; pointer-events: none; z-index: 20;
}
.bar-container { width: 44%; display: flex; flex-direction: column; gap: 3px; }
.bar-label { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: bold; }
.health-frame {
height: 18px; background: rgba(0,0,0,0.6); border: 2px solid #fff;
box-shadow: 0 0 8px rgba(0,0,0,0.8); overflow: hidden;
}
.health-fill {
width: 100%; height: 100%; background: linear-gradient(to bottom, #ffd32a, #ff9f1a);
transition: width 0.08s linear;
}
.key {
background: #000; border: 1px solid #444; border-radius: 3px;
padding: 1px 4px; color: var(--highlight); font-weight: bold; font-size: 0.7rem;
}
/* Modal */
.modal-backdrop {
display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.88); z-index: 100; align-items: center; justify-content: center;
}
.modal {
background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
width: 84%; max-width: 960px; height: 86vh; display: flex; flex-direction: column; padding: 14px;
}
.modal-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab-btn {
background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border);
padding: 5px 12px; border-radius: 4px; cursor: pointer; font-size: 0.75rem;
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
textarea.code-export {
flex: 1; background: #08090e; color: #a4b0be; border: 1px solid var(--border);
border-radius: 6px; padding: 10px; font-family: monospace; font-size: 0.75rem;
white-space: pre; overflow: auto;
}
</style>
</head>
<body>
<header>
<div class="title-group">
<span>FIGHTER STUDIO + ARENA</span>
<span class="badge">ULTIMATE EDITION</span>
<input type="text" id="charName" class="char-input" value="homelander" title="Character ID">
<!-- Image Upload -->
<input type="file" id="fileInput" accept="image/*" style="display:none;">
<button class="btn btn-sec" onclick="document.getElementById('fileInput').click()">Upload Sheet PNG</button>
<!-- JS Configs Upload (NEW) -->
<input type="file" id="jsFilesInput" accept=".js" multiple style="display:none;">
<button class="btn btn-sec" style="border-color:var(--highlight); color:var(--highlight);" onclick="document.getElementById('jsFilesInput').click()">📂 Load Character JS Files</button>
<button class="btn btn-gold" onclick="autoDetectSprites()">🔍 Auto-Detect</button>
<button class="btn btn-gold" onclick="smartAutoFillAll()">⚡ Smart Auto-Map</button>
</div>
<div class="view-tabs">
<button class="view-tab active" id="tabStudioBtn" onclick="switchView('studio')">Sprite Slicer & Baseline</button>
<button class="view-tab" id="tabArenaBtn" onclick="switchView('arena')">Interactive Arena Test</button>
</div>
<div>
<button class="btn btn-green" onclick="openExportModal()">Generate & Export JS</button>
</div>
</header>
<div class="workspace">
<!-- VIEW 1: SPRITE SLICER & STABILIZER VIEW -->
<div class="view-container" id="viewStudio">
<!-- Left Moves List -->
<div class="moves-sidebar" id="movesList"></div>
<!-- Center Sheet Canvas -->
<div class="canvas-viewport" id="sheetViewport">
<canvas id="sheetCanvas"></canvas>
<div class="viewport-hud">
<span>Zoom: <strong id="lblZoom" style="color:var(--highlight)">100%</strong></span>
<button class="btn btn-sec" onclick="changeZoom(1.2)">+</button>
<button class="btn btn-sec" onclick="changeZoom(1/1.2)">-</button>
<button class="btn btn-sec" onclick="resetZoom()">Reset View</button>
<span style="color:var(--text-muted)">| Space+Drag to Pan. Click box to assign. Del to delete.</span>
</div>
</div>
<!-- Right Tools & Ground Baseline Stabilizer -->
<div class="tools-sidebar">
<div class="tool-card">
<header>Mini Frame Preview</header>
<div style="height:140px; background:#07080b; border:1px solid var(--border); border-radius:4px; display:flex; justify-content:center; align-items:center; overflow:hidden;">
<canvas id="miniPreviewCanvas" width="160" height="140"></canvas>
</div>
<div style="display:flex; justify-content:space-between; align-items:center; margin-top:2px;">
<button class="btn btn-sec" style="flex:1;" onclick="togglePlayPreview()" id="btnPlayPause">Pause</button>
<span style="font-size:0.7rem; color:var(--text-muted); margin-left:8px;">Speed: <strong id="lblFps">8fps</strong></span>
<input type="range" id="rngFps" min="2" max="24" value="8" style="width:70px; margin-left:6px;" oninput="previewFps = parseInt(this.value); document.getElementById('lblFps').innerText = this.value + 'fps';">
</div>
</div>
<!-- Anti-Flicker Foot Grounding (ImageOffsetY) -->
<div class="tool-card">
<header>Anti-Flicker Foot Baseline (ImageOffsetY)</header>
<div style="color:var(--text-muted); font-size:0.68rem;">Short crouching/striking sprites stay planted on floor:</div>
<div style="display:flex; justify-content:space-between; margin-top:4px;">
<span>Active Frame Y-Offset:</span>
<strong id="lblCurOffsetY" style="color:var(--highlight)">0px</strong>
</div>
<input type="range" id="rngFrameOffsetY" min="-40" max="80" value="0" step="1" oninput="adjustActiveFrameOffset('y', parseInt(this.value))">
<div style="display:flex; justify-content:space-between; margin-top:4px;">
<span>Active Frame X-Offset:</span>
<strong id="lblCurOffsetX" style="color:var(--highlight)">0px</strong>
</div>
<input type="range" id="rngFrameOffsetX" min="-60" max="60" value="0" step="1" oninput="adjustActiveFrameOffset('x', parseInt(this.value))">
<div style="display:flex; gap:4px; margin-top:4px;">
<button class="btn btn-sec" style="flex:1;" onclick="autoStabilizeCurrentMove()">Auto-Align Baseline</button>
<button class="btn btn-sec" style="flex:1;" onclick="resetFrameOffsets()">Reset Offsets</button>
</div>
</div>
<div class="tool-card">
<header>Hitbox & Attack Setup</header>
<label><input type="checkbox" id="chkFrameIsHit" onchange="toggleActiveFrameHit(this.checked)"> Mark Frame as Active Attack Hit</label>
<div style="display:flex; justify-content:space-between; margin-top:4px;">
<span>Damage Power:</span>
<input type="number" id="numDamage" value="15" style="width:60px; background:#000; border:1px solid #444; color:#fff; padding:2px 4px; font-size:0.75rem;" onchange="setActiveFrameProp('damage', parseInt(this.value))">
</div>
<div style="display:flex; justify-content:space-between; margin-top:4px;">
<span>Hit Stun (ticks):</span>
<input type="number" id="numStun" value="10" style="width:60px; background:#000; border:1px solid #444; color:#fff; padding:2px 4px; font-size:0.75rem;" onchange="setActiveFrameProp('stun', parseInt(this.value))">
</div>
</div>
<div class="tool-card">
<header>Sprite Box Slicer Tools</header>
<div style="display:grid; grid-template-columns:1fr 1fr; gap:4px;">
<button class="btn btn-sec" onclick="splitSelectedBox(2)">✂️ Split in 2</button>
<button class="btn btn-sec" onclick="splitSelectedBox(3)">✂️ Split in 3</button>
</div>
<button class="btn btn-sec" style="color:var(--accent);" onclick="deleteSelectedBox()">🗑️ Delete Selected Box</button>
<button class="btn btn-sec" onclick="assignRowToActiveMove()">⚡ Assign Row to Active Move</button>
</div>
</div>
</div>
<!-- VIEW 2: INTERACTIVE COMBAT ARENA -->
<div class="view-container hidden" id="viewArena">
<div class="stage-viewport">
<div class="hud-health">
<div class="bar-container">
<div class="bar-label">
<span style="color:var(--blue);" id="lblP1Name">HOMELANDER (P1)</span>
<span id="lblP1HpVal">100%</span>
</div>
<div class="health-frame"><div class="health-fill" id="hpBarP1"></div></div>
</div>
<div style="color:var(--gold); font-weight:bold; font-size:1.4rem; text-shadow:0 0 6px #000; padding-top:4px;">VS</div>
<div class="bar-container">
<div class="bar-label">
<span style="color:var(--gold);">SAGAT (DUMMY 247px)</span>
<span id="lblDummyHpVal">100%</span>
</div>
<div class="health-frame"><div class="health-fill" id="hpBarDummy"></div></div>
</div>
</div>
<canvas id="stageCanvas" width="768" height="448"></canvas>
</div>
<!-- Arena Real-Time Controls -->
<div class="tools-sidebar" style="width:280px;">
<div class="tool-card">
<header>Engine Controls</header>
<div><span class="key">←</span> / <span class="key">→</span>: Walk Forward / Back</div>
<div><span class="key">↑</span>: Exact Parabolic Jump</div>
<div><span class="key">↓</span>: Crouch Stance</div>
<div style="margin-top:4px; color:var(--highlight); font-weight:bold;">Standing Attacks (Works while walking!):</div>
<div><span class="key">A</span>, <span class="key">S</span>, <span class="key">D</span>: Light / Med / Hard Punch</div>
<div><span class="key">Z</span>, <span class="key">X</span>, <span class="key">C</span>: Light / Med / Hard Kick</div>
<div style="margin-top:4px; color:var(--gold); font-weight:bold;">Crouching Attacks:</div>
<div><span class="key">↓</span> + <span class="key">A</span>, <span class="key">S</span>, <span class="key">D</span>: Crouch Punches</div>
<div><span class="key">↓</span> + <span class="key">Z</span>, <span class="key">X</span>, <span class="key">C</span>: Crouch Kicks</div>
<div style="margin-top:4px; color:var(--blue); font-weight:bold;">Jumping Attacks:</div>
<div><span class="key">↑</span> then <span class="key">A</span>, <span class="key">S</span>, <span class="key">D</span>: Aerial Punches</div>
<div><span class="key">↑</span> then <span class="key">Z</span>, <span class="key">X</span>, <span class="key">C</span>: Aerial Kicks</div>
<div style="margin-top:4px;"><span class="key">Q</span>: Special Heat Vision Laser</div>
</div>
<div class="tool-card">
<header>Scale Multiplier vs Sagat</header>
<div style="display:flex; justify-content:space-between;">
<span>Multiplier: <strong id="lblArenaScale" style="color:var(--highlight)">1.85x</strong></span>
<span>Height: <strong id="lblArenaHeight" style="color:var(--gold)">247px</strong></span>
</div>
<input type="range" id="rngArenaScale" min="1.0" max="3.5" step="0.05" value="1.85" oninput="setGlobalScale(this.value)">
<div style="display:flex; gap:4px; margin-top:2px;">
<button class="btn btn-sec" style="flex:1; font-size:0.68rem;" onclick="setGlobalScale(2.05)">Homelander (2.05x)</button>
<button class="btn btn-sec" style="flex:1; font-size:0.68rem;" onclick="setGlobalScale(1.85)">Sagat (1.85x)</button>
<button class="btn btn-sec" style="flex:1; font-size:0.68rem;" onclick="setGlobalScale(1.0)">1.0x (Raw)</button>
</div>
</div>
<div class="tool-card">
<header>Authentic SF2 Jump Physics</header>
<div style="display:flex; justify-content:space-between;">
<span>Launch Velocity (Vy): <strong id="lblJumpSpeed">210</strong></span>
</div>
<input type="range" id="rngJumpVy" min="140" max="260" step="5" value="210" oninput="ARENA.jumpVy = parseInt(this.value); document.getElementById('lblJumpSpeed').innerText = this.value;">
<div style="display:flex; justify-content:space-between; margin-top:4px;">
<span>Forward/Back Vx: <strong id="lblJumpVx">35</strong></span>
</div>
<input type="range" id="rngJumpVx" min="15" max="55" step="1" value="35" oninput="ARENA.jumpVx = parseInt(this.value); document.getElementById('lblJumpVx').innerText = this.value;">
</div>
<div class="tool-card">
<header>Display Options</header>
<label><input type="checkbox" id="chkInvertFlip" checked> Invert Spritesheet (Sheet Faces Left)</label>
<label><input type="checkbox" id="chkHitboxes" checked> Show Hurtboxes (Green) & Hitboxes (Red)</label>
<label><input type="checkbox" id="chkFloorLine" checked> Floor Reference & Shadows</label>
</div>
<div class="tool-card">
<header>Arena Opponent Reset</header>
<button class="btn btn-sec" onclick="resetArenaMatch()">Reset Dummy & Player</button>
</div>
</div>
</div>
</div>
<!-- Modal For JS Code Export -->
<div class="modal-backdrop" id="exportModal">
<div class="modal">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 10px;">
<h2 style="font-size:1.1rem; color:var(--gold);">100% Engine Aligned JS Exporter</h2>
<button class="btn btn-sec" onclick="closeExportModal()">Close</button>
</div>
<div class="modal-tabs">
<button class="tab-btn active" id="tabCode1" onclick="showExportTab(1)">player-[char]-spritedata.js</button>
<button class="tab-btn" id="tabCode2" onclick="showExportTab(2)">player-[char].js</button>
<button class="btn btn-green" style="margin-left:auto;" onclick="downloadExportFile()">Download Active File</button>
<button class="btn btn-sec" onclick="copyExportCode()">Copy Code</button>
</div>
<textarea class="code-export" id="txtExportCode" readonly></textarea>
</div>
</div>
<script>
/* =========================================================================
1. GLOBAL STATE & UNIFORM MOVES LIST
========================================================================= */
const GROUND_Y = 380;
const CONSTANTS = {
HALF_G: 4.903325,
Y_DAMPING: 0.1,
X_DAMPING: 0.1,
DEFAULT_JUMP_SPEED: 1.2
};
const ARENA = {
jumpVy: 210,
jumpVx: 35
};
const MOVES = [
// Basics
{ id: "stance", name: "Stance (Idle)", frames: 4, speed: 5, loop: true },
{ id: "crouch", name: "Crouch", frames: 3, speed: 2, loop: false },
{ id: "f-walk", name: "Forward Walk", frames: 6, speed: 4, loop: true },
{ id: "b-walk", name: "Back Walk", frames: 4, speed: 4, loop: true },
{ id: "jump", name: "Jump (Ascent/Apex/Fall)", frames: 4, speed: 6, loop: false },
// Standing Attacks
{ id: "p1", name: "Light Punch (LP)", frames: 3, speed: 3, loop: false },
{ id: "p2", name: "Medium Punch (MP)", frames: 3, speed: 4, loop: false },
{ id: "p3", name: "Hard Punch (HP)", frames: 3, speed: 4, loop: false },
{ id: "k1", name: "Light Kick (LK)", frames: 3, speed: 3, loop: false },
{ id: "k2", name: "Medium Kick (MK)", frames: 3, speed: 4, loop: false },
{ id: "k3", name: "Hard Kick (HK)", frames: 3, speed: 4, loop: false },
// Crouching Attacks
{ id: "c-p1", name: "Crouch Light Punch", frames: 3, speed: 2, loop: false },
{ id: "c-p2", name: "Crouch Medium Punch", frames: 3, speed: 3, loop: false },
{ id: "c-p3", name: "Crouch Hard Punch", frames: 3, speed: 4, loop: false },
{ id: "c-k1", name: "Crouch Light Kick", frames: 3, speed: 2, loop: false },
{ id: "c-k2", name: "Crouch Medium Kick", frames: 3, speed: 3, loop: false },
{ id: "c-k3", name: "Crouch Hard Kick (Sweep)", frames: 3, speed: 4, loop: false },
// Aerial Attacks
{ id: "jump_p1", name: "Jump Light Punch", frames: 2, speed: 4, loop: false },
{ id: "jump_p2", name: "Jump Medium Punch", frames: 2, speed: 4, loop: false },
{ id: "jump_p3", name: "Jump Hard Punch", frames: 2, speed: 4, loop: false },
{ id: "jump_k1", name: "Jump Light Kick", frames: 2, speed: 4, loop: false },
{ id: "jump_k2", name: "Jump Medium Kick", frames: 2, speed: 4, loop: false },
{ id: "jump_k3", name: "Jump Hard Kick", frames: 2, speed: 4, loop: false },
// Special & Reactions
{ id: "special-1", name: "Heat Vision Laser", frames: 3, speed: 5, loop: false },
{ id: "hit-sln", name: "Hit Light Reaction", frames: 2, speed: 4, loop: false },
{ id: "hit-trip", name: "Tripped / Fall", frames: 3, speed: 4, loop: false },
{ id: "down", name: "Floored / Down", frames: 1, speed: 15, loop: false },
{ id: "getup", name: "Get Up", frames: 3, speed: 4, loop: false },
{ id: "win", name: "Win Pose", frames: 3, speed: 6, loop: false }
];
let sheetCanvas, sctx, sheetViewport;
let miniCanvas, mctx;
let stageCanvas, actx;
let assignedSprites = {};
let detectedBoxes = [];
let detectedRows = [];
let selectedBox = null;
let currentMove = "stance";
let currentSlot = 0;
let globalScale = 1.85;
let sheetImg = new Image();
let sheetReady = false;
let zoom = 1.0;
let panX = 40, panY = 40;
let isPanning = false;
let startPanX = 0, startPanY = 0;
let spaceKey = false;
let isPreviewPlaying = true;
let previewFps = 8;
let previewFrame = 0;
let previewTimer = 0;
let P1 = {
x: 180, y: 0,
jumpT: 0, jumpVx: 0, jumpVy: 210, jumpSpeed: 1.2,
direction: -1,
state: "stance",
frameIdx: 0, timer: 0,
isAirborne: false, hp: 100, hitCooldown: 0, stunTicks: 0
};
let Dummy = {
x: 520, y: 0, w: 131, h: 247,
hp: 100, direction: 1, hitFlash: 0, stunTimer: 0
};
let keys = {};
/* =========================================================================
2. INITIALIZATION
========================================================================= */
function init() {
sheetCanvas = document.getElementById("sheetCanvas");
sctx = sheetCanvas.getContext("2d");
sheetViewport = document.getElementById("sheetViewport");
miniCanvas = document.getElementById("miniPreviewCanvas");
mctx = miniCanvas.getContext("2d");
stageCanvas = document.getElementById("stageCanvas");
actx = stageCanvas.getContext("2d");
// PNG Spritesheet listener
document.getElementById("fileInput").addEventListener("change", function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = ev => {
sheetImg.onload = () => {
sheetReady = true;
resetZoom();
if (Object.keys(assignedSprites).length === 0) {
autoDetectSprites();
} else {
drawSheetCanvas();
renderMiniPreview();
}
};
sheetImg.src = ev.target.result;
};
reader.readAsDataURL(file);
});
setupJSFilesImporter();
buildMovesSidebar();
setupSheetEvents();
setupArenaInputs();
setGlobalScale(2.05);
window.addEventListener("resize", resizeSheetCanvas);
resizeSheetCanvas();
requestAnimationFrame(masterLoop);
}
window.onload = init;
/* =========================================================================
3. JS FILES IMPORTER & SETTINGS RESTORER (NEW!)
========================================================================= */
function setupJSFilesImporter() {
const input = document.getElementById("jsFilesInput");
input.addEventListener("change", function(e) {
const files = Array.from(e.target.files);
if (!files.length) return;
let filesLoaded = 0;
files.forEach(file => {
const reader = new FileReader();
reader.onload = ev => {
const text = ev.target.result;
parseLoadedJSFile(text, file.name);
filesLoaded++;
if (filesLoaded === files.length) {
postImportSync();
}
};
reader.readAsText(file);
});
});
}
function parseLoadedJSFile(code, fileName) {
const isSpriteData = code.includes("spriteLookup_.load");
const isPlayerLogic = code.includes("new Player") || code.includes("createHomelander") || code.includes("addAnimation");
if (isSpriteData) {
parseSpriteDataScript(code);
}
if (isPlayerLogic) {
parsePlayerLogicScript(code);
}
}
function parseSpriteDataScript(code) {
// Regex: spriteLookup_.load("images/misc/homelander/stance-0.png", "images/misc/homelander/sprites.png", "-314px", "-290px", "72px", "132px");
const regex = /spriteLookup_\.load\s*\(\s*["']([^"']+)["']\s*,\s*["']([^"']+)["']\s*,\s*["'](-?\d+)px?["']\s*,\s*["'](-?\d+)px?["']\s*,\s*["'](\d+)px?["']\s*,\s*["'](\d+)px?["']/g;
let match;
let count = 0;
while ((match = regex.exec(code)) !== null) {
const filePath = match[1];
const x = Math.abs(parseInt(match[3]));
const y = Math.abs(parseInt(match[4]));
const w = parseInt(match[5]);
const h = parseInt(match[6]);
// Extract character name from folder if possible
const parts = filePath.split('/');
if (parts.length >= 3) {
const folderName = parts[parts.length - 2];
if (folderName && folderName !== "misc") {
document.getElementById("charName").value = folderName;
}
}
const fileNameNoExt = parts.pop().replace(/\.png$/i, "");
const dashIdx = fileNameNoExt.lastIndexOf('-');
if (dashIdx !== -1) {
const rawMove = fileNameNoExt.slice(0, dashIdx);
const frameIdx = parseInt(fileNameNoExt.slice(dashIdx + 1));
// Match to our known MOVES
const m = MOVES.find(x => x.id === rawMove || x.id.replace(/_/g, '-') === rawMove.replace(/_/g, '-'));
if (m) {
const key = `${m.id}_${frameIdx}`;
if (!assignedSprites[key]) {
assignedSprites[key] = {
x, y, w, h, offX: 0, offY: 0, hit: false, damage: 15, stun: 10
};
} else {
assignedSprites[key].x = x;
assignedSprites[key].y = y;
assignedSprites[key].w = w;
assignedSprites[key].h = h;
}
if (frameIdx >= m.frames) {
m.frames = frameIdx + 1;
}
count++;
}
}
}
}
function parsePlayerLogicScript(code) {
// 1. Character Name
const charMatch = code.match(/new\s+Player\s*\(\s*["']([^"']+)["']/i);
if (charMatch) {
document.getElementById("charName").value = charMatch[1];
document.getElementById("lblP1Name").innerText = charMatch[1].toUpperCase() + " (P1)";
}
// 2. Global Scaling Multiplier (SCALE = 2.05)
const scaleMatch = code.match(/var\s+SCALE\s*=\s*([0-9.]+)/i);
if (scaleMatch) {
setGlobalScale(parseFloat(scaleMatch[1]));
}
// 3. Jump Physics (Vy & Vx)
const vyMatch = code.match(/jump\.Vy\s*=\s*(\d+)/i);
if (vyMatch) {
ARENA.jumpVy = parseInt(vyMatch[1]);
document.getElementById("rngJumpVy").value = ARENA.jumpVy;
document.getElementById("lblJumpSpeed").innerText = ARENA.jumpVy;
P1.jumpVy = ARENA.jumpVy;
}
const vxMatch = code.match(/f_jump\.Vx\s*=\s*(-?\d+)/i);
if (vxMatch) {
ARENA.jumpVx = Math.abs(parseInt(vxMatch[1]));
document.getElementById("rngJumpVx").value = ARENA.jumpVx;
document.getElementById("lblJumpVx").innerText = ARENA.jumpVx;
}
// 4. Frame Offsets & Hitbox Properties Parser
const lines = code.split('\n');
lines.forEach(line => {
const fMatch = line.match(/f\s*\(\s*["']([^"']+)["']\s*,\s*(\d+)\s*\)/);
if (fMatch) {
const rawMove = fMatch[1];
const frameIdx = parseInt(fMatch[2]);
const m = MOVES.find(x => x.id === rawMove || x.id.replace(/_/g, '-') === rawMove.replace(/_/g, '-'));
if (m) {
const key = `${m.id}_${frameIdx}`;
if (!assignedSprites[key]) {
assignedSprites[key] = { x: 0, y: 0, w: 70, h: 130, offX: 0, offY: 0, hit: false, damage: 15, stun: 10 };
}
// Check for attack hit
if (line.includes("COMBAT_FLAGS.ATTACK") || line.includes("ATTACK_FLAGS")) {
assignedSprites[key].hit = true;
}
// Damage detection (e.g. , 15, null, 0, ...)
const dmgMatch = line.match(/,\s*(\d+)\s*,\s*(?:null|0)\s*,\s*0/);
if (dmgMatch) {
assignedSprites[key].damage = parseInt(dmgMatch[1]);
}
// ImageOffsetY parser (often located after null, 0, or at the end of args)
const offYMatch = line.match(/null\s*,\s*0\s*,\s*(-?\d+)/);
if (offYMatch) {
assignedSprites[key].offY = parseInt(offYMatch[1]);
}
// clipMove offset parser (e.g. clipMove({Front: 20}))
const clipMoveMatch = line.match(/clipMove\s*\(\s*\{\s*Front\s*:\s*(-?\d+)\s*\}\s*\)/);
if (clipMoveMatch) {
assignedSprites[key].offX = parseInt(clipMoveMatch[1]);
}
}
}
});
}
function postImportSync() {
// Re-populate slice boxes directly from the imported sprite coordinates
detectedBoxes = Object.values(assignedSprites).filter(b => b.w > 0 && b.h > 0).map(b => ({
x: b.x, y: b.y, w: b.w, h: b.h,
offX: b.offX || 0, offY: b.offY || 0,
hit: !!b.hit, damage: b.damage || 15, stun: b.stun || 10
}));
clusterIntoRows();
buildMovesSidebar();
selectMove("stance");
loadActiveFrameDetails();
drawSheetCanvas();
renderMiniPreview();
alert("Settings & Sprite Data successfully restored from your JS files!");
}
/* =========================================================================
4. UI CONTROLS & VIEWS
========================================================================= */
function switchView(viewName) {
const isStudio = (viewName === 'studio');
document.getElementById("viewStudio").classList.toggle("hidden", !isStudio);
document.getElementById("viewArena").classList.toggle("hidden", isStudio);
document.getElementById("tabStudioBtn").classList.toggle("active", isStudio);
document.getElementById("tabArenaBtn").classList.toggle("active", !isStudio);
if (isStudio) resizeSheetCanvas();
}
function buildMovesSidebar() {
const container = document.getElementById("movesList");
container.innerHTML = "";
MOVES.forEach(m => {
const row = document.createElement("div");
row.className = "move-row" + (m.id === currentMove ? " active" : "");
row.onclick = (e) => {
if (!e.target.classList.contains("frame-pill")) selectMove(m.id);
};
const header = document.createElement("div");
header.className = "move-header";
header.innerHTML = `<span>${m.name}</span><span style="font-size:0.65rem; color:var(--text-muted);">${m.frames}f</span>`;
row.appendChild(header);
const strip = document.createElement("div");
strip.className = "frame-strip";
for (let i = 0; i < m.frames; i++) {
const pill = document.createElement("div");
pill.className = "frame-pill";
pill.innerText = i;
const key = `${m.id}_${i}`;
if (assignedSprites[key]) pill.classList.add("assigned");
if (m.id === currentMove && i === currentSlot) pill.classList.add("active");
pill.onclick = (e) => {
e.stopPropagation();
selectMove(m.id);
selectSlot(i);
};
strip.appendChild(pill);
}
row.appendChild(strip);
container.appendChild(row);
});
}
function selectMove(moveId) {
currentMove = moveId;
currentSlot = 0;
buildMovesSidebar();
loadActiveFrameDetails();
}
function selectSlot(slotIdx) {
currentSlot = slotIdx;
buildMovesSidebar();
loadActiveFrameDetails();
}
function setGlobalScale(val) {
globalScale = parseFloat(val);
document.getElementById("rngArenaScale").value = globalScale;
document.getElementById("lblArenaScale").innerText = globalScale.toFixed(2) + "x";
document.getElementById("lblArenaHeight").innerText = Math.round(132 * globalScale) + "px";
renderMiniPreview();
}
/* =========================================================================
5. AUTO-DETECT & SMART MAP LOGIC
========================================================================= */
function autoDetectSprites() {
if (!sheetReady) {
alert("Upload a spritesheet PNG first!");
return;
}
const off = document.createElement("canvas");
off.width = sheetImg.width;
off.height = sheetImg.height;
const octx = off.getContext("2d");
octx.drawImage(sheetImg, 0, 0);
const imgData = octx.getImageData(0, 0, off.width, off.height).data;
const w = off.width, h = off.height;
const visited = new Uint8Array(w * h);
let rawBoxes = [];
for (let y = 0; y < h; y += 4) {
for (let x = 0; x < w; x += 4) {
const idx = y * w + x;
if (!visited[idx] && imgData[idx * 4 + 3] > 25) {
let minX = x, maxX = x, minY = y, maxY = y;
const q = [x, y];
visited[idx] = 1;
let ptr = 0;
while (ptr < q.length) {
const cx = q[ptr++];
const cy = q[ptr++];
if (cx < minX) minX = cx;
if (cx > maxX) maxX = cx;
if (cy < minY) minY = cy;
if (cy > maxY) maxY = cy;
const nbrs = [[cx + 4, cy], [cx - 4, cy], [cx, cy + 4], [cx, cy - 4]];
for (let n = 0; n < nbrs.length; n++) {
const nx = nbrs[n][0], ny = nbrs[n][1];
if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
const nidx = ny * w + nx;
if (!visited[nidx] && imgData[nidx * 4 + 3] > 25) {
visited[nidx] = 1;
q.push(nx, ny);
}
}
}
}
const bw = maxX - minX;
const bh = maxY - minY;
if (bw > 20 && bh > 30) {
rawBoxes.push({
x: Math.max(0, minX - 2),
y: Math.max(0, minY - 2),
w: Math.min(w - minX, bw + 4),
h: Math.min(h - minY, bh + 4),
offX: 0, offY: 0, hit: false, damage: 15, stun: 10
});
}
}
}
}
if (rawBoxes.length > 6) {
const medH = [...rawBoxes].map(b => b.h).sort((a,b) => a - b)[Math.floor(rawBoxes.length / 2)];
rawBoxes = rawBoxes.filter(b => b.h >= medH * 0.45 && b.h <= medH * 1.85 && b.w <= 400);
}
detectedBoxes = rawBoxes;
clusterIntoRows();
drawSheetCanvas();
}
function clusterIntoRows() {
if (!detectedBoxes.length) { detectedRows = []; return; }
detectedBoxes.sort((a, b) => a.y - b.y);
let rows = [];
let curRow = [detectedBoxes[0]];
let curY = detectedBoxes[0].y;
for (let i = 1; i < detectedBoxes.length; i++) {
const b = detectedBoxes[i];
if (Math.abs(b.y - curY) < 38) {
curRow.push(b);
} else {
curRow.sort((a, b) => a.x - b.x);
rows.push(curRow);
curRow = [b];
curY = b.y;
}
}
if (curRow.length) {
curRow.sort((a, b) => a.x - b.x);
rows.push(curRow);
}
detectedRows = rows;
detectedBoxes = rows.flat();
}
function smartAutoFillAll() {
if (!sheetReady || detectedRows.length === 0) autoDetectSprites();
assignedSprites = {};
if (detectedRows[0]) {
assignSliceToMove("stance", detectedRows[0].slice(0, 4));
if (detectedRows[0].length > 4) assignSliceToMove("crouch", detectedRows[0].slice(4, 7));
}
if (detectedRows[1]) {
assignSliceToMove("f-walk", detectedRows[1].slice(0, 6));
if (detectedRows[1].length > 6) assignSliceToMove("b-walk", detectedRows[1].slice(6, 10));
}
if (detectedRows[2]) assignSliceToMove("jump", detectedRows[2].slice(0, 4));
if (detectedRows[3]) {
assignSliceToMove("p1", detectedRows[3].slice(0, 3));
assignSliceToMove("p2", detectedRows[3].slice(3, 6));
assignSliceToMove("p3", detectedRows[3].slice(6, 9));
}
if (detectedRows[4]) {
assignSliceToMove("k1", detectedRows[4].slice(0, 3));
assignSliceToMove("k2", detectedRows[4].slice(3, 6));
assignSliceToMove("k3", detectedRows[4].slice(6, 9));
}
if (detectedRows[5]) {
assignSliceToMove("c-p1", detectedRows[5].slice(0, 3));
assignSliceToMove("c-p2", detectedRows[5].slice(3, 6));
assignSliceToMove("c-p3", detectedRows[5].slice(6, 9));
}
if (detectedRows[6]) {
assignSliceToMove("c-k1", detectedRows[6].slice(0, 3));
assignSliceToMove("c-k2", detectedRows[6].slice(3, 6));
assignSliceToMove("c-k3", detectedRows[6].slice(6, 9));
}
if (detectedRows[7]) {
assignSliceToMove("jump_p1", detectedRows[7].slice(0, 2));
assignSliceToMove("jump_p2", detectedRows[7].slice(2, 4));
assignSliceToMove("jump_p3", detectedRows[7].slice(4, 6));
}
if (detectedRows[8]) {
assignSliceToMove("jump_k1", detectedRows[8].slice(0, 2));
assignSliceToMove("jump_k2", detectedRows[8].slice(2, 4));
assignSliceToMove("jump_k3", detectedRows[8].slice(4, 6));
}
if (detectedRows[9]) assignSliceToMove("special-1", detectedRows[9].slice(0, 3));
if (detectedRows[10]) {
assignSliceToMove("hit-sln", detectedRows[10].slice(0, 2));
if (detectedRows[10].length > 2) assignSliceToMove("hit-trip", detectedRows[10].slice(2, 5));
}
if (detectedRows[11]) {
assignSliceToMove("down", detectedRows[11].slice(0, 1));
if (detectedRows[11].length > 1) assignSliceToMove("getup", detectedRows[11].slice(1, 4));
}
if (detectedRows[12]) assignSliceToMove("win", detectedRows[12].slice(0, 3));
markHitActive("p1", 1, 10, 8); markHitActive("p2", 1, 15, 10); markHitActive("p3", 1, 20, 12);
markHitActive("k1", 1, 10, 8); markHitActive("k2", 1, 15, 10); markHitActive("k3", 1, 20, 12);
markHitActive("c-p1", 1, 10, 8); markHitActive("c-p2", 1, 15, 10); markHitActive("c-p3", 1, 20, 12);
markHitActive("c-k1", 1, 10, 8); markHitActive("c-k2", 1, 15, 10); markHitActive("c-k3", 1, 20, 14);
markHitActive("jump_p1", 1, 10, 8); markHitActive("jump_p2", 1, 15, 10); markHitActive("jump_p3", 1, 20, 12);
markHitActive("jump_k1", 1, 10, 8); markHitActive("jump_k2", 1, 15, 10); markHitActive("jump_k3", 1, 20, 12);
markHitActive("special-1", 1, 25, 16);
MOVES.forEach(m => autoStabilizeMoveBaseline(m.id));
buildMovesSidebar();
selectMove("stance");
drawSheetCanvas();
renderMiniPreview();
alert("Smart Mapping complete!");
}
function assignSliceToMove(moveId, boxList) {
const m = MOVES.find(x => x.id === moveId);
if (!m || !boxList.length) return;
m.frames = boxList.length;
boxList.forEach((box, i) => {
assignedSprites[`${moveId}_${i}`] = {
x: box.x, y: box.y, w: box.w, h: box.h,
offX: box.offX || 0,
offY: box.offY || 0,
hit: !!box.hit,
damage: box.damage || 15,
stun: box.stun || 10
};
});
}
function markHitActive(moveId, frameIdx, dmg, stun) {
const key = `${moveId}_${frameIdx}`;
if (assignedSprites[key]) {
assignedSprites[key].hit = true;
assignedSprites[key].damage = dmg;
assignedSprites[key].stun = stun;
}
}
function autoStabilizeMoveBaseline(moveId) {
const m = MOVES.find(x => x.id === moveId);
if (!m) return;
let baseH = 132;
const s0 = assignedSprites["stance_0"];
if (s0) baseH = s0.h;
for (let i = 0; i < m.frames; i++) {
const b = assignedSprites[`${moveId}_${i}`];
if (b) {
b.offY = (baseH - b.h);
}
}
}
function autoStabilizeCurrentMove() {
autoStabilizeMoveBaseline(currentMove);