@rbxts/covenant 2.0.1 → 2.1.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,48 +1,48 @@
1
- {
2
- "name": "@rbxts/covenant",
3
- "version": "2.0.1",
4
- "main": "src/init.luau",
5
- "scripts": {
6
- "build": "rbxtsc",
7
- "watch": "rbxtsc -w",
8
- "prepublishOnly": "npm run build"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/cuberootmctoasted/covenant.git"
13
- },
14
- "keywords": [],
15
- "author": "",
16
- "license": "ISC",
17
- "bugs": {
18
- "url": "https://github.com/cuberootmctoasted/covenant/issues"
19
- },
20
- "homepage": "https://github.com/cuberootmctoasted/covenant#readme",
21
- "description": "",
22
- "types": "src/covenant.d.ts",
23
- "files": [
24
- "src",
25
- "!**/*.tsbuildinfo"
26
- ],
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "devDependencies": {
31
- "@rbxts/compiler-types": "^3.0.0-types.0",
32
- "@rbxts/covenant": "^1.4.1",
33
- "@rbxts/types": "^1.0.860",
34
- "@typescript-eslint/eslint-plugin": "^8.35.0",
35
- "@typescript-eslint/parser": "^8.35.0",
36
- "eslint": "^8.57.1",
37
- "eslint-config-prettier": "^10.1.5",
38
- "eslint-plugin-prettier": "^5.5.1",
39
- "eslint-plugin-roblox-ts": "^0.0.36",
40
- "prettier": "^3.6.1",
41
- "roblox-ts": "^3.0.0",
42
- "typescript": "^5.8.3"
43
- },
44
- "dependencies": {
45
- "@rbxts/jecs": "^0.6.1",
46
- "@rbxts/services": "^1.5.5"
47
- }
48
- }
1
+ {
2
+ "name": "@rbxts/covenant",
3
+ "version": "2.1.0",
4
+ "main": "src/init.luau",
5
+ "scripts": {
6
+ "build": "rbxtsc",
7
+ "watch": "rbxtsc -w",
8
+ "prepublishOnly": "npm run build"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/cuberootmctoasted/covenant.git"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "bugs": {
18
+ "url": "https://github.com/cuberootmctoasted/covenant/issues"
19
+ },
20
+ "homepage": "https://github.com/cuberootmctoasted/covenant#readme",
21
+ "description": "",
22
+ "types": "src/covenant.d.ts",
23
+ "files": [
24
+ "src",
25
+ "!**/*.tsbuildinfo"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "devDependencies": {
31
+ "@rbxts/compiler-types": "^3.0.0-types.0",
32
+ "@rbxts/covenant": "^2.1.0",
33
+ "@rbxts/types": "^1.0.890",
34
+ "@typescript-eslint/eslint-plugin": "^8.46.4",
35
+ "@typescript-eslint/parser": "^8.46.4",
36
+ "eslint": "^9.39.1",
37
+ "eslint-config-prettier": "^10.1.8",
38
+ "eslint-plugin-prettier": "^5.5.4",
39
+ "eslint-plugin-roblox-ts": "^1.2.1",
40
+ "prettier": "^3.6.2",
41
+ "roblox-ts": "^3.0.0",
42
+ "typescript": "^5.9.3"
43
+ },
44
+ "dependencies": {
45
+ "@rbxts/jecs": "^0.9.0",
46
+ "@rbxts/services": "^1.6.0"
47
+ }
48
+ }
package/src/covenant.d.ts CHANGED
@@ -26,6 +26,8 @@ export declare class Covenant {
26
26
  private started;
27
27
  private stringifiedComponentSubscribers;
28
28
  private stringifiedComponentValidators;
29
+ private clientToServerEntityMap;
30
+ private serverToClientEntityMap;
29
31
  private requestPayloadSend;
30
32
  private requestPayloadConnect;
31
33
  private replicationSend;
@@ -71,7 +73,7 @@ export declare class Covenant {
71
73
  } | undefined;
72
74
  }): void;
73
75
  private worldEntity;
74
- worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<import("@rbxts/jecs").InferComponents<T>>;
76
+ worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<T>;
75
77
  worldHas(entity: Entity, ...components: Id[]): boolean;
76
78
  worldGet<T extends [Id] | [Id, Id] | [Id, Id, Id] | [Id, Id, Id, Id]>(entity: Entity, ...components: T): import("@rbxts/jecs").FlattenTuple<[...import("@rbxts/jecs").Nullable<import("@rbxts/jecs").InferComponents<T>>]>;
77
79
  worldContains(entity: Entity): boolean;
package/src/covenant.luau CHANGED
@@ -4,7 +4,7 @@ local exports = {}
4
4
  local _jecs = TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs)
5
5
  local ChildOf = _jecs.ChildOf
6
6
  local pair = _jecs.pair
7
- local World = _jecs.World
7
+ local world = _jecs.world
8
8
  local _services = TS.import(script, TS.getModule(script, "@rbxts", "services"))
9
9
  local Players = _services.Players
10
10
  local RunService = _services.RunService
@@ -19,16 +19,6 @@ for _k, _v in TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs) or
19
19
  end
20
20
  -- Map<Entity, Delete | Map<Component, state | Remove>>
21
21
  -- Map<Component, Map<Entity, state | Remove>>
22
- local function createWorldWithRange(minClientEntity, maxClientEntity)
23
- local world = World.new()
24
- if RunService:IsClient() then
25
- world:range(minClientEntity, maxClientEntity)
26
- end
27
- if RunService:IsServer() then
28
- world:range(maxClientEntity)
29
- end
30
- return world
31
- end
32
22
  local Covenant
33
23
  do
34
24
  Covenant = setmetatable({}, {
@@ -50,7 +40,7 @@ do
50
40
  local replicationSendAll = _param.replicationSendAll
51
41
  local predictionSend = _param.predictionSend
52
42
  local predictionConnect = _param.predictionConnect
53
- self._world = createWorldWithRange(1000, 20000)
43
+ self._world = world()
54
44
  self.systems = EventMap.new()
55
45
  self.worldChangesForReplication = {}
56
46
  self.worldChangesForPrediction = {}
@@ -60,6 +50,8 @@ do
60
50
  self.started = false
61
51
  self.stringifiedComponentSubscribers = {}
62
52
  self.stringifiedComponentValidators = {}
53
+ self.clientToServerEntityMap = {}
54
+ self.serverToClientEntityMap = {}
63
55
  self.logging = logging
64
56
  self.requestPayloadSend = requestPayloadSend
65
57
  self.requestPayloadConnect = requestPayloadConnect
@@ -245,10 +237,29 @@ do
245
237
  -- ▼ ReadonlyArray.forEach ▼
246
238
  local _callback = function(worldChanges)
247
239
  -- ▼ ReadonlyMap.forEach ▼
248
- local _callback_1 = function(entityData, stringifiedEntity)
249
- local entity = tonumber(stringifiedEntity)
240
+ local _callback_1 = function(entityData, stringifiedServerEntity)
241
+ local _serverToClientEntityMap = self.serverToClientEntityMap
242
+ local _stringifiedServerEntity = stringifiedServerEntity
243
+ local entity = _serverToClientEntityMap[_stringifiedServerEntity]
244
+ if entity == nil then
245
+ entity = self._world:entity()
246
+ local _serverToClientEntityMap_1 = self.serverToClientEntityMap
247
+ local _stringifiedServerEntity_1 = stringifiedServerEntity
248
+ local _entity = entity
249
+ _serverToClientEntityMap_1[_stringifiedServerEntity_1] = _entity
250
+ local _clientToServerEntityMap = self.clientToServerEntityMap
251
+ local _arg0 = tostring(entity)
252
+ local _arg1 = tonumber(stringifiedServerEntity)
253
+ _clientToServerEntityMap[_arg0] = _arg1
254
+ end
250
255
  if entityData == Delete then
251
256
  self:worldDelete(entity)
257
+ local _serverToClientEntityMap_1 = self.serverToClientEntityMap
258
+ local _stringifiedServerEntity_1 = stringifiedServerEntity
259
+ _serverToClientEntityMap_1[_stringifiedServerEntity_1] = nil
260
+ local _clientToServerEntityMap = self.clientToServerEntityMap
261
+ local _arg0 = tostring(entity)
262
+ _clientToServerEntityMap[_arg0] = nil
252
263
  return nil
253
264
  end
254
265
  -- ▼ ReadonlyMap.forEach ▼
@@ -349,9 +360,6 @@ do
349
360
  if doNotReconcile == nil then
350
361
  doNotReconcile = false
351
362
  end
352
- if not self:worldContains(entity) then
353
- self._world:entity(entity)
354
- end
355
363
  local lastState = self:worldGet(entity, component)
356
364
  if newState == lastState then
357
365
  return nil
@@ -380,53 +388,61 @@ do
380
388
  if doNotReconcile then
381
389
  return nil
382
390
  end
383
- local _replicatedStringifiedComponents = self.replicatedStringifiedComponents
384
- local _arg0_1 = tostring(component)
385
- if _replicatedStringifiedComponents[_arg0_1] ~= nil then
391
+ local _condition = RunService:IsServer()
392
+ if _condition then
393
+ local _replicatedStringifiedComponents = self.replicatedStringifiedComponents
394
+ local _arg0_1 = tostring(component)
395
+ _condition = _replicatedStringifiedComponents[_arg0_1] ~= nil
396
+ end
397
+ if _condition then
386
398
  local _worldChangesForReplication = self.worldChangesForReplication
387
- local _arg0_2 = tostring(entity)
388
- local entityChanges = _worldChangesForReplication[_arg0_2]
399
+ local _arg0_1 = tostring(entity)
400
+ local entityChanges = _worldChangesForReplication[_arg0_1]
389
401
  if entityChanges == nil then
390
402
  entityChanges = {}
391
403
  local _worldChangesForReplication_1 = self.worldChangesForReplication
392
- local _arg0_3 = tostring(entity)
404
+ local _arg0_2 = tostring(entity)
393
405
  local _entityChanges = entityChanges
394
- _worldChangesForReplication_1[_arg0_3] = _entityChanges
406
+ _worldChangesForReplication_1[_arg0_2] = _entityChanges
395
407
  end
396
408
  if entityChanges ~= Delete then
397
409
  local _entityChanges = entityChanges
398
410
  local _exp = tostring(component)
399
- local _condition = newState
400
- if _condition == nil then
401
- _condition = Remove
411
+ local _condition_1 = newState
412
+ if _condition_1 == nil then
413
+ _condition_1 = Remove
402
414
  end
403
- _entityChanges[_exp] = _condition
415
+ _entityChanges[_exp] = _condition_1
404
416
  end
405
417
  end
406
- local _condition = RunService:IsClient()
407
- if _condition then
418
+ local _condition_1 = RunService:IsClient()
419
+ if _condition_1 then
408
420
  local _predictedStringifiedComponents = self.predictedStringifiedComponents
409
- local _arg0_2 = tostring(component)
410
- _condition = _predictedStringifiedComponents[_arg0_2] ~= nil
421
+ local _arg0_1 = tostring(component)
422
+ _condition_1 = _predictedStringifiedComponents[_arg0_1] ~= nil
411
423
  end
412
- if _condition then
424
+ if _condition_1 then
413
425
  local _worldChangesForPrediction = self.worldChangesForPrediction
414
- local _arg0_2 = tostring(component)
415
- local componentChanges = _worldChangesForPrediction[_arg0_2]
426
+ local _arg0_1 = tostring(component)
427
+ local componentChanges = _worldChangesForPrediction[_arg0_1]
416
428
  if componentChanges == nil then
417
429
  componentChanges = {}
418
430
  local _worldChangesForPrediction_1 = self.worldChangesForPrediction
419
- local _arg0_3 = tostring(component)
431
+ local _arg0_2 = tostring(component)
420
432
  local _componentChanges = componentChanges
421
- _worldChangesForPrediction_1[_arg0_3] = _componentChanges
433
+ _worldChangesForPrediction_1[_arg0_2] = _componentChanges
422
434
  end
435
+ local _clientToServerEntityMap = self.clientToServerEntityMap
436
+ local _arg0_2 = tostring(entity)
437
+ local serverEntity = _clientToServerEntityMap[_arg0_2]
438
+ assert(serverEntity ~= 0 and serverEntity == serverEntity and serverEntity, "This entity should exist.")
423
439
  local _componentChanges = componentChanges
424
- local _exp = tostring(entity)
425
- local _condition_1 = newState
426
- if _condition_1 == nil then
427
- _condition_1 = Remove
440
+ local _exp = tostring(serverEntity)
441
+ local _condition_2 = newState
442
+ if _condition_2 == nil then
443
+ _condition_2 = Remove
428
444
  end
429
- _componentChanges[_exp] = _condition_1
445
+ _componentChanges[_exp] = _condition_2
430
446
  end
431
447
  end
432
448
  function Covenant:subscribeComponent(component, subscriber)
@@ -470,9 +486,11 @@ do
470
486
  -- ▼ ReadonlySet.forEach ▼
471
487
  local _callback = function(entityToDelete)
472
488
  self._world:delete(entityToDelete)
473
- local _worldChangesForReplication = self.worldChangesForReplication
474
- local _arg0 = tostring(entityToDelete)
475
- _worldChangesForReplication[_arg0] = Delete
489
+ if RunService:IsServer() then
490
+ local _worldChangesForReplication = self.worldChangesForReplication
491
+ local _arg0 = tostring(entityToDelete)
492
+ _worldChangesForReplication[_arg0] = Delete
493
+ end
476
494
  end
477
495
  for _v in processed do
478
496
  _callback(_v, _v, processed)
package/src/helpers.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { Discriminator } from "./hooks";
2
-
3
- export declare function turnArrayWithIdentifierToMap<T extends defined>(
4
- array: ReadonlyArray<T>,
5
- getIdentifier: (state: T) => Discriminator,
6
- ): Map<defined, T>;
7
- export declare function compareMaps<TKey extends Discriminator, TValue extends defined>(
8
- previousMap: ReadonlyMap<TKey, TValue>,
9
- newMap: ReadonlyMap<TKey, TValue>,
10
- ): {
11
- entriesAdded: {
12
- key: TKey;
13
- value: TValue;
14
- }[];
15
- entriesChanged: {
16
- key: TKey;
17
- value: TValue;
18
- previousValue: TValue;
19
- }[];
20
- keysRemoved: TKey[];
21
- };
package/src/helpers.luau DELETED
@@ -1,71 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- -- Manually modified
3
- local function turnArrayWithIdentifierToMap(array, getIdentifier)
4
- local newMap = {}
5
- -- ▼ ReadonlyArray.forEach ▼
6
- local _callback = function(value)
7
- local identifier = getIdentifier(value)
8
- local _value = value
9
- newMap[identifier] = _value
10
- end
11
- for _k, _v in array do
12
- _callback(_v)
13
- end
14
- -- ▲ ReadonlyArray.forEach ▲
15
- return newMap
16
- end
17
- local function compareMaps(previousMap, newMap)
18
- local entriesAdded = {}
19
- local entriesChanged = {}
20
- local keysRemoved = {}
21
- -- ▼ ReadonlyMap.forEach ▼
22
- local _callback = function(value, key)
23
- local _previousMap = previousMap
24
- local _key = key
25
- if not (_previousMap[_key] ~= nil) then
26
- local _arg0 = {
27
- key = key,
28
- value = value,
29
- }
30
- table.insert(entriesAdded, _arg0)
31
- else
32
- local _previousMap_1 = previousMap
33
- local _key_1 = key
34
- local previousValue = _previousMap_1[_key_1]
35
- if previousValue ~= value then
36
- local _arg0 = {
37
- key = key,
38
- value = value,
39
- previousValue = previousValue,
40
- }
41
- table.insert(entriesChanged, _arg0)
42
- end
43
- end
44
- end
45
- for _k, _v in newMap do
46
- _callback(_v, _k, newMap)
47
- end
48
- -- ▲ ReadonlyMap.forEach ▲
49
- -- ▼ ReadonlyMap.forEach ▼
50
- local _callback_1 = function(_, key)
51
- local _newMap = newMap
52
- local _key = key
53
- if not (_newMap[_key] ~= nil) then
54
- local _key_1 = key
55
- table.insert(keysRemoved, _key_1)
56
- end
57
- end
58
- for _k, _v in previousMap do
59
- _callback_1(_v, _k, previousMap)
60
- end
61
- -- ▲ ReadonlyMap.forEach ▲
62
- return {
63
- entriesAdded = entriesAdded,
64
- entriesChanged = entriesChanged,
65
- keysRemoved = keysRemoved,
66
- }
67
- end
68
- return {
69
- turnArrayWithIdentifierToMap = turnArrayWithIdentifierToMap,
70
- compareMaps = compareMaps,
71
- }