@rbxts/covenant 2.1.0 → 3.0.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 +6 -6
- package/src/covenant.d.ts +6 -7
- package/src/covenant.luau +17 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/covenant",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "src/init.luau",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rbxtsc",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
32
|
-
"@rbxts/covenant": "^2.1.
|
|
33
|
-
"@rbxts/types": "^1.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
32
|
+
"@rbxts/covenant": "^2.1.1",
|
|
33
|
+
"@rbxts/types": "^1.0.891",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
36
36
|
"eslint": "^9.39.1",
|
|
37
37
|
"eslint-config-prettier": "^10.1.8",
|
|
38
38
|
"eslint-plugin-prettier": "^5.5.4",
|
|
39
|
-
"eslint-plugin-roblox-ts": "^1.
|
|
39
|
+
"eslint-plugin-roblox-ts": "^1.3.0",
|
|
40
40
|
"prettier": "^3.6.2",
|
|
41
41
|
"roblox-ts": "^3.0.0",
|
|
42
42
|
"typescript": "^5.9.3"
|
package/src/covenant.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Entity, Id } from "@rbxts/jecs";
|
|
2
|
-
import { CovenantHooks
|
|
2
|
+
import { CovenantHooks } from "./hooks";
|
|
3
3
|
import { Remove, Delete } from "./stringEnums";
|
|
4
4
|
export * from "@rbxts/jecs";
|
|
5
5
|
export type WorldChangesForReplication = Map<string, Delete | Map<string, defined | Remove>>;
|
|
@@ -36,6 +36,8 @@ export declare class Covenant {
|
|
|
36
36
|
private predictionSend;
|
|
37
37
|
private predictionConnect;
|
|
38
38
|
constructor({ logging, requestPayloadSend, requestPayloadConnect, replicationSend, replicationConnect, replicationSendAll, predictionSend, predictionConnect, }: CovenantProps);
|
|
39
|
+
getClientEntity(entity: Entity): Entity | undefined;
|
|
40
|
+
getServerEntity(entity: Entity): Entity | undefined;
|
|
39
41
|
private logging;
|
|
40
42
|
enableLogging(): void;
|
|
41
43
|
disableLogging(): void;
|
|
@@ -64,13 +66,10 @@ export declare class Covenant {
|
|
|
64
66
|
queriedComponents: Entity[][];
|
|
65
67
|
recipe: (entity: Entity, lastState: T | undefined, updateId: number, hooks: CovenantHooks) => T | undefined;
|
|
66
68
|
}): void;
|
|
67
|
-
defineIdentity<T extends
|
|
68
|
-
replicated: boolean;
|
|
69
|
+
defineIdentity<T extends defined>({ identityComponent, replicated, factory, }: {
|
|
69
70
|
identityComponent: Entity<T>;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
statesToDelete?: T[];
|
|
73
|
-
} | undefined;
|
|
71
|
+
replicated: boolean;
|
|
72
|
+
factory: (spawn: (state: T) => Entity, despawn: (entity: Entity) => void) => void;
|
|
74
73
|
}): void;
|
|
75
74
|
private worldEntity;
|
|
76
75
|
worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<T>;
|
package/src/covenant.luau
CHANGED
|
@@ -63,6 +63,16 @@ do
|
|
|
63
63
|
self:setupReplication()
|
|
64
64
|
self:setupPrediction()
|
|
65
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
|
|
66
76
|
function Covenant:enableLogging()
|
|
67
77
|
self.logging = true
|
|
68
78
|
end
|
|
@@ -660,78 +670,16 @@ do
|
|
|
660
670
|
end
|
|
661
671
|
function Covenant:defineIdentity(_param)
|
|
662
672
|
local identityComponent = _param.identityComponent
|
|
663
|
-
local recipe = _param.recipe
|
|
664
673
|
local replicated = _param.replicated
|
|
674
|
+
local factory = _param.factory
|
|
665
675
|
self:checkComponentDefined(identityComponent)
|
|
666
676
|
self:defineComponentNetworkBehavior(identityComponent, replicated, false)
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
subscribeComponent = function(component, subscriber)
|
|
674
|
-
self:subscribeComponent(component, subscriber)
|
|
675
|
-
end,
|
|
676
|
-
})
|
|
677
|
-
local entities = {}
|
|
678
|
-
self:subscribeComponent(identityComponent, function(entity, state, prevState)
|
|
679
|
-
if prevState ~= nil then
|
|
680
|
-
local _prevState = prevState
|
|
681
|
-
entities[_prevState] = nil
|
|
682
|
-
end
|
|
683
|
-
if state ~= nil then
|
|
684
|
-
local _state = state
|
|
685
|
-
local _entity = entity
|
|
686
|
-
entities[_state] = _entity
|
|
687
|
-
end
|
|
688
|
-
end)
|
|
689
|
-
local lastUpdateId = 0
|
|
690
|
-
local updater = function()
|
|
691
|
-
lastUpdateId += 1
|
|
692
|
-
local updateId = lastUpdateId
|
|
693
|
-
local modifiers = recipe(entities, updateId, hooks)
|
|
694
|
-
if modifiers == nil then
|
|
695
|
-
return nil
|
|
696
|
-
end
|
|
697
|
-
local _binding = modifiers
|
|
698
|
-
local statesToCreate = _binding.statesToCreate
|
|
699
|
-
local statesToDelete = _binding.statesToDelete
|
|
700
|
-
local _result = statesToCreate
|
|
701
|
-
if _result ~= nil then
|
|
702
|
-
-- ▼ ReadonlyArray.forEach ▼
|
|
703
|
-
local _callback = function(state)
|
|
704
|
-
local entity = self:worldEntity()
|
|
705
|
-
self:worldSet(entity, identityComponent, state)
|
|
706
|
-
end
|
|
707
|
-
for _k, _v in _result do
|
|
708
|
-
_callback(_v, _k - 1, _result)
|
|
709
|
-
end
|
|
710
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
711
|
-
end
|
|
712
|
-
local _result_1 = statesToDelete
|
|
713
|
-
if _result_1 ~= nil then
|
|
714
|
-
-- ▼ ReadonlyArray.forEach ▼
|
|
715
|
-
local _callback = function(state)
|
|
716
|
-
local _state = state
|
|
717
|
-
local entity = entities[_state]
|
|
718
|
-
if entity == nil then
|
|
719
|
-
return nil
|
|
720
|
-
end
|
|
721
|
-
self:worldDelete(entity)
|
|
722
|
-
end
|
|
723
|
-
for _k, _v in _result_1 do
|
|
724
|
-
_callback(_v, _k - 1, _result_1)
|
|
725
|
-
end
|
|
726
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
727
|
-
end
|
|
728
|
-
end
|
|
729
|
-
self:schedule(RunService.Heartbeat, function()
|
|
730
|
-
if not willUpdate then
|
|
731
|
-
return nil
|
|
732
|
-
end
|
|
733
|
-
willUpdate = false
|
|
734
|
-
updater()
|
|
677
|
+
factory(function(state)
|
|
678
|
+
local entity = self:worldEntity()
|
|
679
|
+
self:worldSet(entity, identityComponent, state)
|
|
680
|
+
return entity
|
|
681
|
+
end, function(entity)
|
|
682
|
+
self:worldDelete(entity)
|
|
735
683
|
end)
|
|
736
684
|
end
|
|
737
685
|
function Covenant:worldEntity()
|