-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
5076 lines (4114 loc) · 186 KB
/
Copy pathapp.js
File metadata and controls
5076 lines (4114 loc) · 186 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
// KingBell on ItchIO
// BellBlitzKing@gmail.com
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
const pad2 = (n) => ("000" + n).slice(-2);
const b2Hex = (r, g, b) => ( "#" +
pad2(r.toString(16)) +
pad2(g.toString(16)) +
pad2(b.toString(16))
);
const hex2R = (hex) => parseInt(hex.slice(1, 3), 16);
const hex2G = (hex) => parseInt(hex.slice(3, 5), 16);
const hex2B = (hex) => parseInt(hex.slice(5, 7), 16);
const hex2Arr = (h) => [hex2R(h), hex2G(h), hex2B(h)];
const img2b64 = (img) => {
const canvas = document.createElement('canvas');
//const ctx = canvas.getContext('2d'); //this was updated to prevent a warning on GetContext.
const ctx = canvas.getContext("2d", { willReadFrequently: true });
canvas.height = img.naturalHeight;
canvas.width = img.naturalWidth;
ctx.drawImage(img, 0, 0);
return canvas.toDataURL("image/png").replace("data:image/png;base64,", "");
}
const getData = async (filename) => {
const resp = await fetch(filename);
const buf = await resp.arrayBuffer();
loadZip(buf);
}
const loadZip = (buf) => {
const data = new Uint8Array(buf)
JSZip.loadAsync(data).then((zip) => {
zip.file("conf.json").async("string").then((str) => {
const conf = JSON.parse(str);
setupConf(conf, zip.files);
});
}).catch(function(err) {
console.error("Failed to open", filename, " as ZIP file:", err);
});
}
{
let configFileInput = $("#importconfig");
configFileInput.onchange = () => {
const file = configFileInput.files[0];
const fr = new FileReader();
fr.addEventListener("load", () => {
console.log(fr.result);
loadZip(fr.result);
configFileInput.value = "";
}, false);
fr.readAsArrayBuffer(file);
}
}
//This GetData is only relevant when on a server to load a .zip at startup.
getData("./data/Import_config_Hero.zip");
//getData("./data/default.zip");
//getData("./data/Archive.zip");
//getData("Start_ImportMe_pixelconfig_template.zip");
// Update below for new anim. Add anim, frame name, frame count and modF anim frame return. (Anim Part 1)
const State = {
anim: "base_run", // "stand", "idle", "run", "hurt", "die", Defaul animation after loading in
base: 0,
head: Math.floor(Math.random() * (163 - 0 + 1)) + 0,
face: 0,
getAnimX0: function(animName, frame) {
if (animName == "base_stand") return 0 + frame;
if (animName == "base_idle") return 2 + frame;
if (animName == "base_run") return 7 + frame;
if (animName == "base_hurt") return 12 + frame;
if (animName == "base_die") return 17 + frame;
if (animName == "base_press") return 22 + frame;
if (animName == "jump") return 28 + frame;
if (animName == "jump_hop") return 35 + frame;
if (animName == "jump_double") return 42 + frame;
if (animName == "run_ninja") return 51 + frame;
if (animName == "run_one") return 58 + frame;
if (animName == "run_two") return 63 + frame;
if (animName == "run_wobble") return 68 + frame;
if (animName == "run_leap") return 75 + frame;
if (animName == "duck") return 82 + frame;
if (animName == "duck_pose") return 89 + frame;
if (animName == "re_spawn") return 91 + frame;
if (animName == "re_teleport") return 98 + frame;
if (animName == "re_warp") return 103 + frame;
if (animName == "re_land") return 115 + frame;
if (animName == "re_drop") return 120 + frame;
if (animName == "re_hard") return 125 + frame;
if (animName == "re_squash") return 130 + frame;
if (animName == "air_one") return 136 + frame;
if (animName == "air_two") return 141 + frame;
if (animName == "air_three") return 146 + frame;
if (animName == "air_four") return 148 + frame;
if (animName == "air_five") return 150 + frame;
if (animName == "air_six") return 152 + frame;
if (animName == "knock_up_one") return 154 + frame;
if (animName == "knock_up_two") return 159 + frame;
if (animName == "knock_back_one") return 164 + frame;
if (animName == "knock_back_two") return 169 + frame;
if (animName == "knock_down_one") return 174 + frame;
if (animName == "knock_down_two") return 179 + frame;
if (animName == "life_rest") return 184 + frame;
if (animName == "life_heal") return 193 + frame;
if (animName == "life_sleep") return 200 + frame;
if (animName == "fly_idle_one") return 207 + frame;
if (animName == "fly_idle_two") return 212 + frame;
if (animName == "fly_up_one") return 217 + frame;
if (animName == "fly_up_two") return 222 + frame;
if (animName == "fly_run_one") return 227 + frame;
if (animName == "fly_run_two") return 233 + frame;
if (animName == "dash_one") return 239 + frame;
if (animName == "dash_two") return 244 + frame;
if (animName == "dash_pose_one") return 249 + frame;
if (animName == "dash_pose_two") return 251 + frame;
if (animName == "dash_flash_step_one") return 253 + frame;
if (animName == "dash_flash_step_two") return 257 + frame;
if (animName == "spell_fire") return 261 + frame;
if (animName == "spell_charge") return 267 + frame;
if (animName == "spell_charge_staff") return 275 + frame;
if (animName == "spell_charge_wand") return 283 + frame;
if (animName == "spell_casting") return 291 + frame;
if (animName == "spell_pose") return 300 + frame;
if (animName == "hurt_one") return 302 + frame;
if (animName == "hurt_skull") return 307 + frame;
if (animName == "hurt_tear") return 312 + frame;
if (animName == "hurt_blink") return 317 + frame;
if (animName == "hurt_air_one") return 322 + frame;
if (animName == "hurt_air_two") return 324 + frame;
if (animName == "die_one") return 326 + frame;
if (animName == "die_shrink") return 331 + frame;
if (animName == "die_head") return 336 + frame;
if (animName == "die_skull") return 343 + frame;
if (animName == "die_poof") return 351 + frame;
if (animName == "die_smoke") return 356 + frame;
if (animName == "die_spark") return 363 + frame;
if (animName == "die_explode") return 372 + frame;
if (animName == "die_melt") return 384 + frame;
if (animName == "die_melt_effect") return 393 + frame;
if (animName == "die_soul") return 402 + frame;
if (animName == "die_drown") return 412 + frame;
if (animName == "die_sink") return 422 + frame;
if (animName == "die_sink_trap") return 431 + frame;
if (animName == "swim_idle_one") return 440 + frame;
if (animName == "swim_idle_two") return 447 + frame;
if (animName == "swim_idle_three") return 454 + frame;
if (animName == "swim_idle_four") return 461 + frame;
if (animName == "swim_idle_five") return 468 + frame;
if (animName == "swim_idle_six") return 473 + frame;
if (animName == "swim_idle_seven") return 478 + frame;
if (animName == "swim_idle_eight") return 483 + frame;
if (animName == "swim_move_one") return 488 + frame;
if (animName == "swim_move_two") return 493 + frame;
if (animName == "swim_move_three") return 500 + frame;
if (animName == "swim_move_four") return 505 + frame;
if (animName == "swim_arms_one") return 510 + frame;
if (animName == "swim_arms_two") return 515 + frame;
if (animName == "swim_arms_three") return 520 + frame;
if (animName == "swim_arms_four") return 525 + frame;
if (animName == "weapon_sword_idle") return 530 + frame;
if (animName == "weapon_shield_idle") return 535 + frame;
if (animName == "weapon_staff_idle") return 540 + frame;
if (animName == "weapon_wand_idle") return 545 + frame;
if (animName == "weapon_bow_tall_idle") return 550 + frame;
if (animName == "weapon_bow_short_idle") return 555 + frame;
if (animName == "weapon_sword_run") return 560 + frame;
if (animName == "weapon_shield_run") return 565 + frame;
if (animName == "weapon_staff_run") return 570 + frame;
if (animName == "weapon_wand_run") return 575 + frame;
if (animName == "weapon_bow_tall_run") return 580 + frame;
if (animName == "weapon_bow_short_run") return 585 + frame;
if (animName == "weapon_bow_tall_fire_fast") return 590 + frame;
if (animName == "weapon_bow_tall_fire_slow") return 596 + frame;
if (animName == "weapon_bow_tall_fire_fast_bag") return 603 + frame;
if (animName == "weapon_bow_tall_fire_slow_bag") return 609 + frame;
if (animName == "weapon_bow_short_fire_fast") return 616 + frame;
if (animName == "weapon_bow_short_fire_slow") return 622 + frame;
if (animName == "weapon_bow_short_fire_fast_bag") return 629 + frame;
if (animName == "weapon_bow_short_fire_slow_bag") return 635 + frame;
if (animName == "base_stands") return 642 + frame;
if (animName == "die_extended") return 651 + frame;
if (animName == "weapon_sword_atk_melee") return 662 + frame;
if (animName == "weapon_staff_atk_melee") return 669 + frame;
if (animName == "weapon_wand_atk_melee") return 676 + frame;
if (animName == "weapon_shield_atk_melee") return 683 + frame;
if (animName == "weapon_staff_atk_fire") return 692 + frame;
if (animName == "weapon_wand_atk_fire") return 698 + frame;
return 0;
},
modF: function(f) {
if (this.anim == "base_stand") return (f % 1);
if (this.anim == "base_idle") return (f % 4);
if (this.anim == "base_run") return (f % 4);
if (this.anim == "base_hurt") return (f % 4);
if (this.anim == "base_die") return (f % 4);
if (this.anim == "base_press") return (f % 5);
if (this.anim == "jump") return (f % 6);
if (this.anim == "jump_hop") return (f % 6);
if (this.anim == "jump_double") return (f % 8);
if (this.anim == "run_ninja") return (f % 6);
if (this.anim == "run_one") return (f % 4);
if (this.anim == "run_two") return (f % 4);
if (this.anim == "run_wobble") return (f % 6);
if (this.anim == "run_leap") return (f % 6);
if (this.anim == "duck") return (f % 6);
if (this.anim == "duck_pose") return (f % 1);
if (this.anim == "re_spawn") return (f % 6);
if (this.anim == "re_teleport") return (f % 4);
if (this.anim == "re_warp") return (f % 11);
if (this.anim == "re_land") return (f % 4);
if (this.anim == "re_drop") return (f % 4);
if (this.anim == "re_hard") return (f % 4);
if (this.anim == "re_squash") return (f % 5);
if (this.anim == "air_one") return (f % 4);
if (this.anim == "air_two") return (f % 4);
if (this.anim == "air_three") return (f % 1);
if (this.anim == "air_four") return (f % 1);
if (this.anim == "air_five") return (f % 1);
if (this.anim == "air_six") return (f % 1);
if (this.anim == "knock_up_one") return (f % 4);
if (this.anim == "knock_up_two") return (f % 4);
if (this.anim == "knock_back_one") return (f % 4);
if (this.anim == "knock_back_two") return (f % 4);
if (this.anim == "knock_down_one") return (f % 4);
if (this.anim == "knock_down_two") return (f % 4);
if (this.anim == "life_rest") return (f % 8);
if (this.anim == "life_heal") return (f % 6);
if (this.anim == "life_sleep") return (f % 6);
if (this.anim == "fly_idle_one") return (f % 4);
if (this.anim == "fly_idle_two") return (f % 4);
if (this.anim == "fly_up_one") return (f % 4);
if (this.anim == "fly_up_two") return (f % 4);
if (this.anim == "fly_run_one") return (f % 5);
if (this.anim == "fly_run_two") return (f % 5);
if (this.anim == "dash_one") return (f % 4);
if (this.anim == "dash_two") return (f % 4);
if (this.anim == "dash_pose_one") return (f % 1);
if (this.anim == "dash_pose_two") return (f % 1);
if (this.anim == "dash_flash_step_one") return (f % 3);
if (this.anim == "dash_flash_step_two") return (f % 3);
if (this.anim == "spell_fire") return (f % 5);
if (this.anim == "spell_charge") return (f % 7);
if (this.anim == "spell_charge_staff") return (f % 7);
if (this.anim == "spell_charge_wand") return (f % 7);
if (this.anim == "spell_casting") return (f % 8);
if (this.anim == "spell_pose") return (f % 1);
if (this.anim == "hurt_one") return (f % 4);
if (this.anim == "hurt_skull") return (f % 4);
if (this.anim == "hurt_tear") return (f % 4);
if (this.anim == "hurt_blink") return (f % 4);
if (this.anim == "hurt_air_one") return (f % 1);
if (this.anim == "hurt_air_two") return (f % 1);
if (this.anim == "die_one") return (f % 4);
if (this.anim == "die_shrink") return (f % 4);
if (this.anim == "die_head") return (f % 6);
if (this.anim == "die_skull") return (f % 7);
if (this.anim == "die_poof") return (f % 4);
if (this.anim == "die_smoke") return (f % 6);
if (this.anim == "die_spark") return (f % 8);
if (this.anim == "die_explode") return (f % 11);
if (this.anim == "die_melt") return (f % 8);
if (this.anim == "die_melt_effect") return (f % 8);
if (this.anim == "die_soul") return (f % 9);
if (this.anim == "die_drown") return (f % 9);
if (this.anim == "die_sink") return (f % 8);
if (this.anim == "die_sink_trap") return (f % 8);
if (this.anim == "swim_idle_one") return (f % 6);
if (this.anim == "swim_idle_two") return (f % 6);
if (this.anim == "swim_idle_three") return (f % 6);
if (this.anim == "swim_idle_four") return (f % 6);
if (this.anim == "swim_idle_five") return (f % 4);
if (this.anim == "swim_idle_six") return (f % 4);
if (this.anim == "swim_idle_seven") return (f % 4);
if (this.anim == "swim_idle_eight") return (f % 4);
if (this.anim == "swim_move_one") return (f % 4);
if (this.anim == "swim_move_two") return (f % 6);
if (this.anim == "swim_move_three") return (f % 4);
if (this.anim == "swim_move_four") return (f % 4);
if (this.anim == "swim_arms_one") return (f % 4);
if (this.anim == "swim_arms_two") return (f % 4);
if (this.anim == "swim_arms_three") return (f % 4);
if (this.anim == "swim_arms_four") return (f % 4);
if (this.anim == "weapon_sword_idle") return (f % 4);
if (this.anim == "weapon_shield_idle") return (f % 4);
if (this.anim == "weapon_staff_idle") return (f % 4);
if (this.anim == "weapon_wand_idle") return (f % 4);
if (this.anim == "weapon_bow_tall_idle") return (f % 4);
if (this.anim == "weapon_bow_short_idle") return (f % 4);
if (this.anim == "weapon_sword_run") return (f % 4);
if (this.anim == "weapon_shield_run") return (f % 4);
if (this.anim == "weapon_staff_run") return (f % 4);
if (this.anim == "weapon_wand_run") return (f % 4);
if (this.anim == "weapon_bow_tall_run") return (f % 4);
if (this.anim == "weapon_bow_short_run") return (f % 4);
if (this.anim == "weapon_bow_tall_fire_fast") return (f % 5);
if (this.anim == "weapon_bow_tall_fire_slow") return (f % 6);
if (this.anim == "weapon_bow_tall_fire_fast_bag") return (f % 5);
if (this.anim == "weapon_bow_tall_fire_slow_bag") return (f % 6);
if (this.anim == "weapon_bow_short_fire_fast") return (f % 5);
if (this.anim == "weapon_bow_short_fire_slow") return (f % 6);
if (this.anim == "weapon_bow_short_fire_fast_bag") return (f % 5);
if (this.anim == "weapon_bow_short_fire_slow_bag") return (f % 6);
if (this.anim == "die_extended") return (f % 10);
if (this.anim == "base_stands") return (f % 8);
if (this.anim == "weapon_sword_atk_melee") return (f % 6);
if (this.anim == "weapon_staff_atk_melee") return (f % 6);
if (this.anim == "weapon_wand_atk_melee") return (f % 6);
if (this.anim == "weapon_shield_atk_melee") return (f % 8);
if (this.anim == "weapon_staff_atk_fire") return (f % 5);
if (this.anim == "weapon_wand_atk_fire") return (f % 5);
return 0;
},
readFromUi: function() {
this.base = +Parts.els.bases.value;
this.head = +Parts.els.heads.value;
this.face = +Parts.els.faces.value;
}
};
const Conf = {
data: {},
getW: function() { return this.data.w || 16; },
getH: function() { return this.data.h || 16; },
getOy: function(key, anim, frame)
{
const d = this.data;
if (!d || !d.parts || !d.parts[key]) return 0;
const p = d.parts[key];
if (!p || !p[anim]) return 0;
return p[anim][frame] || 0;
},
shadowSuit: function() { return this.data.suitShadowMod || 0.5; },
shadowItem: function() { return this.data.itemShadowMod || 0.5; },
shadowBody: function() { return this.data.bodyShadowMod || 0.5; },
shadowMore: function() { return this.data.moreShadowMod || 0.5; },
};
let outlineColorComponent;
const setupConf = (conf, files) => {
Conf.data = conf;
sliderShadowModsAllSetup();
const cc = ColorComponent(conf.outlineColor,
(rgb) => (Conf.data.outlineColor = rgb));
cc.el.style.display = "inlie-block";
$("#color_outline").innerText = "";
$("#color_outline").append(cc.el);
outlineColorComponent = cc;
Pal.all.eyes.setColors(conf.pals.eyes);
Pal.all.body.setColors(conf.pals.body);
Pal.all.item.setColors(conf.pals.item);
Pal.all.suit.setColors(conf.pals.suit);
Pal.all.more.setColors(conf.pals.more);
// parts
Parts.reset();
console.assert(files["base.png"], "base.png expected");
console.assert(files["heads.png"], "heads.png expected");
console.assert(files["faces.png"], "faces.png expected");
Parts.addBase(files["base.png"]);
Parts.addHead(files["heads.png"]);
Parts.addFace(files["faces.png"]);
//_____________________________________________________________________________________________________ADD-ONS // Copy to Line 404 general populating area
document.getElementById('set_pal_reset_outline').style.display = 'inline-block'; //reset outline buttion hidden by default. Show it after Conf is setup.
document.getElementById('set_pal_shift').style.display = 'inline-block';
document.getElementById("details_shadow").removeAttribute("open");
//document.getElementById("details_color").removeAttribute("open");
document.getElementById("details_export").removeAttribute("open");
//window.location = "#details";
// const _png = (prefix, n) => (n.startsWith(prefix) && n.endsWith(".png"));
// for (let name in files) {
// if (_png("head_", name)) Parts.addHead(files[name]);
// else if (_png("face_", name)) Parts.addFace(files[name]);
// else if (_png("base_", name))
// // else ignore!
// }
}
const b64_to_img = (b64, onload) => {
const img = new Image();
img.src = "data:image/png;base64," + b64;
img.onload = () => onload(img);
}
const setupPalette = (pal, pal64) => {
b64_to_img(pal64, (img) => {
const canvas = document.createElement("canvas");
canvas.height = 1;
canvas.width = Math.min(64, img.width);
//const ctx = canvas.getContext("2d");
const ctx = canvas.getContext("2d", { willReadFrequently: true });
ctx.drawImage(img, 0, 0);
const id = ctx.getImageData(0, 0, img.width, img.height).data;
for (let i=0; i<img.width*4; i+=4) {
pal.addColor(b2Hex(id[i+0], id[i+1], id[i+2]));
}
pal.render();
});
}
const Pal = (key, sel) => {
Pal.all = Pal.all || {};
Pal.all[key] = {
el: $(sel),
active: "",
isLocked: false,
colors: [],
resetColors: function() { this.colors = []; },
addColor: function(c) { this.colors.push(c); },
setColors: function(arr) {
this.colors = arr;
this.render();
this.randomize();
},
mkBtn: function(itemsEl, hex) {
const c = document.createElement("button");
this.btns.push(c);
c.className = "palItem";
c.dataset.color = hex;
c.style.background = hex;
itemsEl.append(c);
c.onclick = (e) => {
this.active = c.dataset.color;
this.activeBtn = c;
this.refreshActive();
this.colorComponent.set(c.dataset.color);
this.activeR = hex2R(this.active);
this.activeG = hex2G(this.active);
this.activeB = hex2B(this.active);
}
return c;
},
render: function() {
this.el.innerText = "";
const locked = document.createElement("input");
locked.type = "checkbox";
locked.checked = !!this.isLocked;
locked.onchange = () => (this.isLocked = locked.checked);
const label = document.createElement("text");
label.className = "lock";
label.append(locked);
label.append(document.createElement("span"));
label.append(" " + key + " ")
//const more = document.createElement("button");
//more.innerText = "edit▮";
//more.style.margin = "0 10px";
//more.className = "btn sm";
const more = document.createElement("button");
more.innerText = "";
more.style.margin = "0 -6px";
more.className = "";
more.style.visibility = "hidden";
const itemsEl = document.createElement("div");
this.itemsEl = itemsEl;
itemsEl.className = "palItems";
itemsEl.append(label);
itemsEl.append(more);
this.el.append(itemsEl);
this.btns = [];
this.colors.forEach((hex) => {
this.mkBtn(itemsEl, hex);
});
this.colorComponent = ColorComponent(this.colors[0] || "#000000", (rgb, hex) => {
const idx = this.btns.indexOf(this.activeBtn);
this.colors[idx] = hex;
this.activeBtn.style.background = hex;
this.activeBtn.dataset.color = hex;
this.active = hex;
this.activeR = hex2R(this.active);
this.activeG = hex2G(this.active);
this.activeB = hex2B(this.active);
});
this.colorComponent.el.style.paddingLeft = "90px";
//this.colorComponent.toggle();
this.colorComponentWrap = document.createElement("div");
this.colorComponentWrap.append(this.colorComponent.el);
this.el.append(this.colorComponentWrap);
more.onclick = () => {
const n = this.colorComponentWrap.style.display !== "none";
this.colorComponentWrap.style.display = n ? "none" : "inline-block";
}
more.onclick();
this.colorComponentWrap.append(" :: ");
const rem = document.createElement("button");
rem.className = "btn sm";
rem.innerText = "delete▮";
rem.onclick = () => this.removeActive();
this.colorComponentWrap.append(rem);
this.colorComponentWrap.append(" ");
const dup = document.createElement("button");
dup.className = "btn sm";
dup.innerText = "clone▮";
dup.onclick = () => this.dupActive();
this.colorComponentWrap.append(dup);
},
dupActive: function() {
this.colors.push(this.active);
const c = this.mkBtn(this.itemsEl, this.active);
this.activeBtn = c;
this.refreshActive();
},
removeActive: function() {
if (this.btns.length <= 1) return;
const idx = this.btns.indexOf(this.activeBtn);
this.activeBtn.parentNode.removeChild(this.activeBtn);
this.btns.splice(idx, 1);
this.colors.splice(idx, 1);
const other = this.btns[Math.min(this.btns.length - 1, idx)];
this.activeBtn = other;
this.refreshActive();
},
refreshActive: function() {
this.el.querySelectorAll(".active").forEach(it => it.classList.remove("active"));
this.activeBtn.classList.add("active");
this.active = this.activeBtn.dataset.color;
this.activeR = hex2R(this.active);
this.activeG = hex2G(this.active);
this.activeB = hex2B(this.active);
// show
},
randomize: function() {
if (this.isLocked) return;
if (!this.btns) return;
const idx = parseInt(this.colors.length * Math.random());
this.active = this.colors[idx];
this.activeBtn = this.btns[idx];
this.refreshActive();
this.colorComponent.set(this.active);
this.activeR = hex2R(this.active);
this.activeG = hex2G(this.active);
this.activeB = hex2B(this.active);
}
};
return Pal.all[key];
}
Pal.renderAll = () => Object.values(Pal.all).forEach((it) => it.render());
const palBody = Pal("eyes", "#palBody");
const palEyes = Pal("body", "#palEyes");
const palMore = Pal("more", "#palMore");
const palSuit = Pal("suit", "#palSuit");
const palItem = Pal("item", "#palItem");
const b64ImagesCache = {};
const Parts = {
uuid: 0x72, // If you read this: Have a nice day! :)
heads: [],
faces: [],
els: {
heads: $("#sliderHeads"),
faces: $("#sliderFaces"),
bases: $("#sliderBases"),
},
reset: function() {
Object.values(this.els).forEach(it => (it.max = 0));
},
_load: (file, fn) => file.async("base64").then((b64) => b64_to_img(b64, fn)),
addFace: function(file) {
this._load(file, (img) => {
this.facesImg = img;
b64ImagesCache.faces = img2b64(img);
this.els.faces.max = parseInt(img.width / Conf.data.w) - 1;
randomizeAllMaybe();
});
},
addHead: function(file) {
this._load(file, (img) => {
this.headsImg = img;
b64ImagesCache.heads = img2b64(img);
this.els.heads.max = parseInt(img.width / Conf.data.w) - 1;
randomizeAllMaybe();
});
},
addBase: function(file) {
this._load(file, (img) => {
this.baseImg = img;
b64ImagesCache.base = img2b64(img);
this.els.bases.max = parseInt(img.height / Conf.data.h) - 1; // note: h!
randomizeAllMaybe();
});
},
}
const onslide = (el, fn) => {
el.addEventListener("change", () => fn(+el.value));
el.addEventListener("input", () => fn(+el.value));
}
onslide(Parts.els.bases, (val) => (State.base = val));
onslide(Parts.els.heads, (val) => (State.head = val));
onslide(Parts.els.faces, (val) => (State.face = val));
//_____________________________________________________________________________________________________ADD-ONS
document.getElementById("inputSliderBases").value = document.getElementById("sliderBases").value;
document.getElementById("inputSliderBases").max = document.getElementById("sliderBases").max;
document.getElementById("inputSliderBases").min = document.getElementById("sliderBases").min;
document.getElementById("inputSliderHeads").value = document.getElementById("sliderHeads").value;
document.getElementById("inputSliderHeads").max = document.getElementById("sliderHeads").max;
document.getElementById("inputSliderHeads").min = document.getElementById("sliderHeads").min;
document.getElementById("inputSliderFaces").value = document.getElementById("sliderFaces").value;
document.getElementById("inputSliderFaces").max = document.getElementById("sliderFaces").max;
document.getElementById("inputSliderFaces").min = document.getElementById("sliderFaces").min;
//Parts.els.faces.value = 0;
//State.face = 0;
//document.getElementById("inputSliderFaces").value = 0;
//document.getElementById("sliderFaces").value = 0;
document.getElementById("sharecode").textContent = "Share: " + document.getElementById("sliderBases").value + " " + document.getElementById("sliderHeads").value + " " + document.getElementById("sliderFaces").value;
// damn not sure why but it's kinda broken on windows (even the same browser O.o)
const isSame = (x, y) => x === y || x === y-1 || x === y+1;
const isAboutSameRgb = (col, r, g, b) => isSame(col[0], r) && isSame(col[1], g) && isSame(col[2], b);
const Canvas = {
c: $("#c"),
//ctx: $("#c").getContext("2d"),
ctx: $("#c").getContext("2d", { willReadFrequently: true }),
scale: 10,
w: 16,
h: 24,
clear: function(ctx) { ctx.clearRect(0, 0, this.w, this.h); },
reset: function() {
this.c.width = this.w;
this.c.height = this.h;
this.c.style.width = (this.w * this.scale) + "px";
this.c.style.height = (this.h * this.scale) + "px";
},
blit: function(ctx, img, x, y)
{
if (!img || typeof(img) === "number") return;
ctx.drawImage(img, x, y);
},
blitAll: function(ctx, frame, animName) {
this.clear(ctx);
this.blit(ctx, Parts.baseImg,
-State.getAnimX0(animName, frame) * Conf.getW(),
-State.base * Conf.getH()
);
this.blit(ctx, Parts.headsImg,
-State.head * Conf.getW(),
Conf.getOy("head", animName, frame)
);
this.blit(ctx, Parts.facesImg,
-State.face * Conf.getW(),
Conf.getOy("face", animName, frame)
);
this.recolor(ctx);
},
recolor: function(ctx) {
var imd = ctx.getImageData(0, 0, this.w, this.h);
var data = imd.data;
const fc = Conf.data.fromColors;
if (!fc) return;
for (let i=0; i<data.length*4; i+=4)
{
const _r = data[i+0];
const _g = data[i+1];
const _b = data[i+2];
// outline
if (isAboutSameRgb(fc.outline, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Conf.data.outlineColor[0];
data[i+1] = Conf.data.outlineColor[1];
data[i+2] = Conf.data.outlineColor[2];
}
// eyes
else if (isAboutSameRgb(fc.eyes, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Pal.all.eyes.activeR;
data[i+1] = Pal.all.eyes.activeG;
data[i+2] = Pal.all.eyes.activeB;
}
// skin
else if (isAboutSameRgb(fc.skin, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Pal.all.body.activeR;
data[i+1] = Pal.all.body.activeG;
data[i+2] = Pal.all.body.activeB;
}
else if (isAboutSameRgb(fc.skin2, data[i+0], data[i+1], data[i+2])) {
data[i+0] = parseInt(Pal.all.body.activeR * Conf.shadowBody());
data[i+1] = parseInt(Pal.all.body.activeG * Conf.shadowBody());
data[i+2] = parseInt(Pal.all.body.activeB * Conf.shadowBody());
}
// more
else if (isAboutSameRgb(fc.more, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Pal.all.more.activeR;
data[i+1] = Pal.all.more.activeG;
data[i+2] = Pal.all.more.activeB;
}
else if (isAboutSameRgb(fc.more2, data[i+0], data[i+1], data[i+2])) {
data[i+0] = parseInt(Pal.all.more.activeR * Conf.shadowMore());
data[i+1] = parseInt(Pal.all.more.activeG * Conf.shadowMore());
data[i+2] = parseInt(Pal.all.more.activeB * Conf.shadowMore());
}
// item
else if (isAboutSameRgb(fc.item, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Pal.all.item.activeR;
data[i+1] = Pal.all.item.activeG;
data[i+2] = Pal.all.item.activeB;
}
else if (isAboutSameRgb(fc.item2, data[i+0], data[i+1], data[i+2])) {
data[i+0] = parseInt(Pal.all.item.activeR * Conf.shadowItem());
data[i+1] = parseInt(Pal.all.item.activeG * Conf.shadowItem());
data[i+2] = parseInt(Pal.all.item.activeB * Conf.shadowItem());
}
// suit
else if (isAboutSameRgb(fc.suit, data[i+0], data[i+1], data[i+2])) {
data[i+0] = Pal.all.suit.activeR;
data[i+1] = Pal.all.suit.activeG;
data[i+2] = Pal.all.suit.activeB;
}
else if (isAboutSameRgb(fc.suit2, data[i+0], data[i+1], data[i+2])) {
data[i+0] = parseInt(Pal.all.suit.activeR * Conf.shadowSuit());
data[i+1] = parseInt(Pal.all.suit.activeG * Conf.shadowSuit());
data[i+2] = parseInt(Pal.all.suit.activeB * Conf.shadowSuit());
}
}
ctx.putImageData(imd, 0, 0);
}
};
Canvas.reset();
const step = () => {
const f = parseInt((Date.now() / 110));
//$("#debug").innerText = f % 4;
Canvas.blitAll(Canvas.ctx, State.modF(f), State.anim);
window.requestAnimationFrame(step);
}
// Update below for new anim. Add else if anim state order (Anim Part 2, if using anim button)
(() => {
const btn = $("#animbtn");
btn.addEventListener("click", () => {
if (State.anim == "stand") { State.anim = "idle"; }
else if (State.anim == "idle") { State.anim = "run"; } //based on click order
else if (State.anim == "run") { State.anim = "hurt"; }
else if (State.anim == "hurt") { State.anim = "die"; }
else if (State.anim == "die") { State.anim = "jump"; }
else { State.anim = "stand"; }
btn.innerText = "anim: " + State.anim;
});
})();
//______________________________________NEW ADDITIONS Anim Part 2 B
(() => {
const btn = $("#anim_base_idle_btn");
btn.addEventListener("click", () => {
State.anim = "base_idle";
});
})();
(() => {
const btn = $("#anim_base_run_btn");
btn.addEventListener("click", () => {
State.anim = "base_run";
});
})();
(() => {
const btn = $("#anim_base_hurt_btn");
btn.addEventListener("click", () => {
State.anim = "base_hurt";
});
})();
(() => {
const btn = $("#anim_base_die_btn");
btn.addEventListener("click", () => {
State.anim = "base_die";
});
})();
(() => {
const btn = $("#anim_base_press_btn");
btn.addEventListener("click", () => {
State.anim = "base_press";
});
})();
(() => {
const btn = $("#anim_jump_btn");
btn.addEventListener("click", () => {
State.anim = "jump";
});
})();
(() => {
const btn = $("#anim_jump_hop_btn");
btn.addEventListener("click", () => {
State.anim = "jump_hop";
});
})();
(() => {
const btn = $("#anim_jump_double_btn");
btn.addEventListener("click", () => {
State.anim = "jump_double";
});
})();
(() => {
const btn = $("#anim_run_ninja_btn");
btn.addEventListener("click", () => {
State.anim = "run_ninja";
});
})();
(() => {
const btn = $("#anim_run_one_btn");
btn.addEventListener("click", () => {
State.anim = "run_one";
});
})();
(() => {
const btn = $("#anim_run_two_btn");
btn.addEventListener("click", () => {
State.anim = "run_two";
});
})();
(() => {
const btn = $("#anim_run_wobble_btn");
btn.addEventListener("click", () => {
State.anim = "run_wobble";
});
})();
(() => {
const btn = $("#anim_run_leap_btn");
btn.addEventListener("click", () => {
State.anim = "run_leap";
});
})();
(() => {
const btn = $("#anim_duck_btn");
btn.addEventListener("click", () => {
State.anim = "duck";
});
})();
(() => {
const btn = $("#anim_duck_pose_btn");
btn.addEventListener("click", () => {
State.anim = "duck_pose";
});
})();
(() => {
const btn = $("#anim_re_spawn_btn");
btn.addEventListener("click", () => {
State.anim = "re_spawn";
});
})();
(() => {
const btn = $("#anim_re_teleport_btn");
btn.addEventListener("click", () => {
State.anim = "re_teleport";
});
})();
(() => {
const btn = $("#anim_re_warp_btn");
btn.addEventListener("click", () => {
State.anim = "re_warp";
});
})();
(() => {
const btn = $("#anim_re_land_btn");
btn.addEventListener("click", () => {
State.anim = "re_land";
});
})();
(() => {
const btn = $("#anim_re_drop_btn");
btn.addEventListener("click", () => {
State.anim = "re_drop";
});
})();
(() => {
const btn = $("#anim_re_hard_btn");
btn.addEventListener("click", () => {
State.anim = "re_hard";
});
})();
(() => {
const btn = $("#anim_re_squash_btn");
btn.addEventListener("click", () => {
State.anim = "re_squash";
});
})();
(() => {
const btn = $("#anim_air_one_btn");
btn.addEventListener("click", () => {
State.anim = "air_one";
});
})();