@rbxts/covenant 2.1.1 → 3.0.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 +5 -5
- package/src/covenant.d.ts +4 -7
- package/src/covenant.luau +8 -67
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/covenant",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"main": "src/init.luau",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rbxtsc",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
32
32
|
"@rbxts/covenant": "^2.1.1",
|
|
33
|
-
"@rbxts/types": "^1.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
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>>;
|
|
@@ -66,13 +66,10 @@ export declare class Covenant {
|
|
|
66
66
|
queriedComponents: Entity[][];
|
|
67
67
|
recipe: (entity: Entity, lastState: T | undefined, updateId: number, hooks: CovenantHooks) => T | undefined;
|
|
68
68
|
}): void;
|
|
69
|
-
defineIdentity<T extends
|
|
70
|
-
replicated: boolean;
|
|
69
|
+
defineIdentity<T extends defined>({ identityComponent, replicated, factory, }: {
|
|
71
70
|
identityComponent: Entity<T>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
statesToDelete?: T[];
|
|
75
|
-
} | undefined;
|
|
71
|
+
replicated: boolean;
|
|
72
|
+
factory: (spawn: (state: T) => Entity, despawn: (entity: Entity) => void) => void;
|
|
76
73
|
}): void;
|
|
77
74
|
private worldEntity;
|
|
78
75
|
worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<T>;
|
package/src/covenant.luau
CHANGED
|
@@ -670,78 +670,19 @@ do
|
|
|
670
670
|
end
|
|
671
671
|
function Covenant:defineIdentity(_param)
|
|
672
672
|
local identityComponent = _param.identityComponent
|
|
673
|
-
local recipe = _param.recipe
|
|
674
673
|
local replicated = _param.replicated
|
|
674
|
+
local factory = _param.factory
|
|
675
675
|
self:checkComponentDefined(identityComponent)
|
|
676
676
|
self:defineComponentNetworkBehavior(identityComponent, replicated, false)
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
subscribeComponent = function(component, subscriber)
|
|
684
|
-
self:subscribeComponent(component, subscriber)
|
|
685
|
-
end,
|
|
686
|
-
})
|
|
687
|
-
local entities = {}
|
|
688
|
-
self:subscribeComponent(identityComponent, function(entity, state, prevState)
|
|
689
|
-
if prevState ~= nil then
|
|
690
|
-
local _prevState = prevState
|
|
691
|
-
entities[_prevState] = nil
|
|
692
|
-
end
|
|
693
|
-
if state ~= nil then
|
|
694
|
-
local _state = state
|
|
695
|
-
local _entity = entity
|
|
696
|
-
entities[_state] = _entity
|
|
697
|
-
end
|
|
698
|
-
end)
|
|
699
|
-
local lastUpdateId = 0
|
|
700
|
-
local updater = function()
|
|
701
|
-
lastUpdateId += 1
|
|
702
|
-
local updateId = lastUpdateId
|
|
703
|
-
local modifiers = recipe(entities, updateId, hooks)
|
|
704
|
-
if modifiers == nil then
|
|
705
|
-
return nil
|
|
706
|
-
end
|
|
707
|
-
local _binding = modifiers
|
|
708
|
-
local statesToCreate = _binding.statesToCreate
|
|
709
|
-
local statesToDelete = _binding.statesToDelete
|
|
710
|
-
local _result = statesToCreate
|
|
711
|
-
if _result ~= nil then
|
|
712
|
-
-- ▼ ReadonlyArray.forEach ▼
|
|
713
|
-
local _callback = function(state)
|
|
714
|
-
local entity = self:worldEntity()
|
|
715
|
-
self:worldSet(entity, identityComponent, state)
|
|
716
|
-
end
|
|
717
|
-
for _k, _v in _result do
|
|
718
|
-
_callback(_v, _k - 1, _result)
|
|
719
|
-
end
|
|
720
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
721
|
-
end
|
|
722
|
-
local _result_1 = statesToDelete
|
|
723
|
-
if _result_1 ~= nil then
|
|
724
|
-
-- ▼ ReadonlyArray.forEach ▼
|
|
725
|
-
local _callback = function(state)
|
|
726
|
-
local _state = state
|
|
727
|
-
local entity = entities[_state]
|
|
728
|
-
if entity == nil then
|
|
729
|
-
return nil
|
|
730
|
-
end
|
|
731
|
-
self:worldDelete(entity)
|
|
732
|
-
end
|
|
733
|
-
for _k, _v in _result_1 do
|
|
734
|
-
_callback(_v, _k - 1, _result_1)
|
|
735
|
-
end
|
|
736
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
737
|
-
end
|
|
738
|
-
end
|
|
739
|
-
self:schedule(RunService.Heartbeat, function()
|
|
740
|
-
if not willUpdate then
|
|
677
|
+
factory(function(state)
|
|
678
|
+
local entity = self:worldEntity()
|
|
679
|
+
self:worldSet(entity, identityComponent, state)
|
|
680
|
+
return entity
|
|
681
|
+
end, function(entity)
|
|
682
|
+
if not self:worldHas(entity, identityComponent) then
|
|
741
683
|
return nil
|
|
742
684
|
end
|
|
743
|
-
|
|
744
|
-
updater()
|
|
685
|
+
self:worldDelete(entity)
|
|
745
686
|
end)
|
|
746
687
|
end
|
|
747
688
|
function Covenant:worldEntity()
|