ecspresso 0.12.0 → 0.12.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/README.md +18 -1005
- package/dist/ecspresso.d.ts +0 -1
- package/dist/screen-manager.d.ts +9 -3
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +6 -6
- package/dist/src/plugins/audio.js +2 -2
- package/dist/src/plugins/audio.js.map +2 -2
- package/dist/src/plugins/bounds.js +2 -2
- package/dist/src/plugins/bounds.js.map +2 -2
- package/dist/src/plugins/camera.js +2 -2
- package/dist/src/plugins/camera.js.map +2 -2
- package/dist/src/plugins/collision.js +2 -2
- package/dist/src/plugins/collision.js.map +2 -2
- package/dist/src/plugins/coroutine.js +2 -2
- package/dist/src/plugins/coroutine.js.map +2 -2
- package/dist/src/plugins/diagnostics.js +3 -3
- package/dist/src/plugins/diagnostics.js.map +2 -2
- package/dist/src/plugins/input.js +2 -2
- package/dist/src/plugins/input.js.map +2 -2
- package/dist/src/plugins/particles.js +2 -2
- package/dist/src/plugins/particles.js.map +2 -2
- package/dist/src/plugins/physics2D.js +2 -2
- package/dist/src/plugins/physics2D.js.map +2 -2
- package/dist/src/plugins/renderers/renderer2D.js +2 -2
- package/dist/src/plugins/renderers/renderer2D.js.map +3 -3
- package/dist/src/plugins/spatial-index.js +2 -2
- package/dist/src/plugins/spatial-index.js.map +2 -2
- package/dist/src/plugins/sprite-animation.js +2 -2
- package/dist/src/plugins/sprite-animation.js.map +2 -2
- package/dist/src/plugins/state-machine.js +2 -2
- package/dist/src/plugins/state-machine.js.map +2 -2
- package/dist/src/plugins/timers.js +2 -2
- package/dist/src/plugins/timers.js.map +2 -2
- package/dist/src/plugins/transform.js +2 -2
- package/dist/src/plugins/transform.js.map +2 -2
- package/dist/src/plugins/tween.js +2 -2
- package/dist/src/plugins/tween.js.map +2 -2
- package/package.json +10 -2
package/dist/ecspresso.d.ts
CHANGED
|
@@ -161,7 +161,6 @@ export default class ECSpresso<Cfg extends WorldConfig = EmptyConfig, Labels ext
|
|
|
161
161
|
* This is useful for game startup to ensure all resources are ready
|
|
162
162
|
* and systems are properly initialized before the game loop begins.
|
|
163
163
|
*
|
|
164
|
-
* @param resourceKeys Optional array of specific resource keys to initialize
|
|
165
164
|
* @returns Promise that resolves when everything is initialized
|
|
166
165
|
*/
|
|
167
166
|
initialize(): Promise<void>;
|
package/dist/screen-manager.d.ts
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
* Screen/State management for ECSpresso ECS framework
|
|
3
3
|
*/
|
|
4
4
|
import type EventBus from './event-bus';
|
|
5
|
-
import type AssetManager from './asset-manager';
|
|
6
|
-
import type ECSpresso from './ecspresso';
|
|
7
5
|
import type { ScreenDefinition, ScreenResource, ScreenEvents, ScreenConfigurator, ScreenConfig, ScreenState } from './screen-types';
|
|
6
|
+
/** Structural interface covering only the AssetManager methods ScreenManager uses. */
|
|
7
|
+
interface ScreenManagerAssetDeps {
|
|
8
|
+
isLoaded(key: string): boolean;
|
|
9
|
+
loadAsset(key: string): Promise<unknown>;
|
|
10
|
+
isGroupLoaded(group: string): boolean;
|
|
11
|
+
loadAssetGroup(group: string): Promise<void>;
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* Manages screen/state transitions for ECSpresso
|
|
10
15
|
*/
|
|
@@ -19,7 +24,7 @@ export default class ScreenManager<Screens extends Record<string, ScreenDefiniti
|
|
|
19
24
|
* Set dependencies for screen transitions
|
|
20
25
|
* @internal
|
|
21
26
|
*/
|
|
22
|
-
setDependencies(eventBus: EventBus<ScreenEvents<keyof Screens & string>>, assetManager:
|
|
27
|
+
setDependencies(eventBus: EventBus<ScreenEvents<keyof Screens & string>>, assetManager: ScreenManagerAssetDeps | null, ecs: unknown): void;
|
|
23
28
|
private requireEcs;
|
|
24
29
|
/**
|
|
25
30
|
* Register a screen definition
|
|
@@ -120,3 +125,4 @@ export declare class ScreenConfiguratorImpl<Screens extends Record<string, Scree
|
|
|
120
125
|
* Create a new ScreenConfigurator for builder pattern usage
|
|
121
126
|
*/
|
|
122
127
|
export declare function createScreenConfigurator<Screens extends Record<string, ScreenDefinition<any, any>> = Record<string, never>, W = unknown>(manager?: ScreenManager<Screens>): ScreenConfiguratorImpl<Screens, W>;
|
|
128
|
+
export {};
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var{defineProperty:C,getOwnPropertyNames:i,getOwnPropertyDescriptor:o}=Object,r=Object.prototype.hasOwnProperty;function a(j){return this[j]}var t=(j)=>{var $=(k??=new WeakMap).get(j),L;if($)return $;if($=C({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var J of i(j))if(!r.call($,J))C($,J,{get:a.bind(j,J),enumerable:!(L=o(j,J))||L.enumerable})}return k.set(j,$),$},k;var n=(j)=>j;function e(j,$){this[j]=n.bind(null,$)}var jj=(j,$)=>{for(var L in $)C(j,L,{get:$[L],enumerable:!0,configurable:!0,set:e.bind($,L)})};var V=(j,$)=>()=>(j&&($=j(j=0)),$);var Yj=((j)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(j,{get:($,L)=>(typeof require<"u"?require:$)[L]}):j)(function(j){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+j+'" is not supported')});class H{parentMap=new Map;childrenMap=new Map;setParent(j,$){if(j===$)throw Error(`Cannot set entity ${j} as its own parent`);if(this.wouldCreateCycle(j,$))throw Error("Cannot set parent: would create circular reference");let L=this.parentMap.get(j);if(L!==void 0){let X=this.childrenMap.get(L);if(X){let Y=X.indexOf(j);if(Y!==-1)X.splice(Y,1)}}this.parentMap.set(j,$);let J=this.childrenMap.get($);if(J)J.push(j);else this.childrenMap.set($,[j]);return this}removeParent(j){let $=this.parentMap.get(j);if($===void 0)return!1;let L=this.childrenMap.get($);if(L){let J=L.indexOf(j);if(J!==-1)L.splice(J,1)}return this.parentMap.delete(j),!0}getParent(j){return this.parentMap.get(j)??null}getChildren(j){let $=this.childrenMap.get(j);return $?[...$]:[]}getChildAt(j,$){if($<0)return null;let L=this.childrenMap.get(j);if(!L||$>=L.length)return null;return L[$]??null}getChildIndex(j,$){let L=this.childrenMap.get(j);if(!L)return-1;return L.indexOf($)}removeEntity(j){let $=this.parentMap.get(j)??null;if($!==null){let X=this.childrenMap.get($);if(X){let Y=X.indexOf(j);if(Y!==-1)X.splice(Y,1)}}this.parentMap.delete(j);let L=this.childrenMap.get(j)??[],J=[...L];for(let X of L)this.parentMap.delete(X);return this.childrenMap.delete(j),{oldParent:$,orphanedChildren:J}}getAncestors(j){let $=[],L=this.parentMap.get(j);while(L!==void 0)$.push(L),L=this.parentMap.get(L);return $}getDescendants(j){let $=[],L=this.childrenMap.get(j);if(!L)return $;let J=L.slice().reverse();while(J.length>0){let X=J.pop();$.push(X);let Y=this.childrenMap.get(X);if(Y)for(let Z=Y.length-1;Z>=0;Z--)J.push(Y[Z])}return $}getRoot(j){let $=j,L=this.parentMap.get($);while(L!==void 0)$=L,L=this.parentMap.get($);return $}getSiblings(j){let $=this.parentMap.get(j);if($===void 0)return[];let L=this.childrenMap.get($);if(!L)return[];return L.filter((J)=>J!==j)}isDescendantOf(j,$){if(j===$)return!1;let L=this.parentMap.get(j);while(L!==void 0){if(L===$)return!0;L=this.parentMap.get(L)}return!1}isAncestorOf(j,$){return this.isDescendantOf($,j)}getRootEntities(){let j=[];for(let $ of this.childrenMap.keys())if(!this.parentMap.has($))j.push($);return j}wouldCreateCycle(j,$){let L=$;while(L!==void 0){if(L===j)return!0;L=this.parentMap.get(L)}return!1}forEachInHierarchy(j,$){let L=$?.roots??this.getRootEntities(),J=[];for(let X of L)J.push({entityId:X,parentId:null,depth:0});for(let X of J){j(X.entityId,X.parentId,X.depth);let Y=this.childrenMap.get(X.entityId);if(Y)for(let Z of Y)J.push({entityId:Z,parentId:X.entityId,depth:X.depth+1})}}*hierarchyIterator(j){let $=j?.roots??this.getRootEntities(),L=[];for(let J of $)L.push({entityId:J,parentId:null,depth:0});for(let J of L){yield J;let X=this.childrenMap.get(J.entityId);if(X)for(let Y of X)L.push({entityId:Y,parentId:J.entityId,depth:J.depth+1})}}}class E{nextId=1;entities=new Map;componentIndices=new Map;addedCallbacks=new Map;removedCallbacks=new Map;hierarchyManager=new H;disposeCallbacks=new Map;changeSeqs=new Map;_changeSeq=0;_afterComponentAddedHooks=[];_afterEntityMutatedHooks=[];_afterComponentRemovedHooks=[];_beforeEntityRemovedHooks=[];_afterParentChangedHooks=[];_batchingDepth=0;_batchedEntityIds=new Set;_pendingBatchKeys=null;get entityCount(){return this.entities.size}createEntity(){let j=this.nextId++,$={id:j,components:{}};return this.entities.set(j,$),$}registerDispose(j,$){this.disposeCallbacks.set(j,$)}getDisposeCallbacks(){return this.disposeCallbacks}invokeDispose(j,$,L){let J=this.disposeCallbacks.get(j);if(!J)return;try{J({value:$,entityId:L})}catch(X){console.warn(`Component dispose callback for '${String(j)}' threw:`,X)}}addComponent(j,$,L){let J=this.entities.get(j);if(!J)throw Error(`Cannot add component '${String($)}': Entity with ID ${j} does not exist`);let X=J.components[$];if(X!==void 0)this.invokeDispose($,X,J.id);if(J.components[$]=L,!this.componentIndices.has($))this.componentIndices.set($,new Set);this.componentIndices.get($)?.add(J.id);let Y=this.addedCallbacks.get($);if(Y)for(let Z of[...Y])Z({value:L,entity:J});this._batchingDepth++;for(let Z of this._afterComponentAddedHooks)Z(J.id,$);if(this._batchedEntityIds.add(J.id),this._batchingDepth--,this._batchingDepth===0){for(let Z of this._batchedEntityIds)for(let B of this._afterEntityMutatedHooks)B(Z);this._batchedEntityIds.clear()}return this}addComponents(j,$){let L=this.entities.get(j);if(!L)throw Error(`Cannot add components: Entity with ID ${j} does not exist`);let J=this._pendingBatchKeys;this._pendingBatchKeys=new Set(Object.keys($)),this._batchingDepth++;for(let X in $)this.addComponent(L.id,X,$[X]);if(this._batchingDepth--,this._pendingBatchKeys=J,this._batchingDepth===0){for(let X of this._batchedEntityIds)for(let Y of this._afterEntityMutatedHooks)Y(X);this._batchedEntityIds.clear()}return this}removeComponent(j,$){let L=this.entities.get(j);if(!L)throw Error(`Cannot remove component '${String($)}': Entity with ID ${j} does not exist`);let J=L.components[$];if(J!==void 0)this.invokeDispose($,J,L.id);delete L.components[$];let X=this.removedCallbacks.get($);if(X&&J!==void 0)for(let Y of[...X])Y({value:J,entity:L});if(this.componentIndices.get($)?.delete(L.id),J!==void 0)for(let Y of this._afterComponentRemovedHooks)Y(L.id,$);return this}getComponent(j,$){let L=this.entities.get(j);if(!L)throw Error(`Cannot get component '${String($)}': Entity with ID ${j} does not exist`);return L.components[$]}getEntitiesWithQuery(j=[],$=[],L,J,X){let Y=L!==void 0&&L.length>0&&J!==void 0,Z=X!==void 0&&X.length>0;if(j.length===0){if($.length===0&&!Y&&!Z)return Array.from(this.entities.values());return Array.from(this.entities.values()).filter((D)=>{if($.length>0&&!$.every((_)=>!(_ in D.components)))return!1;if(Y){let _=this.changeSeqs.get(D.id);if(!_)return!1;if(!L.some((Q)=>(_.get(Q)??-1)>J))return!1}if(Z&&!this.parentHasComponents(D.id,X))return!1;return!0})}let B=j[0];if(B===void 0)return[];let K=j.reduce((D,_)=>{let Q=this.componentIndices.get(_)?.size??0,A=this.componentIndices.get(D)?.size??1/0;return Q<A?_:D},B),U=this.componentIndices.get(K);if(!U||U.size===0)return[];let W=[],F=$.length>0;for(let D of U){let _=this.entities.get(D);if(_&&j.every((Q)=>(Q in _.components))&&(!F||$.every((Q)=>!(Q in _.components)))){if(Y){let Q=this.changeSeqs.get(D);if(!Q||!L.some((A)=>(Q.get(A)??-1)>J))continue}if(Z&&!this.parentHasComponents(D,X))continue;W.push(_)}}return W}parentHasComponents(j,$){let L=this.hierarchyManager.getParent(j);if(L===null)return!1;let J=this.entities.get(L);if(!J)return!1;for(let X of $)if(!(X in J.components))return!1;return!0}removeEntity(j,$){let L=this.entities.get(j);if(!L)return!1;if($?.cascade??!0){let X=this.hierarchyManager.getDescendants(L.id);for(let Y=X.length-1;Y>=0;Y--){let Z=X[Y];if(Z===void 0)continue;for(let B of this._beforeEntityRemovedHooks)B(Z)}for(let Y of this._beforeEntityRemovedHooks)Y(L.id);for(let Y=X.length-1;Y>=0;Y--){let Z=X[Y];if(Z===void 0)continue;this.removeEntityInternal(Z)}}else for(let X of this._beforeEntityRemovedHooks)X(L.id);return this.removeEntityInternal(L.id)}removeEntityInternal(j){let $=this.entities.get(j);if(!$)return!1;this.hierarchyManager.removeEntity(j);for(let L of Object.keys($.components)){let J=$.components[L];if(J!==void 0){this.invokeDispose(L,J,$.id);let X=this.removedCallbacks.get(L);if(X)for(let Y of[...X])Y({value:J,entity:$})}this.componentIndices.get(L)?.delete($.id)}return this.changeSeqs.delete($.id),this.entities.delete($.id)}getEntity(j){return this.entities.get(j)}onComponentAdded(j,$){let L=$,J=this.addedCallbacks.get(j);if(!J)J=new Set,this.addedCallbacks.set(j,J);return J.add(L),()=>{this.addedCallbacks.get(j)?.delete(L)}}onComponentRemoved(j,$){let L=$,J=this.removedCallbacks.get(j);if(!J)J=new Set,this.removedCallbacks.set(j,J);return J.add(L),()=>{this.removedCallbacks.get(j)?.delete(L)}}onAfterComponentAdded(j){return this._afterComponentAddedHooks.push(j),()=>{let $=this._afterComponentAddedHooks.indexOf(j);if($!==-1)this._afterComponentAddedHooks.splice($,1)}}onAfterEntityMutated(j){return this._afterEntityMutatedHooks.push(j),()=>{let $=this._afterEntityMutatedHooks.indexOf(j);if($!==-1)this._afterEntityMutatedHooks.splice($,1)}}onAfterComponentRemoved(j){return this._afterComponentRemovedHooks.push(j),()=>{let $=this._afterComponentRemovedHooks.indexOf(j);if($!==-1)this._afterComponentRemovedHooks.splice($,1)}}onBeforeEntityRemoved(j){return this._beforeEntityRemovedHooks.push(j),()=>{let $=this._beforeEntityRemovedHooks.indexOf(j);if($!==-1)this._beforeEntityRemovedHooks.splice($,1)}}onAfterParentChanged(j){return this._afterParentChangedHooks.push(j),()=>{let $=this._afterParentChangedHooks.indexOf(j);if($!==-1)this._afterParentChangedHooks.splice($,1)}}get changeSeq(){return this._changeSeq}markChanged(j,$){let L=++this._changeSeq,J=this.changeSeqs.get(j);if(!J)J=new Map,this.changeSeqs.set(j,J);J.set($,L)}getChangeSeq(j,$){return this.changeSeqs.get(j)?.get($)??-1}spawnChild(j,$){let L=this.createEntity();return this.addComponents(L.id,$),this.setParent(L.id,j),L}setParent(j,$){this.hierarchyManager.setParent(j,$);for(let L of this._afterParentChangedHooks)L(j);return this}removeParent(j){let $=this.hierarchyManager.removeParent(j);if($)for(let L of this._afterParentChangedHooks)L(j);return $}getParent(j){return this.hierarchyManager.getParent(j)}getChildren(j){return this.hierarchyManager.getChildren(j)}getChildAt(j,$){return this.hierarchyManager.getChildAt(j,$)}getChildIndex(j,$){return this.hierarchyManager.getChildIndex(j,$)}getAncestors(j){return this.hierarchyManager.getAncestors(j)}getDescendants(j){return this.hierarchyManager.getDescendants(j)}getRoot(j){return this.hierarchyManager.getRoot(j)}getSiblings(j){return this.hierarchyManager.getSiblings(j)}isDescendantOf(j,$){return this.hierarchyManager.isDescendantOf(j,$)}isAncestorOf(j,$){return this.hierarchyManager.isAncestorOf(j,$)}getRootEntities(){return this.hierarchyManager.getRootEntities()}forEachInHierarchy(j,$){this.hierarchyManager.forEachInHierarchy(j,$)}hierarchyIterator(j){return this.hierarchyManager.hierarchyIterator(j)}}var h=()=>{};class w{handlers=new Map;subscribe(j,$){return this.addHandler(j,$,!1)}once(j,$){return this.addHandler(j,$,!0)}unsubscribe(j,$){let L=this.handlers.get(j);if(!L)return!1;let J=L.findIndex((X)=>X.callback===$);if(J===-1)return!1;return L.splice(J,1),!0}addHandler(j,$,L){let J=this.handlers.get(j);if(!J)J=[],this.handlers.set(j,J);let X={callback:$,once:L};return J.push(X),()=>{let Y=this.handlers.get(j);if(Y){let Z=Y.indexOf(X);if(Z!==-1)Y.splice(Z,1)}}}publish(...[j,$]){let L=this.handlers.get(j);if(!L||L.length===0)return;let J=!1,X=L.length;for(let Y=0;Y<X&&Y<L.length;Y++){let Z=L[Y];if(!Z)continue;if(Z.callback($),Z.once)J=!0}if(J){for(let Y=L.length-1;Y>=0;Y--)if(L[Y]?.once)L.splice(Y,1)}}clear(){this.handlers.clear()}clearEvent(j){this.handlers.delete(j)}}function $j(j){return{[q]:j}}function Lj(j){return typeof j==="object"&&j!==null&&"factory"in j&&typeof j.factory==="function"}function Jj(j){return typeof j==="object"&&j!==null&&q in j}function u(j,$){let L=[],J=new Set,X=new Set;function Y(Z,B=[]){if(J.has(Z))return;if(X.has(Z))throw Error(`Circular resource dependency: ${[...B,Z].join(" -> ")}`);X.add(Z);for(let K of $(Z)){let U=j.find((W)=>W===K);if(U)Y(U,[...B,Z])}X.delete(Z),J.add(Z),L.push(Z)}for(let Z of j)Y(Z);return L}class R{resources=new Map;resourceFactories=new Map;resourceDependencies=new Map;resourceDisposers=new Map;initializedResourceKeys=new Set;add(j,$){let L=(J)=>{this.resources.set(j,J),this.initializedResourceKeys.add(j),this.resourceDependencies.set(j,[])};if(Lj($)){if(this.resourceFactories.set(j,$.factory),this.resourceDependencies.set(j,$.dependsOn??[]),$.onDispose)this.resourceDisposers.set(j,$.onDispose)}else if(Jj($))L($[q]);else if(typeof $==="function")this.resourceFactories.set(j,$),this.resourceDependencies.set(j,[]);else L($);return this}tryGet(j,...$){if(!this.has(j))return;return this.get(j,...$)}get(j,...$){let L=this.resources.get(j);if(L!==void 0)return L;let J=this.resourceFactories.get(j);if(J===void 0)throw Error(`Resource ${String(j)} not found`);let X=$[0],Y=J(X);if(!(Y instanceof Promise))this.resources.set(j,Y),this.initializedResourceKeys.add(j);return Y}has(j){return this.resources.has(j)||this.resourceFactories.has(j)}remove(j){let $=this.resources.delete(j),L=this.resourceFactories.delete(j);return this.resourceDependencies.delete(j),this.resourceDisposers.delete(j),this.initializedResourceKeys.delete(j),$||L}getKeys(){let j=new Set([...this.resources.keys(),...this.resourceFactories.keys()]);return Array.from(j)}needsInitialization(j){return this.resourceFactories.has(j)&&!this.initializedResourceKeys.has(j)}getPendingInitializationKeys(){return Array.from(this.resourceFactories.keys()).filter((j)=>!this.initializedResourceKeys.has(j))}async initializeResource(j,...$){if(!this.resourceFactories.has(j)||this.initializedResourceKeys.has(j))return;let L=this.resourceFactories.get(j);if(!L)return;let J=$[0],X=await L(J);this.resources.set(j,X),this.initializedResourceKeys.add(j),this.resourceFactories.delete(j)}async initializeResources(...j){let $=j.slice(1),L=$.length===0?this.getPendingInitializationKeys():$;if(L.length===0)return;let J=u(L,(X)=>[...this.resourceDependencies.get(X)??[]]);for(let X of J)await this.initializeResource(X,...j.slice(0,1))}getDependencies(j){return this.resourceDependencies.get(j)??[]}async disposeResource(j,...$){if(!this.resources.has(j)&&!this.resourceFactories.has(j))return!1;if(this.initializedResourceKeys.has(j)){let L=this.resourceDisposers.get(j),J=this.resources.get(j);if(L&&J!==void 0){let X=$[0];await L(J,X)}}return this.resources.delete(j),this.resourceFactories.delete(j),this.resourceDependencies.delete(j),this.resourceDisposers.delete(j),this.initializedResourceKeys.delete(j),!0}async disposeResources(...j){let $=Array.from(this.initializedResourceKeys);if($.length===0)return;let L=u($,(J)=>[...this.resourceDependencies.get(J)??[]]).reverse();for(let J of L)await this.disposeResource(J,...j)}}var q;var v=V(()=>{q=Symbol("resource-direct")});class S{queries=new Map;entityManager;_hasParentHasQueries=!1;constructor(j){this.entityManager=j}get hasParentHasQueries(){return this._hasParentHasQueries}addQuery(j,$){let L={definition:$,matchingEntities:new Set};if(this.queries.set(j,L),$.parentHas?.length)this._hasParentHasQueries=!0;let J=this.entityManager.getEntitiesWithQuery($.with,$.without??[]);for(let X of J)if(this.entityMatchesQuery(X,L.definition))L.matchingEntities.add(X.id),L.definition.onEnter?.(X)}removeQuery(j){let $=this.queries.delete(j);if($)this._recalcParentHasFlag();return $}entityMatchesQuery(j,$){for(let L of $.with)if(!(L in j.components))return!1;if($.without){for(let L of $.without)if(L in j.components)return!1}if($.parentHas?.length){let L=this.entityManager.getParent(j.id);if(L===null)return!1;let J=this.entityManager.getEntity(L);if(!J)return!1;for(let X of $.parentHas)if(!(X in J.components))return!1}return!0}_applyQueryTransition(j,$){let L=$.matchingEntities.has(j.id),J=this.entityMatchesQuery(j,$.definition);if(!L&&J)$.matchingEntities.add(j.id),$.definition.onEnter?.(j);else if(L&&!J)$.matchingEntities.delete(j.id),$.definition.onExit?.(j.id)}onComponentAdded(j,$){for(let[,L]of this.queries)this._applyQueryTransition(j,L);if(this._hasParentHasQueries)this._recheckChildren(j.id)}onComponentRemoved(j,$){for(let[,L]of this.queries)this._applyQueryTransition(j,L);if(this._hasParentHasQueries)this._recheckChildren(j.id)}onEntityRemoved(j){for(let[$,L]of this.queries)if(L.matchingEntities.has(j))L.matchingEntities.delete(j),L.definition.onExit?.(j)}recheckEntity(j){for(let[,$]of this.queries)this._applyQueryTransition(j,$)}recheckEntityAndChildren(j){if(this.recheckEntity(j),this._hasParentHasQueries)this._recheckChildren(j.id)}_recheckChildren(j){let $=this.entityManager.getChildren(j);for(let L of $){let J=this.entityManager.getEntity(L);if(J)this.recheckEntity(J)}}_recalcParentHasFlag(){this._hasParentHasQueries=!1;for(let[,j]of this.queries)if(j.definition.parentHas?.length){this._hasParentHasQueries=!0;return}}}class x{commands=[];removeEntity(j,$){this.commands.push((L)=>{L.removeEntity(j,$)})}addComponent(j,$,L){this.commands.push((J)=>{J.addComponent(j,$,L)})}removeComponent(j,$){this.commands.push((L)=>{L.removeComponent(j,$)})}spawn(j){this.commands.push(($)=>{$.spawn(j)})}spawnChild(j,$){this.commands.push((L)=>{L.spawnChild(j,$)})}addComponents(j,$){this.commands.push((L)=>{L.addComponents(j,$)})}setParent(j,$){this.commands.push((L)=>{L.setParent(j,$)})}mutateComponent(j,$,L){this.commands.push((J)=>{J.mutateComponent(j,$,L)})}markChanged(j,$){this.commands.push((L)=>{L.markChanged(j,$)})}removeParent(j){this.commands.push(($)=>{$.removeParent(j)})}playback(j){for(let $ of this.commands)try{$(j)}catch(L){console.warn("CommandBuffer: Command failed during playback:",L)}this.commands=[]}clear(){this.commands=[]}get length(){return this.commands.length}}function z(j){return j}class T{_label;queries={};processFunction;detachFunction;initializeFunction;eventHandlers;_priority=0;_phase="update";_groups=[];_inScreens;_excludeScreens;_requiredAssets;_runWhenEmpty=!1;_entityEnterHandlers={};_resourceKeys;constructor(j){this._label=j}get label(){return this._label}_createSystemObject(){let j={label:this._label,entityQueries:this.queries,priority:this._priority,phase:this._phase};if(this.processFunction)j.process=this.processFunction;if(this.detachFunction)j.onDetach=this.detachFunction;if(this.initializeFunction)j.onInitialize=this.initializeFunction;if(this.eventHandlers)j.eventHandlers=this.eventHandlers;if(this._groups.length>0)j.groups=[...this._groups];if(this._inScreens)j.inScreens=this._inScreens;if(this._excludeScreens)j.excludeScreens=this._excludeScreens;if(this._requiredAssets)j.requiredAssets=this._requiredAssets;if(this._runWhenEmpty)j.runWhenEmpty=!0;if(Object.keys(this._entityEnterHandlers).length>0)j.onEntityEnter={...this._entityEnterHandlers};return j}setPriority(j){return this._priority=j,this}inPhase(j){return this._phase=j,this}inGroup(j){if(!this._groups.includes(j))this._groups.push(j);return this}inScreens(j){return this._inScreens=[...j],this}excludeScreens(j){return this._excludeScreens=[...j],this}requiresAssets(j){return this._requiredAssets=[...j],this}runWhenEmpty(){return this._runWhenEmpty=!0,this}withResources(j){return this._resourceKeys=[...j],this}addQuery(j,$){let L=this;return L.queries={...this.queries,[j]:$},L}setProcess(j){if(this._resourceKeys?.length){let $=this._resourceKeys,L;this.processFunction=(J)=>{if(!L){L={};for(let X of $)L[X]=J.ecs.getResource(X)}J.resources=L,j(J)}}else this.processFunction=j;return this}setOnEntityEnter(j,$){return this._entityEnterHandlers[j]=$,this}setOnDetach(j){return this.detachFunction=j,this}setOnInitialize(j){return this.initializeFunction=j,this}setEventHandlers(j){return this.eventHandlers=j,this}}function I(j,$,L){let J=new Set,X=[$];while(X.length>0){let Y=X.pop();if(Y===void 0)break;if(Y===j)throw Error(`Circular required component dependency: '${String(j)}' -> '${String($)}' -> ... -> '${String(j)}'`);if(J.has(Y))continue;J.add(Y);let Z=L(Y);if(Z)for(let B of Z)X.push(B.component)}}var m="0.12.0";var p=()=>{};class O{assets=new Map;groups=new Map;eventBus=null;setEventBus(j){this.eventBus=j}register(j,$){if(this.assets.set(j,{definition:$,status:"pending"}),$.group){let L=this.groups.get($.group)??new Set;L.add(j),this.groups.set($.group,L)}}async loadEagerAssets(){let j=[];for(let[$,L]of this.assets)if(L.definition.eager&&L.status==="pending")j.push($);await Promise.all(j.map(($)=>this.loadAsset($)))}async loadAsset(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);if($.status==="loaded"&&$.value!==void 0)return $.value;if($.status==="loading"&&$.loadPromise)return $.loadPromise;if($.status==="failed")$.status="pending";$.status="loading",$.loadPromise=$.definition.loader();try{let L=await $.loadPromise;return $.value=L,$.status="loaded",$.loadPromise=void 0,this.eventBus?.publish("assetLoaded",{key:j}),this.checkGroupProgress($.definition.group),L}catch(L){let J=L instanceof Error?L:Error(String(L));throw $.status="failed",$.error=J,$.loadPromise=void 0,this.eventBus?.publish("assetFailed",{key:j,error:J}),J}}async loadAssetGroup(j){let $=this.groups.get(j);if(!$||$.size===0)throw Error(`Asset group '${j}' not found or empty`);await Promise.all(Array.from($).map((L)=>this.loadAsset(L)))}get(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);if($.status!=="loaded"||$.value===void 0)throw Error(`Asset '${String(j)}' is not loaded (status: ${$.status})`);return $.value}tryGet(j){let $=this.assets.get(j);if(!$||$.status!=="loaded")return;return $.value}getHandle(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);let L=this;return{get status(){return $.status},get isLoaded(){return $.status==="loaded"},get(){return L.get(j)},tryGet(){return L.tryGet(j)}}}getStatus(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);return $.status}isLoaded(j){return this.assets.get(j)?.status==="loaded"}isGroupLoaded(j){let $=this.groups.get(j);if(!$||$.size===0)return!1;for(let L of $){let J=this.assets.get(L);if(!J||J.status!=="loaded")return!1}return!0}getGroupProgress(j){return this.getGroupProgressDetails(j).progress}getGroupProgressDetails(j){let $=this.groups.get(j);if(!$||$.size===0)return{loaded:0,total:0,progress:0};let L=0;for(let X of $)if(this.assets.get(X)?.status==="loaded")L++;let J=$.size;return{loaded:L,total:J,progress:L/J}}checkGroupProgress(j){if(!j||!this.eventBus)return;let $=j,L=this.getGroupProgressDetails($);if(this.eventBus.publish("assetGroupProgress",{group:$,...L}),L.loaded===L.total)this.eventBus.publish("assetGroupLoaded",{group:$})}createResource(){let j=this;return{getStatus($){return j.getStatus($)},isLoaded($){return j.isLoaded($)},isGroupLoaded($){return j.isGroupLoaded($)},getGroupProgress($){return j.getGroupProgress($)},get($){return j.get($)},tryGet($){return j.tryGet($)},getHandle($){return j.getHandle($)}}}getKeys(){return Array.from(this.assets.keys())}getGroupNames(){return Array.from(this.groups.keys())}getGroupKeys(j){let $=this.groups.get(j);return $?Array.from($):[]}}class l{manager;constructor(j){this.manager=j}add(j,$){return this.manager.register(j,{loader:$,eager:!0}),this}addWithConfig(j,$){return this.manager.register(j,$),this}addGroup(j,$){for(let[L,J]of Object.entries($))this.manager.register(L,{loader:J,eager:!1,group:j});return this}getManager(){return this.manager}}function f(j){return new l(j??new O)}class P{screens=new Map;currentScreen=null;screenStack=[];eventBus=null;assetManager=null;ecs=null;setDependencies(j,$,L){this.eventBus=j,this.assetManager=$,this.ecs=L}requireEcs(){if(!this.ecs)throw Error("ScreenManager: dependencies not set. Call setDependencies() first.");return this.ecs}register(j,$){this.screens.set(j,{definition:$})}async setScreen(j,$){let L=this.screens.get(j);if(!L)throw Error(`Screen '${String(j)}' not found`);await this.verifyRequiredAssets(L.definition);while(this.screenStack.length>0){let X=this.screenStack.pop();if(X)await this.exitScreen(X.name)}if(this.currentScreen)await this.exitScreen(this.currentScreen.name);let J=L.definition.initialState($);this.currentScreen={name:j,config:$,state:J},await L.definition.onEnter?.({config:$,ecs:this.requireEcs()}),this.eventBus?.publish("screenEnter",{screen:j,config:$})}async pushScreen(j,$){let L=this.screens.get(j);if(!L)throw Error(`Screen '${String(j)}' not found`);if(await this.verifyRequiredAssets(L.definition),this.currentScreen)this.screenStack.push(this.currentScreen);let J=L.definition.initialState($);this.currentScreen={name:j,config:$,state:J},await L.definition.onEnter?.({config:$,ecs:this.requireEcs()}),this.eventBus?.publish("screenPush",{screen:j,config:$})}async popScreen(){if(this.screenStack.length===0)throw Error("Cannot pop screen: stack is empty");if(this.currentScreen)await this.exitScreen(this.currentScreen.name),this.eventBus?.publish("screenPop",{screen:this.currentScreen.name});this.currentScreen=this.screenStack.pop()??null}async exitScreen(j){let $=this.screens.get(j);if($?.definition.onExit)await $.definition.onExit(this.requireEcs());this.eventBus?.publish("screenExit",{screen:j})}async verifyRequiredAssets(j){if(!this.assetManager)return;if(j.requiredAssets){for(let $ of j.requiredAssets)if(!this.assetManager.isLoaded($))await this.assetManager.loadAsset($)}if(j.requiredAssetGroups){for(let $ of j.requiredAssetGroups)if(!this.assetManager.isGroupLoaded($))await this.assetManager.loadAssetGroup($)}}getCurrentScreen(){return this.currentScreen?.name??null}getConfig(j){if(!this.currentScreen)throw Error("No current screen");if(j!==void 0&&this.currentScreen.name!==j)throw Error(`Expected current screen '${String(j)}', but current is '${String(this.currentScreen.name)}'`);return this.currentScreen.config}tryGetConfig(j){if(!this.currentScreen)return;if(j!==void 0&&this.currentScreen.name!==j)return;return this.currentScreen.config}getState(j){if(!this.currentScreen)throw Error("No current screen");if(j!==void 0&&this.currentScreen.name!==j)throw Error(`Expected current screen '${String(j)}', but current is '${String(this.currentScreen.name)}'`);return this.currentScreen.state}tryGetState(j){if(!this.currentScreen)return;if(j!==void 0&&this.currentScreen.name!==j)return;return this.currentScreen.state}updateState(j,$){if(!this.currentScreen)throw Error("No current screen");if($!==void 0&&this.currentScreen.name!==$)throw Error(`Expected current screen '${String($)}', but current is '${String(this.currentScreen.name)}'`);let L=typeof j==="function"?j(this.currentScreen.state):j;this.currentScreen.state={...this.currentScreen.state,...L}}getStackDepth(){return this.screenStack.length}isOverlay(){return this.screenStack.length>0}isActive(j){if(this.currentScreen?.name===j)return!0;return this.screenStack.some(($)=>$.name===j)}isCurrent(j){return this.currentScreen?.name===j}createResource(){let j=this;return{get current(){return j.getCurrentScreen()},get config(){return j.tryGetConfig()??null},get state(){return j.tryGetState()??null},set state($){if(j.currentScreen&&$!==null)j.currentScreen.state=$},get stack(){return j.screenStack},get isOverlay(){return j.isOverlay()},get stackDepth(){return j.getStackDepth()},isActive($){return j.isActive($)},isCurrent($){return j.isCurrent($)}}}getScreenNames(){return Array.from(this.screens.keys())}hasScreen(j){return this.screens.has(j)}}class s{manager;constructor(j){this.manager=j}add(j,$){return this.manager.register(j,$),this}getManager(){return this.manager}}function b(j){return new s(j??new P)}class N{ecspresso;assetConfigurator=null;screenConfigurator=null;pendingResources=[];pendingDisposeCallbacks=[];pendingRequiredComponents=[];pendingPlugins=[];_fixedDt=null;constructor(){let{default:j}=(g(),t(c));this.ecspresso=new j}withPlugin(j){return this.pendingPlugins.push(j),this}withComponentTypes(){return this}withEventTypes(){return this}withResourceTypes(){return this}withResource(j,$){return this.pendingResources.push({key:j,value:$}),this}withDispose(j,$){return this.pendingDisposeCallbacks.push({key:j,callback:$}),this}withRequired(j,$,L){return this.pendingRequiredComponents.push({trigger:j,required:$,factory:L}),this}withAssets(j){let $=f();return j($),this.assetConfigurator=$,this}withScreens(j){let $=b();return j($),this.screenConfigurator=$,this}withFixedTimestep(j){return this._fixedDt=j,this}withReactiveQueryNames(){return this}pluginFactory(){return z}build(){for(let j of this.pendingPlugins)this.ecspresso.installPlugin(j);for(let{key:j,value:$}of this.pendingResources)this.ecspresso.addResource(j,$);for(let{key:j,callback:$}of this.pendingDisposeCallbacks)this.ecspresso.registerDispose(j,$);for(let{trigger:j,required:$,factory:L}of this.pendingRequiredComponents)this.ecspresso.registerRequired(j,$,L);if(this.assetConfigurator)this.ecspresso._setAssetManager(this.assetConfigurator.getManager());else if(this.ecspresso._hasPendingPluginAssets())this.ecspresso._setAssetManager(new O);if(this.screenConfigurator)this.ecspresso._setScreenManager(this.screenConfigurator.getManager());else if(this.ecspresso._hasPendingPluginScreens())this.ecspresso._setScreenManager(new P);if(this._fixedDt!==null)this.ecspresso._setFixedDt(this._fixedDt);return this.ecspresso}}var y=()=>{};var c={};jj(c,{default:()=>M});var d,M;var g=V(()=>{h();v();p();y();d=["preUpdate","fixedUpdate","update","postUpdate","render"];M=class M{static VERSION=m;_entityManager;_eventBus;_resourceManager;_commandBuffer;_systems=[];_phaseSystems={preUpdate:[],fixedUpdate:[],update:[],postUpdate:[],render:[]};_installedPlugins=new Set;_disabledGroups=new Set;_assetManager=null;_screenManager=null;_reactiveQueryManager;_postUpdateHooks=[];_currentTick=0;_systemLastSeqs=new Map;_changeThreshold=0;_fixedDt=0.016666666666666666;_fixedAccumulator=0;_interpolationAlpha=0;_maxFixedSteps=8;_requiredComponents=new Map;_pendingPluginAssets=[];_pendingPluginScreens=[];_diagnosticsEnabled=!1;_systemTimings=new Map;_phaseTimings={preUpdate:0,fixedUpdate:0,update:0,postUpdate:0,render:0};_entityEnterTracking=new Map;_entityEnterFrameSet=new Set;_systemContexts=new WeakMap;_pendingFinalizers=[];_batchingRegistrations=!1;constructor(){this._entityManager=new E,this._eventBus=new w,this._resourceManager=new R,this._reactiveQueryManager=new S(this._entityManager),this._commandBuffer=new x,this._subscribeLifecycleHooks()}_subscribeLifecycleHooks(){this._entityManager.onAfterComponentAdded((j,$)=>{this._entityManager.markChanged(j,$);let L=this._requiredComponents.get($);if(L){let J=this._entityManager.getEntity(j);if(J){let X=J.components[$];for(let{component:Y,factory:Z}of L){if(this._entityManager._pendingBatchKeys?.has(Y))continue;if(!(Y in J.components))this._entityManager.addComponent(j,Y,Z(X))}}}}),this._entityManager.onAfterEntityMutated((j)=>{let $=this._entityManager.getEntity(j);if($)this._reactiveQueryManager.recheckEntityAndChildren($)}),this._entityManager.onAfterComponentRemoved((j,$)=>{let L=this._entityManager.getEntity(j);if(L)this._reactiveQueryManager.onComponentRemoved(L,$)}),this._entityManager.onBeforeEntityRemoved((j)=>{this._reactiveQueryManager.onEntityRemoved(j)}),this._entityManager.onAfterParentChanged((j)=>{if(this._reactiveQueryManager.hasParentHasQueries){let $=this._entityManager.getEntity(j);if($)this._reactiveQueryManager.recheckEntity($)}})}static create(){return new N}addSystem(j){let $=new T(j);return this._pendingFinalizers.push(()=>{this._registerSystem($._createSystemObject())}),$}_finalizePendingBuilders(){if(this._pendingFinalizers.length===0)return;this._batchingRegistrations=!0;while(this._pendingFinalizers.length>0){let j=this._pendingFinalizers;this._pendingFinalizers=[];for(let $ of j)$()}this._batchingRegistrations=!1,this._rebuildPhaseSystems()}update(j){this._finalizePendingBuilders();let $=this._screenManager?.getCurrentScreen()??null,L=this._diagnosticsEnabled;this._runPhase("preUpdate",j,$,L);let J=L?performance.now():0;this._fixedAccumulator+=j;let X=0;while(this._fixedAccumulator>=this._fixedDt&&X<this._maxFixedSteps)this._executePhase(this._phaseSystems.fixedUpdate,this._fixedDt,$),this._commandBuffer.playback(this),this._fixedAccumulator-=this._fixedDt,X++;if(this._fixedAccumulator>=this._fixedDt)this._fixedAccumulator=0;if(L)this._phaseTimings.fixedUpdate=performance.now()-J;this._interpolationAlpha=this._fixedAccumulator/this._fixedDt,this._runPhase("update",j,$,L),this._runPhase("postUpdate",j,$,L);for(let Y of this._postUpdateHooks)Y({ecs:this,dt:j});this._runPhase("render",j,$,L),this._changeThreshold=this._entityManager.changeSeq,this._currentTick++}_executePhase(j,$,L){for(let J of j){if(!J.process&&!J.onEntityEnter)continue;if(J.groups?.length){let W=!1;for(let F of J.groups)if(this._disabledGroups.has(F)){W=!0;break}if(W)continue}if(J.inScreens?.length){if(L===null||!J.inScreens.includes(L))continue}if(J.excludeScreens?.length){if(L!==null&&J.excludeScreens.includes(L))continue}if(J.requiredAssets?.length&&this._assetManager){let W=!0;for(let F of J.requiredAssets)if(!this._assetManager.isLoaded(F)){W=!1;break}if(!W)continue}let X=this._systemLastSeqs.get(J)??0;this._changeThreshold=X;let Y=this._systemContexts.get(J);if(!Y)Y={queries:{},dt:0,ecs:this},this._systemContexts.set(J,Y);Y.dt=$;let Z=Y.queries,B=!1,K=!1;if(J.entityQueries)for(let W in J.entityQueries){K=!0;let F=J.entityQueries[W];if(F){if(Z[W]=this._entityManager.getEntitiesWithQuery(F.with,F.without||[],F.changed,F.changed?this._changeThreshold:void 0,F.parentHas),Z[W].length)B=!0}}let U=this._entityEnterTracking.get(J);if(U&&J.onEntityEnter)for(let W in J.onEntityEnter){let F=Z[W],D=U.get(W);if(!F||!D)continue;let _=J.onEntityEnter[W];if(!_)continue;let Q=this._entityEnterFrameSet;Q.clear();for(let A of F)if(Q.add(A.id),!D.has(A.id))D.add(A.id),_({entity:A,ecs:this});for(let A of D)if(!Q.has(A))D.delete(A)}if(J.process){if(this._diagnosticsEnabled){let W=performance.now();if(B||J.runWhenEmpty)J.process(Y);else if(!K)J.process(Y);this._systemTimings.set(J.label,performance.now()-W)}else if(B||J.runWhenEmpty)J.process(Y);else if(!K)J.process(Y)}this._systemLastSeqs.set(J,this._entityManager.changeSeq)}}_runPhase(j,$,L,J){if(J){let X=performance.now();this._executePhase(this._phaseSystems[j],$,L),this._phaseTimings[j]=performance.now()-X}else this._executePhase(this._phaseSystems[j],$,L);this._commandBuffer.playback(this)}async initialize(){if(this._finalizePendingBuilders(),await this.initializeResources(),this._assetManager)this._assetManager.setEventBus(this._eventBus),await this._assetManager.loadEagerAssets(),this._resourceManager.add("$assets",this._assetManager.createResource());if(this._screenManager)this._screenManager.setDependencies(this._eventBus,this._assetManager,this),this._resourceManager.add("$screen",this._screenManager.createResource());for(let j of this._systems)await j.onInitialize?.(this)}async initializeResources(...j){await this._resourceManager.initializeResources(this,...j)}_rebuildPhaseSystems(){for(let j of d)this._phaseSystems[j]=[];for(let j of this._systems){let $=j.phase??"update";this._phaseSystems[$].push(j)}for(let j of d)this._phaseSystems[j].sort(($,L)=>{let J=$.priority??0;return(L.priority??0)-J})}updateSystemPriority(j,$){this._finalizePendingBuilders();let L=this._systems.find((J)=>J.label===j);if(!L)return!1;return L.priority=$,this._rebuildPhaseSystems(),!0}updateSystemPhase(j,$){this._finalizePendingBuilders();let L=this._systems.find((J)=>J.label===j);if(!L)return!1;return L.phase=$,this._rebuildPhaseSystems(),!0}get interpolationAlpha(){return this._interpolationAlpha}get fixedDt(){return this._fixedDt}disableSystemGroup(j){this._disabledGroups.add(j)}enableSystemGroup(j){this._disabledGroups.delete(j)}isSystemGroupEnabled(j){return!this._disabledGroups.has(j)}getSystemsInGroup(j){return this._finalizePendingBuilders(),this._systems.filter(($)=>$.groups?.includes(j)).map(($)=>$.label)}removeSystem(j){this._finalizePendingBuilders();let $=this._systems.findIndex((J)=>J.label===j);if($===-1)return!1;let L=this._systems[$];if(!L)return!1;if(L.onDetach)L.onDetach(this);return this._systems.splice($,1),this._systemLastSeqs.delete(L),this._entityEnterTracking.delete(L),this._rebuildPhaseSystems(),!0}_registerSystem(j){if(this._systems.push(j),this._systemLastSeqs.set(j,this._changeThreshold),!this._batchingRegistrations)this._rebuildPhaseSystems();if(j.onEntityEnter){let $=new Map;for(let L in j.onEntityEnter)$.set(L,new Set);this._entityEnterTracking.set(j,$)}if(!j.eventHandlers)return;for(let $ in j.eventHandlers){let L=j.eventHandlers[$];if(L)this._eventBus.subscribe($,(J)=>{L({data:J,ecs:this})})}}hasResource(j){return this._resourceManager.has(j)}getResource(j){if(!this._resourceManager.has(j))throw Error(`Resource '${String(j)}' not found. Available resources: [${this.getResourceKeys().map(($)=>String($)).join(", ")}]`);return this._resourceManager.get(j,this)}tryGetResource(j){let $=j;if(!this._resourceManager.has($))return;return this._resourceManager.get($,this)}addResource(j,$){return this._resourceManager.add(j,$),this}removeResource(j){return this._resourceManager.remove(j)}async disposeResource(j){return this._resourceManager.disposeResource(j,this)}async disposeResources(){return this._resourceManager.disposeResources(this)}updateResource(j,$){let L=this.getResource(j),J=$(L);return this._resourceManager.add(j,J),this}getResourceKeys(){return this._resourceManager.getKeys()}resourceNeedsInitialization(j){return this._resourceManager.needsInitialization(j)}getComponent(j,$){return this._entityManager.getComponent(j,$)}addComponent(j,$,L){this._entityManager.addComponent(j,$,L)}addComponents(j,$){this._entityManager.addComponents(j,$)}removeComponent(j,$){this._entityManager.removeComponent(j,$)}hasComponent(j,$){return this._entityManager.getComponent(j,$)!==void 0}spawn(j){let $=this._entityManager.createEntity();return this._entityManager.addComponents($.id,j),$}getEntitiesWithQuery(j,$=[],L,J){return this._entityManager.getEntitiesWithQuery(j,$,L,L?this._changeThreshold:void 0,J)}getSingleton(j,$=[]){let L=this._entityManager.getEntitiesWithQuery(j,$);if(L.length===0)throw Error(`getSingleton: no entity matches query with=[${String(j)}] without=[${String($)}]`);if(L.length>1)throw Error(`getSingleton: expected 1 entity but found ${L.length} matching query with=[${String(j)}] without=[${String($)}]`);let J=L[0];if(!J)throw Error("getSingleton: unexpected empty result");return J}tryGetSingleton(j,$=[]){let L=this._entityManager.getEntitiesWithQuery(j,$);if(L.length===0)return;if(L.length>1)throw Error(`tryGetSingleton: expected 0 or 1 entity but found ${L.length} matching query with=[${String(j)}] without=[${String($)}]`);return L[0]}removeEntity(j,$){return this._entityManager.removeEntity(j,$)}spawnChild(j,$){let L=this._entityManager.spawnChild(j,$);return this._emitHierarchyChanged(L.id,null,j),L}setParent(j,$){let L=this._entityManager.getParent(j);return this._entityManager.setParent(j,$),this._emitHierarchyChanged(j,L,$),this}removeParent(j){let $=this._entityManager.getParent(j),L=this._entityManager.removeParent(j);if(L)this._emitHierarchyChanged(j,$,null);return L}getParent(j){return this._entityManager.getParent(j)}getChildren(j){return this._entityManager.getChildren(j)}getChildAt(j,$){return this._entityManager.getChildAt(j,$)}getChildIndex(j,$){return this._entityManager.getChildIndex(j,$)}getAncestors(j){return this._entityManager.getAncestors(j)}getDescendants(j){return this._entityManager.getDescendants(j)}getRoot(j){return this._entityManager.getRoot(j)}getSiblings(j){return this._entityManager.getSiblings(j)}isDescendantOf(j,$){return this._entityManager.isDescendantOf(j,$)}isAncestorOf(j,$){return this._entityManager.isAncestorOf(j,$)}getRootEntities(){return this._entityManager.getRootEntities()}forEachInHierarchy(j,$){this._entityManager.forEachInHierarchy(j,$)}hierarchyIterator(j){return this._entityManager.hierarchyIterator(j)}_emitHierarchyChanged(j,$,L){this._eventBus.publish("hierarchyChanged",{entityId:j,oldParent:$,newParent:L})}get installedPlugins(){return Array.from(this._installedPlugins)}get entityManager(){return this._entityManager}get eventBus(){return this._finalizePendingBuilders(),this._eventBus}get commands(){return this._commandBuffer}get currentTick(){return this._currentTick}get changeThreshold(){return this._changeThreshold}enableDiagnostics(j){if(this._diagnosticsEnabled=j,!j)this._systemTimings.clear(),this._phaseTimings={preUpdate:0,fixedUpdate:0,update:0,postUpdate:0,render:0}}get diagnosticsEnabled(){return this._diagnosticsEnabled}get systemTimings(){return this._systemTimings}get phaseTimings(){return this._phaseTimings}get entityCount(){return this._entityManager.entityCount}mutateComponent(j,$,L){let J=this._entityManager.getComponent(j,$);if(J===void 0)throw Error(`Entity ${j} does not have component "${String($)}"`);return L(J),this._entityManager.markChanged(j,$),J}markChanged(j,$){this._entityManager.markChanged(j,$)}registerDispose(j,$){this._entityManager.registerDispose(j,$)}registerRequired(j,$,L){if(String(j)===String($))throw Error(`Cannot require a component to depend on itself: '${String(j)}'`);let J=this._requiredComponents.get(j)??[];if(J.some((X)=>X.component===$))throw Error(`Required component '${String($)}' already registered for trigger '${String(j)}'`);this._checkRequiredCycle(j,$),J.push({component:$,factory:L}),this._requiredComponents.set(j,J)}_checkRequiredCycle(j,$){I(j,$,(L)=>this._requiredComponents.get(L))}onComponentAdded(j,$){return this._entityManager.onComponentAdded(j,$)}onComponentRemoved(j,$){return this._entityManager.onComponentRemoved(j,$)}addReactiveQuery(j,$){this._reactiveQueryManager.addQuery(j,$)}removeReactiveQuery(j){return this._reactiveQueryManager.removeQuery(j)}on(j,$){return this._eventBus.subscribe(j,$)}off(j,$){return this._eventBus.unsubscribe(j,$)}onPostUpdate(j){return this._postUpdateHooks.push(j),()=>{let $=this._postUpdateHooks.indexOf(j);if($!==-1)this._postUpdateHooks.splice($,1)}}requireAssetManager(){if(!this._assetManager)throw Error("Asset manager not configured. Use withAssets() in builder.");return this._assetManager}getAsset(j){return this.requireAssetManager().get(j)}tryGetAsset(j){return this._assetManager?.tryGet(j)}getAssetHandle(j){return this.requireAssetManager().getHandle(j)}isAssetLoaded(j){return this._assetManager?.isLoaded(j)??!1}async loadAsset(j){return this.requireAssetManager().loadAsset(j)}async loadAssetGroup(j){return this.requireAssetManager().loadAssetGroup(j)}isAssetGroupLoaded(j){return this._assetManager?.isGroupLoaded(j)??!1}getAssetGroupProgress(j){return this._assetManager?.getGroupProgress(j)??0}requireScreenManager(){if(!this._screenManager)throw Error("Screen manager not configured. Use withScreens() in builder.");return this._screenManager}async setScreen(j,$){return this.requireScreenManager().setScreen(j,$)}async pushScreen(j,$){return this.requireScreenManager().pushScreen(j,$)}async popScreen(){return this.requireScreenManager().popScreen()}getCurrentScreen(){return this._screenManager?.getCurrentScreen()??null}getScreenConfig(j){return this.requireScreenManager().getConfig(j)}tryGetScreenConfig(j){return this._screenManager?.tryGetConfig(j)??void 0}getScreenState(j){return this.requireScreenManager().getState(j)}tryGetScreenState(j){return this._screenManager?.tryGetState(j)??void 0}updateScreenState(j,$){if(typeof j==="string")this.requireScreenManager().updateState($,j);else this.requireScreenManager().updateState(j)}isCurrentScreen(j){return this._screenManager?.isCurrent(j)??!1}isScreenActive(j){return this._screenManager?.isActive(j)??!1}getScreenStackDepth(){return this._screenManager?.getStackDepth()??0}_setAssetManager(j){this._assetManager=j;for(let[$,L]of this._pendingPluginAssets)this._assetManager.register($,L);this._pendingPluginAssets=[]}_setScreenManager(j){this._screenManager=j;for(let[$,L]of this._pendingPluginScreens)this._screenManager.register($,L);this._pendingPluginScreens=[]}_hasPendingPluginAssets(){return this._pendingPluginAssets.length>0}_hasPendingPluginScreens(){return this._pendingPluginScreens.length>0}_setFixedDt(j){this._fixedDt=j}_registerAsset(j,$){this._pendingPluginAssets.push([j,$])}_registerScreen(j,$){this._pendingPluginScreens.push([j,$])}installPlugin(j){if(this._installedPlugins.has(j.id))return this;return this._installedPlugins.add(j.id),j.install(this),this}pluginFactory(){return z}getHelpers(j){return j(this)}}});g();function kj(j){return j}function uj(j,$){return{x:j,y:$}}function Ij(){return{x:0,y:0}}function pj(j,$){return{x:j.x+$.x,y:j.y+$.y}}function mj(j,$){return{x:j.x-$.x,y:j.y-$.y}}function lj(j,$){return{x:j.x*$,y:j.y*$}}function sj(j){return{x:-j.x,y:-j.y}}function yj(j,$){return j.x*$.x+j.y*$.y}function cj(j,$){return j.x*$.y-j.y*$.x}function dj(j){return j.x*j.x+j.y*j.y}function ij(j){return Math.sqrt(j.x*j.x+j.y*j.y)}function oj(j){let $=Math.sqrt(j.x*j.x+j.y*j.y);if($===0)return{x:0,y:0};return{x:j.x/$,y:j.y/$}}function rj(j,$){let L=j.x-$.x,J=j.y-$.y;return L*L+J*J}function aj(j,$){let L=j.x-$.x,J=j.y-$.y;return Math.sqrt(L*L+J*J)}function tj(j,$,L=0.0000000001){return Math.abs(j.x-$.x)<=L&&Math.abs(j.y-$.y)<=L}v();var B2=M;export{Ij as vec2Zero,mj as vec2Sub,lj as vec2Scale,oj as vec2Normalize,sj as vec2Negate,dj as vec2LengthSq,ij as vec2Length,tj as vec2Equals,yj as vec2Dot,rj as vec2DistanceSq,aj as vec2Distance,cj as vec2Cross,pj as vec2Add,uj as vec2,$j as directValue,z as definePlugin,B2 as default,b as createScreenConfigurator,kj as createQueryDefinition,f as createAssetConfigurator,T as SystemBuilder,P as ScreenManager,O as AssetManager};
|
|
1
|
+
var{defineProperty:C,getOwnPropertyNames:o,getOwnPropertyDescriptor:r}=Object,a=Object.prototype.hasOwnProperty;var h=new WeakMap,n=(j)=>{var $=h.get(j),J;if($)return $;if($=C({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function")o(j).map((X)=>!a.call($,X)&&C($,X,{get:()=>j[X],enumerable:!(J=r(j,X))||J.enumerable}));return h.set(j,$),$};var t=(j,$)=>{for(var J in $)C(j,J,{get:$[J],enumerable:!0,configurable:!0,set:(X)=>$[J]=()=>X})};var V=(j,$)=>()=>(j&&($=j(j=0)),$);var Xj=((j)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(j,{get:($,J)=>(typeof require<"u"?require:$)[J]}):j)(function(j){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+j+'" is not supported')});class H{parentMap=new Map;childrenMap=new Map;setParent(j,$){if(j===$)throw Error(`Cannot set entity ${j} as its own parent`);if(this.wouldCreateCycle(j,$))throw Error("Cannot set parent: would create circular reference");let J=this.parentMap.get(j);if(J!==void 0){let Y=this.childrenMap.get(J);if(Y){let Z=Y.indexOf(j);if(Z!==-1)Y.splice(Z,1)}}this.parentMap.set(j,$);let X=this.childrenMap.get($);if(X)X.push(j);else this.childrenMap.set($,[j]);return this}removeParent(j){let $=this.parentMap.get(j);if($===void 0)return!1;let J=this.childrenMap.get($);if(J){let X=J.indexOf(j);if(X!==-1)J.splice(X,1)}return this.parentMap.delete(j),!0}getParent(j){return this.parentMap.get(j)??null}getChildren(j){let $=this.childrenMap.get(j);return $?[...$]:[]}getChildAt(j,$){if($<0)return null;let J=this.childrenMap.get(j);if(!J||$>=J.length)return null;return J[$]??null}getChildIndex(j,$){let J=this.childrenMap.get(j);if(!J)return-1;return J.indexOf($)}removeEntity(j){let $=this.parentMap.get(j)??null;if($!==null){let Y=this.childrenMap.get($);if(Y){let Z=Y.indexOf(j);if(Z!==-1)Y.splice(Z,1)}}this.parentMap.delete(j);let J=this.childrenMap.get(j)??[],X=[...J];for(let Y of J)this.parentMap.delete(Y);return this.childrenMap.delete(j),{oldParent:$,orphanedChildren:X}}getAncestors(j){let $=[],J=this.parentMap.get(j);while(J!==void 0)$.push(J),J=this.parentMap.get(J);return $}getDescendants(j){let $=[],J=this.childrenMap.get(j);if(!J)return $;let X=J.slice().reverse();while(X.length>0){let Y=X.pop();$.push(Y);let Z=this.childrenMap.get(Y);if(Z)for(let W=Z.length-1;W>=0;W--)X.push(Z[W])}return $}getRoot(j){let $=j,J=this.parentMap.get($);while(J!==void 0)$=J,J=this.parentMap.get($);return $}getSiblings(j){let $=this.parentMap.get(j);if($===void 0)return[];let J=this.childrenMap.get($);if(!J)return[];return J.filter((X)=>X!==j)}isDescendantOf(j,$){if(j===$)return!1;let J=this.parentMap.get(j);while(J!==void 0){if(J===$)return!0;J=this.parentMap.get(J)}return!1}isAncestorOf(j,$){return this.isDescendantOf($,j)}getRootEntities(){let j=[];for(let $ of this.childrenMap.keys())if(!this.parentMap.has($))j.push($);return j}wouldCreateCycle(j,$){let J=$;while(J!==void 0){if(J===j)return!0;J=this.parentMap.get(J)}return!1}forEachInHierarchy(j,$){let J=$?.roots??this.getRootEntities(),X=[];for(let Y of J)X.push({entityId:Y,parentId:null,depth:0});for(let Y of X){j(Y.entityId,Y.parentId,Y.depth);let Z=this.childrenMap.get(Y.entityId);if(Z)for(let W of Z)X.push({entityId:W,parentId:Y.entityId,depth:Y.depth+1})}}*hierarchyIterator(j){let $=j?.roots??this.getRootEntities(),J=[];for(let X of $)J.push({entityId:X,parentId:null,depth:0});for(let X of J){yield X;let Y=this.childrenMap.get(X.entityId);if(Y)for(let Z of Y)J.push({entityId:Z,parentId:X.entityId,depth:X.depth+1})}}}class q{callbacks=[];_iterDepth=0;_pendingRemovals=[];add(j){this.callbacks.push(j)}remove(j){if(this._iterDepth>0){this._pendingRemovals.push(j);return}let $=this.callbacks.indexOf(j);if($!==-1)this.callbacks.splice($,1)}invoke(j){this._iterDepth++;let $=this.callbacks.length;for(let J=0;J<$;J++){let X=this.callbacks[J];if(X)X(j)}if(this._iterDepth--,this._iterDepth===0&&this._pendingRemovals.length>0){for(let J of this._pendingRemovals){let X=this.callbacks.indexOf(J);if(X!==-1)this.callbacks.splice(X,1)}this._pendingRemovals.length=0}}}class E{nextId=1;entities=new Map;componentIndices=new Map;addedCallbacks=new Map;removedCallbacks=new Map;hierarchyManager=new H;disposeCallbacks=new Map;changeSeqs=new Map;_changeSeq=0;_afterComponentAddedHooks=[];_afterEntityMutatedHooks=[];_afterComponentRemovedHooks=[];_beforeEntityRemovedHooks=[];_afterParentChangedHooks=[];_batchingDepth=0;_batchedEntityIds=new Set;_pendingBatchKeys=null;get entityCount(){return this.entities.size}createEntity(){let j=this.nextId++,$={id:j,components:{}};return this.entities.set(j,$),$}registerDispose(j,$){this.disposeCallbacks.set(j,$)}getDisposeCallbacks(){return this.disposeCallbacks}invokeDispose(j,$,J){let X=this.disposeCallbacks.get(j);if(!X)return;try{X({value:$,entityId:J})}catch(Y){console.warn(`Component dispose callback for '${String(j)}' threw:`,Y)}}addComponent(j,$,J){let X=this.entities.get(j);if(!X)throw Error(`Cannot add component '${String($)}': Entity with ID ${j} does not exist`);let Y=X.components[$];if(Y!==void 0)this.invokeDispose($,Y,X.id);if(X.components[$]=J,!this.componentIndices.has($))this.componentIndices.set($,new Set);this.componentIndices.get($)?.add(X.id);let Z=this.addedCallbacks.get($);if(Z)Z.invoke({value:J,entity:X});this._batchingDepth++;for(let W of this._afterComponentAddedHooks)W(X.id,$);if(this._batchedEntityIds.add(X.id),this._batchingDepth--,this._batchingDepth===0){for(let W of this._batchedEntityIds)for(let B of this._afterEntityMutatedHooks)B(W);this._batchedEntityIds.clear()}return this}addComponents(j,$){let J=this.entities.get(j);if(!J)throw Error(`Cannot add components: Entity with ID ${j} does not exist`);let X=this._pendingBatchKeys;this._pendingBatchKeys=new Set(Object.keys($)),this._batchingDepth++;for(let Y in $)this.addComponent(J.id,Y,$[Y]);if(this._batchingDepth--,this._pendingBatchKeys=X,this._batchingDepth===0){for(let Y of this._batchedEntityIds)for(let Z of this._afterEntityMutatedHooks)Z(Y);this._batchedEntityIds.clear()}return this}removeComponent(j,$){let J=this.entities.get(j);if(!J)throw Error(`Cannot remove component '${String($)}': Entity with ID ${j} does not exist`);let X=J.components[$];if(X!==void 0)this.invokeDispose($,X,J.id);delete J.components[$];let Y=this.removedCallbacks.get($);if(Y&&X!==void 0)Y.invoke({value:X,entity:J});if(this.componentIndices.get($)?.delete(J.id),X!==void 0)for(let Z of this._afterComponentRemovedHooks)Z(J.id,$);return this}getComponent(j,$){let J=this.entities.get(j);if(!J)throw Error(`Cannot get component '${String($)}': Entity with ID ${j} does not exist`);return J.components[$]}getEntitiesWithQuery(j=[],$=[],J,X,Y){let Z=J!==void 0&&J.length>0&&X!==void 0,W=Y!==void 0&&Y.length>0;if(j.length===0){if($.length===0&&!Z&&!W)return Array.from(this.entities.values());return Array.from(this.entities.values()).filter((D)=>{if($.length>0&&!$.every((_)=>!(_ in D.components)))return!1;if(Z){let _=this.changeSeqs.get(D.id);if(!_)return!1;if(!J.some((Q)=>(_.get(Q)??-1)>X))return!1}if(W&&!this.parentHasComponents(D.id,Y))return!1;return!0})}let B=j[0];if(B===void 0)return[];let K=j.reduce((D,_)=>{let Q=this.componentIndices.get(_)?.size??0,A=this.componentIndices.get(D)?.size??1/0;return Q<A?_:D},B),U=this.componentIndices.get(K);if(!U||U.size===0)return[];let G=[],F=$.length>0;for(let D of U){let _=this.entities.get(D);if(_&&j.every((Q)=>(Q in _.components))&&(!F||$.every((Q)=>!(Q in _.components)))){if(Z){let Q=this.changeSeqs.get(D);if(!Q||!J.some((A)=>(Q.get(A)??-1)>X))continue}if(W&&!this.parentHasComponents(D,Y))continue;G.push(_)}}return G}parentHasComponents(j,$){let J=this.hierarchyManager.getParent(j);if(J===null)return!1;let X=this.entities.get(J);if(!X)return!1;for(let Y of $)if(!(Y in X.components))return!1;return!0}removeEntity(j,$){let J=this.entities.get(j);if(!J)return!1;if($?.cascade??!0){let Y=this.hierarchyManager.getDescendants(J.id);for(let Z=Y.length-1;Z>=0;Z--){let W=Y[Z];if(W===void 0)continue;for(let B of this._beforeEntityRemovedHooks)B(W)}for(let Z of this._beforeEntityRemovedHooks)Z(J.id);for(let Z=Y.length-1;Z>=0;Z--){let W=Y[Z];if(W===void 0)continue;this.removeEntityInternal(W)}}else for(let Y of this._beforeEntityRemovedHooks)Y(J.id);return this.removeEntityInternal(J.id)}removeEntityInternal(j){let $=this.entities.get(j);if(!$)return!1;this.hierarchyManager.removeEntity(j);for(let J of Object.keys($.components)){let X=$.components[J];if(X!==void 0){this.invokeDispose(J,X,$.id);let Y=this.removedCallbacks.get(J);if(Y)Y.invoke({value:X,entity:$})}this.componentIndices.get(J)?.delete($.id)}return this.changeSeqs.delete($.id),this.entities.delete($.id)}getEntity(j){return this.entities.get(j)}onComponentAdded(j,$){let J=$,X=this.addedCallbacks.get(j);if(!X)X=new q,this.addedCallbacks.set(j,X);return X.add(J),()=>{this.addedCallbacks.get(j)?.remove(J)}}onComponentRemoved(j,$){let J=$,X=this.removedCallbacks.get(j);if(!X)X=new q,this.removedCallbacks.set(j,X);return X.add(J),()=>{this.removedCallbacks.get(j)?.remove(J)}}onAfterComponentAdded(j){return this._afterComponentAddedHooks.push(j),()=>{let $=this._afterComponentAddedHooks.indexOf(j);if($!==-1)this._afterComponentAddedHooks.splice($,1)}}onAfterEntityMutated(j){return this._afterEntityMutatedHooks.push(j),()=>{let $=this._afterEntityMutatedHooks.indexOf(j);if($!==-1)this._afterEntityMutatedHooks.splice($,1)}}onAfterComponentRemoved(j){return this._afterComponentRemovedHooks.push(j),()=>{let $=this._afterComponentRemovedHooks.indexOf(j);if($!==-1)this._afterComponentRemovedHooks.splice($,1)}}onBeforeEntityRemoved(j){return this._beforeEntityRemovedHooks.push(j),()=>{let $=this._beforeEntityRemovedHooks.indexOf(j);if($!==-1)this._beforeEntityRemovedHooks.splice($,1)}}onAfterParentChanged(j){return this._afterParentChangedHooks.push(j),()=>{let $=this._afterParentChangedHooks.indexOf(j);if($!==-1)this._afterParentChangedHooks.splice($,1)}}get changeSeq(){return this._changeSeq}markChanged(j,$){let J=++this._changeSeq,X=this.changeSeqs.get(j);if(!X)X=new Map,this.changeSeqs.set(j,X);X.set($,J)}getChangeSeq(j,$){return this.changeSeqs.get(j)?.get($)??-1}spawnChild(j,$){let J=this.createEntity();return this.addComponents(J.id,$),this.setParent(J.id,j),J}setParent(j,$){this.hierarchyManager.setParent(j,$);for(let J of this._afterParentChangedHooks)J(j);return this}removeParent(j){let $=this.hierarchyManager.removeParent(j);if($)for(let J of this._afterParentChangedHooks)J(j);return $}getParent(j){return this.hierarchyManager.getParent(j)}getChildren(j){return this.hierarchyManager.getChildren(j)}getChildAt(j,$){return this.hierarchyManager.getChildAt(j,$)}getChildIndex(j,$){return this.hierarchyManager.getChildIndex(j,$)}getAncestors(j){return this.hierarchyManager.getAncestors(j)}getDescendants(j){return this.hierarchyManager.getDescendants(j)}getRoot(j){return this.hierarchyManager.getRoot(j)}getSiblings(j){return this.hierarchyManager.getSiblings(j)}isDescendantOf(j,$){return this.hierarchyManager.isDescendantOf(j,$)}isAncestorOf(j,$){return this.hierarchyManager.isAncestorOf(j,$)}getRootEntities(){return this.hierarchyManager.getRootEntities()}forEachInHierarchy(j,$){this.hierarchyManager.forEachInHierarchy(j,$)}hierarchyIterator(j){return this.hierarchyManager.hierarchyIterator(j)}}var u=()=>{};class w{handlers=new Map;subscribe(j,$){return this.addHandler(j,$,!1)}once(j,$){return this.addHandler(j,$,!0)}unsubscribe(j,$){let J=this.handlers.get(j);if(!J)return!1;let X=J.findIndex((Y)=>Y.callback===$);if(X===-1)return!1;return J.splice(X,1),!0}addHandler(j,$,J){let X=this.handlers.get(j);if(!X)X=[],this.handlers.set(j,X);let Y={callback:$,once:J};return X.push(Y),()=>{let Z=this.handlers.get(j);if(Z){let W=Z.indexOf(Y);if(W!==-1)Z.splice(W,1)}}}publish(...[j,$]){let J=this.handlers.get(j);if(!J||J.length===0)return;let X=!1,Y=J.length;for(let Z=0;Z<Y&&Z<J.length;Z++){let W=J[Z];if(!W)continue;if(W.callback($),W.once)X=!0}if(X){for(let Z=J.length-1;Z>=0;Z--)if(J[Z]?.once)J.splice(Z,1)}}clear(){this.handlers.clear()}clearEvent(j){this.handlers.delete(j)}}function e(j){return{[v]:j}}function jj(j){return typeof j==="object"&&j!==null&&"factory"in j&&typeof j.factory==="function"}function $j(j){return typeof j==="object"&&j!==null&&v in j}function p(j,$){let J=[],X=new Set,Y=new Set;function Z(W,B=[]){if(X.has(W))return;if(Y.has(W))throw Error(`Circular resource dependency: ${[...B,W].join(" -> ")}`);Y.add(W);for(let K of $(W)){let U=j.find((G)=>G===K);if(U)Z(U,[...B,W])}Y.delete(W),X.add(W),J.push(W)}for(let W of j)Z(W);return J}class R{resources=new Map;resourceFactories=new Map;resourceDependencies=new Map;resourceDisposers=new Map;initializedResourceKeys=new Set;add(j,$){let J=(X)=>{this.resources.set(j,X),this.initializedResourceKeys.add(j),this.resourceDependencies.set(j,[])};if(jj($)){if(this.resourceFactories.set(j,$.factory),this.resourceDependencies.set(j,$.dependsOn??[]),$.onDispose)this.resourceDisposers.set(j,$.onDispose)}else if($j($))J($[v]);else if(typeof $==="function")this.resourceFactories.set(j,$),this.resourceDependencies.set(j,[]);else J($);return this}tryGet(j,...$){if(!this.has(j))return;return this.get(j,...$)}get(j,...$){let J=this.resources.get(j);if(J!==void 0)return J;let X=this.resourceFactories.get(j);if(X===void 0)throw Error(`Resource ${String(j)} not found`);let Y=$[0],Z=X(Y);if(!(Z instanceof Promise))this.resources.set(j,Z),this.initializedResourceKeys.add(j);return Z}has(j){return this.resources.has(j)||this.resourceFactories.has(j)}remove(j){let $=this.resources.delete(j),J=this.resourceFactories.delete(j);return this.resourceDependencies.delete(j),this.resourceDisposers.delete(j),this.initializedResourceKeys.delete(j),$||J}getKeys(){let j=new Set([...this.resources.keys(),...this.resourceFactories.keys()]);return Array.from(j)}needsInitialization(j){return this.resourceFactories.has(j)&&!this.initializedResourceKeys.has(j)}getPendingInitializationKeys(){return Array.from(this.resourceFactories.keys()).filter((j)=>!this.initializedResourceKeys.has(j))}async initializeResource(j,...$){if(!this.resourceFactories.has(j)||this.initializedResourceKeys.has(j))return;let J=this.resourceFactories.get(j);if(!J)return;let X=$[0],Y=await J(X);this.resources.set(j,Y),this.initializedResourceKeys.add(j),this.resourceFactories.delete(j)}async initializeResources(...j){let $=j.slice(1),J=$.length===0?this.getPendingInitializationKeys():$;if(J.length===0)return;let X=p(J,(Y)=>[...this.resourceDependencies.get(Y)??[]]);for(let Y of X)await this.initializeResource(Y,...j.slice(0,1))}getDependencies(j){return this.resourceDependencies.get(j)??[]}async disposeResource(j,...$){if(!this.resources.has(j)&&!this.resourceFactories.has(j))return!1;if(this.initializedResourceKeys.has(j)){let J=this.resourceDisposers.get(j),X=this.resources.get(j);if(J&&X!==void 0){let Y=$[0];await J(X,Y)}}return this.resources.delete(j),this.resourceFactories.delete(j),this.resourceDependencies.delete(j),this.resourceDisposers.delete(j),this.initializedResourceKeys.delete(j),!0}async disposeResources(...j){let $=Array.from(this.initializedResourceKeys);if($.length===0)return;let J=p($,(X)=>[...this.resourceDependencies.get(X)??[]]).reverse();for(let X of J)await this.disposeResource(X,...j)}}var v;var f=V(()=>{v=Symbol("resource-direct")});class S{queries=new Map;entityManager;_hasParentHasQueries=!1;constructor(j){this.entityManager=j}get hasParentHasQueries(){return this._hasParentHasQueries}addQuery(j,$){let J={definition:$,matchingEntities:new Set};if(this.queries.set(j,J),$.parentHas?.length)this._hasParentHasQueries=!0;let X=this.entityManager.getEntitiesWithQuery($.with,$.without??[]);for(let Y of X)if(this.entityMatchesQuery(Y,J.definition))J.matchingEntities.add(Y.id),J.definition.onEnter?.(Y)}removeQuery(j){let $=this.queries.delete(j);if($)this._recalcParentHasFlag();return $}entityMatchesQuery(j,$){for(let J of $.with)if(!(J in j.components))return!1;if($.without){for(let J of $.without)if(J in j.components)return!1}if($.parentHas?.length){let J=this.entityManager.getParent(j.id);if(J===null)return!1;let X=this.entityManager.getEntity(J);if(!X)return!1;for(let Y of $.parentHas)if(!(Y in X.components))return!1}return!0}_applyQueryTransition(j,$){let J=$.matchingEntities.has(j.id),X=this.entityMatchesQuery(j,$.definition);if(!J&&X)$.matchingEntities.add(j.id),$.definition.onEnter?.(j);else if(J&&!X)$.matchingEntities.delete(j.id),$.definition.onExit?.(j.id)}onComponentAdded(j,$){for(let[,J]of this.queries)this._applyQueryTransition(j,J);if(this._hasParentHasQueries)this._recheckChildren(j.id)}onComponentRemoved(j,$){for(let[,J]of this.queries)this._applyQueryTransition(j,J);if(this._hasParentHasQueries)this._recheckChildren(j.id)}onEntityRemoved(j){for(let[$,J]of this.queries)if(J.matchingEntities.has(j))J.matchingEntities.delete(j),J.definition.onExit?.(j)}recheckEntity(j){for(let[,$]of this.queries)this._applyQueryTransition(j,$)}recheckEntityAndChildren(j){if(this.recheckEntity(j),this._hasParentHasQueries)this._recheckChildren(j.id)}_recheckChildren(j){let $=this.entityManager.getChildren(j);for(let J of $){let X=this.entityManager.getEntity(J);if(X)this.recheckEntity(X)}}_recalcParentHasFlag(){this._hasParentHasQueries=!1;for(let[,j]of this.queries)if(j.definition.parentHas?.length){this._hasParentHasQueries=!0;return}}}class T{commands=[];removeEntity(j,$){this.commands.push((J)=>{J.removeEntity(j,$)})}addComponent(j,$,J){this.commands.push((X)=>{X.addComponent(j,$,J)})}removeComponent(j,$){this.commands.push((J)=>{J.removeComponent(j,$)})}spawn(j){this.commands.push(($)=>{$.spawn(j)})}spawnChild(j,$){this.commands.push((J)=>{J.spawnChild(j,$)})}addComponents(j,$){this.commands.push((J)=>{J.addComponents(j,$)})}setParent(j,$){this.commands.push((J)=>{J.setParent(j,$)})}mutateComponent(j,$,J){this.commands.push((X)=>{X.mutateComponent(j,$,J)})}markChanged(j,$){this.commands.push((J)=>{J.markChanged(j,$)})}removeParent(j){this.commands.push(($)=>{$.removeParent(j)})}playback(j){for(let $ of this.commands)try{$(j)}catch(J){console.warn("CommandBuffer: Command failed during playback:",J)}this.commands.length=0}clear(){this.commands.length=0}get length(){return this.commands.length}}function z(j){return j}class x{_label;queries={};processFunction;detachFunction;initializeFunction;eventHandlers;_priority=0;_phase="update";_groups=[];_inScreens;_excludeScreens;_requiredAssets;_runWhenEmpty=!1;_entityEnterHandlers={};_resourceKeys;constructor(j){this._label=j}get label(){return this._label}_createSystemObject(){let j={label:this._label,entityQueries:this.queries,priority:this._priority,phase:this._phase};if(this.processFunction)j.process=this.processFunction;if(this.detachFunction)j.onDetach=this.detachFunction;if(this.initializeFunction)j.onInitialize=this.initializeFunction;if(this.eventHandlers)j.eventHandlers=this.eventHandlers;if(this._groups.length>0)j.groups=[...this._groups];if(this._inScreens)j.inScreens=this._inScreens;if(this._excludeScreens)j.excludeScreens=this._excludeScreens;if(this._requiredAssets)j.requiredAssets=this._requiredAssets;if(this._runWhenEmpty)j.runWhenEmpty=!0;if(Object.keys(this._entityEnterHandlers).length>0)j.onEntityEnter={...this._entityEnterHandlers};return j}setPriority(j){return this._priority=j,this}inPhase(j){return this._phase=j,this}inGroup(j){if(!this._groups.includes(j))this._groups.push(j);return this}inScreens(j){return this._inScreens=[...j],this}excludeScreens(j){return this._excludeScreens=[...j],this}requiresAssets(j){return this._requiredAssets=[...j],this}runWhenEmpty(){return this._runWhenEmpty=!0,this}withResources(j){return this._resourceKeys=[...j],this}addQuery(j,$){let J=this;return J.queries={...this.queries,[j]:$},J}setProcess(j){if(this._resourceKeys?.length){let $=this._resourceKeys,J;this.processFunction=(X)=>{if(!J){J={};for(let Y of $)J[Y]=X.ecs.getResource(Y)}X.resources=J,j(X)}}else this.processFunction=j;return this}setOnEntityEnter(j,$){return this._entityEnterHandlers[j]=$,this}setOnDetach(j){return this.detachFunction=j,this}setOnInitialize(j){return this.initializeFunction=j,this}setEventHandlers(j){return this.eventHandlers=j,this}}function I(j,$,J){let X=new Set,Y=[$];while(Y.length>0){let Z=Y.pop();if(Z===void 0)break;if(Z===j)throw Error(`Circular required component dependency: '${String(j)}' -> '${String($)}' -> ... -> '${String(j)}'`);if(X.has(Z))continue;X.add(Z);let W=J(Z);if(W)for(let B of W)Y.push(B.component)}}var l="0.12.1";var m=()=>{};class O{assets=new Map;groups=new Map;eventBus=null;setEventBus(j){this.eventBus=j}register(j,$){if(this.assets.set(j,{definition:$,status:"pending"}),$.group){let J=this.groups.get($.group)??new Set;J.add(j),this.groups.set($.group,J)}}async loadEagerAssets(){let j=[];for(let[$,J]of this.assets)if(J.definition.eager&&J.status==="pending")j.push($);await Promise.all(j.map(($)=>this.loadAsset($)))}async loadAsset(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);if($.status==="loaded"&&$.value!==void 0)return $.value;if($.status==="loading"&&$.loadPromise)return $.loadPromise;if($.status==="failed")$.status="pending";$.status="loading",$.loadPromise=$.definition.loader();try{let J=await $.loadPromise;return $.value=J,$.status="loaded",$.loadPromise=void 0,this.eventBus?.publish("assetLoaded",{key:j}),this.checkGroupProgress($.definition.group),J}catch(J){let X=J instanceof Error?J:Error(String(J));throw $.status="failed",$.error=X,$.loadPromise=void 0,this.eventBus?.publish("assetFailed",{key:j,error:X}),X}}async loadAssetGroup(j){let $=this.groups.get(j);if(!$||$.size===0)throw Error(`Asset group '${j}' not found or empty`);await Promise.all(Array.from($).map((J)=>this.loadAsset(J)))}get(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);if($.status!=="loaded"||$.value===void 0)throw Error(`Asset '${String(j)}' is not loaded (status: ${$.status})`);return $.value}tryGet(j){let $=this.assets.get(j);if(!$||$.status!=="loaded")return;return $.value}getHandle(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);let J=this;return{get status(){return $.status},get isLoaded(){return $.status==="loaded"},get(){return J.get(j)},tryGet(){return J.tryGet(j)}}}getStatus(j){let $=this.assets.get(j);if(!$)throw Error(`Asset '${String(j)}' not found`);return $.status}isLoaded(j){return this.assets.get(j)?.status==="loaded"}isGroupLoaded(j){let $=this.groups.get(j);if(!$||$.size===0)return!1;for(let J of $){let X=this.assets.get(J);if(!X||X.status!=="loaded")return!1}return!0}getGroupProgress(j){return this.getGroupProgressDetails(j).progress}getGroupProgressDetails(j){let $=this.groups.get(j);if(!$||$.size===0)return{loaded:0,total:0,progress:0};let J=0;for(let Y of $)if(this.assets.get(Y)?.status==="loaded")J++;let X=$.size;return{loaded:J,total:X,progress:J/X}}checkGroupProgress(j){if(!j||!this.eventBus)return;let $=j,J=this.getGroupProgressDetails($);if(this.eventBus.publish("assetGroupProgress",{group:$,...J}),J.loaded===J.total)this.eventBus.publish("assetGroupLoaded",{group:$})}createResource(){let j=this;return{getStatus($){return j.getStatus($)},isLoaded($){return j.isLoaded($)},isGroupLoaded($){return j.isGroupLoaded($)},getGroupProgress($){return j.getGroupProgress($)},get($){return j.get($)},tryGet($){return j.tryGet($)},getHandle($){return j.getHandle($)}}}getKeys(){return Array.from(this.assets.keys())}getGroupNames(){return Array.from(this.groups.keys())}getGroupKeys(j){let $=this.groups.get(j);return $?Array.from($):[]}}class s{manager;constructor(j){this.manager=j}add(j,$){return this.manager.register(j,{loader:$,eager:!0}),this}addWithConfig(j,$){return this.manager.register(j,$),this}addGroup(j,$){for(let[J,X]of Object.entries($))this.manager.register(J,{loader:X,eager:!1,group:j});return this}getManager(){return this.manager}}function b(j){return new s(j??new O)}class P{screens=new Map;currentScreen=null;screenStack=[];eventBus=null;assetManager=null;ecs=null;setDependencies(j,$,J){this.eventBus=j,this.assetManager=$,this.ecs=J}requireEcs(){if(!this.ecs)throw Error("ScreenManager: dependencies not set. Call setDependencies() first.");return this.ecs}register(j,$){this.screens.set(j,{definition:$})}async setScreen(j,$){let J=this.screens.get(j);if(!J)throw Error(`Screen '${String(j)}' not found`);await this.verifyRequiredAssets(J.definition.requiredAssets,J.definition.requiredAssetGroups);while(this.screenStack.length>0){let Y=this.screenStack.pop();if(Y)await this.exitScreen(Y.name)}if(this.currentScreen)await this.exitScreen(this.currentScreen.name);let X=J.definition.initialState($);this.currentScreen={name:j,config:$,state:X},await J.definition.onEnter?.({config:$,ecs:this.requireEcs()}),this.eventBus?.publish("screenEnter",{screen:j,config:$})}async pushScreen(j,$){let J=this.screens.get(j);if(!J)throw Error(`Screen '${String(j)}' not found`);if(await this.verifyRequiredAssets(J.definition.requiredAssets,J.definition.requiredAssetGroups),this.currentScreen)this.screenStack.push(this.currentScreen);let X=J.definition.initialState($);this.currentScreen={name:j,config:$,state:X},await J.definition.onEnter?.({config:$,ecs:this.requireEcs()}),this.eventBus?.publish("screenPush",{screen:j,config:$})}async popScreen(){if(this.screenStack.length===0)throw Error("Cannot pop screen: stack is empty");if(this.currentScreen)await this.exitScreen(this.currentScreen.name),this.eventBus?.publish("screenPop",{screen:this.currentScreen.name});this.currentScreen=this.screenStack.pop()??null}async exitScreen(j){let $=this.screens.get(j);if($?.definition.onExit)await $.definition.onExit(this.requireEcs());this.eventBus?.publish("screenExit",{screen:j})}async verifyRequiredAssets(j,$){if(!this.assetManager)return;if(j){for(let J of j)if(!this.assetManager.isLoaded(J))await this.assetManager.loadAsset(J)}if($){for(let J of $)if(!this.assetManager.isGroupLoaded(J))await this.assetManager.loadAssetGroup(J)}}getCurrentScreen(){return this.currentScreen?.name??null}getConfig(j){if(!this.currentScreen)throw Error("No current screen");if(j!==void 0&&this.currentScreen.name!==j)throw Error(`Expected current screen '${String(j)}', but current is '${String(this.currentScreen.name)}'`);return this.currentScreen.config}tryGetConfig(j){if(!this.currentScreen)return;if(j!==void 0&&this.currentScreen.name!==j)return;return this.currentScreen.config}getState(j){if(!this.currentScreen)throw Error("No current screen");if(j!==void 0&&this.currentScreen.name!==j)throw Error(`Expected current screen '${String(j)}', but current is '${String(this.currentScreen.name)}'`);return this.currentScreen.state}tryGetState(j){if(!this.currentScreen)return;if(j!==void 0&&this.currentScreen.name!==j)return;return this.currentScreen.state}updateState(j,$){if(!this.currentScreen)throw Error("No current screen");if($!==void 0&&this.currentScreen.name!==$)throw Error(`Expected current screen '${String($)}', but current is '${String(this.currentScreen.name)}'`);let J=typeof j==="function"?j(this.currentScreen.state):j;this.currentScreen.state={...this.currentScreen.state,...J}}getStackDepth(){return this.screenStack.length}isOverlay(){return this.screenStack.length>0}isActive(j){if(this.currentScreen?.name===j)return!0;return this.screenStack.some(($)=>$.name===j)}isCurrent(j){return this.currentScreen?.name===j}createResource(){let j=this;return{get current(){return j.getCurrentScreen()},get config(){return j.tryGetConfig()??null},get state(){return j.tryGetState()??null},set state($){if(j.currentScreen&&$!==null)j.currentScreen.state=$},get stack(){return j.screenStack},get isOverlay(){return j.isOverlay()},get stackDepth(){return j.getStackDepth()},isActive($){return j.isActive($)},isCurrent($){return j.isCurrent($)}}}getScreenNames(){return Array.from(this.screens.keys())}hasScreen(j){return this.screens.has(j)}}class y{manager;constructor(j){this.manager=j}add(j,$){return this.manager.register(j,$),this}getManager(){return this.manager}}function N(j){return new y(j??new P)}class g{ecspresso;assetConfigurator=null;screenConfigurator=null;pendingResources=[];pendingDisposeCallbacks=[];pendingRequiredComponents=[];pendingPlugins=[];_fixedDt=null;constructor(){let{default:j}=(k(),n(c));this.ecspresso=new j}withPlugin(j){return this.pendingPlugins.push(j),this}withComponentTypes(){return this}withEventTypes(){return this}withResourceTypes(){return this}withResource(j,$){return this.pendingResources.push({key:j,value:$}),this}withDispose(j,$){return this.pendingDisposeCallbacks.push({key:j,callback:$}),this}withRequired(j,$,J){return this.pendingRequiredComponents.push({trigger:j,required:$,factory:J}),this}withAssets(j){let $=b();return j($),this.assetConfigurator=$,this}withScreens(j){let $=N();return j($),this.screenConfigurator=$,this}withFixedTimestep(j){return this._fixedDt=j,this}withReactiveQueryNames(){return this}pluginFactory(){return z}build(){for(let j of this.pendingPlugins)this.ecspresso.installPlugin(j);for(let{key:j,value:$}of this.pendingResources)this.ecspresso.addResource(j,$);for(let{key:j,callback:$}of this.pendingDisposeCallbacks)this.ecspresso.registerDispose(j,$);for(let{trigger:j,required:$,factory:J}of this.pendingRequiredComponents)this.ecspresso.registerRequired(j,$,J);if(this.assetConfigurator)this.ecspresso._setAssetManager(this.assetConfigurator.getManager());else if(this.ecspresso._hasPendingPluginAssets())this.ecspresso._setAssetManager(new O);if(this.screenConfigurator)this.ecspresso._setScreenManager(this.screenConfigurator.getManager());else if(this.ecspresso._hasPendingPluginScreens())this.ecspresso._setScreenManager(new P);if(this._fixedDt!==null)this.ecspresso._setFixedDt(this._fixedDt);return this.ecspresso}}var d=()=>{};var c={};t(c,{default:()=>M});var i,M;var k=V(()=>{u();f();m();d();i=["preUpdate","fixedUpdate","update","postUpdate","render"];M=class M{static VERSION=l;_entityManager;_eventBus;_resourceManager;_commandBuffer;_systems=[];_phaseSystems={preUpdate:[],fixedUpdate:[],update:[],postUpdate:[],render:[]};_installedPlugins=new Set;_disabledGroups=new Set;_assetManager=null;_screenManager=null;_reactiveQueryManager;_postUpdateHooks=[];_currentTick=0;_systemLastSeqs=new Map;_changeThreshold=0;_fixedDt=0.016666666666666666;_fixedAccumulator=0;_interpolationAlpha=0;_maxFixedSteps=8;_requiredComponents=new Map;_pendingPluginAssets=[];_pendingPluginScreens=[];_diagnosticsEnabled=!1;_systemTimings=new Map;_phaseTimings={preUpdate:0,fixedUpdate:0,update:0,postUpdate:0,render:0};_entityEnterTracking=new Map;_entityEnterFrameSet=new Set;_systemContexts=new WeakMap;_pendingFinalizers=[];_batchingRegistrations=!1;constructor(){this._entityManager=new E,this._eventBus=new w,this._resourceManager=new R,this._reactiveQueryManager=new S(this._entityManager),this._commandBuffer=new T,this._subscribeLifecycleHooks()}_subscribeLifecycleHooks(){this._entityManager.onAfterComponentAdded((j,$)=>{this._entityManager.markChanged(j,$);let J=this._requiredComponents.get($);if(J){let X=this._entityManager.getEntity(j);if(X){let Y=X.components[$];for(let{component:Z,factory:W}of J){if(this._entityManager._pendingBatchKeys?.has(Z))continue;if(!(Z in X.components))this._entityManager.addComponent(j,Z,W(Y))}}}}),this._entityManager.onAfterEntityMutated((j)=>{let $=this._entityManager.getEntity(j);if($)this._reactiveQueryManager.recheckEntityAndChildren($)}),this._entityManager.onAfterComponentRemoved((j,$)=>{let J=this._entityManager.getEntity(j);if(J)this._reactiveQueryManager.onComponentRemoved(J,$)}),this._entityManager.onBeforeEntityRemoved((j)=>{this._reactiveQueryManager.onEntityRemoved(j)}),this._entityManager.onAfterParentChanged((j)=>{if(this._reactiveQueryManager.hasParentHasQueries){let $=this._entityManager.getEntity(j);if($)this._reactiveQueryManager.recheckEntity($)}})}static create(){return new g}addSystem(j){let $=new x(j);return this._pendingFinalizers.push(()=>{this._registerSystem($._createSystemObject())}),$}_finalizePendingBuilders(){if(this._pendingFinalizers.length===0)return;this._batchingRegistrations=!0;while(this._pendingFinalizers.length>0){let j=this._pendingFinalizers;this._pendingFinalizers=[];for(let $ of j)$()}this._batchingRegistrations=!1,this._rebuildPhaseSystems()}update(j){this._finalizePendingBuilders();let $=this._screenManager?.getCurrentScreen()??null,J=this._diagnosticsEnabled;this._runPhase("preUpdate",j,$,J);let X=J?performance.now():0;this._fixedAccumulator+=j;let Y=0;while(this._fixedAccumulator>=this._fixedDt&&Y<this._maxFixedSteps)this._executePhase(this._phaseSystems.fixedUpdate,this._fixedDt,$),this._commandBuffer.playback(this),this._fixedAccumulator-=this._fixedDt,Y++;if(this._fixedAccumulator>=this._fixedDt)this._fixedAccumulator=0;if(J)this._phaseTimings.fixedUpdate=performance.now()-X;this._interpolationAlpha=this._fixedAccumulator/this._fixedDt,this._runPhase("update",j,$,J),this._runPhase("postUpdate",j,$,J);for(let Z of this._postUpdateHooks)Z({ecs:this,dt:j});this._runPhase("render",j,$,J),this._changeThreshold=this._entityManager.changeSeq,this._currentTick++}_executePhase(j,$,J){for(let X of j){if(!X.process&&!X.onEntityEnter)continue;if(X.groups?.length){let G=!1;for(let F of X.groups)if(this._disabledGroups.has(F)){G=!0;break}if(G)continue}if(X.inScreens?.length){if(J===null||!X.inScreens.includes(J))continue}if(X.excludeScreens?.length){if(J!==null&&X.excludeScreens.includes(J))continue}if(X.requiredAssets?.length&&this._assetManager){let G=!0;for(let F of X.requiredAssets)if(!this._assetManager.isLoaded(F)){G=!1;break}if(!G)continue}let Y=this._systemLastSeqs.get(X)??0;this._changeThreshold=Y;let Z=this._systemContexts.get(X);if(!Z)Z={queries:{},dt:0,ecs:this},this._systemContexts.set(X,Z);Z.dt=$;let W=Z.queries,B=!1,K=!1;if(X.entityQueries)for(let G in X.entityQueries){K=!0;let F=X.entityQueries[G];if(F){if(W[G]=this._entityManager.getEntitiesWithQuery(F.with,F.without||[],F.changed,F.changed?this._changeThreshold:void 0,F.parentHas),W[G].length)B=!0}}let U=this._entityEnterTracking.get(X);if(U&&X.onEntityEnter)for(let G in X.onEntityEnter){let F=W[G],D=U.get(G);if(!F||!D)continue;let _=X.onEntityEnter[G];if(!_)continue;let Q=this._entityEnterFrameSet;Q.clear();for(let A of F)if(Q.add(A.id),!D.has(A.id))D.add(A.id),_({entity:A,ecs:this});for(let A of D)if(!Q.has(A))D.delete(A)}if(X.process){if(this._diagnosticsEnabled){let G=performance.now();if(B||X.runWhenEmpty)X.process(Z);else if(!K)X.process(Z);this._systemTimings.set(X.label,performance.now()-G)}else if(B||X.runWhenEmpty)X.process(Z);else if(!K)X.process(Z)}this._systemLastSeqs.set(X,this._entityManager.changeSeq)}}_runPhase(j,$,J,X){if(X){let Y=performance.now();this._executePhase(this._phaseSystems[j],$,J),this._phaseTimings[j]=performance.now()-Y}else this._executePhase(this._phaseSystems[j],$,J);this._commandBuffer.playback(this)}async initialize(){if(this._finalizePendingBuilders(),await this.initializeResources(),this._assetManager)this._assetManager.setEventBus(this._eventBus),await this._assetManager.loadEagerAssets(),this._resourceManager.add("$assets",this._assetManager.createResource());if(this._screenManager)this._screenManager.setDependencies(this._eventBus,this._assetManager,this),this._resourceManager.add("$screen",this._screenManager.createResource());for(let j of this._systems)await j.onInitialize?.(this)}async initializeResources(...j){await this._resourceManager.initializeResources(this,...j)}_rebuildPhaseSystems(){for(let j of i)this._phaseSystems[j]=[];for(let j of this._systems){let $=j.phase??"update";this._phaseSystems[$].push(j)}for(let j of i)this._phaseSystems[j].sort(($,J)=>{let X=$.priority??0;return(J.priority??0)-X})}updateSystemPriority(j,$){this._finalizePendingBuilders();let J=this._systems.find((X)=>X.label===j);if(!J)return!1;return J.priority=$,this._rebuildPhaseSystems(),!0}updateSystemPhase(j,$){this._finalizePendingBuilders();let J=this._systems.find((X)=>X.label===j);if(!J)return!1;return J.phase=$,this._rebuildPhaseSystems(),!0}get interpolationAlpha(){return this._interpolationAlpha}get fixedDt(){return this._fixedDt}disableSystemGroup(j){this._disabledGroups.add(j)}enableSystemGroup(j){this._disabledGroups.delete(j)}isSystemGroupEnabled(j){return!this._disabledGroups.has(j)}getSystemsInGroup(j){return this._finalizePendingBuilders(),this._systems.filter(($)=>$.groups?.includes(j)).map(($)=>$.label)}removeSystem(j){this._finalizePendingBuilders();let $=this._systems.findIndex((X)=>X.label===j);if($===-1)return!1;let J=this._systems[$];if(!J)return!1;if(J.onDetach)J.onDetach(this);return this._systems.splice($,1),this._systemLastSeqs.delete(J),this._entityEnterTracking.delete(J),this._rebuildPhaseSystems(),!0}_registerSystem(j){if(this._systems.push(j),this._systemLastSeqs.set(j,this._changeThreshold),!this._batchingRegistrations)this._rebuildPhaseSystems();if(j.onEntityEnter){let $=new Map;for(let J in j.onEntityEnter)$.set(J,new Set);this._entityEnterTracking.set(j,$)}if(!j.eventHandlers)return;for(let $ in j.eventHandlers){let J=j.eventHandlers[$];if(J)this._eventBus.subscribe($,(X)=>{J({data:X,ecs:this})})}}hasResource(j){return this._resourceManager.has(j)}getResource(j){if(!this._resourceManager.has(j))throw Error(`Resource '${String(j)}' not found. Available resources: [${this.getResourceKeys().map(($)=>String($)).join(", ")}]`);return this._resourceManager.get(j,this)}tryGetResource(j){let $=j;if(!this._resourceManager.has($))return;return this._resourceManager.get($,this)}addResource(j,$){return this._resourceManager.add(j,$),this}removeResource(j){return this._resourceManager.remove(j)}async disposeResource(j){return this._resourceManager.disposeResource(j,this)}async disposeResources(){return this._resourceManager.disposeResources(this)}updateResource(j,$){let J=this.getResource(j),X=$(J);return this._resourceManager.add(j,X),this}getResourceKeys(){return this._resourceManager.getKeys()}resourceNeedsInitialization(j){return this._resourceManager.needsInitialization(j)}getComponent(j,$){return this._entityManager.getComponent(j,$)}addComponent(j,$,J){this._entityManager.addComponent(j,$,J)}addComponents(j,$){this._entityManager.addComponents(j,$)}removeComponent(j,$){this._entityManager.removeComponent(j,$)}hasComponent(j,$){return this._entityManager.getComponent(j,$)!==void 0}spawn(j){let $=this._entityManager.createEntity();return this._entityManager.addComponents($.id,j),$}getEntitiesWithQuery(j,$=[],J,X){return this._entityManager.getEntitiesWithQuery(j,$,J,J?this._changeThreshold:void 0,X)}getSingleton(j,$=[]){let J=this._entityManager.getEntitiesWithQuery(j,$);if(J.length===0)throw Error(`getSingleton: no entity matches query with=[${String(j)}] without=[${String($)}]`);if(J.length>1)throw Error(`getSingleton: expected 1 entity but found ${J.length} matching query with=[${String(j)}] without=[${String($)}]`);let X=J[0];if(!X)throw Error("getSingleton: unexpected empty result");return X}tryGetSingleton(j,$=[]){let J=this._entityManager.getEntitiesWithQuery(j,$);if(J.length===0)return;if(J.length>1)throw Error(`tryGetSingleton: expected 0 or 1 entity but found ${J.length} matching query with=[${String(j)}] without=[${String($)}]`);return J[0]}removeEntity(j,$){return this._entityManager.removeEntity(j,$)}spawnChild(j,$){let J=this._entityManager.spawnChild(j,$);return this._emitHierarchyChanged(J.id,null,j),J}setParent(j,$){let J=this._entityManager.getParent(j);return this._entityManager.setParent(j,$),this._emitHierarchyChanged(j,J,$),this}removeParent(j){let $=this._entityManager.getParent(j),J=this._entityManager.removeParent(j);if(J)this._emitHierarchyChanged(j,$,null);return J}getParent(j){return this._entityManager.getParent(j)}getChildren(j){return this._entityManager.getChildren(j)}getChildAt(j,$){return this._entityManager.getChildAt(j,$)}getChildIndex(j,$){return this._entityManager.getChildIndex(j,$)}getAncestors(j){return this._entityManager.getAncestors(j)}getDescendants(j){return this._entityManager.getDescendants(j)}getRoot(j){return this._entityManager.getRoot(j)}getSiblings(j){return this._entityManager.getSiblings(j)}isDescendantOf(j,$){return this._entityManager.isDescendantOf(j,$)}isAncestorOf(j,$){return this._entityManager.isAncestorOf(j,$)}getRootEntities(){return this._entityManager.getRootEntities()}forEachInHierarchy(j,$){this._entityManager.forEachInHierarchy(j,$)}hierarchyIterator(j){return this._entityManager.hierarchyIterator(j)}_emitHierarchyChanged(j,$,J){this._eventBus.publish("hierarchyChanged",{entityId:j,oldParent:$,newParent:J})}get installedPlugins(){return Array.from(this._installedPlugins)}get entityManager(){return this._entityManager}get eventBus(){return this._finalizePendingBuilders(),this._eventBus}get commands(){return this._commandBuffer}get currentTick(){return this._currentTick}get changeThreshold(){return this._changeThreshold}enableDiagnostics(j){if(this._diagnosticsEnabled=j,!j)this._systemTimings.clear(),this._phaseTimings={preUpdate:0,fixedUpdate:0,update:0,postUpdate:0,render:0}}get diagnosticsEnabled(){return this._diagnosticsEnabled}get systemTimings(){return this._systemTimings}get phaseTimings(){return this._phaseTimings}get entityCount(){return this._entityManager.entityCount}mutateComponent(j,$,J){let X=this._entityManager.getComponent(j,$);if(X===void 0)throw Error(`Entity ${j} does not have component "${String($)}"`);return J(X),this._entityManager.markChanged(j,$),X}markChanged(j,$){this._entityManager.markChanged(j,$)}registerDispose(j,$){this._entityManager.registerDispose(j,$)}registerRequired(j,$,J){if(String(j)===String($))throw Error(`Cannot require a component to depend on itself: '${String(j)}'`);let X=this._requiredComponents.get(j)??[];if(X.some((Y)=>Y.component===$))throw Error(`Required component '${String($)}' already registered for trigger '${String(j)}'`);this._checkRequiredCycle(j,$),X.push({component:$,factory:J}),this._requiredComponents.set(j,X)}_checkRequiredCycle(j,$){I(j,$,(J)=>this._requiredComponents.get(J))}onComponentAdded(j,$){return this._entityManager.onComponentAdded(j,$)}onComponentRemoved(j,$){return this._entityManager.onComponentRemoved(j,$)}addReactiveQuery(j,$){this._reactiveQueryManager.addQuery(j,$)}removeReactiveQuery(j){return this._reactiveQueryManager.removeQuery(j)}on(j,$){return this._eventBus.subscribe(j,$)}off(j,$){return this._eventBus.unsubscribe(j,$)}onPostUpdate(j){return this._postUpdateHooks.push(j),()=>{let $=this._postUpdateHooks.indexOf(j);if($!==-1)this._postUpdateHooks.splice($,1)}}requireAssetManager(){if(!this._assetManager)throw Error("Asset manager not configured. Use withAssets() in builder.");return this._assetManager}getAsset(j){return this.requireAssetManager().get(j)}tryGetAsset(j){return this._assetManager?.tryGet(j)}getAssetHandle(j){return this.requireAssetManager().getHandle(j)}isAssetLoaded(j){return this._assetManager?.isLoaded(j)??!1}async loadAsset(j){return this.requireAssetManager().loadAsset(j)}async loadAssetGroup(j){return this.requireAssetManager().loadAssetGroup(j)}isAssetGroupLoaded(j){return this._assetManager?.isGroupLoaded(j)??!1}getAssetGroupProgress(j){return this._assetManager?.getGroupProgress(j)??0}requireScreenManager(){if(!this._screenManager)throw Error("Screen manager not configured. Use withScreens() in builder.");return this._screenManager}async setScreen(j,$){return this.requireScreenManager().setScreen(j,$)}async pushScreen(j,$){return this.requireScreenManager().pushScreen(j,$)}async popScreen(){return this.requireScreenManager().popScreen()}getCurrentScreen(){return this._screenManager?.getCurrentScreen()??null}getScreenConfig(j){return this.requireScreenManager().getConfig(j)}tryGetScreenConfig(j){return this._screenManager?.tryGetConfig(j)??void 0}getScreenState(j){return this.requireScreenManager().getState(j)}tryGetScreenState(j){return this._screenManager?.tryGetState(j)??void 0}updateScreenState(j,$){if(typeof j==="string")this.requireScreenManager().updateState($,j);else this.requireScreenManager().updateState(j)}isCurrentScreen(j){return this._screenManager?.isCurrent(j)??!1}isScreenActive(j){return this._screenManager?.isActive(j)??!1}getScreenStackDepth(){return this._screenManager?.getStackDepth()??0}_setAssetManager(j){this._assetManager=j;for(let[$,J]of this._pendingPluginAssets)this._assetManager.register($,J);this._pendingPluginAssets=[]}_setScreenManager(j){this._screenManager=j;for(let[$,J]of this._pendingPluginScreens)this._screenManager.register($,J);this._pendingPluginScreens=[]}_hasPendingPluginAssets(){return this._pendingPluginAssets.length>0}_hasPendingPluginScreens(){return this._pendingPluginScreens.length>0}_setFixedDt(j){this._fixedDt=j}_registerAsset(j,$){this._pendingPluginAssets.push([j,$])}_registerScreen(j,$){this._pendingPluginScreens.push([j,$])}installPlugin(j){if(this._installedPlugins.has(j.id))return this;return this._installedPlugins.add(j.id),j.install(this),this}pluginFactory(){return z}getHelpers(j){return j(this)}}});k();function Nj(j){return j}function kj(j,$){return{x:j,y:$}}function hj(){return{x:0,y:0}}function uj(j,$){return{x:j.x+$.x,y:j.y+$.y}}function pj(j,$){return{x:j.x-$.x,y:j.y-$.y}}function Ij(j,$){return{x:j.x*$,y:j.y*$}}function mj(j){return{x:-j.x,y:-j.y}}function lj(j,$){return j.x*$.x+j.y*$.y}function sj(j,$){return j.x*$.y-j.y*$.x}function yj(j){return j.x*j.x+j.y*j.y}function dj(j){return Math.sqrt(j.x*j.x+j.y*j.y)}function cj(j){let $=Math.sqrt(j.x*j.x+j.y*j.y);if($===0)return{x:0,y:0};return{x:j.x/$,y:j.y/$}}function ij(j,$){let J=j.x-$.x,X=j.y-$.y;return J*J+X*X}function oj(j,$){let J=j.x-$.x,X=j.y-$.y;return Math.sqrt(J*J+X*X)}function rj(j,$,J=0.0000000001){return Math.abs(j.x-$.x)<=J&&Math.abs(j.y-$.y)<=J}f();var L2=M;export{hj as vec2Zero,pj as vec2Sub,Ij as vec2Scale,cj as vec2Normalize,mj as vec2Negate,yj as vec2LengthSq,dj as vec2Length,rj as vec2Equals,lj as vec2Dot,ij as vec2DistanceSq,oj as vec2Distance,sj as vec2Cross,uj as vec2Add,kj as vec2,e as directValue,z as definePlugin,L2 as default,N as createScreenConfigurator,Nj as createQueryDefinition,b as createAssetConfigurator,x as SystemBuilder,P as ScreenManager,O as AssetManager};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=6A2072153E6A68CE64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|