@rbxts/covenant 1.3.4 → 1.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class Covenant {
19
19
  private undefinedStringifiedComponents;
20
20
  private replicatedStringifiedComponents;
21
21
  private predictedStringifiedComponents;
22
+ private internalStringifiedComponents;
22
23
  private started;
23
24
  private stringifiedComponentSubscribers;
24
25
  private stringifiedComponentValidators;
@@ -29,6 +30,7 @@ export declare class Covenant {
29
30
  private predictionConnect;
30
31
  constructor({ replicationSend, replicationConnect, replicationSendAll, predictionSend, predictionConnect, }: CovenantProps);
31
32
  private setupPredictionClient;
33
+ private forEachComponentChanges;
32
34
  private setupPredictionServer;
33
35
  private setupPrediction;
34
36
  private setupReplicationServer;
@@ -59,7 +61,7 @@ export declare class Covenant {
59
61
  childIdentityComponent: Entity<T>;
60
62
  getIdentifier: (state: T) => Discriminator;
61
63
  queriedComponents: Entity[][];
62
- recipe: (entity: Entity, lastChildrenStates: ReadonlyArray<T>, updateId: number, hooks: CovenantHooks) => ReadonlyArray<T>;
64
+ recipe: (entity: Entity, lastChildrenStates: ReadonlySet<T>, updateId: number, hooks: CovenantHooks) => ReadonlySet<T>;
63
65
  }): void;
64
66
  defineStaticEntity<T extends defined>({ identityComponent, recipe, replicated, }: {
65
67
  replicated: boolean;
package/src/covenant.luau CHANGED
@@ -13,7 +13,7 @@ local Remove = _stringEnums.Remove
13
13
  local Delete = _stringEnums.Delete
14
14
  local _helpers = TS.import(script, script.Parent, "helpers")
15
15
  local compareMaps = _helpers.compareMaps
16
- local turnArrayWithIdentifierToMap = _helpers.turnArrayWithIdentifierToMap
16
+ local turnSetWithIdentifierToMap = _helpers.turnSetWithIdentifierToMap
17
17
  local EventMap = TS.import(script, script.Parent, "dataStructureWithEvents").EventMap
18
18
  -- Map<Entity, Delete | Map<Component, state | Remove>>
19
19
  -- Map<Component, Map<Entity, state | Remove>>
@@ -52,6 +52,7 @@ do
52
52
  self.undefinedStringifiedComponents = {}
53
53
  self.replicatedStringifiedComponents = {}
54
54
  self.predictedStringifiedComponents = {}
55
+ self.internalStringifiedComponents = {}
55
56
  self.started = false
56
57
  self.stringifiedComponentSubscribers = {}
57
58
  self.stringifiedComponentValidators = {}
@@ -73,58 +74,81 @@ do
73
74
  self.predictionSend(currentWorldChanges)
74
75
  end, math.huge)
75
76
  end
77
+ function Covenant:forEachComponentChanges(player, worldReconciliation, componentChanges, stringifiedComponent)
78
+ local component = tonumber(stringifiedComponent)
79
+ local _stringifiedComponentValidators = self.stringifiedComponentValidators
80
+ local _stringifiedComponent = stringifiedComponent
81
+ local validator = _stringifiedComponentValidators[_stringifiedComponent]
82
+ if not validator then
83
+ return nil
84
+ end
85
+ -- ▼ ReadonlyMap.forEach ▼
86
+ local _callback = function(state, stringifiedEntity)
87
+ local entity = tonumber(stringifiedEntity)
88
+ if not self:worldContains(entity) then
89
+ return nil
90
+ end
91
+ local newState = if state == Remove then nil else state
92
+ local lastState = self:worldGet(entity, component)
93
+ local valid = validator(player, entity, newState, lastState)
94
+ if valid then
95
+ self:worldSet(entity, component, newState)
96
+ else
97
+ local _worldReconciliation = worldReconciliation
98
+ local _stringifiedEntity = stringifiedEntity
99
+ local entityReconciliations = _worldReconciliation[_stringifiedEntity]
100
+ local _arg0 = entityReconciliations ~= Delete
101
+ assert(_arg0)
102
+ if entityReconciliations == nil then
103
+ entityReconciliations = {}
104
+ local _worldReconciliation_1 = worldReconciliation
105
+ local _stringifiedEntity_1 = stringifiedEntity
106
+ local _entityReconciliations = entityReconciliations
107
+ _worldReconciliation_1[_stringifiedEntity_1] = _entityReconciliations
108
+ end
109
+ local _entityReconciliations = entityReconciliations
110
+ local _exp = stringifiedComponent
111
+ local _condition = self:worldGet(entity, component)
112
+ if _condition == nil then
113
+ _condition = Remove
114
+ end
115
+ _entityReconciliations[_exp] = _condition
116
+ end
117
+ end
118
+ for _k, _v in componentChanges do
119
+ _callback(_v, _k, componentChanges)
120
+ end
121
+ -- ▲ ReadonlyMap.forEach ▲
122
+ end
76
123
  function Covenant:setupPredictionServer()
77
124
  self.predictionConnect(function(player, worldChanges)
78
125
  local worldReconciliation = {}
79
126
  -- ▼ ReadonlyMap.forEach ▼
80
127
  local _callback = function(componentChanges, stringifiedComponent)
81
- local component = tonumber(stringifiedComponent)
82
- local _stringifiedComponentValidators = self.stringifiedComponentValidators
128
+ local _internalStringifiedComponents = self.internalStringifiedComponents
83
129
  local _stringifiedComponent = stringifiedComponent
84
- local validator = _stringifiedComponentValidators[_stringifiedComponent]
85
- if not validator then
130
+ if not (_internalStringifiedComponents[_stringifiedComponent] ~= nil) then
86
131
  return nil
87
132
  end
88
- -- ReadonlyMap.forEach
89
- local _callback_1 = function(state, stringifiedEntity)
90
- local entity = tonumber(stringifiedEntity)
91
- if not self:worldContains(entity) then
92
- return nil
93
- end
94
- local newState = if state == Remove then nil else state
95
- local lastState = self:worldGet(entity, component)
96
- local valid = validator(player, entity, newState, lastState)
97
- if valid then
98
- self:worldSet(entity, component, newState)
99
- else
100
- local _stringifiedEntity = stringifiedEntity
101
- local entityReconciliations = worldReconciliation[_stringifiedEntity]
102
- local _arg0 = entityReconciliations ~= Delete
103
- assert(_arg0)
104
- if entityReconciliations == nil then
105
- entityReconciliations = {}
106
- local _stringifiedEntity_1 = stringifiedEntity
107
- local _entityReconciliations = entityReconciliations
108
- worldReconciliation[_stringifiedEntity_1] = _entityReconciliations
109
- end
110
- local _entityReconciliations = entityReconciliations
111
- local _exp = stringifiedComponent
112
- local _condition = self:worldGet(entity, component)
113
- if _condition == nil then
114
- _condition = Remove
115
- end
116
- _entityReconciliations[_exp] = _condition
117
- end
118
- end
119
- for _k, _v in componentChanges do
120
- _callback_1(_v, _k, componentChanges)
121
- end
122
- -- ▲ ReadonlyMap.forEach ▲
133
+ self:forEachComponentChanges(player, worldReconciliation, componentChanges, stringifiedComponent)
123
134
  end
124
135
  for _k, _v in worldChanges do
125
136
  _callback(_v, _k, worldChanges)
126
137
  end
127
138
  -- ▲ ReadonlyMap.forEach ▲
139
+ -- ▼ ReadonlyMap.forEach ▼
140
+ local _callback_1 = function(componentChanges, stringifiedComponent)
141
+ local _internalStringifiedComponents = self.internalStringifiedComponents
142
+ local _stringifiedComponent = stringifiedComponent
143
+ if _internalStringifiedComponents[_stringifiedComponent] ~= nil then
144
+ return nil
145
+ end
146
+ self:forEachComponentChanges(player, worldReconciliation, componentChanges, stringifiedComponent)
147
+ end
148
+ for _k, _v in worldChanges do
149
+ _callback_1(_v, _k, worldChanges)
150
+ end
151
+ -- ▲ ReadonlyMap.forEach ▲
128
152
  if not (next(worldReconciliation) == nil) then
129
153
  self.replicationSend(player, worldReconciliation)
130
154
  end
@@ -206,6 +230,11 @@ do
206
230
  end
207
231
  -- ▼ ReadonlyMap.forEach ▼
208
232
  local _callback_1 = function(state, stringifiedComponent)
233
+ local _internalStringifiedComponents = self.internalStringifiedComponents
234
+ local _stringifiedComponent = stringifiedComponent
235
+ if not (_internalStringifiedComponents[_stringifiedComponent] ~= nil) then
236
+ return nil
237
+ end
209
238
  local component = tonumber(stringifiedComponent)
210
239
  if state == Remove then
211
240
  self:worldSet(entity, component, nil, true)
@@ -217,6 +246,24 @@ do
217
246
  _callback_1(_v, _k, entityData)
218
247
  end
219
248
  -- ▲ ReadonlyMap.forEach ▲
249
+ -- ▼ ReadonlyMap.forEach ▼
250
+ local _callback_2 = function(state, stringifiedComponent)
251
+ local _internalStringifiedComponents = self.internalStringifiedComponents
252
+ local _stringifiedComponent = stringifiedComponent
253
+ if _internalStringifiedComponents[_stringifiedComponent] ~= nil then
254
+ return nil
255
+ end
256
+ local component = tonumber(stringifiedComponent)
257
+ if state == Remove then
258
+ self:worldSet(entity, component, nil, true)
259
+ else
260
+ self:worldSet(entity, component, state, true)
261
+ end
262
+ end
263
+ for _k, _v in entityData do
264
+ _callback_2(_v, _k, entityData)
265
+ end
266
+ -- ▲ ReadonlyMap.forEach ▲
220
267
  end
221
268
  for _k, _v in worldChanges do
222
269
  _callback(_v, _k, worldChanges)
@@ -438,7 +485,11 @@ do
438
485
  end
439
486
  function Covenant:worldInternalComponent()
440
487
  self:preventPostStartCall()
441
- return self._world:component()
488
+ local c = self._world:component()
489
+ local _internalStringifiedComponents = self.internalStringifiedComponents
490
+ local _arg0 = tostring(c)
491
+ _internalStringifiedComponents[_arg0] = true
492
+ return c
442
493
  end
443
494
  function Covenant:checkComponentDefined(component)
444
495
  local _undefinedStringifiedComponents = self.undefinedStringifiedComponents
@@ -658,8 +709,8 @@ do
658
709
  -- ▲ ReadonlyArray.forEach ▲
659
710
  local lastUpdateId = 0
660
711
  self:subscribeComponent(parentComponent, function(entity, newState, lastState)
661
- local lastStateMap = turnArrayWithIdentifierToMap(lastState or {}, getIdentifier)
662
- local newStateMap = turnArrayWithIdentifierToMap(newState or {}, getIdentifier)
712
+ local lastStateMap = turnSetWithIdentifierToMap(lastState or {}, getIdentifier)
713
+ local newStateMap = turnSetWithIdentifierToMap(newState or {}, getIdentifier)
663
714
  local entityTracker = self:worldGet(entity, parentEntityTrackerComponent)
664
715
  if entityTracker == nil then
665
716
  entityTracker = {}
package/src/helpers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Discriminator } from "./hooks";
2
2
 
3
- export declare function turnArrayWithIdentifierToMap<T extends defined>(
4
- array: ReadonlyArray<T>,
3
+ export declare function turnSetWithIdentifierToMap<T extends defined>(
4
+ set: ReadonlySet<T>,
5
5
  getIdentifier: (state: T) => Discriminator,
6
6
  ): Map<defined, T>;
7
7
  export declare function compareMaps<
package/src/helpers.luau CHANGED
@@ -1,5 +1,6 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
- local function turnArrayWithIdentifierToMap(array, getIdentifier)
2
+ -- Manually modified
3
+ local function turnSetWithIdentifierToMap(set, getIdentifier)
3
4
  local newMap = {}
4
5
  -- ▼ ReadonlyArray.forEach ▼
5
6
  local _callback = function(value)
@@ -7,7 +8,7 @@ local function turnArrayWithIdentifierToMap(array, getIdentifier)
7
8
  local _value = value
8
9
  newMap[identifier] = _value
9
10
  end
10
- for _k, _v in array do
11
+ for _v, _ in set do
11
12
  _callback(_v)
12
13
  end
13
14
  -- ▲ ReadonlyArray.forEach ▲