@quenty/loader 10.8.0 → 10.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +2 -2
- package/src/Dependencies/DependencyUtils.lua +45 -20
- package/src/Dependencies/PackageTracker.lua +129 -47
- package/src/Dependencies/PackageTrackerProvider.lua +27 -8
- package/src/LoaderLink/LoaderLink.lua +2 -1
- package/src/LoaderLink/LoaderLinkCreator.lua +41 -21
- package/src/LoaderLink/LoaderLinkUtils.lua +2 -1
- package/src/LoaderUtils.lua +1 -0
- package/src/Maid.lua +43 -29
- package/src/Replication/ReplicationType.lua +16 -5
- package/src/Replication/ReplicationTypeUtils.lua +8 -4
- package/src/Replication/Replicator.lua +112 -70
- package/src/Replication/ReplicatorReferences.lua +22 -12
- package/src/Utils.lua +44 -17
- package/src/init.lua +1 -1
- package/src/Replication/ReplicatorUtils.lua +0 -25
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Monitors dependencies primarily for replication. Handles the following scenarios.
|
|
3
4
|
|
|
@@ -29,26 +30,39 @@ local loader = script.Parent.Parent
|
|
|
29
30
|
local Maid = require(loader.Maid)
|
|
30
31
|
local ReplicationType = require(loader.Replication.ReplicationType)
|
|
31
32
|
local ReplicationTypeUtils = require(loader.Replication.ReplicationTypeUtils)
|
|
32
|
-
local ReplicatorUtils = require(loader.Replication.ReplicatorUtils)
|
|
33
33
|
local ReplicatorReferences = require(loader.Replication.ReplicatorReferences)
|
|
34
34
|
|
|
35
35
|
local Replicator = {}
|
|
36
36
|
Replicator.ClassName = "Replicator"
|
|
37
37
|
Replicator.__index = Replicator
|
|
38
38
|
|
|
39
|
+
export type Replicator = typeof(setmetatable(
|
|
40
|
+
{} :: {
|
|
41
|
+
_maid: Maid.Maid,
|
|
42
|
+
_replicationStarted: boolean,
|
|
43
|
+
_references: ReplicatorReferences.ReplicatorReferences,
|
|
44
|
+
_target: ObjectValue,
|
|
45
|
+
_replicatedDescendantCount: IntValue,
|
|
46
|
+
_hasReplicatedDescendants: BoolValue,
|
|
47
|
+
_replicationType: StringValue,
|
|
48
|
+
},
|
|
49
|
+
Replicator
|
|
50
|
+
))
|
|
51
|
+
|
|
39
52
|
--[=[
|
|
40
53
|
Constructs a new Replicator which will do the syncing.
|
|
41
54
|
|
|
42
55
|
@param references ReplicatorReferences
|
|
43
56
|
@return Replicator
|
|
44
57
|
]=]
|
|
45
|
-
function Replicator.new(references)
|
|
58
|
+
function Replicator.new(references: ReplicatorReferences.ReplicatorReferences): Replicator
|
|
46
59
|
local self = setmetatable({}, Replicator)
|
|
47
60
|
|
|
48
61
|
assert(ReplicatorReferences.isReplicatorReferences(references), "Bad references")
|
|
49
62
|
|
|
50
63
|
self._maid = Maid.new()
|
|
51
64
|
self._references = references
|
|
65
|
+
self._replicationStarted = false
|
|
52
66
|
|
|
53
67
|
self._target = self._maid:Add(Instance.new("ObjectValue"))
|
|
54
68
|
self._target.Value = nil
|
|
@@ -77,10 +91,12 @@ end
|
|
|
77
91
|
|
|
78
92
|
@param root Instance
|
|
79
93
|
]=]
|
|
80
|
-
function Replicator
|
|
94
|
+
function Replicator.ReplicateFrom(self: Replicator, root: Instance)
|
|
81
95
|
assert(typeof(root) == "Instance", "Bad root")
|
|
96
|
+
if self._replicationStarted then
|
|
97
|
+
(error :: any)("[Replicator] - Replication already started")
|
|
98
|
+
end
|
|
82
99
|
|
|
83
|
-
assert(not self._replicationStarted, "Already bound events")
|
|
84
100
|
self._replicationStarted = true
|
|
85
101
|
|
|
86
102
|
self._maid:GiveTask(root.ChildAdded:Connect(function(child)
|
|
@@ -89,7 +105,7 @@ function Replicator:ReplicateFrom(root)
|
|
|
89
105
|
self._maid:GiveTask(root.ChildRemoved:Connect(function(child)
|
|
90
106
|
self:_handleChildRemoved(child)
|
|
91
107
|
end))
|
|
92
|
-
for _, child in
|
|
108
|
+
for _, child in root:GetChildren() do
|
|
93
109
|
self:_handleChildAdded(child)
|
|
94
110
|
end
|
|
95
111
|
end
|
|
@@ -100,15 +116,15 @@ end
|
|
|
100
116
|
@param replicator any?
|
|
101
117
|
@return boolean
|
|
102
118
|
]=]
|
|
103
|
-
function Replicator.isReplicator(replicator)
|
|
104
|
-
return type(replicator) == "table" and getmetatable(replicator) == Replicator
|
|
119
|
+
function Replicator.isReplicator(replicator: any): boolean
|
|
120
|
+
return type(replicator) == "table" and getmetatable(replicator :: any) == Replicator
|
|
105
121
|
end
|
|
106
122
|
|
|
107
123
|
--[=[
|
|
108
124
|
Returns the replicated descendant count value.
|
|
109
125
|
@return IntValue
|
|
110
126
|
]=]
|
|
111
|
-
function Replicator
|
|
127
|
+
function Replicator.GetReplicatedDescendantCountValue(self: Replicator): IntValue
|
|
112
128
|
return self._replicatedDescendantCount
|
|
113
129
|
end
|
|
114
130
|
|
|
@@ -117,7 +133,7 @@ end
|
|
|
117
133
|
|
|
118
134
|
@param replicationType ReplicationType
|
|
119
135
|
]=]
|
|
120
|
-
function Replicator
|
|
136
|
+
function Replicator.SetReplicationType(self: Replicator, replicationType: ReplicationType.ReplicationType)
|
|
121
137
|
assert(ReplicationTypeUtils.isReplicationType(replicationType), "Bad replicationType")
|
|
122
138
|
|
|
123
139
|
self._replicationType.Value = replicationType
|
|
@@ -128,7 +144,7 @@ end
|
|
|
128
144
|
|
|
129
145
|
@param target Instance?
|
|
130
146
|
]=]
|
|
131
|
-
function Replicator
|
|
147
|
+
function Replicator.SetTarget(self: Replicator, target: Instance?)
|
|
132
148
|
assert(typeof(target) == "Instance" or target == nil, "Bad target")
|
|
133
149
|
|
|
134
150
|
self._target.Value = target
|
|
@@ -139,7 +155,7 @@ end
|
|
|
139
155
|
|
|
140
156
|
@return Instance?
|
|
141
157
|
]=]
|
|
142
|
-
function Replicator
|
|
158
|
+
function Replicator.GetTarget(self: Replicator): Instance?
|
|
143
159
|
return self._target.Value
|
|
144
160
|
end
|
|
145
161
|
|
|
@@ -149,19 +165,19 @@ end
|
|
|
149
165
|
|
|
150
166
|
@return BoolValue
|
|
151
167
|
]=]
|
|
152
|
-
function Replicator
|
|
168
|
+
function Replicator.GetHasReplicatedChildrenValue(self: Replicator): BoolValue
|
|
153
169
|
return self._hasReplicatedDescendants
|
|
154
170
|
end
|
|
155
171
|
|
|
156
|
-
function Replicator
|
|
172
|
+
function Replicator.GetReplicationTypeValue(self: Replicator): StringValue
|
|
157
173
|
return self._replicationType
|
|
158
174
|
end
|
|
159
175
|
|
|
160
|
-
function Replicator
|
|
176
|
+
function Replicator._handleChildRemoved(self: Replicator, child: Instance)
|
|
161
177
|
self._maid[child] = nil
|
|
162
178
|
end
|
|
163
179
|
|
|
164
|
-
function Replicator
|
|
180
|
+
function Replicator._handleChildAdded(self: Replicator, child: Instance)
|
|
165
181
|
assert(typeof(child) == "Instance", "Bad child")
|
|
166
182
|
|
|
167
183
|
local maid = Maid.new()
|
|
@@ -181,7 +197,7 @@ function Replicator:_handleChildAdded(child)
|
|
|
181
197
|
self._maid[child] = maid
|
|
182
198
|
end
|
|
183
199
|
|
|
184
|
-
function Replicator
|
|
200
|
+
function Replicator._renderChild(self: Replicator, child: Instance)
|
|
185
201
|
local maid = Maid.new()
|
|
186
202
|
|
|
187
203
|
local replicator = Replicator.new(self._references)
|
|
@@ -195,10 +211,15 @@ function Replicator:_renderChild(child)
|
|
|
195
211
|
end
|
|
196
212
|
|
|
197
213
|
local replicationTypeValue = replicator:GetReplicationTypeValue()
|
|
198
|
-
maid._current =
|
|
214
|
+
maid._current =
|
|
215
|
+
self:_replicateBasedUponMode(replicator, replicationTypeValue.Value :: ReplicationType.ReplicationType, child)
|
|
199
216
|
maid:GiveTask(replicationTypeValue.Changed:Connect(function()
|
|
200
217
|
maid._current = nil
|
|
201
|
-
maid._current = self:_replicateBasedUponMode(
|
|
218
|
+
maid._current = self:_replicateBasedUponMode(
|
|
219
|
+
replicator,
|
|
220
|
+
replicationTypeValue.Value :: ReplicationType.ReplicationType,
|
|
221
|
+
child
|
|
222
|
+
)
|
|
202
223
|
end))
|
|
203
224
|
|
|
204
225
|
replicator:ReplicateFrom(child)
|
|
@@ -206,23 +227,26 @@ function Replicator:_renderChild(child)
|
|
|
206
227
|
return maid
|
|
207
228
|
end
|
|
208
229
|
|
|
209
|
-
|
|
210
|
-
|
|
230
|
+
function Replicator._replicateBasedUponMode(
|
|
231
|
+
self: Replicator,
|
|
232
|
+
replicator: Replicator,
|
|
233
|
+
replicationType: ReplicationType.ReplicationType,
|
|
234
|
+
child: Instance
|
|
235
|
+
)
|
|
211
236
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
212
237
|
assert(ReplicationTypeUtils.isReplicationType(replicationType), "Bad replicationType")
|
|
213
238
|
assert(typeof(child) == "Instance", "Bad child")
|
|
214
239
|
|
|
215
240
|
if replicationType == ReplicationType.SERVER then
|
|
216
241
|
return self:_doReplicationServer(replicator, child)
|
|
217
|
-
elseif replicationType == ReplicationType.SHARED
|
|
218
|
-
or replicationType == ReplicationType.CLIENT then
|
|
242
|
+
elseif replicationType == ReplicationType.SHARED or replicationType == ReplicationType.CLIENT then
|
|
219
243
|
return self:_doReplicationClient(replicator, child)
|
|
220
244
|
else
|
|
221
245
|
error("[Replicator] - Unknown replicationType")
|
|
222
246
|
end
|
|
223
247
|
end
|
|
224
248
|
|
|
225
|
-
function Replicator
|
|
249
|
+
function Replicator._doReplicationServer(self: Replicator, replicator: Replicator, child: Instance)
|
|
226
250
|
local maid = Maid.new()
|
|
227
251
|
|
|
228
252
|
local hasReplicatedChildren = replicator:GetHasReplicatedChildrenValue()
|
|
@@ -240,7 +264,7 @@ function Replicator:_doReplicationServer(replicator, child)
|
|
|
240
264
|
end
|
|
241
265
|
end
|
|
242
266
|
|
|
243
|
-
function Replicator
|
|
267
|
+
function Replicator._doServerClone(self: Replicator, replicator: Replicator, child: Instance): Maid.Maid
|
|
244
268
|
-- Always a folder to prevent information from leaking...
|
|
245
269
|
local maid = Maid.new()
|
|
246
270
|
local copy = maid:Add(Instance.new("Folder"))
|
|
@@ -255,7 +279,7 @@ function Replicator:_doServerClone(replicator, child)
|
|
|
255
279
|
return maid
|
|
256
280
|
end
|
|
257
281
|
|
|
258
|
-
function Replicator
|
|
282
|
+
function Replicator._doReplicationClient(self: Replicator, replicator: Replicator, child: Instance): Maid.Maid
|
|
259
283
|
local maid = Maid.new()
|
|
260
284
|
|
|
261
285
|
if child:IsA("ModuleScript") then
|
|
@@ -278,7 +302,8 @@ function Replicator:_doReplicationClient(replicator, child)
|
|
|
278
302
|
self:_setupObjectValueReplication(maid, child, copy)
|
|
279
303
|
self:_doStandardReplication(maid, replicator, child, copy)
|
|
280
304
|
else
|
|
281
|
-
|
|
305
|
+
-- selene: allow(incorrect_standard_library_use)
|
|
306
|
+
local copy = maid:Add(Instance.fromExisting(child))
|
|
282
307
|
|
|
283
308
|
-- TODO: Maybe do better
|
|
284
309
|
self:_setupReplicatedDescendantCountAdd(maid, 1)
|
|
@@ -288,20 +313,27 @@ function Replicator:_doReplicationClient(replicator, child)
|
|
|
288
313
|
return maid
|
|
289
314
|
end
|
|
290
315
|
|
|
291
|
-
function Replicator
|
|
316
|
+
function Replicator._doModuleScriptCloneClient(self: Replicator, replicator: Replicator, child: Instance): Maid.Maid
|
|
292
317
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
293
318
|
assert(typeof(child) == "Instance", "Bad child")
|
|
294
319
|
|
|
295
320
|
local maid = Maid.new()
|
|
296
321
|
|
|
297
|
-
|
|
322
|
+
-- selene: allow(incorrect_standard_library_use)
|
|
323
|
+
local copy = maid:Add(Instance.fromExisting(child))
|
|
298
324
|
|
|
299
325
|
self:_doStandardReplication(maid, replicator, child, copy)
|
|
300
326
|
|
|
301
327
|
return maid
|
|
302
328
|
end
|
|
303
329
|
|
|
304
|
-
function Replicator
|
|
330
|
+
function Replicator._doStandardReplication(
|
|
331
|
+
self: Replicator,
|
|
332
|
+
maid: Maid.Maid,
|
|
333
|
+
replicator: Replicator,
|
|
334
|
+
child: Instance,
|
|
335
|
+
copy: Instance
|
|
336
|
+
)
|
|
305
337
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
306
338
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
307
339
|
assert(typeof(child) == "Instance", "Bad child")
|
|
@@ -316,15 +348,15 @@ function Replicator:_doStandardReplication(maid, replicator, child, copy)
|
|
|
316
348
|
self:_setupReplicatorTarget(maid, replicator, copy)
|
|
317
349
|
end
|
|
318
350
|
|
|
319
|
-
function Replicator
|
|
351
|
+
function Replicator._setupReplicatedDescendantCountAdd(self: Replicator, maid: Maid.Maid, amount: number)
|
|
320
352
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
321
353
|
assert(type(amount) == "number", "Bad amount")
|
|
322
354
|
|
|
323
355
|
-- Do this replication count here so when the source changes we don't
|
|
324
356
|
-- have any flickering.
|
|
325
|
-
self._replicatedDescendantCount.Value
|
|
357
|
+
self._replicatedDescendantCount.Value += amount
|
|
326
358
|
maid:GiveTask(function()
|
|
327
|
-
self._replicatedDescendantCount.Value
|
|
359
|
+
self._replicatedDescendantCount.Value -= amount
|
|
328
360
|
end)
|
|
329
361
|
end
|
|
330
362
|
|
|
@@ -338,7 +370,7 @@ end
|
|
|
338
370
|
@param replicator Replicator
|
|
339
371
|
@param copy Instance
|
|
340
372
|
]]
|
|
341
|
-
function Replicator
|
|
373
|
+
function Replicator._setupReplicatorTarget(_self: Replicator, maid: Maid.Maid, replicator: Replicator, copy: Instance)
|
|
342
374
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
343
375
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
344
376
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
@@ -346,7 +378,11 @@ function Replicator:_setupReplicatorTarget(maid, replicator, copy)
|
|
|
346
378
|
replicator:SetTarget(copy)
|
|
347
379
|
|
|
348
380
|
maid:GiveTask(function()
|
|
349
|
-
if replicator.Destroy
|
|
381
|
+
if not replicator.Destroy then
|
|
382
|
+
return
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
if (replicator :: any):GetTarget() == copy then
|
|
350
386
|
replicator:SetTarget(nil)
|
|
351
387
|
end
|
|
352
388
|
end)
|
|
@@ -361,25 +397,25 @@ end
|
|
|
361
397
|
@param maid Maid
|
|
362
398
|
@param replicator Replicator
|
|
363
399
|
]]
|
|
364
|
-
function Replicator
|
|
400
|
+
function Replicator._setupReplicatorDescendantCount(self: Replicator, maid: Maid.Maid, replicator: Replicator)
|
|
365
401
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
366
402
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
367
403
|
|
|
368
404
|
local replicatedChildrenCount = replicator:GetReplicatedDescendantCountValue()
|
|
369
405
|
local lastValue = replicatedChildrenCount.Value
|
|
370
|
-
self._replicatedDescendantCount.Value
|
|
406
|
+
self._replicatedDescendantCount.Value += lastValue
|
|
371
407
|
|
|
372
408
|
maid:GiveTask(replicatedChildrenCount.Changed:Connect(function()
|
|
373
409
|
local value = replicatedChildrenCount.Value
|
|
374
410
|
local delta = value - lastValue
|
|
375
411
|
lastValue = value
|
|
376
|
-
self._replicatedDescendantCount.Value
|
|
412
|
+
self._replicatedDescendantCount.Value += delta
|
|
377
413
|
end))
|
|
378
414
|
|
|
379
415
|
maid:GiveTask(function()
|
|
380
416
|
local value = lastValue
|
|
381
417
|
lastValue = 0
|
|
382
|
-
self._replicatedDescendantCount.Value
|
|
418
|
+
self._replicatedDescendantCount.Value -= value
|
|
383
419
|
end)
|
|
384
420
|
end
|
|
385
421
|
|
|
@@ -390,7 +426,7 @@ end
|
|
|
390
426
|
@param child Instance
|
|
391
427
|
@param copy Instance
|
|
392
428
|
]]
|
|
393
|
-
function Replicator
|
|
429
|
+
function Replicator._setupReference(self: Replicator, maid, child: Instance, copy: Instance)
|
|
394
430
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
395
431
|
assert(typeof(child) == "Instance", "Bad child")
|
|
396
432
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
@@ -410,7 +446,12 @@ end
|
|
|
410
446
|
@param replicator
|
|
411
447
|
@param child Instance
|
|
412
448
|
]]
|
|
413
|
-
function Replicator
|
|
449
|
+
function Replicator._setupReplicatorTypeFromFolderName(
|
|
450
|
+
self: Replicator,
|
|
451
|
+
maid: Maid.Maid,
|
|
452
|
+
replicator: Replicator,
|
|
453
|
+
child: Instance
|
|
454
|
+
)
|
|
414
455
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
415
456
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
416
457
|
assert(typeof(child) == "Instance", "Bad child")
|
|
@@ -424,7 +465,7 @@ function Replicator:_setupReplicatorTypeFromFolderName(maid, replicator, child)
|
|
|
424
465
|
replicator:SetReplicationType(self:_getFolderReplicationType(child.Name))
|
|
425
466
|
end
|
|
426
467
|
|
|
427
|
-
function Replicator
|
|
468
|
+
function Replicator._setupReplicatorType(self: Replicator, maid, replicator)
|
|
428
469
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
429
470
|
assert(Replicator.isReplicator(replicator), "Bad replicator")
|
|
430
471
|
|
|
@@ -441,7 +482,7 @@ end
|
|
|
441
482
|
@param child Instance
|
|
442
483
|
@param copy Instance
|
|
443
484
|
]]
|
|
444
|
-
function Replicator
|
|
485
|
+
function Replicator._setupNameReplication(_self: Replicator, maid: Maid.Maid, child: Instance, copy: Instance)
|
|
445
486
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
446
487
|
assert(typeof(child) == "Instance", "Bad child")
|
|
447
488
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
@@ -458,7 +499,7 @@ end
|
|
|
458
499
|
@param maid Maid
|
|
459
500
|
@param copy Instance
|
|
460
501
|
]]
|
|
461
|
-
function Replicator
|
|
502
|
+
function Replicator._setupParentReplication(self: Replicator, maid: Maid.Maid, copy: Instance)
|
|
462
503
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
463
504
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
464
505
|
|
|
@@ -475,23 +516,23 @@ end
|
|
|
475
516
|
@param child Instance
|
|
476
517
|
@param copy Instance
|
|
477
518
|
]]
|
|
478
|
-
function Replicator
|
|
519
|
+
function Replicator._setupTagReplication(_self: Replicator, maid: Maid.Maid, child: Instance, copy: Instance)
|
|
479
520
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
480
521
|
assert(typeof(child) == "Instance", "Bad child")
|
|
481
522
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
482
523
|
|
|
483
|
-
for _, tag in
|
|
524
|
+
for _, tag in child:GetTags() do
|
|
484
525
|
copy:AddTag(tag)
|
|
485
526
|
end
|
|
486
527
|
|
|
487
528
|
maid:GiveTask(child.Changed:Connect(function(property)
|
|
488
529
|
if property == "Tags" then
|
|
489
|
-
local ourTagSet = {}
|
|
490
|
-
for _, tag in
|
|
530
|
+
local ourTagSet: { [string]: true } = {}
|
|
531
|
+
for _, tag in copy:GetTags() do
|
|
491
532
|
ourTagSet[tag] = true
|
|
492
533
|
end
|
|
493
534
|
|
|
494
|
-
for _, tag in
|
|
535
|
+
for _, tag in child:GetTags() do
|
|
495
536
|
if not ourTagSet[tag] then
|
|
496
537
|
copy:AddTag(tag)
|
|
497
538
|
end
|
|
@@ -499,7 +540,7 @@ function Replicator:_setupTagReplication(maid, child, copy)
|
|
|
499
540
|
ourTagSet[tag] = nil
|
|
500
541
|
end
|
|
501
542
|
|
|
502
|
-
for tag, _ in
|
|
543
|
+
for tag, _ in ourTagSet do
|
|
503
544
|
copy:RemoveTag(tag)
|
|
504
545
|
end
|
|
505
546
|
end
|
|
@@ -513,7 +554,7 @@ end
|
|
|
513
554
|
@param child Instance
|
|
514
555
|
@param copy Instance
|
|
515
556
|
]]
|
|
516
|
-
function Replicator
|
|
557
|
+
function Replicator._setupObjectValueReplication(self: Replicator, maid: Maid.Maid, child: ObjectValue, copy: Instance)
|
|
517
558
|
assert(Maid.isMaid(maid), "Bad maid")
|
|
518
559
|
assert(typeof(child) == "Instance", "Bad child")
|
|
519
560
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
@@ -526,27 +567,27 @@ function Replicator:_setupObjectValueReplication(maid, child, copy)
|
|
|
526
567
|
maid[symbol] = self:_doObjectValueReplication(child, copy)
|
|
527
568
|
end
|
|
528
569
|
|
|
529
|
-
function Replicator
|
|
570
|
+
function Replicator._doObjectValueReplication(self: Replicator, child: ValueBase, copy: Instance): Maid.Maid?
|
|
530
571
|
assert(typeof(child) == "Instance", "Bad child")
|
|
531
572
|
assert(typeof(copy) == "Instance", "Bad copy")
|
|
532
573
|
|
|
533
|
-
local childValue = child.Value
|
|
574
|
+
local childValue: Instance? = (child :: any).Value
|
|
534
575
|
if childValue then
|
|
535
576
|
local maid = Maid.new()
|
|
536
577
|
|
|
537
|
-
maid:GiveTask(self._references:ObserveReferenceChanged(childValue,
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
end))
|
|
578
|
+
maid:GiveTask(self._references:ObserveReferenceChanged(childValue, function(newValue)
|
|
579
|
+
if newValue then
|
|
580
|
+
(copy :: any).Value = newValue
|
|
581
|
+
else
|
|
582
|
+
-- Fall back to original value (pointing outside of tree)
|
|
583
|
+
newValue = childValue
|
|
584
|
+
end
|
|
585
|
+
end))
|
|
546
586
|
|
|
547
587
|
return maid
|
|
548
588
|
else
|
|
549
|
-
copy.Value = nil
|
|
589
|
+
(copy :: any).Value = nil
|
|
590
|
+
|
|
550
591
|
return nil
|
|
551
592
|
end
|
|
552
593
|
end
|
|
@@ -557,16 +598,17 @@ end
|
|
|
557
598
|
|
|
558
599
|
@param childName string
|
|
559
600
|
]]
|
|
560
|
-
function Replicator
|
|
601
|
+
function Replicator._getFolderReplicationType(self: Replicator, childName: string): ReplicationType.ReplicationType
|
|
561
602
|
assert(type(childName) == "string", "Bad childName")
|
|
562
603
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
604
|
+
local replicationType: ReplicationType.ReplicationType =
|
|
605
|
+
self._replicationType.Value :: ReplicationType.ReplicationType
|
|
606
|
+
|
|
607
|
+
return ReplicationTypeUtils.getFolderReplicationType(childName, replicationType)
|
|
566
608
|
end
|
|
567
609
|
|
|
568
|
-
function Replicator
|
|
569
|
-
for key, value in
|
|
610
|
+
function Replicator._setupAttributeReplication(_self: Replicator, maid: Maid.Maid, child: Instance, copy: Instance)
|
|
611
|
+
for key, value in child:GetAttributes() do
|
|
570
612
|
copy:SetAttribute(key, value)
|
|
571
613
|
end
|
|
572
614
|
|
|
@@ -579,9 +621,9 @@ end
|
|
|
579
621
|
Cleans up the replicator disconnecting all events and cleaning up
|
|
580
622
|
created instances.
|
|
581
623
|
]=]
|
|
582
|
-
function Replicator
|
|
624
|
+
function Replicator.Destroy(self: Replicator)
|
|
583
625
|
self._maid:DoCleaning()
|
|
584
|
-
setmetatable(self, nil)
|
|
626
|
+
setmetatable(self :: any, nil)
|
|
585
627
|
end
|
|
586
628
|
|
|
587
629
|
return Replicator
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Handles mapping of references to the new value.
|
|
3
4
|
|
|
@@ -8,7 +9,17 @@ local ReplicatorReferences = {}
|
|
|
8
9
|
ReplicatorReferences.ClassName = "ReplicatorReferences"
|
|
9
10
|
ReplicatorReferences.__index = ReplicatorReferences
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
export type ListenerCallback = (Instance?) -> ()
|
|
13
|
+
|
|
14
|
+
export type ReplicatorReferences = typeof(setmetatable(
|
|
15
|
+
{} :: {
|
|
16
|
+
_lookup: { [Instance]: Instance },
|
|
17
|
+
_listeners: { [Instance]: { ListenerCallback } },
|
|
18
|
+
},
|
|
19
|
+
ReplicatorReferences
|
|
20
|
+
))
|
|
21
|
+
|
|
22
|
+
function ReplicatorReferences.new(): ReplicatorReferences
|
|
12
23
|
local self = setmetatable({}, ReplicatorReferences)
|
|
13
24
|
|
|
14
25
|
self._lookup = {}
|
|
@@ -23,12 +34,11 @@ end
|
|
|
23
34
|
@param replicatorReferences any?
|
|
24
35
|
@return boolean
|
|
25
36
|
]=]
|
|
26
|
-
function ReplicatorReferences.isReplicatorReferences(replicatorReferences)
|
|
27
|
-
return type(replicatorReferences) == "table" and
|
|
28
|
-
getmetatable(replicatorReferences) == ReplicatorReferences
|
|
37
|
+
function ReplicatorReferences.isReplicatorReferences(replicatorReferences: any): boolean
|
|
38
|
+
return type(replicatorReferences) == "table" and getmetatable(replicatorReferences :: any) == ReplicatorReferences
|
|
29
39
|
end
|
|
30
40
|
|
|
31
|
-
function ReplicatorReferences
|
|
41
|
+
function ReplicatorReferences.SetReference(self: ReplicatorReferences, orig: Instance, replicated: Instance)
|
|
32
42
|
assert(typeof(orig) == "Instance", "Bad orig")
|
|
33
43
|
assert(typeof(replicated) == "Instance", "Bad replicated")
|
|
34
44
|
|
|
@@ -38,7 +48,7 @@ function ReplicatorReferences:SetReference(orig, replicated)
|
|
|
38
48
|
end
|
|
39
49
|
end
|
|
40
50
|
|
|
41
|
-
function ReplicatorReferences
|
|
51
|
+
function ReplicatorReferences.UnsetReference(self: ReplicatorReferences, orig: Instance, replicated: Instance)
|
|
42
52
|
assert(typeof(orig) == "Instance", "Bad orig")
|
|
43
53
|
assert(typeof(replicated) == "Instance", "Bad replicated")
|
|
44
54
|
|
|
@@ -48,11 +58,11 @@ function ReplicatorReferences:UnsetReference(orig, replicated)
|
|
|
48
58
|
end
|
|
49
59
|
end
|
|
50
60
|
|
|
51
|
-
function ReplicatorReferences
|
|
61
|
+
function ReplicatorReferences.GetReference(self: ReplicatorReferences, orig: Instance): Instance?
|
|
52
62
|
return self._lookup[orig]
|
|
53
63
|
end
|
|
54
64
|
|
|
55
|
-
function ReplicatorReferences
|
|
65
|
+
function ReplicatorReferences._fireSubs(self: ReplicatorReferences, orig: Instance, newValue: Instance?)
|
|
56
66
|
assert(typeof(orig) == "Instance", "Bad orig")
|
|
57
67
|
|
|
58
68
|
local listeners = self._listeners[orig]
|
|
@@ -60,7 +70,7 @@ function ReplicatorReferences:_fireSubs(orig, newValue)
|
|
|
60
70
|
return
|
|
61
71
|
end
|
|
62
72
|
|
|
63
|
-
for _, callback in
|
|
73
|
+
for _, callback in listeners do
|
|
64
74
|
task.spawn(callback, newValue)
|
|
65
75
|
end
|
|
66
76
|
end
|
|
@@ -71,9 +81,9 @@ end
|
|
|
71
81
|
|
|
72
82
|
@param orig Instance
|
|
73
83
|
@param callback function
|
|
74
|
-
@return
|
|
84
|
+
@return () -> () -- Call to disconnect
|
|
75
85
|
]=]
|
|
76
|
-
function ReplicatorReferences
|
|
86
|
+
function ReplicatorReferences.ObserveReferenceChanged(self: ReplicatorReferences, orig: Instance, callback: ListenerCallback): () -> ()
|
|
77
87
|
assert(typeof(orig) == "Instance", "Bad orig")
|
|
78
88
|
assert(type(callback) == "function", "Bad callback")
|
|
79
89
|
|
|
@@ -81,7 +91,7 @@ function ReplicatorReferences:ObserveReferenceChanged(orig, callback)
|
|
|
81
91
|
do
|
|
82
92
|
local listeners = self._listeners[orig]
|
|
83
93
|
if not listeners then
|
|
84
|
-
listeners = {}
|
|
94
|
+
listeners = {} :: { ListenerCallback }
|
|
85
95
|
self._listeners[orig] = listeners
|
|
86
96
|
end
|
|
87
97
|
|