@rbxts/covenant 3.2.4 → 3.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "3.2.4",
3
+ "version": "3.3.1",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare class Covenant {
24
24
  private undefinedStringifiedComponents;
25
25
  private replicatedStringifiedComponents;
26
26
  private predictedStringifiedComponents;
27
+ private stringfiedComponentsToNameMap;
27
28
  private started;
28
29
  private stringifiedComponentSubscribers;
29
30
  private stringifiedComponentValidators;
@@ -56,7 +57,8 @@ export declare class Covenant {
56
57
  private worldSet;
57
58
  subscribeComponent<T>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void): () => void;
58
59
  private worldDelete;
59
- worldComponent<T extends defined>(): Entity<T>;
60
+ worldComponent<T extends defined>(name: string): Entity<T>;
61
+ getComponentName(component: Entity): string;
60
62
  worldTag(): Entity<undefined>;
61
63
  private checkComponentDefined;
62
64
  private defineComponentNetworkBehavior;
package/src/covenant.luau CHANGED
@@ -45,6 +45,7 @@ do
45
45
  self.undefinedStringifiedComponents = {}
46
46
  self.replicatedStringifiedComponents = {}
47
47
  self.predictedStringifiedComponents = {}
48
+ self.stringfiedComponentsToNameMap = {}
48
49
  self.started = false
49
50
  self.stringifiedComponentSubscribers = {}
50
51
  self.stringifiedComponentValidators = {}
@@ -120,12 +121,9 @@ do
120
121
  _worldReconciliation_1[_stringifiedEntity_1] = _entityReconciliations
121
122
  end
122
123
  local _entityReconciliations = entityReconciliations
123
- local _exp = stringifiedComponent
124
- local _condition = self:worldGet(entity, component)
125
- if _condition == nil then
126
- _condition = Remove
127
- end
128
- _entityReconciliations[_exp] = _condition
124
+ local _stringifiedComponent_1 = stringifiedComponent
125
+ local _arg1 = if self:worldHas(entity, component) then self:worldGet(entity, component) else Remove
126
+ _entityReconciliations[_stringifiedComponent_1] = _arg1
129
127
  end
130
128
  end
131
129
  for _k, _v in componentChanges do
@@ -249,6 +247,18 @@ do
249
247
  local _serverToClientEntityMap = self.serverToClientEntityMap
250
248
  local _stringifiedServerEntity = stringifiedServerEntity
251
249
  local entity = _serverToClientEntityMap[_stringifiedServerEntity]
250
+ if entityData == Delete then
251
+ if entity ~= nil then
252
+ self:worldDelete(entity)
253
+ end
254
+ local _serverToClientEntityMap_1 = self.serverToClientEntityMap
255
+ local _stringifiedServerEntity_1 = stringifiedServerEntity
256
+ _serverToClientEntityMap_1[_stringifiedServerEntity_1] = nil
257
+ local _clientToServerEntityMap = self.clientToServerEntityMap
258
+ local _arg0 = tostring(entity)
259
+ _clientToServerEntityMap[_arg0] = nil
260
+ return nil
261
+ end
252
262
  if entity == nil then
253
263
  entity = self._world:entity()
254
264
  local _serverToClientEntityMap_1 = self.serverToClientEntityMap
@@ -260,16 +270,6 @@ do
260
270
  local _arg1 = tonumber(stringifiedServerEntity)
261
271
  _clientToServerEntityMap[_arg0] = _arg1
262
272
  end
263
- if entityData == Delete then
264
- self:worldDelete(entity)
265
- local _serverToClientEntityMap_1 = self.serverToClientEntityMap
266
- local _stringifiedServerEntity_1 = stringifiedServerEntity
267
- _serverToClientEntityMap_1[_stringifiedServerEntity_1] = nil
268
- local _clientToServerEntityMap = self.clientToServerEntityMap
269
- local _arg0 = tostring(entity)
270
- _clientToServerEntityMap[_arg0] = nil
271
- return nil
272
- end
273
273
  -- ▼ ReadonlyMap.forEach ▼
274
274
  local _callback_2 = function(state, stringifiedComponent)
275
275
  local component = tonumber(stringifiedComponent)
@@ -415,12 +415,9 @@ do
415
415
  end
416
416
  if entityChanges ~= Delete then
417
417
  local _entityChanges = entityChanges
418
- local _exp = tostring(component)
419
- local _condition_1 = newState
420
- if _condition_1 == nil then
421
- _condition_1 = Remove
422
- end
423
- _entityChanges[_exp] = _condition_1
418
+ local _arg0_2 = tostring(component)
419
+ local _arg1 = if newState ~= nil then newState else Remove
420
+ _entityChanges[_arg0_2] = _arg1
424
421
  end
425
422
  end
426
423
  local _condition_1 = RunService:IsClient()
@@ -443,14 +440,12 @@ do
443
440
  local _clientToServerEntityMap = self.clientToServerEntityMap
444
441
  local _arg0_2 = tostring(entity)
445
442
  local serverEntity = _clientToServerEntityMap[_arg0_2]
446
- assert(serverEntity ~= 0 and serverEntity == serverEntity and serverEntity, "This entity should exist.")
447
- local _componentChanges = componentChanges
448
- local _exp = tostring(serverEntity)
449
- local _condition_2 = newState
450
- if _condition_2 == nil then
451
- _condition_2 = Remove
443
+ if serverEntity ~= nil then
444
+ local _componentChanges = componentChanges
445
+ local _arg0_3 = tostring(serverEntity)
446
+ local _arg1 = if newState ~= nil then newState else Remove
447
+ _componentChanges[_arg0_3] = _arg1
452
448
  end
453
- _componentChanges[_exp] = _condition_2
454
449
  end
455
450
  end
456
451
  function Covenant:subscribeComponent(component, subscriber)
@@ -506,20 +501,25 @@ do
506
501
  _worldChangesForReplication[_arg0] = Delete
507
502
  end
508
503
  end
509
- function Covenant:worldComponent()
504
+ function Covenant:worldComponent(name)
510
505
  self:preventPostStartCall()
511
506
  local c = self._world:component()
512
- local _undefinedStringifiedComponents = self.undefinedStringifiedComponents
513
- local _arg0 = tostring(c)
514
- _undefinedStringifiedComponents[_arg0] = true
515
- local _stringfiedComponents = self.stringfiedComponents
516
- local _arg0_1 = tostring(c)
517
- _stringfiedComponents[_arg0_1] = true
507
+ local cStr = tostring(c)
508
+ local _stringfiedComponentsToNameMap = self.stringfiedComponentsToNameMap
509
+ local _name = name
510
+ _stringfiedComponentsToNameMap[cStr] = _name
511
+ self.undefinedStringifiedComponents[cStr] = true
512
+ self.stringfiedComponents[cStr] = true
518
513
  if RunService:IsStudio() and self.logging then
519
514
  print(`{(debug.info(2, "sl"))}:{c}`)
520
515
  end
521
516
  return c
522
517
  end
518
+ function Covenant:getComponentName(component)
519
+ local _stringfiedComponentsToNameMap = self.stringfiedComponentsToNameMap
520
+ local _arg0 = tostring(component)
521
+ return _stringfiedComponentsToNameMap[_arg0]
522
+ end
523
523
  function Covenant:worldTag()
524
524
  self:preventPostStartCall()
525
525
  local c = self._world:component()