@rbxts/covenant 2.0.2 → 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 +48 -48
- package/src/covenant.d.ts +3 -1
- package/src/covenant.luau +63 -45
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@rbxts/covenant",
|
|
3
|
-
"version": "2.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": "^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.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<
|
|
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
|
|
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
|
|
@@ -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,
|
|
249
|
-
local
|
|
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
|
|
384
|
-
|
|
385
|
-
|
|
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
|
|
388
|
-
local entityChanges = _worldChangesForReplication[
|
|
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
|
|
404
|
+
local _arg0_2 = tostring(entity)
|
|
393
405
|
local _entityChanges = entityChanges
|
|
394
|
-
_worldChangesForReplication_1[
|
|
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
|
|
400
|
-
if
|
|
401
|
-
|
|
411
|
+
local _condition_1 = newState
|
|
412
|
+
if _condition_1 == nil then
|
|
413
|
+
_condition_1 = Remove
|
|
402
414
|
end
|
|
403
|
-
_entityChanges[_exp] =
|
|
415
|
+
_entityChanges[_exp] = _condition_1
|
|
404
416
|
end
|
|
405
417
|
end
|
|
406
|
-
local
|
|
407
|
-
if
|
|
418
|
+
local _condition_1 = RunService:IsClient()
|
|
419
|
+
if _condition_1 then
|
|
408
420
|
local _predictedStringifiedComponents = self.predictedStringifiedComponents
|
|
409
|
-
local
|
|
410
|
-
|
|
421
|
+
local _arg0_1 = tostring(component)
|
|
422
|
+
_condition_1 = _predictedStringifiedComponents[_arg0_1] ~= nil
|
|
411
423
|
end
|
|
412
|
-
if
|
|
424
|
+
if _condition_1 then
|
|
413
425
|
local _worldChangesForPrediction = self.worldChangesForPrediction
|
|
414
|
-
local
|
|
415
|
-
local componentChanges = _worldChangesForPrediction[
|
|
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
|
|
431
|
+
local _arg0_2 = tostring(component)
|
|
420
432
|
local _componentChanges = componentChanges
|
|
421
|
-
_worldChangesForPrediction_1[
|
|
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(
|
|
425
|
-
local
|
|
426
|
-
if
|
|
427
|
-
|
|
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] =
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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)
|