@rbxts/covenant 2.0.2 → 2.1.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 +48 -48
- package/src/covenant.d.ts +5 -1
- package/src/covenant.luau +73 -45
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@rbxts/covenant",
|
|
3
|
-
"version": "2.
|
|
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.
|
|
33
|
-
"@rbxts/types": "^1.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"eslint-config-prettier": "^10.1.
|
|
38
|
-
"eslint-plugin-prettier": "^5.5.
|
|
39
|
-
"eslint-plugin-roblox-ts": "^
|
|
40
|
-
"prettier": "^3.6.
|
|
41
|
-
"roblox-ts": "^3.0.0",
|
|
42
|
-
"typescript": "^5.
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"@rbxts/jecs": "^0.
|
|
46
|
-
"@rbxts/services": "^1.
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@rbxts/covenant",
|
|
3
|
+
"version": "2.1.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": "^2.1.1",
|
|
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;
|
|
@@ -34,6 +36,8 @@ export declare class Covenant {
|
|
|
34
36
|
private predictionSend;
|
|
35
37
|
private predictionConnect;
|
|
36
38
|
constructor({ logging, requestPayloadSend, requestPayloadConnect, replicationSend, replicationConnect, replicationSendAll, predictionSend, predictionConnect, }: CovenantProps);
|
|
39
|
+
getClientEntity(entity: Entity): Entity | undefined;
|
|
40
|
+
getServerEntity(entity: Entity): Entity | undefined;
|
|
37
41
|
private logging;
|
|
38
42
|
enableLogging(): void;
|
|
39
43
|
disableLogging(): void;
|
|
@@ -71,7 +75,7 @@ export declare class Covenant {
|
|
|
71
75
|
} | undefined;
|
|
72
76
|
}): void;
|
|
73
77
|
private worldEntity;
|
|
74
|
-
worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<
|
|
78
|
+
worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<T>;
|
|
75
79
|
worldHas(entity: Entity, ...components: Id[]): boolean;
|
|
76
80
|
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
81
|
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
|
|
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 =
|
|
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
|
|
@@ -71,6 +63,16 @@ do
|
|
|
71
63
|
self:setupReplication()
|
|
72
64
|
self:setupPrediction()
|
|
73
65
|
end
|
|
66
|
+
function Covenant:getClientEntity(entity)
|
|
67
|
+
local _serverToClientEntityMap = self.serverToClientEntityMap
|
|
68
|
+
local _arg0 = tostring(entity)
|
|
69
|
+
return _serverToClientEntityMap[_arg0]
|
|
70
|
+
end
|
|
71
|
+
function Covenant:getServerEntity(entity)
|
|
72
|
+
local _clientToServerEntityMap = self.clientToServerEntityMap
|
|
73
|
+
local _arg0 = tostring(entity)
|
|
74
|
+
return _clientToServerEntityMap[_arg0]
|
|
75
|
+
end
|
|
74
76
|
function Covenant:enableLogging()
|
|
75
77
|
self.logging = true
|
|
76
78
|
end
|
|
@@ -245,10 +247,29 @@ do
|
|
|
245
247
|
-- ▼ ReadonlyArray.forEach ▼
|
|
246
248
|
local _callback = function(worldChanges)
|
|
247
249
|
-- ▼ ReadonlyMap.forEach ▼
|
|
248
|
-
local _callback_1 = function(entityData,
|
|
249
|
-
local
|
|
250
|
+
local _callback_1 = function(entityData, stringifiedServerEntity)
|
|
251
|
+
local _serverToClientEntityMap = self.serverToClientEntityMap
|
|
252
|
+
local _stringifiedServerEntity = stringifiedServerEntity
|
|
253
|
+
local entity = _serverToClientEntityMap[_stringifiedServerEntity]
|
|
254
|
+
if entity == nil then
|
|
255
|
+
entity = self._world:entity()
|
|
256
|
+
local _serverToClientEntityMap_1 = self.serverToClientEntityMap
|
|
257
|
+
local _stringifiedServerEntity_1 = stringifiedServerEntity
|
|
258
|
+
local _entity = entity
|
|
259
|
+
_serverToClientEntityMap_1[_stringifiedServerEntity_1] = _entity
|
|
260
|
+
local _clientToServerEntityMap = self.clientToServerEntityMap
|
|
261
|
+
local _arg0 = tostring(entity)
|
|
262
|
+
local _arg1 = tonumber(stringifiedServerEntity)
|
|
263
|
+
_clientToServerEntityMap[_arg0] = _arg1
|
|
264
|
+
end
|
|
250
265
|
if entityData == Delete then
|
|
251
266
|
self:worldDelete(entity)
|
|
267
|
+
local _serverToClientEntityMap_1 = self.serverToClientEntityMap
|
|
268
|
+
local _stringifiedServerEntity_1 = stringifiedServerEntity
|
|
269
|
+
_serverToClientEntityMap_1[_stringifiedServerEntity_1] = nil
|
|
270
|
+
local _clientToServerEntityMap = self.clientToServerEntityMap
|
|
271
|
+
local _arg0 = tostring(entity)
|
|
272
|
+
_clientToServerEntityMap[_arg0] = nil
|
|
252
273
|
return nil
|
|
253
274
|
end
|
|
254
275
|
-- ▼ ReadonlyMap.forEach ▼
|
|
@@ -349,9 +370,6 @@ do
|
|
|
349
370
|
if doNotReconcile == nil then
|
|
350
371
|
doNotReconcile = false
|
|
351
372
|
end
|
|
352
|
-
if not self:worldContains(entity) then
|
|
353
|
-
self._world:entity(entity)
|
|
354
|
-
end
|
|
355
373
|
local lastState = self:worldGet(entity, component)
|
|
356
374
|
if newState == lastState then
|
|
357
375
|
return nil
|
|
@@ -380,53 +398,61 @@ do
|
|
|
380
398
|
if doNotReconcile then
|
|
381
399
|
return nil
|
|
382
400
|
end
|
|
383
|
-
local
|
|
384
|
-
|
|
385
|
-
|
|
401
|
+
local _condition = RunService:IsServer()
|
|
402
|
+
if _condition then
|
|
403
|
+
local _replicatedStringifiedComponents = self.replicatedStringifiedComponents
|
|
404
|
+
local _arg0_1 = tostring(component)
|
|
405
|
+
_condition = _replicatedStringifiedComponents[_arg0_1] ~= nil
|
|
406
|
+
end
|
|
407
|
+
if _condition then
|
|
386
408
|
local _worldChangesForReplication = self.worldChangesForReplication
|
|
387
|
-
local
|
|
388
|
-
local entityChanges = _worldChangesForReplication[
|
|
409
|
+
local _arg0_1 = tostring(entity)
|
|
410
|
+
local entityChanges = _worldChangesForReplication[_arg0_1]
|
|
389
411
|
if entityChanges == nil then
|
|
390
412
|
entityChanges = {}
|
|
391
413
|
local _worldChangesForReplication_1 = self.worldChangesForReplication
|
|
392
|
-
local
|
|
414
|
+
local _arg0_2 = tostring(entity)
|
|
393
415
|
local _entityChanges = entityChanges
|
|
394
|
-
_worldChangesForReplication_1[
|
|
416
|
+
_worldChangesForReplication_1[_arg0_2] = _entityChanges
|
|
395
417
|
end
|
|
396
418
|
if entityChanges ~= Delete then
|
|
397
419
|
local _entityChanges = entityChanges
|
|
398
420
|
local _exp = tostring(component)
|
|
399
|
-
local
|
|
400
|
-
if
|
|
401
|
-
|
|
421
|
+
local _condition_1 = newState
|
|
422
|
+
if _condition_1 == nil then
|
|
423
|
+
_condition_1 = Remove
|
|
402
424
|
end
|
|
403
|
-
_entityChanges[_exp] =
|
|
425
|
+
_entityChanges[_exp] = _condition_1
|
|
404
426
|
end
|
|
405
427
|
end
|
|
406
|
-
local
|
|
407
|
-
if
|
|
428
|
+
local _condition_1 = RunService:IsClient()
|
|
429
|
+
if _condition_1 then
|
|
408
430
|
local _predictedStringifiedComponents = self.predictedStringifiedComponents
|
|
409
|
-
local
|
|
410
|
-
|
|
431
|
+
local _arg0_1 = tostring(component)
|
|
432
|
+
_condition_1 = _predictedStringifiedComponents[_arg0_1] ~= nil
|
|
411
433
|
end
|
|
412
|
-
if
|
|
434
|
+
if _condition_1 then
|
|
413
435
|
local _worldChangesForPrediction = self.worldChangesForPrediction
|
|
414
|
-
local
|
|
415
|
-
local componentChanges = _worldChangesForPrediction[
|
|
436
|
+
local _arg0_1 = tostring(component)
|
|
437
|
+
local componentChanges = _worldChangesForPrediction[_arg0_1]
|
|
416
438
|
if componentChanges == nil then
|
|
417
439
|
componentChanges = {}
|
|
418
440
|
local _worldChangesForPrediction_1 = self.worldChangesForPrediction
|
|
419
|
-
local
|
|
441
|
+
local _arg0_2 = tostring(component)
|
|
420
442
|
local _componentChanges = componentChanges
|
|
421
|
-
_worldChangesForPrediction_1[
|
|
443
|
+
_worldChangesForPrediction_1[_arg0_2] = _componentChanges
|
|
422
444
|
end
|
|
445
|
+
local _clientToServerEntityMap = self.clientToServerEntityMap
|
|
446
|
+
local _arg0_2 = tostring(entity)
|
|
447
|
+
local serverEntity = _clientToServerEntityMap[_arg0_2]
|
|
448
|
+
assert(serverEntity ~= 0 and serverEntity == serverEntity and serverEntity, "This entity should exist.")
|
|
423
449
|
local _componentChanges = componentChanges
|
|
424
|
-
local _exp = tostring(
|
|
425
|
-
local
|
|
426
|
-
if
|
|
427
|
-
|
|
450
|
+
local _exp = tostring(serverEntity)
|
|
451
|
+
local _condition_2 = newState
|
|
452
|
+
if _condition_2 == nil then
|
|
453
|
+
_condition_2 = Remove
|
|
428
454
|
end
|
|
429
|
-
_componentChanges[_exp] =
|
|
455
|
+
_componentChanges[_exp] = _condition_2
|
|
430
456
|
end
|
|
431
457
|
end
|
|
432
458
|
function Covenant:subscribeComponent(component, subscriber)
|
|
@@ -470,9 +496,11 @@ do
|
|
|
470
496
|
-- ▼ ReadonlySet.forEach ▼
|
|
471
497
|
local _callback = function(entityToDelete)
|
|
472
498
|
self._world:delete(entityToDelete)
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
499
|
+
if RunService:IsServer() then
|
|
500
|
+
local _worldChangesForReplication = self.worldChangesForReplication
|
|
501
|
+
local _arg0 = tostring(entityToDelete)
|
|
502
|
+
_worldChangesForReplication[_arg0] = Delete
|
|
503
|
+
end
|
|
476
504
|
end
|
|
477
505
|
for _v in processed do
|
|
478
506
|
_callback(_v, _v, processed)
|