-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stylesheets.lua
1172 lines (1117 loc) · 46.4 KB
/
Stylesheets.lua
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
do
local camera2D = AK.Cam2D
camera2D.__index = camera2D
local CheckScript = function(gameObject)
local ScriptedBehavior = gameObject:GetComponent("ScriptedBehavior")
local Asset
do local Craft = CS
Asset = Craft.FindAsset( "Data/AKInScript/Button" , "Script" )
end
if ScriptedBehavior == nil then
gameObject:CreateScriptedBehavior( Asset , nil )
end
return true
end
local CSSCallAction
local CSSubAction
local CSSCut = {
["text"] = function(object,value,primary)
primary = primary or false
local compx = object.behavior
if type(value) == "string" then
primary = primary or false
if object.textRenderer ~= nil then
if primary and compx ~= nil then
compx.actu_text = value
end
object.textRenderer:SetText( value )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
if primary and compx ~= nil then
compx.actu_text = value
end
child_object.textRenderer:SetText( value )
end
end
end
elseif type(value) == "table" then
if not primary then
local tablevalue
local comp
if object.textRenderer ~= nil then
comp = true
end
if tablevalue == nil then
if comp then
if object.textRenderer:GetText() == value[2] then tablevalue = value[1] elseif object.textRenderer:GetText() == value[1] then tablevalue = value[2] else tablevalue = value[1] end
else
local child = object:GetChildren()[1]
if child.textRenderer:GetText() == value[2] then tablevalue = value[1] elseif child.textRenderer:GetText() == value[1] then tablevalue = value[2] else tablevalue = value[1] end
end
end
if comp then
if primary and compx ~= nil then
object.behavior.actu_text = tablevalue
end
object.textRenderer:SetText( tablevalue )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
if primary and comp ~= nil then
object.behavior.actu_text = tablevalue
end
child_object.textRenderer:SetText( tablevalue )
end
end
end
end
end
end,
["text_scale"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
if type(value) == "string" then
local str = string
local _,_,a,b,c = str.find(value, '([%d%p]*)[%s]([%d%p]*)[%s]([%d%p]*)')
if object.textRenderer ~= nil then
local scale = object.Scale
a = tonumber(a) or scale.x
b = tonumber(b) or scale.y
c = tonumber(c) or scale.z
if a > 1 then a = a / 100 elseif a < 0 then a = 0 end
if b > 1 then b = b / 100 elseif b < 0 then b = 0 end
if c > 1 then c = c / 100 elseif c < 0 then c = 0 end
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( a , b , c )
end
object.transform:SetLocalScale( V3:New( a , b , c ) )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
local scale = child_object.Scale
a = tonumber(a) or scale.x
b = tonumber(b) or scale.y
c = tonumber(c) or scale.z
if a > 1 then a = a / 100 elseif a < 0 then a = 0 end
if b > 1 then b = b / 100 elseif b < 0 then b = 0 end
if c > 1 then c = c / 100 elseif c < 0 then c = 0 end
if child_object.textRenderer ~= nil then
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( a , b , c )
end
child_object.transform:SetLocalScale( V3:New( a , b , c ) )
end
end
end
elseif type(value) == "number" then
if value > 1 then value = value / 100 elseif value < 0 then value = 0 end
if object.textRenderer ~= nil then
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( value )
end
object.transform:SetLocalScale( V3:New( value ) )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( value )
end
child_object.transform:SetLocalScale( V3:New( value ) )
end
end
end
end
end,
["text_opacity"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
if type(value) == "number" then
if object.textRenderer ~= nil then
if primary and comp ~= nil then
comp.text_opacity = value
end
object.textRenderer:SetOpacity( value )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
if primary and comp ~= nil then
comp.text_opacity = value
end
child_object.textRenderer:SetOpacity( value )
end
end
end
end
end,
["font"] = function(object,value,primary)
primary = primary or false
local comp = object.behavior
local Craft = CS
if object.textRenderer ~= nil then
if primary and comp ~= nil then
object.behavior.font = Craft.FindAsset( value )
end
object.textRenderer:SetFont( Craft.FindAsset( value ) )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
if primary and comp ~= nil then
comp.font = Craft.FindAsset( value )
end
child_object.textRenderer:SetFont( Craft.FindAsset( value ) )
end
end
end
end,
["align"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
local var
if value == "left" then
var = TextRenderer.Alignment.Left
elseif value == "right" then
var = TextRenderer.Alignment.Right
else
var = TextRenderer.Alignment.Center
end
if object.textRenderer ~= nil then
if primary and comp ~= nil then
comp.align = var
end
object.textRenderer:SetAlignment( var )
else
local child = object:GetChildren()
if #child == 1 then
local child_object = child[1]
if child_object.textRenderer ~= nil then
if primary and comp ~= nil then
comp.align = var
end
child_object.textRenderer:SetAlignment( var )
end
end
end
end,
["scale"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
if type(value) == "string" then
local _,_,a,b,c = string.find(value, '([%d%p]*)[%s]([%d%p]*)[%s]([%d%p]*)')
local scale = object.Scale
a = tonumber(a) or scale.x
b = tonumber(b) or scale.y
c = tonumber(c) or scale.z
if a > 1 then a = a / 100 elseif a < 0 then a = 0 end
if b > 1 then b = b / 100 elseif b < 0 then b = 0 end
if c > 1 then c = c / 100 elseif c < 0 then c = 0 end
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( a , b , c )
end
object.transform:SetLocalScale( V3:New( a , b , c ) )
elseif type(value) == "number" then
if value > 1 then value = value / 100 elseif value < 0 then value = 0 end
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( value )
end
object.transform:SetLocalScale( V3:New( value ) )
elseif type(value) == "table" then
value = value or {}
value[1] = value[1] or 1
value[2] = value[2] or 1
value[3] = value[3] or 1
-- On vérifie les valeurs
if value[1] > 1 then value[1] = value[1] / 100 elseif value[1] < 0 then value[1] = 0 end
if value[2] > 1 then value[2] = value[1] / 100 elseif value[2] < 0 then value[2] = 0 end
if value[3] > 1 then value[3] = value[1] / 100 elseif value[3] < 0 then value[3] = 0 end
local V3 = Vector3
if primary and comp ~= nil then
comp.scale = V3:New( unpack(value) )
end
object.transform:SetLocalScale( V3:New( unpack(value) ) )
end
end,
["model"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
local Craft = CS
if object.modelRenderer ~= nil then
if primary and comp ~= nil then
comp.model = Craft.FindAsset( value , "Model" )
end
object.modelRenderer:SetModel( Craft.FindAsset( value , "Model" ) )
end
end,
["opacity"] = function(object,value,primary)
primary = primary or false
local comp = object:GetComponent("ScriptedBehavior")
value = tonumber(value)
if type(value) == "number" then
local component
if object.modelRenderer ~= nil then
component = object.modelRenderer
elseif object.mapRenderer ~= nil then
component = object.mapRenderer
elseif object.textRenderer ~= nil then
component = object.textRenderer
end
if primary and comp ~= nil then
comp.opacity = value
end
component:SetOpacity( value )
end
end,
["zindex"] = function(object,value,primary)
primary = primary or false
if type(value) == "number" then
if value >= 0 and value <= 150 then
AK.UI:Zindex(object.Name,value,true)
end
elseif type(value) == "string" then
if value == "inherit" then
local parent = object:GetParent()
if parent ~= nil then
AK.UI:Zindex(object.Name,parent.Pos.z,true)
end
end
end
end,
["show"] = function(object,value)
if type(value) == "number" then
AK.UI:Show(object.Name,value)
elseif type(value) == "table" then
value[1] = value[1] or 1
AK.UI:Show(object.Name,value[1],value[2])
elseif type(value) == "string" then
local str = string
local _,_,a,b = str.find(value, '([%a%d%p]*)[%s]?([%a%d%p]*)')
a = a or 1
AK.UI:Show(object.Name,a,b)
end
end,
["hide"] = function(object,value)
if type(value) == "number" then
AK.UI:Hide(object.Name,value)
elseif type(value) == "table" then
value[1] = value[1] or 0
AK.UI:Hide(object.Name,value[1],value[2])
elseif type(value) == "string" then
local str = string
local _,_,a,b = str.find(value, '([%a%d%p]*)[%s]?([%a%d%p]*)')
a = a or 0
AK.UI:Hide(object.Name,a,b)
end
end,
["atob"] = function(object,value)
if type(value) == "string" then
local str = string
local _,_,a,b = str.find(value, '([%a%d%p]*)[%s]?([%a%d%p]*)')
if a ~= nil then
if b == nil or b == "" then
AK.UI:AtoB(object.Name,a,false)
else
AK.UI:AtoB(a,b,false)
end
end
elseif type(value) == "table" then
end
end,
["button_reset"] = function(object,value)
if type(value) == "boolean" then
local comp = object.behavior
if value then
comp.default_value = true
elseif not value then
comp.default_value = false
end
end
end,
["only_reset"] = function(object,value)
if type(value) == "table" then
local comp = object.behavior
if comp ~= nil then
comp.only_reset = {unpack(value)}
end
end
end,
["dont_reset"] = function(object,value)
if type(value) == "table" then
local comp = object.behavior
if comp ~= nil then
comp.dont_reset = {unpack(value)}
end
end
end,
-- > Timer
["timer"] = function(object,value)
if type(value) == "table" then
if value[1] ~= nil then
value[1] = tonumber(value[1])
if type(value[2]) == "function" then
value[3] = value[3] or false
local ma = math
local random = ma.random(1,1000)
local name = "timer"..random
Declare(name,Timer:New(value[1]*60,value[3],true,value[2]) )
AK.TaskList:Add(name,{value[1]*60},function(Table)
_G[Table.item]()
end)
end
end
end
end,
["escape"] = function(object,value)
if type(value) == "string" then
local comp = object:GetScriptedBehavior( CS.FindAsset( "Data/AKInScript/Cam2D_Container" ) )
if comp ~= nil then
local sub = string.sub
local key = sub(object.Name,11)
AK.UI.Module[key]["Escape"] = value
comp.Escape = value
end
elseif type(value) == "function" then
local comp = object:GetScriptedBehavior( CS.FindAsset( "Data/AKInScript/Cam2D_Container" ) )
if comp ~= nil then
local sub = string.sub
local key = sub(object.Name,11)
AK.UI.Module[key]["Escape_function"] = value
end
elseif type(value) == "table" then
--[[local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
v(object,b)
end
end
end ]]
end
end,
["SwitchIn"] = function(object,value)
if type(value) == "function" then
local comp = object:GetScriptedBehavior( CS.FindAsset( "Data/AKInScript/Cam2D_Container" ) )
if comp ~= nil then
local sub = string.sub
local key = sub(object.Name,11)
AK.UI.Module[key]["Switch_IN"] = value
end
end
end,
["SwitchOut"] = function(object,value)
if type(value) == "function" then
local comp = object:GetScriptedBehavior( CS.FindAsset( "Data/AKInScript/Cam2D_Container" ) )
if comp ~= nil then
local sub = string.sub
local key = sub(object.Name,11)
print("Apply out")
AK.UI.Module[key]["Switch_OUT"] = value
end
end
end
}
-- > Sub Action stylesheets
CSSubAction = {
["echo"] = function(object,value)
local echo = tostring(value)
if echo == "pos" then
echo = object.Pos
elseif echo == "scale" then
echo = object.Scale
end
printx = print
printx(echo)
end,
["escape"] = CSSCut["escape"],
["SwitchIn"] = CSSCut["SwitchIn"],
["SwitchOut"] = CSSCut["SwitchOut"],
["play"] = function(object,value)
if type(value) == "string" then
if value == "this" then
if AK.UI:StateAnim(object.Name) then
AK.UI:Anim(object.Name)
end
else
if AK.UI:StateAnim(value) then
AK.UI:Anim(value)
end
end
elseif type(value) == "table" then
for i=1,#value do
if value[i] == "this" then
if AK.UI:StateAnim(object.Name) then
AK.UI:Anim(object.Name)
end
else
if AK.UI:StateAnim(value[i]) then
AK.UI:Anim(value[i])
end
end
end
end
end,
["url"] = function(object,value)
if type(value) == "string" then
local Craft = CS
Craft.Web.Open( value )
end
end,
["redirect"] = function(object,value)
if type(value) == "string" then
local Craft = CS
Craft.Web.Redirect( value )
end
end,
["get"] = function(object,value)
if type(value) == "table" then
if value[1] ~= nil then
local Craft = CS
local comp
value[3] = value[3] or "json"
value[4] = value[4] or Nil
if value[3] == "text" then
comp = Craft.Web.ResponseType.Text
elseif value[3] == "json" then
comp = Craft.Web.ResponseType.Json
end
Craft.Web.Get( value[1] , value[2] , comp , value[4] )
end
end
end,
["post"] = function(object,value)
if type(value) == "table" then
if value[1] ~= nil then
local Craft = CS
local comp
value[3] = value[3] or "json"
value[4] = value[4] or Nil
if value[3] == "text" then
comp = Craft.Web.ResponseType.Text
elseif value[3] == "json" then
comp = Craft.Web.ResponseType.Json
end
Craft.Web.Post( value[1] , value[2] , comp , value[4] )
end
end
end,
["stop"] = function(object,value,primary,index)
primary = primary or false
if type(value) == "string" then
local Craft = CS
local T = table
if value == "this" then
if AK.UI:StateAnim(object.Name) and AK.UI.LerpTab[object.Name].state then
AK.UI:Anim(object.Name)
T.remove( object.behavior.OnNextCallback , index )
end
else
if AK.UI:StateAnim(value) and AK.UI.LerpTab[value].state then
AK.UI:Anim(value)
local item = Craft.Get(value)
T.remove( item.behavior.OnNextCallback , index )
end
end
elseif type(value) == "table" then
local Craft = CS
local T = table
for i=1,#value do
if value[i] == "this" then
if AK.UI:StateAnim(object.Name) and not AK.UI.LerpTab[object.Name].state then
AK.UI:Anim(object.Name)
T.remove( object.behavior.OnNextCallback , index )
end
else
if AK.UI:StateAnim(value[i]) and not AK.UI.LerpTab[value].state then
AK.UI:Anim(value[i])
local item = Craft.Get(value[i])
T.remove( item.behavior.OnNextCallback , index )
end
end
end
end
end,
["switch"] = function(object,value)
if type(value) == "string" then
local str = string.find
local _,_,a,b = str(value, '([%a%d%p]*)[%s]?([%a%d%p]*)')
local result = {a,b}
if #result == 1 then
AK.UI:Switch(value)
elseif #result == 2 then
if AK.UI.ModuleActive == a then
AK.UI:Switch(b)
elseif AK.UI.ModuleActive == b then
AK.UI:Switch(a)
else
AK.UI:Switch(a)
-- do nothing
end
end
end
end,
["append"] = function(object,value)
if type(value) == "string" then
local Craft = CS
local asset = Craft.FindAsset( value , "Scene" )
if asset ~= nil then
Craft.LoadScene( asset )
end
end
end,
["load"] = function(object,value)
if type(value) == "string" then
local Craft = CS
local asset = Craft.AppendScene( value , "Scene" )
if asset ~= nil then
Craft.AppendScene( asset )
end
end
end,
["instantiate"] = function(object,value)
if type(value) == "table" then
local Craft = CS
value = value or {}
local asset = Craft.FindAsset( value[2] , "Scene" )
if asset ~= nil then
AK.UI[value[1]] = Craft.Instantiate( value[1].."_key" , asset )
end
end
end,
["destroy"] = function(object,value)
if type(value) == "string" then
if AK.UI[value] ~= nil then
local Craft = CS
Craft.Destroy( AK.UI[value] )
AK.UI[value] = nil
end
end
end,
["exit"] = function(object,value)
local Craft = CS
if type(value) == "boolean" then
if value then
Craft.Exit()
end
elseif type(value) == "table" then
value = value or {}
value[1] = value[1] or true
value[2] = value[2] or Nil
if value[1] then
value[2]()
Craft.Exit()
end
end
end,
["next"] = function(object,value)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OnNext( function( gameObject , this, index )
v(object,b,false,index)
end )
end
end
end
elseif type(value) == "function" then
object:OnNext( value )
end
end,
["atob"] = CSSCut["atob"],
["timer"] = CSSCut["timer"],
["show"] = CSSCut["show"],
["hide"] = CSSCut["hide"],
["zindex"] = CSSCut["zindex"],
["scale"] = CSSCut["scale"],
["model"] = CSSCut["model"],
["opacity"] = CSSCut["opacity"],
["text"] = CSSCut["text"],
["font"] = CSSCut["font"],
["align"] = CSSCut["align"],
["text_scale"] = CSSCut["text_scale"],
["text_opacity"] = CSSCut["text_opacity"],
["button_resetset"] = CSSCut["button_reset"]
}
-- > CSS Callable Action
CSSCallAction = {
["onclick"] = function(object,value)
CheckScript(object)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OnClick( function()
v(object,b)
end )
end
end
end
elseif type(value) == "function" then
object:OnClick( value )
end
end,
["onchoice"] = function(object,value)
if type(value) == "function" then
object:OnChoice( value )
end
end,
["outclick"] = function(object,value)
CheckScript(object)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OutClick( function()
v(object,b)
end )
end
end
end
elseif type(value) == "function" then
object:OutClick( value )
end
end,
["onfocus"] = function(object,value)
end,
["outfocus"] = function(object,value)
end,
["onhover"] = function(object,value)
CheckScript(object)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OnHover( function()
v(object,b)
end )
end
end
end
elseif type(value) == "function" then
object:OnHover( value )
end
end,
["outhover"] = function(object,value)
CheckScript(object)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OutHover( function()
v(object,b)
end )
end
end
end
elseif type(value) == "function" then
object:OutHover( value )
end
end,
["oncall"] = function(object,value)
CheckScript(object)
if type(value) == "table" then
local search = pairs
for k,v in search(CSSubAction) do
for a,b in search(value) do
if a == k then
object:OnCall( function()
v(object,b)
end )
end
end
end
elseif type(value) == "function" then
object:OnCall( value )
end
end
}
-- > Head action stylesheets
local CSSAction = {
["switch_call"] = function(object,value)
if type(value) == "function" then
local sub = string.sub
local key = sub(object.Name, 11)
AK.UI.Module[key]["Escape_function"] = value
end
end,
-- model
["model"] = CSSCut["model"],
["animation"] = function(object,value)
if type(value) == "string" and object.modelRenderer ~= nil then
local Craft = CS
object.modelRenderer:SetAnimation( Craft.FindAsset( value, "Animation" ) )
end
end,
-- Map
["map"] = function(object,value)
if value ~= nil and object.mapRenderer ~= nil then
local Craft = CS
object.mapRenderer:SetMap( Craft.FindAsset( value , "Map" ) )
end
end,
["tile"] = function(object,value)
if value ~= nil and object.mapRenderer ~= nil then
local Craft = CS
object.mapRenderer:SetTileSet( Craft.FindAsset( value , "TileSet" ) )
end
end,
-- Input action
["onclick"] = CSSCallAction["onclick"],
["onchoice"] = CSSCallAction["onchoice"],
["outclick"] = CSSCallAction["outclick"],
["onfocus"] = CSSCallAction["onfocus"],
["outfocus"] = CSSCallAction["outfocus"],
["onhover"] = CSSCallAction["onhover"],
["outhover"] = CSSCallAction["outhover"],
["oncall"] = CSSCallAction["oncall"],
["next"] = CSSCallAction["next"],
["SwitchIn"] = CSSCut["SwitchIn"],
["SwitchOut"] = CSSCut["SwitchOut"],
-- Camera action
["projection"] = function(object,value)
if type(value) == "string" then
if object.camera ~= nil then
local cam = Camera
if value == "perspective" then
object.camera:SetProjectionMode( cam.ProjectionMode.Perspective )
else
object.camera:SetProjectionMode( cam.ProjectionMode.Orthographic )
end
end
end
end,
["fov"] = function(object,value)
value = tonumber(value)
if type(value) == "number" then
if object.camera ~= nil then
object.camera:SetFOV( value )
end
end
end,
["orthoscale"] = function(object,value)
if type(value) == "number" then
if object.camera ~= nil then
object.camera:SetOrthographicScale( value )
end
end
end,
["radarsize"] = function(object,value)
if type(value) == "table" then
if object.camera ~= nil then
value = value or {}
value[1] = value[1] or 1
value[2] = value[2] or 1
object.camera:SetRenderViewportSize( unpack(value) )
end
end
end,
["radarposition"] = function(object,value)
if type(value) == "table" then
if object.camera ~= nil then
value = value or {}
value[1] = value[1] or 1
value[2] = value[2] or 1
object.camera:SetRenderViewportPosition( unpack(value) )
end
end
end,
-- Transform action
["scale"] = CSSCut["scale"],
["margin"] = function(object,value)
if type(value) == "string" then
local str = string.find
local _,_,a,b = str(value, '([%d%p]*)[%s]?([%d%p]*)')
local result = {a,b}
result[1] = result[1] or 0
result[2] = result[2] or 0
local pos = object.Pos
local V3 = Vector3
if #result == 1 then
object.transform:SetPosition( V3:New( pos.x + result[1], pos.y + result[1], pos.z ) )
elseif #result == 2 then
object.transform:SetPosition( V3:New( pos.x + result[1], pos.y + result[2], pos.z ) )
else
-- do nothing
end
elseif type(value) == "table" then
value[1] = value[1] or 0
value[2] = value[2] or 0
value[3] = value[3] or true
local V3 = Vector3
if value[3] then
local pos = object.Pos
object.transform:SetPosition( V3:New( pos.x + value[1], pos.y + value[2], pos.z ) )
else
local pos = object.LocalPos
object.transform:SetLocalPosition( V3:New( pos.x + value[1], pos.y + value[2], pos.z ) )
end
end
end,
["position"] = function(object,value)
if type(value) == "string" then
if value == "inherit" then
local parent = object:GetParent()
if parent ~= nil then
object.transform:SetPosition( parent.Pos )
end
elseif value == "center" then
local V3 = Vector3
object.transform:SetPosition( V3:New( 0 , 0 , object.Pos.z ) )
else
-- do nothing
end
end
end,
-- GameObject
["parent"] = function(object,value)
if value ~= nil and type(value) == "string" then
local Craft = CS
local parent = Craft.Get(value)
if parent ~= nil then
object:SetParent( parent )
end
end
end,
["behavior"] = function(object,value)
if type(value) == "table" then
local comp = object.behavior
if comp ~= nil then
local search = pairs
for k,v in search(value) do
if comp[k] ~= nil then
comp[k] = v
end
end
end
end
end,
["escape"] = CSSCut["escape"],
-- > Input
-- > Position
["atob"] = CSSCut["atob"],
["timer"] = CSSCut["timer"],
-- Animation
["show"] = CSSCut["show"],
["hide"] = CSSCut["hide"],
-- Triple contexte
["opacity"] = CSSCut["opacity"],
["zindex"] = CSSCut["zindex"],
-- TextRenderer CSS
["text"] = CSSCut["text"],
["font"] = CSSCut["font"],
["align"] = CSSCut["align"];
["only_reset"] = CSSCut["only_reset"];
["button_reset"] = CSSCut["button_reset"],
["text_scale"] = CSSCut["text_scale"],
["text_opacity"] = CSSCut["text_opacity"]
}
local CSSUnique = {
["keypattern"] = function(object,value,primary)
local search = pairs
for k,v in search(CSSAction) do
for a,b in search(value) do
if a == k then
v(object,b,false)
end
end
end
end
}
-- > UI build CSS function
function camera2D:BuildCSS(autoapply,name,size)
autoapply = autoapply or false
if size ~= nil then
self.DynamicSheets[name] = {
size = size;
exec_min = AK[name.."_min"];
exec_max = AK[name.."_max"];
}
if self.Screen.Size.x >= size then
self:ApplyCSS(self.DynamicSheets[name].exec_max)
else
self:ApplyCSS(self.DynamicSheets[name].exec_min)
end
return
else
if autoapply then
self:ApplyCSS(AK[name])