@rbxts/covenant 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/covenant.d.ts +7 -7
- package/src/covenant.luau +39 -33
package/package.json
CHANGED
package/src/covenant.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Covenant {
|
|
|
16
16
|
private systems;
|
|
17
17
|
private worldChangesForReplication;
|
|
18
18
|
private worldChangesForPrediction;
|
|
19
|
-
private
|
|
19
|
+
private undefinedStringifiedComponents;
|
|
20
20
|
private replicatedStringifiedComponents;
|
|
21
21
|
private predictedStringifiedComponents;
|
|
22
22
|
private started;
|
|
@@ -41,16 +41,16 @@ export declare class Covenant {
|
|
|
41
41
|
subscribeComponent<T>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void): () => void;
|
|
42
42
|
private worldDelete;
|
|
43
43
|
worldComponent<T extends defined>(): Entity<T>;
|
|
44
|
-
private
|
|
44
|
+
private checkComponentDefined;
|
|
45
45
|
private defineComponentNetworkBehavior;
|
|
46
|
-
|
|
46
|
+
defineComputedComponent<T extends defined>({ component, queriedComponents, recipe, replicated, predictionValidator, }: {
|
|
47
47
|
replicated: boolean;
|
|
48
48
|
predictionValidator: ComponentPredictionValidator | false;
|
|
49
49
|
component: Entity<T>;
|
|
50
50
|
queriedComponents: Entity[][];
|
|
51
51
|
recipe: (entity: Entity, lastState: T | undefined, updateId: number, hooks: CovenantHooks) => T | undefined;
|
|
52
52
|
}): void;
|
|
53
|
-
|
|
53
|
+
defineManagedChildren<T extends defined>({ parentComponent, parentEntityTrackerComponent, childIdentityComponent, getIdentifier, queriedComponents, recipe, replicated, predictionValidator, }: {
|
|
54
54
|
replicated: boolean;
|
|
55
55
|
predictionValidator: ComponentPredictionValidator | false;
|
|
56
56
|
parentComponent: Entity<ReadonlyArray<T>>;
|
|
@@ -60,12 +60,12 @@ export declare class Covenant {
|
|
|
60
60
|
queriedComponents: Entity[][];
|
|
61
61
|
recipe: (entity: Entity, lastChildrenStates: ReadonlyArray<T>, updateId: number, hooks: CovenantHooks) => ReadonlyArray<T>;
|
|
62
62
|
}): void;
|
|
63
|
-
|
|
63
|
+
defineEntitySource<T extends defined>({ identityComponent, recipe, replicated, }: {
|
|
64
64
|
replicated: boolean;
|
|
65
65
|
identityComponent: Entity<T>;
|
|
66
66
|
recipe: (updateId: number, hooks: CovenantHooks) => {
|
|
67
|
-
statesToCreate
|
|
68
|
-
entitiesToDelete
|
|
67
|
+
statesToCreate?: ReadonlyArray<T>;
|
|
68
|
+
entitiesToDelete?: ReadonlyArray<Entity>;
|
|
69
69
|
};
|
|
70
70
|
}): void;
|
|
71
71
|
private worldEntity;
|
package/src/covenant.luau
CHANGED
|
@@ -48,7 +48,7 @@ do
|
|
|
48
48
|
self.systems = {}
|
|
49
49
|
self.worldChangesForReplication = {}
|
|
50
50
|
self.worldChangesForPrediction = {}
|
|
51
|
-
self.
|
|
51
|
+
self.undefinedStringifiedComponents = {}
|
|
52
52
|
self.replicatedStringifiedComponents = {}
|
|
53
53
|
self.predictedStringifiedComponents = {}
|
|
54
54
|
self.started = false
|
|
@@ -235,14 +235,14 @@ do
|
|
|
235
235
|
function Covenant:start()
|
|
236
236
|
local _arg0 = not self.started
|
|
237
237
|
assert(_arg0, "Already started")
|
|
238
|
-
local _exp = next(self.
|
|
238
|
+
local _exp = next(self.undefinedStringifiedComponents) == nil
|
|
239
239
|
-- ▼ ReadonlySet.size ▼
|
|
240
240
|
local _size = 0
|
|
241
|
-
for _ in self.
|
|
241
|
+
for _ in self.undefinedStringifiedComponents do
|
|
242
242
|
_size += 1
|
|
243
243
|
end
|
|
244
244
|
-- ▲ ReadonlySet.size ▲
|
|
245
|
-
local _arg1 = `There are {_size} components that are not
|
|
245
|
+
local _arg1 = `There are {_size} components that are not defined`
|
|
246
246
|
assert(_exp, _arg1)
|
|
247
247
|
self.started = true
|
|
248
248
|
local _exp_1 = self.systems
|
|
@@ -439,15 +439,15 @@ do
|
|
|
439
439
|
local c = self._world:component()
|
|
440
440
|
return c
|
|
441
441
|
end
|
|
442
|
-
function Covenant:
|
|
443
|
-
local
|
|
442
|
+
function Covenant:checkComponentDefined(component)
|
|
443
|
+
local _undefinedStringifiedComponents = self.undefinedStringifiedComponents
|
|
444
444
|
local _arg0 = tostring(component)
|
|
445
|
-
local _arg0_1 =
|
|
446
|
-
local _arg1 = `Component {component} is already
|
|
445
|
+
local _arg0_1 = _undefinedStringifiedComponents[_arg0] ~= nil
|
|
446
|
+
local _arg1 = `Component {component} is already defined`
|
|
447
447
|
assert(_arg0_1, _arg1)
|
|
448
|
-
local
|
|
448
|
+
local _undefinedStringifiedComponents_1 = self.undefinedStringifiedComponents
|
|
449
449
|
local _arg0_2 = tostring(component)
|
|
450
|
-
|
|
450
|
+
_undefinedStringifiedComponents_1[_arg0_2] = nil
|
|
451
451
|
end
|
|
452
452
|
function Covenant:defineComponentNetworkBehavior(component, replicated, predictionValidator)
|
|
453
453
|
if replicated then
|
|
@@ -465,13 +465,13 @@ do
|
|
|
465
465
|
_stringifiedComponentValidators[_arg0_1] = _predictionValidator
|
|
466
466
|
end
|
|
467
467
|
end
|
|
468
|
-
function Covenant:
|
|
468
|
+
function Covenant:defineComputedComponent(_param)
|
|
469
469
|
local component = _param.component
|
|
470
470
|
local queriedComponents = _param.queriedComponents
|
|
471
471
|
local recipe = _param.recipe
|
|
472
472
|
local replicated = _param.replicated
|
|
473
473
|
local predictionValidator = _param.predictionValidator
|
|
474
|
-
self:
|
|
474
|
+
self:checkComponentDefined(component)
|
|
475
475
|
self:defineComponentNetworkBehavior(component, replicated, predictionValidator)
|
|
476
476
|
local queryThisComponent = self:worldQuery(component):cached()
|
|
477
477
|
local willUpdate = true
|
|
@@ -581,7 +581,7 @@ do
|
|
|
581
581
|
updater()
|
|
582
582
|
end)
|
|
583
583
|
end
|
|
584
|
-
function Covenant:
|
|
584
|
+
function Covenant:defineManagedChildren(_param)
|
|
585
585
|
local parentComponent = _param.parentComponent
|
|
586
586
|
local parentEntityTrackerComponent = _param.parentEntityTrackerComponent
|
|
587
587
|
local childIdentityComponent = _param.childIdentityComponent
|
|
@@ -590,9 +590,9 @@ do
|
|
|
590
590
|
local recipe = _param.recipe
|
|
591
591
|
local replicated = _param.replicated
|
|
592
592
|
local predictionValidator = _param.predictionValidator
|
|
593
|
-
self:
|
|
594
|
-
self:
|
|
595
|
-
self:
|
|
593
|
+
self:checkComponentDefined(parentComponent)
|
|
594
|
+
self:checkComponentDefined(parentEntityTrackerComponent)
|
|
595
|
+
self:checkComponentDefined(childIdentityComponent)
|
|
596
596
|
self:defineComponentNetworkBehavior(parentComponent, replicated, predictionValidator)
|
|
597
597
|
local queryParentComponent = self:worldQuery(parentComponent):cached()
|
|
598
598
|
local willUpdate = true
|
|
@@ -769,11 +769,11 @@ do
|
|
|
769
769
|
updater()
|
|
770
770
|
end)
|
|
771
771
|
end
|
|
772
|
-
function Covenant:
|
|
772
|
+
function Covenant:defineEntitySource(_param)
|
|
773
773
|
local identityComponent = _param.identityComponent
|
|
774
774
|
local recipe = _param.recipe
|
|
775
775
|
local replicated = _param.replicated
|
|
776
|
-
self:
|
|
776
|
+
self:checkComponentDefined(identityComponent)
|
|
777
777
|
self:defineComponentNetworkBehavior(identityComponent, replicated, false)
|
|
778
778
|
local willUpdate = true
|
|
779
779
|
local function indicateUpdate()
|
|
@@ -791,23 +791,29 @@ do
|
|
|
791
791
|
local _binding = recipe(lastUpdateId, hooks)
|
|
792
792
|
local statesToCreate = _binding.statesToCreate
|
|
793
793
|
local entitiesToDelete = _binding.entitiesToDelete
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
self:worldDelete(entity)
|
|
794
|
+
local _result = statesToCreate
|
|
795
|
+
if _result ~= nil then
|
|
796
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
797
|
+
local _callback = function(state)
|
|
798
|
+
local entity = self:worldEntity()
|
|
799
|
+
self:worldSet(entity, identityComponent, state)
|
|
800
|
+
end
|
|
801
|
+
for _k, _v in _result do
|
|
802
|
+
_callback(_v, _k - 1, _result)
|
|
803
|
+
end
|
|
804
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
806
805
|
end
|
|
807
|
-
|
|
808
|
-
|
|
806
|
+
local _result_1 = entitiesToDelete
|
|
807
|
+
if _result_1 ~= nil then
|
|
808
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
809
|
+
local _callback = function(entity)
|
|
810
|
+
self:worldDelete(entity)
|
|
811
|
+
end
|
|
812
|
+
for _k, _v in _result_1 do
|
|
813
|
+
_callback(_v, _k - 1, _result_1)
|
|
814
|
+
end
|
|
815
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
809
816
|
end
|
|
810
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
811
817
|
end
|
|
812
818
|
self:schedule(RunService.Heartbeat, function()
|
|
813
819
|
if not willUpdate then
|