-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathSyncAPI.lua
1958 lines (1489 loc) · 48.7 KB
/
SyncAPI.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
local HttpService = game:GetService('HttpService')
local RunService = game:GetService('RunService')
-- References
SyncAPI = script.Parent;
Tool = SyncAPI.Parent;
Player = nil;
-- Libraries
Security = require(Tool.Core.Security);
RegionModule = require(Tool.Libraries.Region);
Support = require(Tool.Libraries.SupportLibrary);
Serialization = require(Tool.Libraries.SerializationV3);
-- Import services
Support.ImportServices();
-- Default options
Options = {
DisallowLocked = false
}
-- Keep track of created items in memory to not lose them in garbage collection
CreatedInstances = {};
LastParents = {};
-- Determine whether we're in tool or plugin mode
ToolMode = (Tool.Parent:IsA 'Plugin') and 'Plugin' or 'Tool'
local IsHttpServiceEnabled = nil
-- List of actions that could be requested
Actions = {
['RecolorHandle'] = function (NewColor)
-- Recolors the tool handle
Tool.Handle.BrickColor = NewColor;
end;
['Clone'] = function (Items, Parent)
-- Clones the given items
-- Validate arguments
assert(type(Items) == 'table', 'Invalid items')
assert(typeof(Parent) == 'Instance', 'Invalid parent')
assert(Security.IsLocationAllowed(Parent, Player), 'Permission denied for client')
-- Check if items modifiable
if not CanModifyItems(Items) then
return {}
end
-- Check if parts intruding into private areas
local Parts = GetPartsFromSelection(Items)
if Security.ArePartsViolatingAreas(Parts, Player, false) then
return {}
end
local Clones = {}
-- Clone items
for _, Item in pairs(Items) do
local Clone = Item:Clone()
Clone.Parent = Parent
-- Register the clone
table.insert(Clones, Clone)
CreatedInstances[Item] = Item
end
-- Return the clones
return Clones
end;
['CreatePart'] = function (PartType, Position, Parent)
-- Creates a new part based on `PartType`
-- Validate requested parent
assert(typeof(Parent) == 'Instance', 'Invalid parent')
assert(Security.IsLocationAllowed(Parent, Player), 'Permission denied for client')
-- Create the part
local NewPart = CreatePart(PartType);
-- Position the part
NewPart.CFrame = Position;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas({ NewPart }), Player);
-- Make sure the player is allowed to create parts in the area
if Security.ArePartsViolatingAreas({ NewPart }, Player, false, AreaPermissions) then
return;
end;
-- Parent the part
NewPart.Parent = Parent
-- Register the part
CreatedInstances[NewPart] = NewPart;
-- Return the part
return NewPart;
end;
['CreateGroup'] = function (Type, Parent, Items)
-- Creates a new group of type `Type`
local ValidGroupTypes = {
Model = true,
Folder = true
}
-- Validate arguments
assert(ValidGroupTypes[Type], 'Invalid group type')
assert(typeof(Parent) == 'Instance', 'Invalid parent')
assert(Security.IsLocationAllowed(Parent, Player), 'Permission denied for client')
-- Check if items selectable
if not CanModifyItems(Items) then
return
end
-- Check if parts intruding into private areas
local Parts = GetPartsFromSelection(Items)
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player)
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return
end
-- Create group
local Group = Instance.new(Type)
-- Attach children
for _, Item in pairs(Items) do
Item.Parent = Group
end
-- Parent group
Group.Parent = Parent
-- Make joints
if Type == 'Model' then
Group:MakeJoints()
elseif Type == 'Folder' then
local Parts = Support.GetDescendantsWhichAreA(Group, 'BasePart')
for _, Part in pairs(Parts) do
Part:MakeJoints()
end
end
-- Return the new group
return Group
end,
['Ungroup'] = function (Groups)
-- Validate arguments
assert(type(Groups) == 'table', 'Invalid groups')
-- Check if items modifiable
if not CanModifyItems(Groups) then
return
end
-- Check if parts intruding into private areas
local Parts = GetPartsFromSelection(Groups)
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player)
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return
end
local Results = {}
-- Check each group
for Key, Group in ipairs(Groups) do
assert(typeof(Group) == 'Instance', 'Invalid group')
-- Track group children
local Children = {}
Results[Key] = Children
-- Unpack group children into parent
local NewParent = Group.Parent
for _, Child in pairs(Group:GetChildren()) do
LastParents[Child] = Group
Children[#Children + 1] = Child
Child.Parent = NewParent
if Child:IsA 'BasePart' then
Child:MakeJoints()
elseif Child:IsA 'Folder' then
local Parts = Support.GetDescendantsWhichAreA(Child, 'BasePart')
for _, Part in pairs(Parts) do
Part:MakeJoints()
end
end
end
-- Track removing group
LastParents[Group] = Group.Parent
CreatedInstances[Group] = Group
-- Remove group
Group.Parent = nil
end
return Results
end,
['SetParent'] = function (Items, Parent)
-- Validate arguments
assert(type(Items) == 'table', 'Invalid items')
assert(type(Parent) == 'table' or typeof(Parent) == 'Instance', 'Invalid parent')
-- Check if items modifiable
if not CanModifyItems(Items) then
return
end
-- Check if parts intruding into private areas
local Parts = GetPartsFromSelection(Items)
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player)
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return
end
-- Move each item to different parent
if type(Parent) == 'table' then
for Key, Item in pairs(Items) do
local Parent = Parent[Key]
-- Check if parent allowed
assert(Security.IsLocationAllowed(Parent, Player), 'Permission denied for client')
-- Move item
Item.Parent = Parent
if Item:IsA 'BasePart' then
Item:MakeJoints()
elseif Item:IsA 'Folder' then
local Parts = Support.GetDescendantsWhichAreA(Item, 'BasePart')
for _, Part in pairs(Parts) do
Part:MakeJoints()
end
end
end
-- Move to single parent
elseif typeof(Parent) == 'Instance' then
assert(Security.IsLocationAllowed(Parent, Player), 'Permission denied for client')
-- Reparent items
for _, Item in pairs(Items) do
Item.Parent = Parent
if Item:IsA 'BasePart' then
Item:MakeJoints()
elseif Item:IsA 'Folder' then
local Parts = Support.GetDescendantsWhichAreA(Item, 'BasePart')
for _, Part in pairs(Parts) do
Part:MakeJoints()
end
end
end
end
end,
['SetName'] = function (Items, Name)
-- Validate arguments
assert(type(Items) == 'table', 'Invalid items')
assert(type(Name) == 'table' or type(Name) == 'string', 'Invalid name')
-- Check if items modifiable
if not CanModifyItems(Items) then
return
end
-- Check if parts intruding into private areas
local Parts = GetPartsFromSelection(Items)
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player)
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return
end
-- Rename each item to a different name
if type(Name) == 'table' then
for Key, Item in pairs(Items) do
local Name = Name[Key]
Item.Name = Name
end
-- Rename to single name
elseif type(Name) == 'string' then
for _, Item in pairs(Items) do
Item.Name = Name
end
end
end,
['Remove'] = function (Objects)
-- Removes the given objects
-- Get the relevant parts for each object, for permission checking
local Parts = {};
-- Go through the selection
for _, Object in pairs(Objects) do
-- Make sure the object still exists
if Object then
if Object:IsA 'BasePart' then
table.insert(Parts, Object);
elseif Object:IsA 'Smoke' or Object:IsA 'Fire' or Object:IsA 'Sparkles' or Object:IsA 'DataModelMesh' or Object:IsA 'Decal' or Object:IsA 'Texture' or Object:IsA 'Light' then
table.insert(Parts, Object.Parent);
elseif Object:IsA 'Model' or Object:IsA 'Folder' then
Support.ConcatTable(Parts, Support.GetDescendantsWhichAreA(Object, 'BasePart'))
end
end;
end;
-- Check if items modifiable
if not CanModifyItems(Objects) then
return
end
-- Check if parts intruding into private areas
if Security.ArePartsViolatingAreas(Parts, Player, true) then
return
end
-- After confirming permissions, perform each removal
for _, Object in pairs(Objects) do
-- Store the part's current parent
LastParents[Object] = Object.Parent;
-- Register the object
CreatedInstances[Object] = Object;
-- Set the object's current parent to `nil`
Object.Parent = nil;
end;
end;
['UndoRemove'] = function (Objects)
-- Restores the given removed objects to their last parents
-- Get the relevant parts for each object, for permission checking
local Parts = {};
-- Go through the selection
for _, Object in pairs(Objects) do
-- Make sure the object still exists, and that its last parent is registered
if Object and LastParents[Object] then
if Object:IsA 'BasePart' then
table.insert(Parts, Object);
elseif Object:IsA 'Smoke' or Object:IsA 'Fire' or Object:IsA 'Sparkles' or Object:IsA 'DataModelMesh' or Object:IsA 'Decal' or Object:IsA 'Texture' or Object:IsA 'Light' then
table.insert(Parts, Object.Parent);
elseif Object:IsA 'Model' or Object:IsA 'Folder' then
Support.ConcatTable(Parts, Support.GetDescendantsWhichAreA(Object, 'BasePart'))
end
end;
end;
-- Check if items modifiable
if not CanModifyItems(Objects) then
return
end
-- Check if parts intruding into private areas
if Security.ArePartsViolatingAreas(Parts, Player, false) then
return
end
-- After confirming permissions, perform each removal
for _, Object in pairs(Objects) do
-- Store the part's current parent
local LastParent = LastParents[Object];
LastParents[Object] = Object.Parent;
-- Register the object
CreatedInstances[Object] = Object;
-- Set the object's parent to the last parent
Object.Parent = LastParent;
-- Make joints
if Object:IsA 'BasePart' then
Object:MakeJoints()
else
local Parts = Support.GetDescendantsWhichAreA(Object, 'BasePart')
for _, Part in pairs(Parts) do
Part:MakeJoints()
end
end
end;
end;
['SyncMove'] = function (Changes)
-- Updates parts server-side given their new CFrames
-- Grab a list of every part we're attempting to modify
local Parts = {};
local Models = {}
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
elseif Change.Model then
table.insert(Models, Change.Model)
end
end;
-- Ensure parts are selectable
if not (CanModifyItems(Parts) and CanModifyItems(Models)) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local PartChangeSet = {}
local ModelChangeSet = {}
for _, Change in pairs(Changes) do
if Change.Part then
Change.InitialState = {
Anchored = Change.Part.Anchored;
CFrame = Change.Part.CFrame;
}
PartChangeSet[Change.Part] = Change
elseif Change.Model then
ModelChangeSet[Change.Model] = Change.Pivot
end
end;
-- Preserve joints
for Part, Change in pairs(PartChangeSet) do
Change.Joints = PreserveJoints(Part, PartChangeSet)
end;
-- Perform each change
for Part, Change in pairs(PartChangeSet) do
-- Stabilize the parts and maintain the original anchor state
Part.Anchored = true;
Part:BreakJoints();
Part.Velocity = Vector3.new();
Part.RotVelocity = Vector3.new();
-- Set the part's CFrame
Part.CFrame = Change.CFrame;
end;
for Model, Pivot in pairs(ModelChangeSet) do
Model.WorldPivot = Pivot
end
-- Make sure the player is authorized to move parts into this area
if Security.ArePartsViolatingAreas(Parts, Player, false, AreaPermissions) then
-- Revert changes if unauthorized destination
for Part, Change in pairs(PartChangeSet) do
Part.CFrame = Change.InitialState.CFrame;
end;
end;
-- Restore the parts' original states
for Part, Change in pairs(PartChangeSet) do
Part:MakeJoints();
RestoreJoints(Change.Joints);
Part.Anchored = Change.InitialState.Anchored;
end;
end;
['SyncResize'] = function (Changes)
-- Updates parts server-side given their new sizes and CFrames
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
Change.InitialState = { Anchored = Change.Part.Anchored, Size = Change.Part.Size, CFrame = Change.Part.CFrame };
ChangeSet[Change.Part] = Change;
end;
end;
-- Perform each change
for Part, Change in pairs(ChangeSet) do
-- Stabilize the parts and maintain the original anchor state
Part.Anchored = true;
Part:BreakJoints();
Part.Velocity = Vector3.new();
Part.RotVelocity = Vector3.new();
-- Set the part's size and CFrame
Part.Size = Change.Size;
Part.CFrame = Change.CFrame;
end;
-- Make sure the player is authorized to move parts into this area
if Security.ArePartsViolatingAreas(Parts, Player, false, AreaPermissions) then
-- Revert changes if unauthorized destination
for Part, Change in pairs(ChangeSet) do
Part.Size = Change.InitialState.Size;
Part.CFrame = Change.InitialState.CFrame;
end;
end;
-- Restore the parts' original states
for Part, Change in pairs(ChangeSet) do
Part:MakeJoints();
Part.Anchored = Change.InitialState.Anchored;
end;
end;
['SyncRotate'] = function (Changes)
-- Updates parts server-side given their new CFrames
-- Grab a list of every part and model we're attempting to modify
local Parts = {};
local Models = {}
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
elseif Change.Model then
table.insert(Models, Change.Model)
end
end;
-- Ensure parts are selectable
if not (CanModifyItems(Parts) and CanModifyItems(Models)) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local PartChangeSet = {}
local ModelChangeSet = {}
for _, Change in pairs(Changes) do
if Change.Part then
Change.InitialState = {
Anchored = Change.Part.Anchored;
CFrame = Change.Part.CFrame;
}
PartChangeSet[Change.Part] = Change
elseif Change.Model then
ModelChangeSet[Change.Model] = Change.Pivot
end
end;
-- Preserve joints
for Part, Change in pairs(PartChangeSet) do
Change.Joints = PreserveJoints(Part, PartChangeSet)
end;
-- Perform each change
for Part, Change in pairs(PartChangeSet) do
-- Stabilize the parts and maintain the original anchor state
Part.Anchored = true;
Part:BreakJoints();
Part.Velocity = Vector3.new();
Part.RotVelocity = Vector3.new();
-- Set the part's CFrame
Part.CFrame = Change.CFrame;
end;
for Model, Pivot in pairs(ModelChangeSet) do
Model.WorldPivot = Pivot
end
-- Make sure the player is authorized to move parts into this area
if Security.ArePartsViolatingAreas(Parts, Player, false, AreaPermissions) then
-- Revert changes if unauthorized destination
for Part, Change in pairs(PartChangeSet) do
Part.CFrame = Change.InitialState.CFrame;
end;
end;
-- Restore the parts' original states
for Part, Change in pairs(PartChangeSet) do
Part:MakeJoints();
RestoreJoints(Change.Joints);
Part.Anchored = Change.InitialState.Anchored;
end;
end;
['SyncColor'] = function (Changes)
-- Updates parts server-side given their new colors
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Perform each change
for Part, Change in pairs(ChangeSet) do
-- Set the part's color
Part.Color = Change.Color;
-- If this part is a union, set its UsePartColor state
if Part.ClassName == 'UnionOperation' then
Part.UsePartColor = Change.UnionColoring;
end;
end;
end;
['SyncSurface'] = function (Changes)
-- Updates parts server-side given their new surfaces
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Perform each change
for Part, Change in pairs(ChangeSet) do
-- Apply each surface change
for Surface, SurfaceType in pairs(Change.Surfaces) do
Part[Surface .. 'Surface'] = SurfaceType;
end;
end;
end;
['CreateLights'] = function (Changes)
-- Creates lights in the given parts
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Make a list of allowed light type requests
local AllowedLightTypes = { PointLight = true, SurfaceLight = true, SpotLight = true };
-- Keep track of the newly created lights
local Lights = {};
-- Create each light
for Part, Change in pairs(ChangeSet) do
-- Make sure the requested light type is valid
if AllowedLightTypes[Change.LightType] then
-- Create the light
local Light = Instance.new(Change.LightType, Part);
table.insert(Lights, Light);
-- Register the light
CreatedInstances[Light] = Light;
end;
end;
-- Return the new lights
return Lights;
end;
['SyncLighting'] = function (Changes)
-- Updates aspects of the given selection's lights
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Make a list of allowed light type requests
local AllowedLightTypes = { PointLight = true, SurfaceLight = true, SpotLight = true };
-- Update each part's lights
for Part, Change in pairs(ChangeSet) do
-- Make sure that the light type requested is valid
if AllowedLightTypes[Change.LightType] then
-- Grab the part's light
local Light = Support.GetChildOfClass(Part, Change.LightType);
-- Make sure the light exists
if Light then
-- Make the requested changes
if Change.Range ~= nil then
Light.Range = Change.Range;
end;
if Change.Brightness ~= nil then
Light.Brightness = Change.Brightness;
end;
if Change.Color ~= nil then
Light.Color = Change.Color;
end;
if Change.Shadows ~= nil then
Light.Shadows = Change.Shadows;
end;
if Change.Face ~= nil then
Light.Face = Change.Face;
end;
if Change.Angle ~= nil then
Light.Angle = Change.Angle;
end;
end;
end;
end;
end;
['CreateDecorations'] = function (Changes)
-- Creates decorations in the given parts
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Make a list of allowed decoration type requests
local AllowedDecorationTypes = { Smoke = true, Fire = true, Sparkles = true };
-- Keep track of the newly created decorations
local Decorations = {};
-- Create each decoration
for Part, Change in pairs(ChangeSet) do
-- Make sure the requested decoration type is valid
if AllowedDecorationTypes[Change.DecorationType] then
-- Create the decoration
local Decoration = Instance.new(Change.DecorationType, Part);
table.insert(Decorations, Decoration);
-- Register the decoration
CreatedInstances[Decoration] = Decoration;
end;
end;
-- Return the new decorations
return Decorations;
end;
['SyncDecorate'] = function (Changes)
-- Updates aspects of the given selection's decorations
-- Grab a list of every part we're attempting to modify
local Parts = {};
for _, Change in pairs(Changes) do
if Change.Part then
table.insert(Parts, Change.Part);
end;
end;
-- Ensure parts are selectable
if not CanModifyItems(Parts) then
return;
end;
-- Cache up permissions for all private areas
local AreaPermissions = Security.GetPermissions(Security.GetSelectionAreas(Parts), Player);
-- Make sure the player is allowed to perform changes to these parts
if Security.ArePartsViolatingAreas(Parts, Player, true, AreaPermissions) then
return;
end;
-- Reorganize the changes
local ChangeSet = {};
for _, Change in pairs(Changes) do
if Change.Part then
ChangeSet[Change.Part] = Change;
end;
end;
-- Make a list of allowed decoration type requests
local AllowedDecorationTypes = { Smoke = true, Fire = true, Sparkles = true };
-- Update each part's decorations
for Part, Change in pairs(ChangeSet) do
-- Make sure that the decoration type requested is valid
if AllowedDecorationTypes[Change.DecorationType] then
-- Grab the part's decoration
local Decoration = Support.GetChildOfClass(Part, Change.DecorationType);
-- Make sure the decoration exists
if Decoration then
-- Make the requested changes
if Change.Color ~= nil then
Decoration.Color = Change.Color;
end;
if Change.Opacity ~= nil then
Decoration.Opacity = Change.Opacity;
end;
if Change.RiseVelocity ~= nil then
Decoration.RiseVelocity = Change.RiseVelocity;
end;
if Change.Size ~= nil then
Decoration.Size = Change.Size;
end;
if Change.Heat ~= nil then
Decoration.Heat = Change.Heat;
end;
if Change.SecondaryColor ~= nil then