@rbxts/covenant 1.2.0 → 1.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -42,6 +42,7 @@ export declare class Covenant {
42
42
  subscribeComponent<T>(component: Entity<T>, subscriber: (entity: Entity, state: T | undefined, previousState: T | undefined) => void): () => void;
43
43
  private worldDelete;
44
44
  worldComponent<T extends defined>(): Entity<T>;
45
+ worldTag(): Entity<undefined>;
45
46
  private worldInternalComponent;
46
47
  private checkComponentDefined;
47
48
  private defineComponentNetworkBehavior;
@@ -60,13 +61,10 @@ export declare class Covenant {
60
61
  queriedComponents: Entity[][];
61
62
  recipe: (entity: Entity, lastChildrenStates: ReadonlyArray<T>, updateId: number, hooks: CovenantHooks) => ReadonlyArray<T>;
62
63
  }): void;
63
- defineEntitySource<T extends defined>({ identityComponent, recipe, replicated, }: {
64
+ defineStaticEntity<T extends defined>({ identityComponent, recipe, replicated, }: {
64
65
  replicated: boolean;
65
66
  identityComponent: Entity<T>;
66
- recipe: (updateId: number, hooks: CovenantHooks) => {
67
- statesToCreate?: ReadonlyArray<T>;
68
- entitiesToDelete?: ReadonlyArray<Entity>;
69
- };
67
+ recipe: () => T[];
70
68
  }): void;
71
69
  private worldEntity;
72
70
  worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<import("@rbxts/jecs").InferComponents<T>>;
package/src/covenant.luau CHANGED
@@ -428,6 +428,14 @@ do
428
428
  _undefinedStringifiedComponents[_arg0] = true
429
429
  return c
430
430
  end
431
+ function Covenant:worldTag()
432
+ self:preventPostStartCall()
433
+ local c = self._world:component()
434
+ local _undefinedStringifiedComponents = self.undefinedStringifiedComponents
435
+ local _arg0 = tostring(c)
436
+ _undefinedStringifiedComponents[_arg0] = true
437
+ return c
438
+ end
431
439
  function Covenant:worldInternalComponent()
432
440
  self:preventPostStartCall()
433
441
  return self._world:component()
@@ -762,62 +770,22 @@ do
762
770
  updater()
763
771
  end)
764
772
  end
765
- function Covenant:defineEntitySource(_param)
773
+ function Covenant:defineStaticEntity(_param)
766
774
  local identityComponent = _param.identityComponent
767
775
  local recipe = _param.recipe
768
776
  local replicated = _param.replicated
769
777
  self:checkComponentDefined(identityComponent)
770
778
  self:defineComponentNetworkBehavior(identityComponent, replicated, false)
771
- local willUpdate = true
772
- local function indicateUpdate()
773
- willUpdate = true
779
+ local states = recipe()
780
+ -- ReadonlyArray.forEach ▼
781
+ local _callback = function(state)
782
+ local entity = self:worldEntity()
783
+ self:worldSet(entity, identityComponent, state)
774
784
  end
775
- local hooks = createHooks({
776
- indicateUpdate = indicateUpdate,
777
- subscribeComponent = function(component, subscriber)
778
- self:subscribeComponent(component, subscriber)
779
- end,
780
- })
781
- local lastUpdateId = 0
782
- local updater = function()
783
- lastUpdateId += 1
784
- local _binding = recipe(lastUpdateId, hooks)
785
- local statesToCreate = _binding.statesToCreate
786
- local entitiesToDelete = _binding.entitiesToDelete
787
- local _result = statesToCreate
788
- if _result ~= nil then
789
- -- ▼ ReadonlyArray.forEach ▼
790
- local _callback = function(state)
791
- local entity = self:worldEntity()
792
- self:worldSet(entity, identityComponent, state)
793
- end
794
- for _k, _v in _result do
795
- _callback(_v, _k - 1, _result)
796
- end
797
- -- ▲ ReadonlyArray.forEach ▲
798
- end
799
- local _result_1 = entitiesToDelete
800
- if _result_1 ~= nil then
801
- -- ▼ ReadonlyArray.forEach ▼
802
- local _callback = function(entity)
803
- if not self:worldHas(entity, identityComponent) then
804
- return nil
805
- end
806
- self:worldDelete(entity)
807
- end
808
- for _k, _v in _result_1 do
809
- _callback(_v, _k - 1, _result_1)
810
- end
811
- -- ▲ ReadonlyArray.forEach ▲
812
- end
785
+ for _k, _v in states do
786
+ _callback(_v, _k - 1, states)
813
787
  end
814
- self:schedule(RunService.Heartbeat, function()
815
- if not willUpdate then
816
- return nil
817
- end
818
- willUpdate = false
819
- updater()
820
- end)
788
+ -- ▲ ReadonlyArray.forEach
821
789
  end
822
790
  function Covenant:worldEntity()
823
791
  return self._world:entity()