-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtm_cm.js
2158 lines (1974 loc) · 83 KB
/
tm_cm.js
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
var aLayers = {};
var userImageList = [];
var otherBgList = {};
var type2FuncList = {};
// var groupList = [];
var fontList = {
Prototype: "",
Pagella: "",
times: ""
};
var layerToDrag;
var dragOffsetX;
var dragOffsetY;
var keyFocusLayer;
var blockList = [
{putUnder: "templates", text: "Green Card", src:"green_normal"},
{putUnder: "templates", text: "Green Small Bottom", src:"green_small_bottom"},
{putUnder: "templates", text: "Green Big Bottom", src:"green_big_bottom"},
{putUnder: "templates", text: "Blue Card", src:"blue_normal"},
{putUnder: "templates", text: "Blue Big Bottom", src:"blue_big_bottom"},
{putUnder: "templates", text: "Blue Big Top", src:"blue_big_top"},
{putUnder: "templates", text: "Red Card", src:"red_normal"},
{putUnder: "templates", text: "Red Small Bottom", src:"red_small_bottom"},
{putUnder: "globalparameters", text: "", src:"oxygen"},
{putUnder: "globalparameters", text: "", src:"temperature"},
{putUnder: "globalparameters", text: "", src:"venus"},
{putUnder: "misc", text: "", src:"megacredit", otherbg:"mc_otherbg"},
{putUnder: "misc", text: "mc_otherbg", src:"other_player_background", hidden:true},
{putUnder: "misc", text: "", src:"arrow"},
{putUnder: "misc", text: "Asterisk", src:"asterisc"},
{putUnder: "misc", text: "Slash", src:"bar"},
{putUnder: "misc", text: "", src:"chairman"},
{putUnder: "misc", text: "", src:"colon"},
{putUnder: "misc", text: "", src:"delegate"},
{putUnder: "misc", text: "", src:"influence"},
{putUnder: "parties", text: "", src:"bureacrats"},
{putUnder: "parties", text: "", src:"centrists"},
{putUnder: "parties", text: "", src:"empower"},
{putUnder: "parties", text: "", src:"greens"},
{putUnder: "parties", text: "", src:"kelvinists"},
{putUnder: "parties", text: "", src:"mars_first"},
{putUnder: "parties", text: "", src:"populists"},
{putUnder: "parties", text: "", src:"reds"},
{putUnder: "parties", text: "", src:"scientists"},
{putUnder: "parties", text: "", src:"spome"},
{putUnder: "parties", text: "", src:"transhumanists"},
{putUnder: "parties", text: "", src:"unity"},
{putUnder: "productionboxes", text: "prod_nxn", src:"nxn", hidden: true},
// {putUnder: "productionboxes", text: "prod_otherbg", src:"other_player_background", hidden:true},
{putUnder: "requisites", text: "Max Requirement", src:"max_big"},
{putUnder: "requisites", text: "Min Requirement (big)", src:"min_big"},
{putUnder: "requisites", text: "Min Requirement", src:"min_medium"},
{putUnder: "requisites", text: "Min Requirement (small)", src:"min_small"},
{putUnder: "requisites", text: "No Requirement", src:"normal"},
{putUnder: "resources", text: "", src:"animal", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"card", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"data", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"fighter", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"floater", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"heat", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"microbe", otherbg:"res_otherbg"},
{putUnder: "resources", text: "res_otherbg", src:"other_player_background", hidden:true},
{putUnder: "resources", text: "", src:"plant", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"power", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"radiation", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"science", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"steel", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"titanium", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"TR", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"wild", otherbg:"res_otherbg"},
{putUnder: "tags", text: "", src:"animal", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"building", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"city", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"earth", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"event", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"galactic", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"infrastructure", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"jovian", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"mars", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"microbe", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"moon", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "tag_otherbg", src:"other_player_background", hidden:true},
{putUnder: "tags", text: "", src:"planetary", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"plant", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"power", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"radioactive", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"science", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"space", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"venus", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"wild", otherbg:"tag_otherbg"},
{putUnder: "tiles", text: "", src:"city", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"colony"},
{putUnder: "tiles", text: "", src:"empty", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"greenery_no_O2", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"greenery", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"ocean", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"off-world_city", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"special", otherbg:"tiles_otherbg"},
{putUnder: "tiles", text: "", src:"trade"},
{putUnder: "VPs", text: "VP 1/", src:"1_for"},
{putUnder: "VPs", text: "1 VP", src:"1"},
{putUnder: "VPs", text: "VP 2/", src:"2_for"},
{putUnder: "VPs", text: "2 VP", src:"2"},
{putUnder: "VPs", text: "3 VP", src:"3"},
{putUnder: "VPs", text: "4 VP", src:"4"},
{putUnder: "VPs", text: "5 VP", src:"5"},
{putUnder: "VPs", text: "VP background", src:"blank"},
{putUnder: "VPs", text: "-VP", src:"VPnegative"},
{putUnder: "VPs", text: "/ VP", src:"n_for"},
{putUnder: "misc", text: "", src:"party_leader"},
{putUnder: "templates", text: "", src:"prelude"},
{putUnder: "templates", text: "", src:"corporation"},
{putUnder: "misc", text: "Tag Holder", src:"corp_tag_holder"},
{putUnder: "misc", text: "Effect (bg)", src:"effect"},
{putUnder: "tags", text: "", src:"multitag", otherbg:"tag_otherbg"},
{putUnder: "tiles", text: "tiles_otherbg", src:"other_player_background", hidden:true},
{putUnder: "tags", text: "", src:"tourism", otherbg:"tag_otherbg"},
{putUnder: "tags", text: "", src:"mercury", otherbg:"tag_otherbg"},
{putUnder: "resources", text: "", src:"asteroid", otherbg:"res_otherbg"},
{putUnder: "resources", text: "", src:"ore", otherbg:"res_otherbg"},
{putUnder: "misc", text: "", src:"asset"},
{putUnder: "misc", text: "Colony Tile", src:"colonytile"},
{putUnder: "misc", text: "", src:"population"}
];
var blockDefaults = {
tags: [
{label:"First Tag", x:639, y:67, width:110, height:110},
{label:"Second Tag", x:524, y:67, width:110, height:110},
{label:"Third Tag", x:410, y:67, width:110, height:110},
{label:"Small Tag", x:330, y:536, width:82, height:82},
{label:"First (Prel)", x:937, y:67, width:110, height:110},
{label:"Second (Prel)", x:822, y:67, width:110, height:110},
{label:"Third (Prel)", x:708, y:67, width:110, height:110},
{label:"First (Corp)", x:937, y:90, width:110, height:110},
{label:"Second (Corp)", x:822, y:90, width:110, height:110}
],
templates: [
{label:"Vertical Card", x:0, y:0, width:826, height:1126},
{label:"Horizontal Card", x:0, y:0, width:1126, height:826}
],
text: [
{label:"Card Cost", x:118, y:147, height:66, color:"#000000", font:"Prototype", style:"normal", weight:"normal", justify:"center"},
{label:"Card Name", x:413, y:214, height:46, color:"#000000", font:"Prototype", style:"normal", weight:"normal", justify:"center"},
{label:"Description", x:413, y:643, height:22, lineSpace:4, color:"#000000", font:"Pagella", style:"normal", weight:"normal", justify:"center"},
{label:"Flavor Text", x:413, y:1005, height:22, lineSpace:4, color:"#000000", font:"Pagella", style:"italic", weight:"bold", justify:"center"},
{label:"FAN MADE", x:413, y:611, height:24, color:"#24770d", font:"Prototype", style:"normal", weight:"normal", justify:"center"},
{label:"PRELUDE", data:"P R E L U D E", x:563, y:99, height:22, color:"#000000", font:"Prototype", style:"normal", weight:"normal", justify:"center"},
{label:"CORPORATION", data:"C O R P O R A T I O N", x:563, y:109, height:24, color:"#000000", font:"Prototype", style:"normal", weight:"normal", justify:"center"},
{label:"EFFECT", data:"E F F E C T", x:800, y:333, height:22, color:"#000000", font:"Prototype", style:"normal", weight:"normal", justify:"center"}
],
resources: [
{label:"Standard", x:413, y:643, width:92, height:92},
{label:"Card", x:413, y:643, width:88, height:122},
{label:"TR", x:413, y:643, width:151, height:112}
],
VPs: [
{label:"Standard", x:542, y:836, width:223, height:223},
{label:"Negative", x:652, y:836, width:223, height:223}
],
tiles: [
{label:"Standard tile", height:142}
],
requisites: [
{label:"Max", x:180, y:92, width:200, height:60},
{label:"Min Large", x:180, y:92, width:176, height:60},
{label:"Min Medium", x:180, y:92, width:147, height:60},
{label:"Min Small", x:180, y:92, width:130, height:60},
{label:"No Req", x:180, y:92, width:21, height:60}
],
globalparameters: [
{label:"Oxygen", x:413, y:643, width:118, height:118},
{label:"Temp", x:413, y:643, width:35, height:118},
{label:"Venus", x:413, y:643, width:125, height:71}
],
misc: [
{label:"MC", x:413, y:643, width:92, height:92},
{label:"Arrow", x:413, y:429, width:116, height:55},
{label:"Asterisk", x:413, y:643, width:55, height:55},
{label:"Slash", x:413, y:643, width:55, height:146},
{label:"Colon", x:413, y:643, width:11, height:55},
{label:"Delegate", x:413, y:643, width:77, height:99},
{label:"Effect (bg)", x:631, y:307, width:346, height:36},
{label:"Influence", x:413, y:643, width:117, height:122},
{label:"Tag Holder 0", x:969, y:103, width:257, height:89},
{label:"Tag Holder 1", x:898, y:103, width:257, height:89},
{label:"Tag Holder 2", x:794, y:103, width:257, height:89}
],
parties: [
{label:"Party", x:413, y:643, width:169, height:122}
],
production: [
{label:"1x height", height:143},
{label:"2x height", height:235},
{label:"1x width", width:143},
{label:"1.5x width", width:188},
{label:"2x width", width:235},
{label:"2.5x width", width:279},
{label:"3x width", width:325}
]
};
var megaTemplates = {
green_normal: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:0,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block",iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:612,width:826,height:24,color:"#24770d",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:110,y:770,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
green_big_bottom: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:2,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:562,width:826,height:24,color:"#24770d",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:110,y:770,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
green_small_bottom: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:1,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:664,width:826,height:24,color:"#24770d",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:110,y:770,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
blue_normal: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:3,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:798,width:826,height:24,color:"#0c5e84",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:100,y:860,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:13,x:355,y:265,width:116,height:55,params:"allimages allpreset"},
{type:"text",data:"Effect or Action text!",x:413,y:360,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
blue_big_bottom: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:4,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:753,width:702,height:24,color:"#0c5e84",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:100,y:860,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:13,x:355,y:265,width:116,height:55,params:"allimages allpreset"},
{type:"text",data:"Effect or Action text!",x:413,y:360,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
blue_big_top: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:5,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:849,width:702,height:24,color:"#0c5e84",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:100,y:891,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:13,x:355,y:265,width:116,height:55,params:"allimages allpreset"},
{type:"text",data:"Effect or Action text!",x:413,y:360,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
red_normal: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:6,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:685,width:826,height:24,color:"#c36a17",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:100,y:810,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
red_small_bottom: {
layers: [
{type: "base", color: "#ffffff", height: 1126, width: 826, params: "color"},
{type:"block", iNum:7,x:0,y:0,width:826,height:1126,params:"allimages"},
{type:"text",data:"Cost",x:118,y:147,width:826,height:66,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"block", iNum:37,x:179,y:97,width:22,height:59,params:"allimages allpreset"},
{type:"text",data:"CARD NAME",x:413,y:214,width:826,height:46,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:413,y:718,width:826,height:24,color:"#c36a17",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:100,y:810,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:413,y:1005,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
prelude: {
layers: [
{type: "base", color: "#ffffff", height: 826, width: 1126, params: "color"},
{type:"block", iNum:94,x:0,y:0,width:1126,height:826,params:"allimages"},
{type:"text",data:"CARD NAME",x:563,y:218,width:826,height:48,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"FAN MADE",x:563,y:500,width:826,height:24,color:"#ce809f",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"P R E L U D E",x:563,y:99,width:826,height:24,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text",data:"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:110,y:560,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text",data:"Flavor text!",x:563,y:723,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
},
corporation: {
layers: [
{type:"base", color: "#ffffff", height: 826, width: 1126, params: "color"},
{type:"block","iNum":96,x:969,y:103,width:257,height:89,params:"allimages"},
{type:"block","iNum":95,x:0,y:0,width:1126,height:826,params:"allimages"},
{type:"effect", x: 600, y: 300, width: 400, height: 300, params: "allimages allpreset"},
{type:"block", name: "", iNum: 97, x: 631, y: 307, width: 345.79, height: 36,params:"allimages"},
{type:"text", data: "E F F E C T", x: 800, y: 333, width: 1126, height: 22, color: "#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text","data":"FAN MADE",x:198,y:736,width:826,height:24,color:"#c3c3c3",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text","data":"C O R P O R A T I O N",x:563,y:109,width:826,height:24,color:"#000000",font:"Prototype",style:"normal",weight:"normal",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"},
{type:"text","data":"Card description\nMultiple lines\nand they can be much, much, much longer\n'V space' controls the spacing between lines",x:110,y:560,width:826,height:22,color:"#000000",font:"Pagella",style:"normal",weight:"normal",lineSpace:4,justify:"left",params:"allimages color alltext allpreset"},
{type:"text","data":"Flavor text!",x:563,y:723,width:826,height:22,color:"#000000",font:"Pagella",style:"italic",weight:"bold",lineSpace:4,justify:"center",params:"allimages color alltext allpreset"}
]
}
};
var ddcount = 0;
var maxToLoad;
var numLoaded;
var hiddenImage = {};
var domInputfont = document.getElementById("inputfont");
var domParams = document.getElementById("params").parentNode.removeChild(document.getElementById("params"));
domParams.classList.remove("w3-hide");
function resetProject(loadautosave) {
document.getElementById("layerlist").innerHTML = "";
ddcount = 0;
aLayers = {};
document.getElementById("xcanvases").innerHTML = "";
aCanvases = [];
addLayer("Base",{type:"base", color:"#ffffff", height:1126, width:826, params:"color"});
maxToLoad = 0;
for (let i=0; i < blockList.length; i++) {
if (!blockList[i].obj) {
maxToLoad++;
addBlockMenuItem(i);
}
}
// if (maxToLoad) {
// numLoaded = 0;
// document.getElementById("files").max = maxToLoad;
// document.getElementById("files").value = numLoaded;
// document.getElementById("loadprogress").style.display = "block";
// document.getElementById("cmcanvas").style.display = "none";
// } else {
allLoadingDone(loadautosave);
// }
}
function fetchBlock(num) {
let imageObj = new Image();
imageObj.onload = onBlockLoad;
imageObj.src = blockList[num].putUnder + "/" + blockList[num].src + ".png";
imageObj.dataindex = num;
blockList[num].obj = imageObj;
if (blockList[num].text.indexOf("otherbg") != -1) {
// if this image is an 'other people background', save its name
otherBgList[blockList[num].text] = imageObj;
}
}
function addBlockMenuItem(num) {
if (blockList[num].hidden) {
// hidden images don't get menu items
hiddenImage[blockList[num].text] = num;
} else {
let tmpText = blockList[num].text;
if (!tmpText) {
tmpText = blockList[num].src;
tmpText = tmpText.replace(/_/g, ' ');
tmpText = tmpText.replace(tmpText.charAt(0), tmpText.charAt(0).toUpperCase());
blockList[num].text = tmpText;
}
// add menu item for image
// <a onclick="addBlock('template:green')" href="#" class="w3-bar-item w3-button">Green Card</a>
if (!document.getElementById("image" + num)) {
let toAdd = document.createElement("a");
toAdd.onclick = addBlock;
toAdd.innerText = tmpText;
toAdd.classList.add("w3-bar-item");
toAdd.classList.add("w3-button");
toAdd.href = "#";
toAdd.id = "image" + num;
document.getElementById(blockList[num].putUnder).appendChild(toAdd);
if (blockList[num].putUnder == "templates") {
// add Super Templates
toAdd = document.createElement("a");
toAdd.onclick = addMegaTemplate;
toAdd.innerText = tmpText;
toAdd.classList.add("w3-bar-item");
toAdd.classList.add("w3-button");
toAdd.href = "#";
toAdd.id = "mega" + blockList[num].src;
document.getElementById("fromTemplate").appendChild(toAdd);
}
}
}
}
function addLayer(title, layer) {
// <div id='div1' class='divRec'><div class='inside'>item 1</div></div>
let toAdd = document.createElement("div");
// toAdd.appendChild(downButton());
if (!ddcount && (ddcount != 0)) ddcount = 0;
toAdd.id = "dragdropdiv" + ddcount;
toAdd.classList.add("divRec");
if (ddcount) toAdd.appendChild(createGroupCheckbox());
let childAdd = document.createElement("div");
childAdd.classList.add("inside");
//childAdd.innerHTML = title;
childAdd.appendChild(createTextbox(title));
childAdd.onclick = selectLayer;
// skip delete button for base layer
if (ddcount) childAdd.appendChild(deleteButton());
toAdd.appendChild(childAdd);
document.getElementById("layerlist").appendChild(toAdd);
aLayers[toAdd.id] = layer;
ddcount++;
sortable( document.getElementById('layerlist'), function (item){
/* console.log(item); */
});
return layer;
}
function createGroupCheckbox() {
let toAdd = document.createElement("input");
toAdd.type = "checkbox";
toAdd.classList.add("groupcheck");
toAdd.classList.add("w3-hide");
toAdd.checked = false;
//toAdd.style.display = "none";
return toAdd;
}
function createTextbox(txt) {
let toAdd = document.createElement("input");
toAdd.type = "text";
toAdd.id = "layername" + ddcount;
toAdd.maxLength = 20;
toAdd.size = 15;
toAdd.value = txt;
toAdd.onchange = function () {updateLayerName(event, this)};
return toAdd;
}
function updateLayerName(e, th) {
let layerName = th.parentNode.parentNode.id;
aLayers[layerName].name = th.value;
drawProject();
}
function deleteButton() {
let toAdd = document.createElement("button");
toAdd.innerHTML = "X";
toAdd.style.float = "right";
toAdd.onclick = function () {deleteListItem(event, this)};
return toAdd;
}
function genSpan(txt) {
let toAdd = document.createElement("span");
toAdd.innerText = txt;
}
function deleteListItem(e,th) {
e.stopPropagation();
// delete item from aLayers and from layerlist (DOM)
let toDelete = th.parentNode.parentNode;
// let deleteNum = Number(toDelete.id.slice(11));
// // for every list numbered > than the one being deleted, subtract 1
// let allLayerNodes = toDelete.parentNode.children;
// for (let ch=0; ch < allLayerNodes.length; ch++) {
// let thisNum = Number(allLayerNodes[ch].id.slice(11));
// if (thisNum > deleteNum) {
// thisNum--;
// allLayerNodes[ch].id = "dragdropdiv" + thisNum;
// }
// }
delete aLayers[toDelete.id];
toDelete.parentNode.removeChild(toDelete);
drawProject();
}
function selectLayer() {
removeKeyInputFocus()
let allLayerNodes = document.getElementById("layerlist").children;
for (let ch=0; ch < allLayerNodes.length; ch++) {
if (allLayerNodes[ch].classList.contains("selected")) {
if (domParams.parentNode == allLayerNodes[ch]) {
allLayerNodes[ch].removeChild(domParams);
}
allLayerNodes[ch].classList.remove("selected");
// show delete button
let buttons = allLayerNodes[ch].getElementsByTagName("button");
if (buttons.length) {
buttons[0].style.display = "block";
}
} else if (allLayerNodes[ch] == this.parentNode) {
// hide delete button
let buttons = allLayerNodes[ch].getElementsByTagName("button");
if (buttons.length) {
buttons[0].style.display = "none";
}
allLayerNodes[ch].classList.add("selected");
// hide/unhide correct params for this layer
let thisLayer = aLayers[allLayerNodes[ch].id];
let thisLayerParams = thisLayer.params;
if (this.parentNode.id != "dragdropdiv0") {
thisLayerParams += " allall";
}
for (let pch=0; pch < domParams.children.length; pch++) {
let thispch = domParams.children[pch];
if (thisLayerParams.indexOf(thispch.id) == -1) {
// not in params, hide it
thispch.classList.add("w3-hide");
} else {
// in params list, show it
// thispch is DOM elements such as allpreset allimages etc
thispch.classList.remove("w3-hide");
for (let intype of ["input", "textarea", "select"]) {
let chInputs = thispch.getElementsByTagName(intype);
for (let subch of chInputs) {
if (subch.id.indexOf("input") == 0) {
if (subch.type == "checkbox") {
subch.checked = thisLayer[subch.id.slice(5)];
} else {
subch.value = thisLayer[subch.id.slice(5)];
}
} else if ((subch.id == "lar") || (subch.id == "slar")) {
subch.checked = true;
} else if (subch.id == "presets") {
// set default selections for this layer
// Note: we already checked above that we should do this
let opts = subch.getElementsByTagName("option");
let defType = "";
if (thisLayer.type == "block") {
defType = blockList[thisLayer.iNum].putUnder;
} else if (thisLayer.type == "text") {
defType = "text";
} else if (thisLayer.type == "production") {
defType = "production";
}
if (defType) {
subch.value = "";
while (opts.length < blockDefaults[defType].length + 1) {
let cNode = opts[1].cloneNode(false);
cNode.value = "defselect" + (opts.length - 1);
subch.appendChild(cNode);
}
for (let i=1; i < opts.length; i++) {
// for each usable <option> under presets
if (i <= blockDefaults[defType].length) {
opts[i].innerText = blockDefaults[defType][i-1].label;
opts[i].classList.remove("w3-hide");
} else {
opts[i].classList.add("w3-hide");
}
}
}
}
}
}
}
}
allLayerNodes[ch].appendChild(domParams);
}
}
}
function drawProject() {
if (reloading) return;
let c = document.getElementById("cmcanvas");
let ctx = c.getContext("2d");
let layerDivs = document.getElementsByClassName("divRec");
let imagesForSaving = [];
for (let i=0; i < layerDivs.length; i++) {
let layer = aLayers[layerDivs[i].id];
imagesForSaving.push(layer);
switch (layer.type) {
case "block":
if (i==0) {
c.height = layer.height;
c.width = layer.width;
}
// layer = {type:"block", obj:{}, x:0, y:0, width:0, height:0, params:"allimages"};
if (layer.obg) { // draw others background?
let brdr = 3;
if (!otherBgList[blockList[layer.iNum].otherbg]) {
for (let j=0; j < blockList.length; j++) {
if (blockList[j].text == blockList[layer.iNum].otherbg) {
fetchBlock(j);
break;
}
}
} else if (otherBgList[blockList[layer.iNum].otherbg].complete) {
ctx.drawImage(otherBgList[blockList[layer.iNum].otherbg],layer.x-brdr,layer.y-brdr,layer.width+2*brdr,layer.height+2*brdr);
}
}
if (!blockList[layer.iNum].obj) {
fetchBlock(layer.iNum);
} else if (blockList[layer.iNum].obj.complete) {
ctx.drawImage(blockList[layer.iNum].obj,layer.x,layer.y,layer.width,layer.height);
}
break;
case "text":
// layer = {type:"text", data:"", x:0, y:0, width:0, height:0,
// color:"#000000",
// font:"Prototype", lineSpace:4, justify:"center",
// params:""};
ctx.textAlign = layer.justify;
if (!layer.style) layer.style = "normal";
ctx.font = layer.style + " " + layer.weight + " " + layer.height + "px " + layer.font;
ctx.fillStyle = layer.color;
// TBD break up long text into mutiple parts
// Note that this algorithm is copied in clickIsWithinText()
let lines = layer.data.split("\n");
let cnt = 0;
for (var ln=0; ln < lines.length; ln++) {
let spl = lines[ln].split(" ");
let o = "";
while (spl.length) {
o = spl.shift();
while (spl.length && (ctx.measureText(o + " " + spl[0]).width < layer.width)) {
o += " " + spl.shift();
}
ctx.fillText(o, layer.x, 0 + layer.y + (layer.height + layer.lineSpace) * cnt);
cnt++;
}
}
break;
case "production":
{
let sz = 20;
let border = 3;
let xpos = Number(layer.x);
let ypos = Number(layer.y);
let width = Number(layer.width);
let height = Number(layer.height);
let img = blockList[hiddenImage["prod_nxn"]].obj ;
let x=xpos;
let w=width % sz;
// if (!w) w += sz;
let h=height % sz;
// if (!h) h += sz;
for (x=xpos; x <= xpos+width; x += sz) {
let y=ypos;
for (y=ypos; y <= ypos+height; y += sz) {
if ((x <= xpos+width-sz) && (y <= ypos+height-sz)) {
ctx.drawImage(img,x,y,sz,sz);
} else {
if (x > xpos+width-sz) {
if (y > ypos+height-sz) {
ctx.drawImage(img,0,0,w,h,x,y,w,h);
} else {
ctx.drawImage(img,0,0,w,sz,x,y,w,sz);
}
} else {
if (y > ypos+height-sz) {
ctx.drawImage(img,0,0,sz,h,x,y,sz,h);
} else {
window.alert("What?");
ctx.drawImage(img,0,0,sz,sz,x,y,sz,sz);
}
}
}
}
}
// inner gradient
let my_gradient = ctx.createLinearGradient(0, ypos, 0, ypos + height);
my_gradient.addColorStop(0, "#9d6c43");
my_gradient.addColorStop(1, "#5a412c");
ctx.fillStyle = my_gradient;
ctx.fillRect(xpos, ypos+border, width, border); // top
ctx.fillRect(xpos, ypos+height-border*2, width, border); // bottom
ctx.fillRect(xpos+border, ypos, border, height); // left
ctx.fillRect(xpos+width-border*2, ypos, border, height); // right
// outer gradient
my_gradient = ctx.createLinearGradient(0, ypos, 0, ypos + height);
my_gradient.addColorStop(0, "#505050");
my_gradient.addColorStop(1, "#c0c0c0");
ctx.fillStyle = my_gradient;
ctx.fillRect(xpos, ypos, width, border);// top
ctx.fillRect(xpos, ypos+height-border, width, border); // bottom
ctx.fillRect(xpos, ypos, border, height); // left
ctx.fillRect(xpos+width-border, ypos, border, height); // right
}
break;
case "effect":
{
let border = 5;
let xpos = Number(layer.x);
let ypos = Number(layer.y);
let width = Number(layer.width);
let height = Number(layer.height);
// draw border (actually draws whole rectange but we overwrite below)
let grd = ctx.createLinearGradient(xpos, ypos, xpos+width, ypos);
let stops = [0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.68, 0.76, 0.84, 0.92];
let stopColors = ["#333333", "#999999"];
for (let s=0; s < stops.length; s++) {
grd.addColorStop(stops[s], stopColors[s % 2]);
}
grd.addColorStop(1, "#777777");
ctx.fillStyle = grd;
ctx.fillRect(xpos, ypos, layer.width, layer.height);
// draw center
grd = ctx.createLinearGradient(xpos+border, ypos+border, xpos+layer.width-border, ypos+layer.height-border);
stops = [0, 0.07, 0.25, 0.6, 0.85, 1.0];
stopColors = ["#ffffff", "#999999"];
for (let s=0; s < stops.length; s++) {
grd.addColorStop(stops[s], stopColors[s % 2]);
}
ctx.fillStyle = grd;
ctx.fillRect(xpos+border, ypos+border, layer.width-2*border, layer.height-2*border);
}
break;
case "userFile":
case "embedded":
case "webFile":
if (layer.iNum != -1) {
if (layer.alpha == undefined) layer.alpha = 100;
ctx.globalAlpha = Number(layer.alpha) / 100;
ctx.drawImage(userImageList[layer.iNum],layer.sx,layer.sy,layer.swidth,layer.sheight,layer.x,layer.y,layer.width,layer.height);
ctx.globalAlpha = 1;
}
break;
case "line":
ctx.lineWidth = layer.width;
ctx.strokeStyle = layer.color;
ctx.translate(layer.x, layer.y);
ctx.rotate(Math.PI * layer.angle / 180);
ctx.moveTo(0,0);
ctx.lineTo(layer.len,0);
ctx.stroke();
ctx.setTransform();
ctx.lineWidth = 1;
break;
// case "group":
// break;
case "base":
// set height/width
c.height = layer.height;
c.width = layer.width;
// clear to background color
ctx.fillStyle = layer.color;
// ctx.fillStyle = "rgb(" + layer.red + "," + layer.blue + "," + layer.green + ")";
ctx.fillRect(0,0,layer.width, layer.height);
break;
default:
window.alert("Invalid layer type:" + layer.type);
break;
}
}
autoSave(imagesForSaving);
}
var lastAutoSave = "";
function autoSave(layers) {
lastAutoSave = projectDataToJson(layers);
try {
if (typeof(Storage) !== "undefined") {
localStorage.setItem("autosave", lastAutoSave);
}
} catch (error) {
window.alert("Error with autosave");
}
}
const arAlt = {
width: ["height", "lar"],
height: ["width", "lar"],
swidth: ["sheight", "slar"],
sheight: ["swidth", "slar"]
};
function updateValue(th) {
// called after user updates a value
// OR after user select preset (reloading==true, in this case)
let layer = th.parentNode.parentNode.parentNode.parentNode;
let layerName = layer.id;
let fieldName = th.id.slice(5);
if (th.type == "number") {
let newValue = Number(th.value);
// deal with group moves
if ((fieldName == "x") || (fieldName == "y")) {
// check if part of group
if (layer.getElementsByClassName("groupcheck")[0].checked) {
// adjust all other members of group by same amount
let thisgroup = document.getElementsByClassName("groupcheck");
let diff = newValue - aLayers[layerName][fieldName];
for (let x=0; x < thisgroup.length; x++) {
if (!thisgroup[x].checked) continue;
let groupLayerId = thisgroup[x].parentNode.id;
aLayers[groupLayerId][fieldName] += diff;
}
}
}
if (arAlt[fieldName] && !reloading && (aLayers[layerName].type != "text")) {
// it is width/height/swidth/sheight field
if (document.getElementById(arAlt[fieldName][1]).checked) {
// lar or slar (as appropriate) is checked
// compute otherValue (e.g. if fieldname = width, otherValue = newValue * height/width)
let otherValue = newValue * aLayers[layerName][arAlt[fieldName][0]] / aLayers[layerName][fieldName];
otherValue = Math.round(otherValue * 1000) / 1000;
if ((otherValue) && (Math.abs(otherValue - Math.round(otherValue)) < 0.01)) otherValue = Math.round(otherValue);
aLayers[layerName][arAlt[fieldName][0]] = otherValue;
document.getElementById("input" + arAlt[fieldName][0]).value = otherValue;
}
}
aLayers[layerName][fieldName] = newValue;
} else if (th.type == "checkbox") {
aLayers[layerName][fieldName] = th.checked;
} else {
if (th.id == "inputfont") {
aLayers[layerName].filename = fontList[th.value];
}
aLayers[layerName][fieldName] = th.value;
}
drawProject();
}
function setPresets(th){
let selVal = document.getElementById("presets").value;
if (!selVal) return;
let sel = Number(selVal.slice(9));
let layerDom = th.parentNode.parentNode.parentNode.parentNode;
let layer = aLayers[layerDom.id];
let dName = "";
if (layer.type == "block") {
let a = layer.iNum;
let b = blockList[a];
dName = b.putUnder;
} else if (layer.type == "text") {
dName = "text";
} else if (layer.type == "production") {
dName = "production";
}
if (dName) {
reloading = true;
for (let v in blockDefaults[dName][sel]) {
// fill in presets
if (v == "label") continue;
document.getElementById("input" + v).value = blockDefaults[dName][sel][v];
if (dName == "tiles") {
reloading = false;
}
updateValue(document.getElementById("input" + v));
}
if (dName == "templates") {
aLayers["dragdropdiv0"].height = blockDefaults[dName][sel].height;
aLayers["dragdropdiv0"].width = blockDefaults[dName][sel].width;
}
reloading = false;
}
drawProject();
}
function onBlockLoad() {
if (blockList[this.dataindex].hidden) {
// hidden images don't get menu items
hiddenImage[blockList[this.dataindex].text] = this.dataindex;
} else {
let tmpText = blockList[this.dataindex].text;
if (!tmpText) {
tmpText = blockList[this.dataindex].src;
tmpText = tmpText.replace(/_/g, ' ');
tmpText = tmpText.replace(tmpText.charAt(0), tmpText.charAt(0).toUpperCase());
blockList[this.dataindex].text = tmpText;
}
// add menu item for image
// <a onclick="addBlock('template:green')" href="#" class="w3-bar-item w3-button">Green Card</a>
if (!document.getElementById("image" + this.dataindex)) {
let toAdd = document.createElement("a");
toAdd.onclick = addBlock;
toAdd.innerText = tmpText;
toAdd.classList.add("w3-bar-item");
toAdd.classList.add("w3-button");
toAdd.href = "#";
toAdd.id = "image" + this.dataindex;
document.getElementById(blockList[this.dataindex].putUnder).appendChild(toAdd);
if (blockList[this.dataindex].putUnder == "templates") {
// add Super Templates
toAdd = document.createElement("a");
toAdd.onclick = addMegaTemplate;
toAdd.innerText = tmpText;
toAdd.classList.add("w3-bar-item");
toAdd.classList.add("w3-button");
toAdd.href = "#";
toAdd.id = "mega" + blockList[this.dataindex].src;
document.getElementById("fromTemplate").appendChild(toAdd);
}
}
}
// numLoaded++;
// document.getElementById("files").value = numLoaded;
// if (numLoaded == maxToLoad) {
// allLoadingDone();
// }
for (let l in aLayers) {
if ((aLayers[l].type == "block") && (aLayers[l].iNum == this.dataindex)) {
if (!aLayers[l].width) aLayers[l].width = blockList[this.dataindex].obj.width;
if (!aLayers[l].height) aLayers[l].height = blockList[this.dataindex].obj.height;
}
}
drawProject();
}
var reloading = false;
function allLoadingDone(loadautosave) {
document.getElementById("loadprogress").style.display = "none";
document.getElementById("cmcanvas").style.display = "block";
try {
if (loadautosave) {
loadFrom(JSON.parse(localStorage.getItem("autosave")), true);
} else {
drawProject();
}
} catch (error) {
// no autosave file
}
}
function loadFrom(saved, autoload) {
// load autosave file
reloading = true;
unreloadable = false;
let resize = false;
let scale = {x:1, y:1, width:1, height:1};
try {
for (let layer of saved) {
let ignore = ["type", "params"];
let newLayer = {};
switch (layer.type) {
case "block":
case "text":
case "production":
case "effect":
case "line":
if (layer.type == "block") {
newLayer = addBlock(layer.iNum);
ignore.push("iNum");
} else if (layer.type == "text") {
if (layer.filename && !fontList[layer.font]) {
// this font has not been reloaded
loadFont(layer.filename);
}
newLayer = addTextBox(layer.data);
// } else if (layer.type == "effect") {
// newLayer = addEffectBox();
// } else if (layer.type == "line") {
// newLayer = addLine();
} else {
newLayer = type2FuncList[layer.type]();
// newLayer = addProduction();
}
for (let key in layer) {
if (ignore.indexOf(key) != -1) continue;