@rbxts/covenant 3.0.2 → 3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "3.0.2",
3
+ "version": "3.1.1",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -66,10 +66,11 @@ 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 defined>({ identityComponent, replicated, factory, }: {
69
+ defineIdentity<T extends defined>({ identityComponent, replicated, lifetime, factory, }: {
70
70
  identityComponent: Entity<T>;
71
71
  replicated: boolean;
72
- factory: (spawnEntity: (state: T) => Entity, despawnEntity: (entity: Entity) => void) => void;
72
+ lifetime: (entity: Entity, state: T, despawn: () => void) => (() => void) | undefined;
73
+ factory: (spawnEntity: (state: T) => void) => void;
73
74
  }): void;
74
75
  private worldEntity;
75
76
  worldQuery<T extends Id[]>(...components: T): import("@rbxts/jecs").Query<T>;
package/src/covenant.luau CHANGED
@@ -671,18 +671,20 @@ do
671
671
  function Covenant:defineIdentity(_param)
672
672
  local identityComponent = _param.identityComponent
673
673
  local replicated = _param.replicated
674
+ local lifetime = _param.lifetime
674
675
  local factory = _param.factory
675
676
  self:checkComponentDefined(identityComponent)
676
677
  self:defineComponentNetworkBehavior(identityComponent, replicated, false)
677
678
  factory(function(state)
678
679
  local entity = self:worldEntity()
679
680
  self:worldSet(entity, identityComponent, state)
680
- return entity
681
- end, function(entity)
682
- if not self:worldHas(entity, identityComponent) then
683
- return nil
684
- end
685
- self:worldDelete(entity)
681
+ local cleanup = function() end
682
+ cleanup = lifetime(entity, state, function()
683
+ self:worldDelete(entity)
684
+ if cleanup ~= nil then
685
+ cleanup()
686
+ end
687
+ end)
686
688
  end)
687
689
  end
688
690
  function Covenant:worldEntity()