ecspresso 0.4.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +571 -9
- package/dist/asset-manager.d.ts +111 -0
- package/dist/asset-types.d.ts +104 -0
- package/dist/bundle.d.ts +65 -6
- package/dist/bundles/renderers/pixi.d.ts +248 -0
- package/dist/bundles/renderers/pixi.js +4 -0
- package/dist/bundles/renderers/pixi.js.map +12 -0
- package/dist/bundles/utils/timers.d.ts +113 -0
- package/dist/bundles/utils/timers.js +4 -0
- package/dist/bundles/utils/timers.js.map +12 -0
- package/dist/ecspresso.d.ts +402 -15
- package/dist/entity-manager.d.ts +118 -4
- package/dist/event-bus.d.ts +5 -0
- package/dist/hierarchy-manager.d.ts +122 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +15 -11
- package/dist/reactive-query-manager.d.ts +59 -0
- package/dist/resource-manager.d.ts +37 -5
- package/dist/screen-manager.d.ts +116 -0
- package/dist/screen-types.d.ts +119 -0
- package/dist/system-builder.d.ts +37 -2
- package/dist/types.d.ts +62 -5
- package/package.json +23 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Entity, FilteredEntity } from "./types";
|
|
2
|
+
import type EntityManager from "./entity-manager";
|
|
3
|
+
/**
|
|
4
|
+
* Definition for a reactive query with enter/exit callbacks
|
|
5
|
+
*/
|
|
6
|
+
export interface ReactiveQueryDefinition<ComponentTypes extends Record<string, any>, WithComponents extends keyof ComponentTypes = keyof ComponentTypes, WithoutComponents extends keyof ComponentTypes = never> {
|
|
7
|
+
/** Components the entity must have */
|
|
8
|
+
with: ReadonlyArray<WithComponents>;
|
|
9
|
+
/** Components the entity must not have */
|
|
10
|
+
without?: ReadonlyArray<WithoutComponents>;
|
|
11
|
+
/** Called when an entity starts matching the query */
|
|
12
|
+
onEnter?: (entity: FilteredEntity<ComponentTypes, WithComponents, WithoutComponents>) => void;
|
|
13
|
+
/** Called when an entity stops matching the query (receives just the ID since entity may be gone) */
|
|
14
|
+
onExit?: (entityId: number) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manages reactive queries that trigger callbacks when entities enter/exit query matches
|
|
18
|
+
*/
|
|
19
|
+
export default class ReactiveQueryManager<ComponentTypes extends Record<string, any>> {
|
|
20
|
+
private queries;
|
|
21
|
+
private entityManager;
|
|
22
|
+
constructor(entityManager: EntityManager<ComponentTypes>);
|
|
23
|
+
/**
|
|
24
|
+
* Add a reactive query
|
|
25
|
+
* @param name Unique name for the query
|
|
26
|
+
* @param definition Query definition with callbacks
|
|
27
|
+
*/
|
|
28
|
+
addQuery<WithComponents extends keyof ComponentTypes, WithoutComponents extends keyof ComponentTypes = never>(name: string, definition: ReactiveQueryDefinition<ComponentTypes, WithComponents, WithoutComponents>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Remove a reactive query
|
|
31
|
+
* @param name Name of the query to remove
|
|
32
|
+
* @returns true if the query existed and was removed
|
|
33
|
+
*/
|
|
34
|
+
removeQuery(name: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Check if an entity matches a query definition
|
|
37
|
+
*/
|
|
38
|
+
private entityMatchesQuery;
|
|
39
|
+
/**
|
|
40
|
+
* Called when a component is added to an entity
|
|
41
|
+
* Checks all queries for potential enter/exit events
|
|
42
|
+
*/
|
|
43
|
+
onComponentAdded(entity: Entity<ComponentTypes>, _componentName: keyof ComponentTypes): void;
|
|
44
|
+
/**
|
|
45
|
+
* Called when a component is removed from an entity
|
|
46
|
+
* Checks all queries for potential enter/exit events
|
|
47
|
+
*/
|
|
48
|
+
onComponentRemoved(entity: Entity<ComponentTypes>, _componentName: keyof ComponentTypes): void;
|
|
49
|
+
/**
|
|
50
|
+
* Called when an entity is removed
|
|
51
|
+
* Triggers onExit for all queries the entity was matching
|
|
52
|
+
*/
|
|
53
|
+
onEntityRemoved(entityId: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Recheck an entity against all queries (used after batch component additions)
|
|
56
|
+
* Fires enter/exit callbacks as appropriate based on current state vs tracked state
|
|
57
|
+
*/
|
|
58
|
+
recheckEntity(entity: Entity<ComponentTypes>): void;
|
|
59
|
+
}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource factory with declared dependencies and optional disposal callback
|
|
3
|
+
*/
|
|
4
|
+
interface ResourceFactoryWithDeps<T> {
|
|
5
|
+
dependsOn?: readonly string[];
|
|
6
|
+
factory: (context?: any) => T | Promise<T>;
|
|
7
|
+
onDispose?: (resource: T, context?: any) => void | Promise<void>;
|
|
8
|
+
}
|
|
1
9
|
export default class ResourceManager<ResourceTypes extends Record<string, any> = Record<string, any>> {
|
|
2
10
|
private resources;
|
|
3
11
|
private resourceFactories;
|
|
12
|
+
private resourceDependencies;
|
|
13
|
+
private resourceDisposers;
|
|
4
14
|
private initializedResourceKeys;
|
|
5
15
|
/**
|
|
6
16
|
* Add a resource to the manager
|
|
7
17
|
* @param label The resource key
|
|
8
|
-
* @param resource The resource value
|
|
18
|
+
* @param resource The resource value, a factory function, or a factory with dependencies
|
|
9
19
|
* @returns The resource manager instance for chaining
|
|
10
20
|
*/
|
|
11
|
-
add<K extends keyof ResourceTypes>(label: K, resource: ResourceTypes[K] | ((context?: any) => ResourceTypes[K] | Promise<ResourceTypes[K]>)): this;
|
|
21
|
+
add<K extends keyof ResourceTypes>(label: K, resource: ResourceTypes[K] | ((context?: any) => ResourceTypes[K] | Promise<ResourceTypes[K]>) | ResourceFactoryWithDeps<ResourceTypes[K]>): this;
|
|
12
22
|
/**
|
|
13
23
|
* Improved detection of factory functions vs direct values/classes
|
|
14
24
|
* @private
|
|
@@ -29,7 +39,7 @@ export default class ResourceManager<ResourceTypes extends Record<string, any> =
|
|
|
29
39
|
*/
|
|
30
40
|
has<K extends keyof ResourceTypes>(label: K): boolean;
|
|
31
41
|
/**
|
|
32
|
-
* Remove a resource
|
|
42
|
+
* Remove a resource (without calling onDispose)
|
|
33
43
|
* @param label The resource key
|
|
34
44
|
* @returns True if the resource was removed
|
|
35
45
|
*/
|
|
@@ -58,9 +68,31 @@ export default class ResourceManager<ResourceTypes extends Record<string, any> =
|
|
|
58
68
|
*/
|
|
59
69
|
initializeResource<K extends keyof ResourceTypes>(label: K, context?: any): Promise<void>;
|
|
60
70
|
/**
|
|
61
|
-
* Initialize specific resources or all resources that haven't been initialized yet
|
|
62
|
-
*
|
|
71
|
+
* Initialize specific resources or all resources that haven't been initialized yet.
|
|
72
|
+
* Resources are initialized in topological order based on their dependencies.
|
|
73
|
+
* @param context Optional context to pass to factory functions (usually the ECSpresso instance)
|
|
74
|
+
* @param keys Optional array of resource keys to initialize
|
|
63
75
|
* @returns Promise that resolves when the specified resources are initialized
|
|
64
76
|
*/
|
|
65
77
|
initializeResources<K extends keyof ResourceTypes>(context?: any, ...keys: K[]): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the dependencies of a resource
|
|
80
|
+
* @param label The resource key
|
|
81
|
+
* @returns Array of resource keys that this resource depends on
|
|
82
|
+
*/
|
|
83
|
+
getDependencies<K extends keyof ResourceTypes>(label: K): readonly string[];
|
|
84
|
+
/**
|
|
85
|
+
* Dispose a single resource, calling its onDispose callback if it exists
|
|
86
|
+
* @param label The resource key to dispose
|
|
87
|
+
* @param context Optional context to pass to the onDispose callback
|
|
88
|
+
* @returns True if the resource existed and was disposed, false if it didn't exist
|
|
89
|
+
*/
|
|
90
|
+
disposeResource<K extends keyof ResourceTypes>(label: K, context?: any): Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Dispose all initialized resources in reverse dependency order.
|
|
93
|
+
* Resources that depend on others are disposed first.
|
|
94
|
+
* @param context Optional context to pass to onDispose callbacks
|
|
95
|
+
*/
|
|
96
|
+
disposeResources(context?: any): Promise<void>;
|
|
66
97
|
}
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen/State management for ECSpresso ECS framework
|
|
3
|
+
*/
|
|
4
|
+
import type EventBus from './event-bus';
|
|
5
|
+
import type AssetManager from './asset-manager';
|
|
6
|
+
import type ECSpresso from './ecspresso';
|
|
7
|
+
import type { ScreenDefinition, ScreenResource, ScreenEvents, ScreenConfigurator } from './screen-types';
|
|
8
|
+
/**
|
|
9
|
+
* Manages screen/state transitions for ECSpresso
|
|
10
|
+
*/
|
|
11
|
+
export default class ScreenManager<Screens extends Record<string, ScreenDefinition<any, any>> = Record<string, never>> {
|
|
12
|
+
private readonly screens;
|
|
13
|
+
private currentScreen;
|
|
14
|
+
private screenStack;
|
|
15
|
+
private eventBus;
|
|
16
|
+
private assetManager;
|
|
17
|
+
private ecs;
|
|
18
|
+
/**
|
|
19
|
+
* Set dependencies for screen transitions
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
setDependencies(eventBus: EventBus<ScreenEvents>, assetManager: AssetManager<any> | null, ecs: ECSpresso<any, any, any, any, any>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Register a screen definition
|
|
25
|
+
*/
|
|
26
|
+
register<K extends string, Config extends Record<string, unknown>, State extends Record<string, unknown>>(name: K, definition: ScreenDefinition<Config, State>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Transition to a new screen, clearing the stack
|
|
29
|
+
*/
|
|
30
|
+
setScreen<K extends keyof Screens>(name: K, config: Screens[K] extends ScreenDefinition<infer C, any> ? C : never): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Push a screen onto the stack (overlay)
|
|
33
|
+
*/
|
|
34
|
+
pushScreen<K extends keyof Screens>(name: K, config: Screens[K] extends ScreenDefinition<infer C, any> ? C : never): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Pop the current screen and return to the previous one
|
|
37
|
+
*/
|
|
38
|
+
popScreen(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Exit a screen by name (internal helper)
|
|
41
|
+
*/
|
|
42
|
+
private exitScreen;
|
|
43
|
+
/**
|
|
44
|
+
* Verify required assets are loaded before screen transition
|
|
45
|
+
*/
|
|
46
|
+
private verifyRequiredAssets;
|
|
47
|
+
/**
|
|
48
|
+
* Get the current screen name
|
|
49
|
+
*/
|
|
50
|
+
getCurrentScreen(): keyof Screens | null;
|
|
51
|
+
/**
|
|
52
|
+
* Get the current screen config (immutable)
|
|
53
|
+
*/
|
|
54
|
+
getConfig<K extends keyof Screens>(): Screens[K] extends ScreenDefinition<infer C, any> ? Readonly<C> : never;
|
|
55
|
+
/**
|
|
56
|
+
* Get the current screen config or null
|
|
57
|
+
*/
|
|
58
|
+
getConfigOrNull<K extends keyof Screens>(): (Screens[K] extends ScreenDefinition<infer C, any> ? Readonly<C> : never) | null;
|
|
59
|
+
/**
|
|
60
|
+
* Get the current screen state (mutable)
|
|
61
|
+
*/
|
|
62
|
+
getState<K extends keyof Screens>(): Screens[K] extends ScreenDefinition<any, infer S> ? S : never;
|
|
63
|
+
/**
|
|
64
|
+
* Get the current screen state or null
|
|
65
|
+
*/
|
|
66
|
+
getStateOrNull<K extends keyof Screens>(): (Screens[K] extends ScreenDefinition<any, infer S> ? S : never) | null;
|
|
67
|
+
/**
|
|
68
|
+
* Update the current screen state
|
|
69
|
+
*/
|
|
70
|
+
updateState<K extends keyof Screens>(update: Partial<Screens[K] extends ScreenDefinition<any, infer S> ? S : never> | ((current: Screens[K] extends ScreenDefinition<any, infer S> ? S : never) => Partial<Screens[K] extends ScreenDefinition<any, infer S> ? S : never>)): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get the screen stack depth
|
|
73
|
+
*/
|
|
74
|
+
getStackDepth(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Check if current screen is an overlay
|
|
77
|
+
*/
|
|
78
|
+
isOverlay(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a screen is active (current or in stack)
|
|
81
|
+
*/
|
|
82
|
+
isActive(screenName: keyof Screens): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Check if a screen is the current screen
|
|
85
|
+
*/
|
|
86
|
+
isCurrent(screenName: keyof Screens): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Create the $screen resource object
|
|
89
|
+
*/
|
|
90
|
+
createResource(): ScreenResource<Screens>;
|
|
91
|
+
/**
|
|
92
|
+
* Get all registered screen names
|
|
93
|
+
*/
|
|
94
|
+
getScreenNames(): Array<keyof Screens>;
|
|
95
|
+
/**
|
|
96
|
+
* Check if a screen is registered
|
|
97
|
+
*/
|
|
98
|
+
hasScreen(name: keyof Screens): boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Implementation of ScreenConfigurator for builder pattern
|
|
102
|
+
*/
|
|
103
|
+
export declare class ScreenConfiguratorImpl<Screens extends Record<string, ScreenDefinition<any, any>>> implements ScreenConfigurator<Screens> {
|
|
104
|
+
private readonly manager;
|
|
105
|
+
constructor(manager: ScreenManager<Screens>);
|
|
106
|
+
add<K extends string, Config extends Record<string, unknown>, State extends Record<string, unknown>>(name: K, definition: ScreenDefinition<Config, State>): ScreenConfigurator<Screens & Record<K, ScreenDefinition<Config, State>>>;
|
|
107
|
+
/**
|
|
108
|
+
* Get the underlying manager
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
getManager(): ScreenManager<Screens>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a new ScreenConfigurator for builder pattern usage
|
|
115
|
+
*/
|
|
116
|
+
export declare function createScreenConfigurator<Screens extends Record<string, ScreenDefinition<any, any>> = Record<string, never>>(manager?: ScreenManager<Screens>): ScreenConfiguratorImpl<Screens>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen/State management types for ECSpresso ECS framework
|
|
3
|
+
*/
|
|
4
|
+
import type ECSpresso from './ecspresso';
|
|
5
|
+
/**
|
|
6
|
+
* Definition for a screen including its state, lifecycle hooks, and requirements
|
|
7
|
+
*/
|
|
8
|
+
export interface ScreenDefinition<Config extends Record<string, unknown> = Record<string, never>, State extends Record<string, unknown> = Record<string, never>> {
|
|
9
|
+
/**
|
|
10
|
+
* Function to create initial state from config
|
|
11
|
+
*/
|
|
12
|
+
readonly initialState: (config: Config) => State;
|
|
13
|
+
/**
|
|
14
|
+
* Lifecycle hook called when entering this screen
|
|
15
|
+
*/
|
|
16
|
+
readonly onEnter?: (config: Config, ecs: ECSpresso<any, any, any, any, any>) => void | Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Lifecycle hook called when exiting this screen
|
|
19
|
+
*/
|
|
20
|
+
readonly onExit?: (ecs: ECSpresso<any, any, any, any, any>) => void | Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Asset keys that must be loaded before entering this screen
|
|
23
|
+
*/
|
|
24
|
+
readonly requiredAssets?: ReadonlyArray<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Asset groups that must be loaded before entering this screen
|
|
27
|
+
*/
|
|
28
|
+
readonly requiredAssetGroups?: ReadonlyArray<string>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Entry in the screen stack for overlay support
|
|
32
|
+
*/
|
|
33
|
+
export interface ScreenStackEntry<Screens extends Record<string, ScreenDefinition<any, any>>, K extends keyof Screens = keyof Screens> {
|
|
34
|
+
readonly name: K;
|
|
35
|
+
readonly config: Screens[K] extends ScreenDefinition<infer C, any> ? Readonly<C> : never;
|
|
36
|
+
state: Screens[K] extends ScreenDefinition<any, infer S> ? S : never;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Helper to extract config type from a screen definition
|
|
40
|
+
*/
|
|
41
|
+
export type ScreenConfig<S extends ScreenDefinition<any, any>> = S extends ScreenDefinition<infer C, any> ? C : never;
|
|
42
|
+
/**
|
|
43
|
+
* Helper to extract state type from a screen definition
|
|
44
|
+
*/
|
|
45
|
+
export type ScreenState<S extends ScreenDefinition<any, any>> = S extends ScreenDefinition<any, infer St> ? St : never;
|
|
46
|
+
/**
|
|
47
|
+
* Resource interface for accessing screen state in systems
|
|
48
|
+
* Exposed as $screen resource
|
|
49
|
+
*/
|
|
50
|
+
export interface ScreenResource<Screens extends Record<string, ScreenDefinition<any, any>>> {
|
|
51
|
+
/**
|
|
52
|
+
* Current active screen name, or null if no screen
|
|
53
|
+
*/
|
|
54
|
+
readonly current: keyof Screens | null;
|
|
55
|
+
/**
|
|
56
|
+
* Immutable config of the current screen
|
|
57
|
+
*/
|
|
58
|
+
readonly config: Readonly<ScreenConfig<Screens[keyof Screens]>> | null;
|
|
59
|
+
/**
|
|
60
|
+
* Mutable state of the current screen
|
|
61
|
+
*/
|
|
62
|
+
state: ScreenState<Screens[keyof Screens]> | null;
|
|
63
|
+
/**
|
|
64
|
+
* The screen stack (read-only view)
|
|
65
|
+
*/
|
|
66
|
+
readonly stack: ReadonlyArray<ScreenStackEntry<Screens>>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the current screen is an overlay (has screens beneath it)
|
|
69
|
+
*/
|
|
70
|
+
readonly isOverlay: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Current depth of the screen stack
|
|
73
|
+
*/
|
|
74
|
+
readonly stackDepth: number;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a specific screen is currently active (either current or in stack)
|
|
77
|
+
*/
|
|
78
|
+
isActive(screenName: keyof Screens): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a specific screen is the current screen
|
|
81
|
+
*/
|
|
82
|
+
isCurrent(screenName: keyof Screens): boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Events emitted by the screen system
|
|
86
|
+
*/
|
|
87
|
+
export interface ScreenEvents {
|
|
88
|
+
screenEnter: {
|
|
89
|
+
screen: string;
|
|
90
|
+
config: unknown;
|
|
91
|
+
};
|
|
92
|
+
screenExit: {
|
|
93
|
+
screen: string;
|
|
94
|
+
};
|
|
95
|
+
screenPush: {
|
|
96
|
+
screen: string;
|
|
97
|
+
config: unknown;
|
|
98
|
+
};
|
|
99
|
+
screenPop: {
|
|
100
|
+
screen: string;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for screen definitions during builder setup
|
|
105
|
+
*/
|
|
106
|
+
export interface ScreenConfigurator<Screens extends Record<string, ScreenDefinition<any, any>>> {
|
|
107
|
+
/**
|
|
108
|
+
* Add a screen definition
|
|
109
|
+
*/
|
|
110
|
+
add<K extends string, Config extends Record<string, unknown>, State extends Record<string, unknown>>(name: K, definition: ScreenDefinition<Config, State>): ScreenConfigurator<Screens & Record<K, ScreenDefinition<Config, State>>>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Type-safe screen state getter result
|
|
114
|
+
*/
|
|
115
|
+
export type CurrentScreenState<Screens extends Record<string, ScreenDefinition<any, any>>, CurrentScreen extends keyof Screens> = Screens[CurrentScreen] extends ScreenDefinition<any, infer S> ? S : never;
|
|
116
|
+
/**
|
|
117
|
+
* Type-safe screen config getter result
|
|
118
|
+
*/
|
|
119
|
+
export type CurrentScreenConfig<Screens extends Record<string, ScreenDefinition<any, any>>, CurrentScreen extends keyof Screens> = Screens[CurrentScreen] extends ScreenDefinition<infer C, any> ? Readonly<C> : never;
|
package/dist/system-builder.d.ts
CHANGED
|
@@ -15,16 +15,20 @@ export declare class SystemBuilder<ComponentTypes extends Record<string, any> =
|
|
|
15
15
|
private eventHandlers?;
|
|
16
16
|
private _priority;
|
|
17
17
|
private _isRegistered;
|
|
18
|
+
private _groups;
|
|
19
|
+
private _inScreens?;
|
|
20
|
+
private _excludeScreens?;
|
|
21
|
+
private _requiredAssets?;
|
|
18
22
|
constructor(_label: string, _ecspresso?: ECSpresso<ComponentTypes, EventTypes, ResourceTypes> | null, _bundle?: Bundle<ComponentTypes, EventTypes, ResourceTypes> | null);
|
|
19
23
|
get label(): string;
|
|
20
24
|
/**
|
|
21
25
|
* Returns the associated bundle if one was provided in the constructor
|
|
22
26
|
*/
|
|
23
|
-
get bundle(): Bundle<ComponentTypes, EventTypes, ResourceTypes> | null;
|
|
27
|
+
get bundle(): Bundle<ComponentTypes, EventTypes, ResourceTypes, {}, {}> | null;
|
|
24
28
|
/**
|
|
25
29
|
* Returns the associated ECSpresso instance if one was provided in the constructor
|
|
26
30
|
*/
|
|
27
|
-
get ecspresso(): ECSpresso<ComponentTypes, EventTypes, ResourceTypes> | null;
|
|
31
|
+
get ecspresso(): ECSpresso<ComponentTypes, EventTypes, ResourceTypes, {}, {}> | null;
|
|
28
32
|
/**
|
|
29
33
|
* Auto-register this system with its ECSpresso instance if not already registered
|
|
30
34
|
* @private
|
|
@@ -48,6 +52,37 @@ export declare class SystemBuilder<ComponentTypes extends Record<string, any> =
|
|
|
48
52
|
* @returns This SystemBuilder instance for method chaining
|
|
49
53
|
*/
|
|
50
54
|
setPriority(priority: number): this;
|
|
55
|
+
/**
|
|
56
|
+
* Add this system to a group. Systems can belong to multiple groups.
|
|
57
|
+
* When any group a system belongs to is disabled, the system will be skipped.
|
|
58
|
+
* @param groupName The name of the group to add the system to
|
|
59
|
+
* @returns This SystemBuilder instance for method chaining
|
|
60
|
+
*/
|
|
61
|
+
inGroup(groupName: string): this;
|
|
62
|
+
/**
|
|
63
|
+
* Restrict this system to only run in specified screens.
|
|
64
|
+
* System will be skipped during update() when the current screen
|
|
65
|
+
* is not in this list.
|
|
66
|
+
* @param screens Array of screen names where this system should run
|
|
67
|
+
* @returns This SystemBuilder instance for method chaining
|
|
68
|
+
*/
|
|
69
|
+
inScreens(screens: ReadonlyArray<string>): this;
|
|
70
|
+
/**
|
|
71
|
+
* Exclude this system from running in specified screens.
|
|
72
|
+
* System will be skipped during update() when the current screen
|
|
73
|
+
* is in this list.
|
|
74
|
+
* @param screens Array of screen names where this system should NOT run
|
|
75
|
+
* @returns This SystemBuilder instance for method chaining
|
|
76
|
+
*/
|
|
77
|
+
excludeScreens(screens: ReadonlyArray<string>): this;
|
|
78
|
+
/**
|
|
79
|
+
* Require specific assets to be loaded for this system to run.
|
|
80
|
+
* System will be skipped during update() if any required asset
|
|
81
|
+
* is not loaded.
|
|
82
|
+
* @param assets Array of asset keys that must be loaded
|
|
83
|
+
* @returns This SystemBuilder instance for method chaining
|
|
84
|
+
*/
|
|
85
|
+
requiresAssets(assets: ReadonlyArray<string>): this;
|
|
51
86
|
/**
|
|
52
87
|
* Add a query definition to the system
|
|
53
88
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,44 @@ export interface Entity<ComponentTypes> {
|
|
|
3
3
|
id: number;
|
|
4
4
|
components: Partial<ComponentTypes>;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Options for removing an entity
|
|
8
|
+
*/
|
|
9
|
+
export interface RemoveEntityOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to also remove all descendants (default: true)
|
|
12
|
+
*/
|
|
13
|
+
cascade?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Event data emitted when an entity's parent changes
|
|
17
|
+
*/
|
|
18
|
+
export interface HierarchyChangedEvent {
|
|
19
|
+
/** The entity whose parent changed */
|
|
20
|
+
entityId: number;
|
|
21
|
+
/** The previous parent, or null if entity had no parent */
|
|
22
|
+
oldParent: number | null;
|
|
23
|
+
/** The new parent, or null if entity was orphaned */
|
|
24
|
+
newParent: number | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for hierarchy traversal methods
|
|
28
|
+
*/
|
|
29
|
+
export interface HierarchyIteratorOptions {
|
|
30
|
+
/** Specific root entities to start traversal from. If not provided, all root entities are used. */
|
|
31
|
+
roots?: readonly number[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Entry yielded during hierarchy traversal
|
|
35
|
+
*/
|
|
36
|
+
export interface HierarchyEntry {
|
|
37
|
+
/** The entity being visited */
|
|
38
|
+
entityId: number;
|
|
39
|
+
/** The parent entity ID, or null for root entities */
|
|
40
|
+
parentId: number | null;
|
|
41
|
+
/** Depth in the hierarchy (0 for roots) */
|
|
42
|
+
depth: number;
|
|
43
|
+
}
|
|
6
44
|
export interface EventHandler<T> {
|
|
7
45
|
callback: (data: T) => void;
|
|
8
46
|
once: boolean;
|
|
@@ -80,13 +118,32 @@ export declare function createQueryDefinition<ComponentTypes extends Record<stri
|
|
|
80
118
|
with: ReadonlyArray<keyof ComponentTypes>;
|
|
81
119
|
without?: ReadonlyArray<keyof ComponentTypes>;
|
|
82
120
|
}>(queryDef: QueryDef): QueryDef;
|
|
83
|
-
export interface System<ComponentTypes extends Record<string, any> = {}, WithComponents extends keyof ComponentTypes = never, WithoutComponents extends keyof ComponentTypes = never, EventTypes extends Record<string, any> = {}, ResourceTypes extends Record<string, any> = {}> {
|
|
121
|
+
export interface System<ComponentTypes extends Record<string, any> = {}, WithComponents extends keyof ComponentTypes = never, WithoutComponents extends keyof ComponentTypes = never, EventTypes extends Record<string, any> = {}, ResourceTypes extends Record<string, any> = {}, AssetTypes extends Record<string, unknown> = {}, ScreenStates extends Record<string, any> = {}> {
|
|
84
122
|
label: string;
|
|
85
123
|
/**
|
|
86
124
|
* System priority - higher values execute first (default: 0)
|
|
87
125
|
* When systems have the same priority, they execute in registration order
|
|
88
126
|
*/
|
|
89
127
|
priority?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Groups this system belongs to. If any group is disabled, the system will be skipped.
|
|
130
|
+
*/
|
|
131
|
+
groups?: string[];
|
|
132
|
+
/**
|
|
133
|
+
* Screens where this system should run. If specified, system only runs
|
|
134
|
+
* when current screen is in this list.
|
|
135
|
+
*/
|
|
136
|
+
inScreens?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Screens where this system should NOT run. If specified, system skips
|
|
139
|
+
* when current screen is in this list.
|
|
140
|
+
*/
|
|
141
|
+
excludeScreens?: string[];
|
|
142
|
+
/**
|
|
143
|
+
* Assets that must be loaded for this system to run.
|
|
144
|
+
* System will be skipped if any required asset is not loaded.
|
|
145
|
+
*/
|
|
146
|
+
requiredAssets?: string[];
|
|
90
147
|
entityQueries?: {
|
|
91
148
|
[queryName: string]: QueryConfig<ComponentTypes, WithComponents, WithoutComponents>;
|
|
92
149
|
};
|
|
@@ -98,19 +155,19 @@ export interface System<ComponentTypes extends Record<string, any> = {}, WithCom
|
|
|
98
155
|
*/
|
|
99
156
|
process?(queries: {
|
|
100
157
|
[queryName: string]: Array<FilteredEntity<ComponentTypes, WithComponents, WithoutComponents>>;
|
|
101
|
-
} | Array<FilteredEntity<ComponentTypes, WithComponents, WithoutComponents>>, deltaTime: number, ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes>): void;
|
|
158
|
+
} | Array<FilteredEntity<ComponentTypes, WithComponents, WithoutComponents>>, deltaTime: number, ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes, AssetTypes, ScreenStates>): void;
|
|
102
159
|
/**
|
|
103
160
|
* Lifecycle hook called when the system is initialized
|
|
104
161
|
* This is called when ECSpresso.initialize() is invoked, after resources are initialized
|
|
105
162
|
* Use this for one-time initialization that depends on resources
|
|
106
163
|
* @param ecs The ECSpresso instance providing access to all ECS functionality
|
|
107
164
|
*/
|
|
108
|
-
onInitialize?(ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes>): void | Promise<void>;
|
|
165
|
+
onInitialize?(ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes, AssetTypes, ScreenStates>): void | Promise<void>;
|
|
109
166
|
/**
|
|
110
167
|
* Lifecycle hook called when the system is detached from the ECS
|
|
111
168
|
* @param ecs The ECSpresso instance providing access to all ECS functionality
|
|
112
169
|
*/
|
|
113
|
-
onDetach?(ecs: import("./ecspresso").default<ComponentTypes, EventTypes, ResourceTypes>): void;
|
|
170
|
+
onDetach?(ecs: import("./ecspresso").default<ComponentTypes, EventTypes, ResourceTypes, AssetTypes, ScreenStates>): void;
|
|
114
171
|
/**
|
|
115
172
|
* Event handlers for specific event types
|
|
116
173
|
*/
|
|
@@ -121,7 +178,7 @@ export interface System<ComponentTypes extends Record<string, any> = {}, WithCom
|
|
|
121
178
|
* @param data The event data specific to this event type
|
|
122
179
|
* @param ecs The ECSpresso instance providing access to all ECS functionality
|
|
123
180
|
*/
|
|
124
|
-
handler(data: EventTypes[EventName], ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes>): void;
|
|
181
|
+
handler(data: EventTypes[EventName], ecs: ECSpresso<ComponentTypes, EventTypes, ResourceTypes, AssetTypes, ScreenStates>): void;
|
|
125
182
|
};
|
|
126
183
|
};
|
|
127
184
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecspresso",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"description": "A minimal Entity-Component-System library for typescript and javascript.",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./bundles/renderers/pixi": {
|
|
15
|
+
"import": "./dist/bundles/renderers/pixi.js",
|
|
16
|
+
"types": "./dist/bundles/renderers/pixi.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./bundles/utils/timers": {
|
|
19
|
+
"import": "./dist/bundles/utils/timers.js",
|
|
20
|
+
"types": "./dist/bundles/utils/timers.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
9
23
|
"publishConfig": {
|
|
10
24
|
"registry": "https://npm.pkg.github.com/"
|
|
11
25
|
},
|
|
@@ -30,7 +44,13 @@
|
|
|
30
44
|
"three": "^0.180.0"
|
|
31
45
|
},
|
|
32
46
|
"peerDependencies": {
|
|
33
|
-
"typescript": "^5.9.2"
|
|
47
|
+
"typescript": "^5.9.2",
|
|
48
|
+
"pixi.js": "^8.0.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"pixi.js": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
34
54
|
},
|
|
35
55
|
"files": [
|
|
36
56
|
"dist"
|
|
@@ -38,7 +58,7 @@
|
|
|
38
58
|
"scripts": {
|
|
39
59
|
"build:clean": "rm -rf dist",
|
|
40
60
|
"build:ts": "bun tsc -p tsconfig.build.json",
|
|
41
|
-
"build:js": "bun build --target=browser --sourcemap=linked --minify --outdir=dist src/index.ts",
|
|
61
|
+
"build:js": "bun build --target=browser --sourcemap=linked --minify --external=pixi.js --outdir=dist src/index.ts src/bundles/renderers/pixi.ts src/bundles/utils/timers.ts",
|
|
42
62
|
"build": "bun build:clean && bun build:ts && bun build:js",
|
|
43
63
|
"check:types": "bun tsc --noEmit --skipLibCheck",
|
|
44
64
|
"check": "bun run check:types && bun test",
|