ecspresso 0.10.2 → 0.12.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 +256 -148
- package/dist/asset-manager.d.ts +16 -16
- package/dist/asset-types.d.ts +18 -16
- package/dist/command-buffer.d.ts +30 -20
- package/dist/ecspresso-builder.d.ts +193 -0
- package/dist/ecspresso.d.ts +323 -209
- package/dist/entity-manager.d.ts +76 -30
- package/dist/event-bus.d.ts +6 -1
- package/dist/index.d.ts +6 -13
- package/dist/plugin.d.ts +61 -0
- package/dist/plugins/audio.d.ts +273 -0
- package/dist/{bundles/utils → plugins}/bounds.d.ts +20 -26
- package/dist/plugins/camera.d.ts +88 -0
- package/dist/plugins/collision.d.ts +285 -0
- package/dist/plugins/coroutine.d.ts +126 -0
- package/dist/plugins/diagnostics.d.ts +49 -0
- package/dist/{bundles/utils → plugins}/input.d.ts +22 -29
- package/dist/plugins/particles.d.ts +225 -0
- package/dist/plugins/physics2D.d.ts +163 -0
- package/dist/plugins/renderers/renderer2D.d.ts +262 -0
- package/dist/plugins/spatial-index.d.ts +58 -0
- package/dist/plugins/sprite-animation.d.ts +150 -0
- package/dist/plugins/state-machine.d.ts +244 -0
- package/dist/plugins/timers.d.ts +151 -0
- package/dist/{bundles/utils → plugins}/transform.d.ts +21 -22
- package/dist/plugins/tween.d.ts +162 -0
- package/dist/reactive-query-manager.d.ts +14 -3
- package/dist/resource-manager.d.ts +64 -23
- package/dist/screen-manager.d.ts +21 -15
- package/dist/screen-types.d.ts +15 -11
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +25 -0
- package/dist/src/plugins/audio.js +4 -0
- package/dist/src/plugins/audio.js.map +10 -0
- package/dist/src/plugins/bounds.js +4 -0
- package/dist/src/plugins/bounds.js.map +10 -0
- package/dist/src/plugins/camera.js +4 -0
- package/dist/src/plugins/camera.js.map +10 -0
- package/dist/src/plugins/collision.js +4 -0
- package/dist/src/plugins/collision.js.map +11 -0
- package/dist/src/plugins/coroutine.js +4 -0
- package/dist/src/plugins/coroutine.js.map +10 -0
- package/dist/src/plugins/diagnostics.js +5 -0
- package/dist/src/plugins/diagnostics.js.map +10 -0
- package/dist/src/plugins/input.js +4 -0
- package/dist/src/plugins/input.js.map +10 -0
- package/dist/src/plugins/particles.js +4 -0
- package/dist/src/plugins/particles.js.map +10 -0
- package/dist/src/plugins/physics2D.js +4 -0
- package/dist/src/plugins/physics2D.js.map +11 -0
- package/dist/src/plugins/renderers/renderer2D.js +4 -0
- package/dist/src/plugins/renderers/renderer2D.js.map +10 -0
- package/dist/src/plugins/spatial-index.js +4 -0
- package/dist/src/plugins/spatial-index.js.map +11 -0
- package/dist/src/plugins/sprite-animation.js +4 -0
- package/dist/src/plugins/sprite-animation.js.map +10 -0
- package/dist/src/plugins/state-machine.js +4 -0
- package/dist/src/plugins/state-machine.js.map +10 -0
- package/dist/src/plugins/timers.js +4 -0
- package/dist/src/plugins/timers.js.map +10 -0
- package/dist/src/plugins/transform.js +4 -0
- package/dist/src/plugins/transform.js.map +10 -0
- package/dist/src/plugins/tween.js +4 -0
- package/dist/src/plugins/tween.js.map +11 -0
- package/dist/system-builder.d.ts +75 -112
- package/dist/type-utils.d.ts +247 -7
- package/dist/types.d.ts +58 -39
- package/dist/utils/check-required-cycle.d.ts +12 -0
- package/dist/utils/easing.d.ts +71 -0
- package/dist/utils/math.d.ts +67 -0
- package/dist/utils/narrowphase.d.ts +63 -0
- package/dist/utils/spatial-hash.d.ts +53 -0
- package/package.json +65 -27
- package/dist/bundle.d.ts +0 -123
- package/dist/bundles/renderers/renderer2D.d.ts +0 -220
- package/dist/bundles/renderers/renderer2D.js +0 -4
- package/dist/bundles/renderers/renderer2D.js.map +0 -10
- package/dist/bundles/utils/bounds.js +0 -4
- package/dist/bundles/utils/bounds.js.map +0 -10
- package/dist/bundles/utils/collision.d.ts +0 -204
- package/dist/bundles/utils/collision.js +0 -4
- package/dist/bundles/utils/collision.js.map +0 -10
- package/dist/bundles/utils/input.js +0 -4
- package/dist/bundles/utils/input.js.map +0 -10
- package/dist/bundles/utils/movement.d.ts +0 -86
- package/dist/bundles/utils/movement.js +0 -4
- package/dist/bundles/utils/movement.js.map +0 -10
- package/dist/bundles/utils/timers.d.ts +0 -172
- package/dist/bundles/utils/timers.js +0 -4
- package/dist/bundles/utils/timers.js.map +0 -10
- package/dist/bundles/utils/transform.js +0 -4
- package/dist/bundles/utils/transform.js.map +0 -10
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -22
package/dist/asset-manager.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { AssetStatus, AssetDefinition, AssetHandle, AssetsResource, AssetEv
|
|
|
6
6
|
/**
|
|
7
7
|
* Manages asset loading and access for ECSpresso
|
|
8
8
|
*/
|
|
9
|
-
export default class AssetManager<AssetTypes extends Record<string, unknown> = Record<string, never
|
|
9
|
+
export default class AssetManager<AssetTypes extends Record<string, unknown> = Record<string, never>, AssetGroupNames extends string = string> {
|
|
10
10
|
private readonly assets;
|
|
11
11
|
private readonly groups;
|
|
12
12
|
private eventBus;
|
|
@@ -14,7 +14,7 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
14
14
|
* Set the event bus for asset events
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
|
-
setEventBus(eventBus: EventBus<AssetEvents
|
|
17
|
+
setEventBus(eventBus: EventBus<AssetEvents<keyof AssetTypes & string, AssetGroupNames>>): void;
|
|
18
18
|
/**
|
|
19
19
|
* Register an asset definition
|
|
20
20
|
*/
|
|
@@ -30,7 +30,7 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
30
30
|
/**
|
|
31
31
|
* Load all assets in a group
|
|
32
32
|
*/
|
|
33
|
-
loadAssetGroup(groupName:
|
|
33
|
+
loadAssetGroup(groupName: AssetGroupNames): Promise<void>;
|
|
34
34
|
/**
|
|
35
35
|
* Get a loaded asset. Throws if not loaded.
|
|
36
36
|
*/
|
|
@@ -38,7 +38,7 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
38
38
|
/**
|
|
39
39
|
* Get a loaded asset or undefined
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
tryGet<K extends keyof AssetTypes>(key: K): AssetTypes[K] | undefined;
|
|
42
42
|
/**
|
|
43
43
|
* Get a handle to an asset with status information
|
|
44
44
|
*/
|
|
@@ -54,15 +54,15 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
54
54
|
/**
|
|
55
55
|
* Check if all assets in a group are loaded
|
|
56
56
|
*/
|
|
57
|
-
isGroupLoaded(groupName:
|
|
57
|
+
isGroupLoaded(groupName: AssetGroupNames): boolean;
|
|
58
58
|
/**
|
|
59
59
|
* Get the loading progress of a group (0-1)
|
|
60
60
|
*/
|
|
61
|
-
getGroupProgress(groupName:
|
|
61
|
+
getGroupProgress(groupName: AssetGroupNames): number;
|
|
62
62
|
/**
|
|
63
63
|
* Get detailed group progress
|
|
64
64
|
*/
|
|
65
|
-
getGroupProgressDetails(groupName:
|
|
65
|
+
getGroupProgressDetails(groupName: AssetGroupNames): {
|
|
66
66
|
loaded: number;
|
|
67
67
|
total: number;
|
|
68
68
|
progress: number;
|
|
@@ -74,7 +74,7 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
74
74
|
/**
|
|
75
75
|
* Create the $assets resource object
|
|
76
76
|
*/
|
|
77
|
-
createResource(): AssetsResource<AssetTypes>;
|
|
77
|
+
createResource(): AssetsResource<AssetTypes, AssetGroupNames>;
|
|
78
78
|
/**
|
|
79
79
|
* Get all registered asset keys
|
|
80
80
|
*/
|
|
@@ -91,21 +91,21 @@ export default class AssetManager<AssetTypes extends Record<string, unknown> = R
|
|
|
91
91
|
/**
|
|
92
92
|
* Implementation of AssetConfigurator for builder pattern
|
|
93
93
|
*/
|
|
94
|
-
export declare class AssetConfiguratorImpl<A extends Record<string, unknown
|
|
94
|
+
export declare class AssetConfiguratorImpl<A extends Record<string, unknown>, G extends string = never> implements AssetConfigurator<A, G> {
|
|
95
95
|
private readonly manager;
|
|
96
|
-
constructor(manager: AssetManager<A>);
|
|
97
|
-
add<K extends string, T>(key: K, loader: () => Promise<T>): AssetConfigurator<A & Record<K, T
|
|
98
|
-
addWithConfig<K extends string, T>(key: K, definition: AssetDefinition<T>): AssetConfigurator<A & Record<K, T
|
|
99
|
-
addGroup<
|
|
96
|
+
constructor(manager: AssetManager<A, G>);
|
|
97
|
+
add<K extends string, T>(key: K, loader: () => Promise<T>): AssetConfigurator<A & Record<K, T>, G>;
|
|
98
|
+
addWithConfig<K extends string, T>(key: K, definition: AssetDefinition<T>): AssetConfigurator<A & Record<K, T>, G>;
|
|
99
|
+
addGroup<GN extends string, T extends Record<string, () => Promise<unknown>>>(groupName: GN, assets: T): AssetConfigurator<A & {
|
|
100
100
|
[K in keyof T]: Awaited<ReturnType<T[K]>>;
|
|
101
|
-
}>;
|
|
101
|
+
}, G | GN>;
|
|
102
102
|
/**
|
|
103
103
|
* Get the underlying manager
|
|
104
104
|
* @internal
|
|
105
105
|
*/
|
|
106
|
-
getManager(): AssetManager<A>;
|
|
106
|
+
getManager(): AssetManager<A, G>;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Create a new AssetConfigurator for builder pattern usage
|
|
110
110
|
*/
|
|
111
|
-
export declare function createAssetConfigurator<A extends Record<string, unknown> = Record<string, never
|
|
111
|
+
export declare function createAssetConfigurator<A extends Record<string, unknown> = Record<string, never>, G extends string = never>(manager?: AssetManager<A, G>): AssetConfiguratorImpl<A, G>;
|
package/dist/asset-types.d.ts
CHANGED
|
@@ -26,13 +26,13 @@ export interface AssetHandle<T> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Get the asset value if loaded, undefined otherwise.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
tryGet(): T | undefined;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Resource interface for accessing assets in systems
|
|
33
33
|
* Exposed as $assets resource
|
|
34
34
|
*/
|
|
35
|
-
export interface AssetsResource<A extends Record<string, unknown
|
|
35
|
+
export interface AssetsResource<A extends Record<string, unknown>, G extends string = string> {
|
|
36
36
|
/**
|
|
37
37
|
* Get the loading status of an asset
|
|
38
38
|
*/
|
|
@@ -44,11 +44,11 @@ export interface AssetsResource<A extends Record<string, unknown>> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Check if all assets in a group are loaded
|
|
46
46
|
*/
|
|
47
|
-
isGroupLoaded(groupName:
|
|
47
|
+
isGroupLoaded(groupName: G): boolean;
|
|
48
48
|
/**
|
|
49
49
|
* Get the loading progress of a group (0-1)
|
|
50
50
|
*/
|
|
51
|
-
getGroupProgress(groupName:
|
|
51
|
+
getGroupProgress(groupName: G): number;
|
|
52
52
|
/**
|
|
53
53
|
* Get a loaded asset. Throws if not loaded.
|
|
54
54
|
*/
|
|
@@ -56,28 +56,30 @@ export interface AssetsResource<A extends Record<string, unknown>> {
|
|
|
56
56
|
/**
|
|
57
57
|
* Get a loaded asset or undefined if not loaded
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
tryGet<K extends keyof A>(key: K): A[K] | undefined;
|
|
60
60
|
/**
|
|
61
61
|
* Get a handle to an asset with status information
|
|
62
62
|
*/
|
|
63
63
|
getHandle<K extends keyof A>(key: K): AssetHandle<A[K]>;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Events emitted by the asset system
|
|
66
|
+
* Events emitted by the asset system.
|
|
67
|
+
* @typeParam K - Asset key type (defaults to `string` for backward compatibility)
|
|
68
|
+
* @typeParam G - Asset group name type (defaults to `string` for backward compatibility)
|
|
67
69
|
*/
|
|
68
|
-
export interface AssetEvents {
|
|
70
|
+
export interface AssetEvents<K extends string = string, G extends string = string> {
|
|
69
71
|
assetLoaded: {
|
|
70
|
-
key:
|
|
72
|
+
key: K;
|
|
71
73
|
};
|
|
72
74
|
assetFailed: {
|
|
73
|
-
key:
|
|
75
|
+
key: K;
|
|
74
76
|
error: Error;
|
|
75
77
|
};
|
|
76
78
|
assetGroupLoaded: {
|
|
77
|
-
group:
|
|
79
|
+
group: G;
|
|
78
80
|
};
|
|
79
81
|
assetGroupProgress: {
|
|
80
|
-
group:
|
|
82
|
+
group: G;
|
|
81
83
|
progress: number;
|
|
82
84
|
loaded: number;
|
|
83
85
|
total: number;
|
|
@@ -86,19 +88,19 @@ export interface AssetEvents {
|
|
|
86
88
|
/**
|
|
87
89
|
* Configuration for asset definitions during builder setup
|
|
88
90
|
*/
|
|
89
|
-
export interface AssetConfigurator<A extends Record<string, unknown
|
|
91
|
+
export interface AssetConfigurator<A extends Record<string, unknown>, G extends string = never> {
|
|
90
92
|
/**
|
|
91
93
|
* Add a single eager asset
|
|
92
94
|
*/
|
|
93
|
-
add<K extends string, T>(key: K, loader: () => Promise<T>): AssetConfigurator<A & Record<K, T
|
|
95
|
+
add<K extends string, T>(key: K, loader: () => Promise<T>): AssetConfigurator<A & Record<K, T>, G>;
|
|
94
96
|
/**
|
|
95
97
|
* Add a single asset with full configuration
|
|
96
98
|
*/
|
|
97
|
-
addWithConfig<K extends string, T>(key: K, definition: AssetDefinition<T>): AssetConfigurator<A & Record<K, T
|
|
99
|
+
addWithConfig<K extends string, T>(key: K, definition: AssetDefinition<T>): AssetConfigurator<A & Record<K, T>, G>;
|
|
98
100
|
/**
|
|
99
101
|
* Add a group of assets that can be loaded together
|
|
100
102
|
*/
|
|
101
|
-
addGroup<
|
|
103
|
+
addGroup<GN extends string, T extends Record<string, () => Promise<unknown>>>(groupName: GN, assets: T): AssetConfigurator<A & {
|
|
102
104
|
[K in keyof T]: Awaited<ReturnType<T[K]>>;
|
|
103
|
-
}>;
|
|
105
|
+
}, G | GN>;
|
|
104
106
|
}
|
package/dist/command-buffer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type ECSpresso from './ecspresso';
|
|
2
2
|
import type { RemoveEntityOptions } from './types';
|
|
3
|
+
import type { WorldConfig, EmptyConfig } from './type-utils';
|
|
3
4
|
/**
|
|
4
5
|
* CommandBuffer queues structural changes to be executed later.
|
|
5
6
|
* This prevents ordering issues when modifying entities during system execution.
|
|
@@ -16,66 +17,75 @@ import type { RemoveEntityOptions } from './types';
|
|
|
16
17
|
* ecs.commands.playback(ecs);
|
|
17
18
|
* ```
|
|
18
19
|
*/
|
|
19
|
-
export default class CommandBuffer<
|
|
20
|
+
export default class CommandBuffer<Cfg extends WorldConfig = EmptyConfig> {
|
|
20
21
|
private commands;
|
|
21
22
|
/**
|
|
22
23
|
* Queue an entity removal command
|
|
23
|
-
* @param entityId The ID
|
|
24
|
+
* @param entityId The entity ID to remove
|
|
24
25
|
* @param options Optional removal options (cascade, etc.)
|
|
25
26
|
*/
|
|
26
27
|
removeEntity(entityId: number, options?: RemoveEntityOptions): void;
|
|
27
28
|
/**
|
|
28
29
|
* Queue a component addition command
|
|
29
|
-
* @param entityId The ID
|
|
30
|
+
* @param entityId The entity ID
|
|
30
31
|
* @param componentName The name of the component to add
|
|
31
32
|
* @param componentValue The component data
|
|
32
33
|
*/
|
|
33
|
-
addComponent<K extends keyof
|
|
34
|
+
addComponent<K extends keyof Cfg['components']>(entityId: number, componentName: K, componentValue: Cfg['components'][K]): void;
|
|
34
35
|
/**
|
|
35
36
|
* Queue a component removal command
|
|
36
|
-
* @param entityId The ID
|
|
37
|
+
* @param entityId The entity ID
|
|
37
38
|
* @param componentName The name of the component to remove
|
|
38
39
|
*/
|
|
39
|
-
removeComponent<K extends keyof
|
|
40
|
+
removeComponent<K extends keyof Cfg['components']>(entityId: number, componentName: K): void;
|
|
40
41
|
/**
|
|
41
42
|
* Queue an entity spawn command
|
|
42
43
|
* @param components The initial components for the new entity
|
|
43
44
|
* @returns void (entity ID not available until playback)
|
|
44
45
|
*/
|
|
45
46
|
spawn<T extends {
|
|
46
|
-
[K in keyof
|
|
47
|
-
}>(components: T & Record<Exclude<keyof T, keyof
|
|
47
|
+
[K in keyof Cfg['components']]?: Cfg['components'][K];
|
|
48
|
+
}>(components: T & Record<Exclude<keyof T, keyof Cfg['components']>, never>): void;
|
|
48
49
|
/**
|
|
49
50
|
* Queue a child entity spawn command
|
|
50
|
-
* @param parentId The
|
|
51
|
+
* @param parentId The parent entity ID
|
|
51
52
|
* @param components The initial components for the new child entity
|
|
52
53
|
*/
|
|
53
54
|
spawnChild<T extends {
|
|
54
|
-
[K in keyof
|
|
55
|
-
}>(parentId: number, components: T & Record<Exclude<keyof T, keyof
|
|
55
|
+
[K in keyof Cfg['components']]?: Cfg['components'][K];
|
|
56
|
+
}>(parentId: number, components: T & Record<Exclude<keyof T, keyof Cfg['components']>, never>): void;
|
|
56
57
|
/**
|
|
57
58
|
* Queue multiple component additions
|
|
58
|
-
* @param entityId The ID
|
|
59
|
+
* @param entityId The entity ID
|
|
59
60
|
* @param components Object with component names as keys and component data as values
|
|
60
61
|
*/
|
|
61
62
|
addComponents<T extends {
|
|
62
|
-
[K in keyof
|
|
63
|
-
}>(entityId: number, components: T & Record<Exclude<keyof T, keyof
|
|
63
|
+
[K in keyof Cfg['components']]?: Cfg['components'][K];
|
|
64
|
+
}>(entityId: number, components: T & Record<Exclude<keyof T, keyof Cfg['components']>, never>): void;
|
|
64
65
|
/**
|
|
65
66
|
* Queue a parent assignment command
|
|
66
|
-
* @param childId The
|
|
67
|
-
* @param parentId The
|
|
67
|
+
* @param childId The child entity ID
|
|
68
|
+
* @param parentId The parent entity ID
|
|
68
69
|
*/
|
|
69
70
|
setParent(childId: number, parentId: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Queue a component mutation command.
|
|
73
|
+
* The mutator runs during playback, receiving the component for in-place mutation.
|
|
74
|
+
* Automatically marks the component as changed.
|
|
75
|
+
* @param entityId The entity ID
|
|
76
|
+
* @param componentName The component to mutate
|
|
77
|
+
* @param mutator A function that receives the component value for in-place mutation
|
|
78
|
+
*/
|
|
79
|
+
mutateComponent<K extends keyof Cfg['components']>(entityId: number, componentName: K, mutator: (value: Cfg['components'][K]) => void): void;
|
|
70
80
|
/**
|
|
71
81
|
* Queue a markChanged command
|
|
72
|
-
* @param entityId The ID
|
|
82
|
+
* @param entityId The entity ID
|
|
73
83
|
* @param componentName The component to mark as changed
|
|
74
84
|
*/
|
|
75
|
-
markChanged<K extends keyof
|
|
85
|
+
markChanged<K extends keyof Cfg['components']>(entityId: number, componentName: K): void;
|
|
76
86
|
/**
|
|
77
87
|
* Queue a parent removal command
|
|
78
|
-
* @param childId The
|
|
88
|
+
* @param childId The child entity ID
|
|
79
89
|
*/
|
|
80
90
|
removeParent(childId: number): void;
|
|
81
91
|
/**
|
|
@@ -83,7 +93,7 @@ export default class CommandBuffer<ComponentTypes extends Record<string, any> =
|
|
|
83
93
|
* Errors from individual commands are caught and logged, but do not stop playback.
|
|
84
94
|
* @param ecs The ECSpresso instance to execute commands on
|
|
85
95
|
*/
|
|
86
|
-
playback
|
|
96
|
+
playback(ecs: ECSpresso<Cfg>): void;
|
|
87
97
|
/**
|
|
88
98
|
* Clear all queued commands without executing them
|
|
89
99
|
*/
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type ECSpresso from "./ecspresso";
|
|
2
|
+
import type { ResourceFactoryWithDeps, ResourceDirectValue } from "./resource-manager";
|
|
3
|
+
import { type Plugin } from "./plugin";
|
|
4
|
+
import type { WorldConfig, EmptyConfig, ConfigsAreCompatible, MergeConfigs, TypesAreCompatible, RequirementsSatisfied, WithComponents, WithEvents, WithResources } from "./type-utils";
|
|
5
|
+
import type { AssetConfigurator, AssetsResource } from "./asset-types";
|
|
6
|
+
import type { ScreenDefinition, ScreenConfigurator, ScreenResource } from "./screen-types";
|
|
7
|
+
/**
|
|
8
|
+
* Helper type: finalize built-in resources ($assets, $screen) in the resource map.
|
|
9
|
+
* Auto-injects $assets/$screen when plugins contribute asset/screen types even without
|
|
10
|
+
* explicit withAssets()/withScreens(). Also narrows the AssetGroupNames on $assets.
|
|
11
|
+
*/
|
|
12
|
+
type FinalizeBuiltinResources<Cfg extends WorldConfig, AG extends string> = {
|
|
13
|
+
readonly components: Cfg['components'];
|
|
14
|
+
readonly events: Cfg['events'];
|
|
15
|
+
readonly resources: Omit<Cfg['resources'], '$assets' | '$screen'> & ([keyof Cfg['assets']] extends [never] ? {} : {
|
|
16
|
+
$assets: AssetsResource<Cfg['assets'], AG>;
|
|
17
|
+
}) & ([keyof Cfg['screens']] extends [never] ? {} : {
|
|
18
|
+
$screen: ScreenResource<Cfg['screens']>;
|
|
19
|
+
});
|
|
20
|
+
readonly assets: Cfg['assets'];
|
|
21
|
+
readonly screens: Cfg['screens'];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Builder class for ECSpresso that provides fluent type-safe plugin installation.
|
|
25
|
+
* Handles type checking during build process to ensure type safety.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ECSpressoBuilder<Cfg extends WorldConfig = EmptyConfig, Labels extends string = never, Groups extends string = never, AssetGroupNames extends string = never, ReactiveQueryNames extends string = never> {
|
|
28
|
+
/** The ECSpresso instance being built*/
|
|
29
|
+
private ecspresso;
|
|
30
|
+
/** Asset configurator for collecting asset definitions */
|
|
31
|
+
private assetConfigurator;
|
|
32
|
+
/** Screen configurator for collecting screen definitions */
|
|
33
|
+
private screenConfigurator;
|
|
34
|
+
/** Pending resources to add during build */
|
|
35
|
+
private pendingResources;
|
|
36
|
+
/** Pending dispose callbacks to register during build */
|
|
37
|
+
private pendingDisposeCallbacks;
|
|
38
|
+
/** Pending required component registrations to apply during build */
|
|
39
|
+
private pendingRequiredComponents;
|
|
40
|
+
/** Pending plugins to install during build */
|
|
41
|
+
private pendingPlugins;
|
|
42
|
+
/** Fixed timestep interval (null means use default 1/60) */
|
|
43
|
+
private _fixedDt;
|
|
44
|
+
constructor();
|
|
45
|
+
/**
|
|
46
|
+
* Add the first plugin when starting with empty types.
|
|
47
|
+
* This overload allows any plugin to be added to an empty ECSpresso instance.
|
|
48
|
+
* Only merges the plugin's Provides (PCfg) into accumulated config, not its Requires (PReq).
|
|
49
|
+
*/
|
|
50
|
+
withPlugin<PCfg extends WorldConfig, PReq extends WorldConfig = EmptyConfig, BL extends string = never, BG extends string = never, BAG extends string = never, BRQ extends string = never>(this: ECSpressoBuilder<{
|
|
51
|
+
readonly components: {};
|
|
52
|
+
readonly events: {};
|
|
53
|
+
readonly resources: {};
|
|
54
|
+
readonly assets: Cfg['assets'];
|
|
55
|
+
readonly screens: Cfg['screens'];
|
|
56
|
+
}, Labels, Groups, AssetGroupNames, ReactiveQueryNames>, plugin: Plugin<PCfg, PReq, BL, BG, BAG, BRQ>): ECSpressoBuilder<{
|
|
57
|
+
readonly components: PCfg['components'];
|
|
58
|
+
readonly events: PCfg['events'];
|
|
59
|
+
readonly resources: PCfg['resources'];
|
|
60
|
+
readonly assets: Cfg['assets'] & PCfg['assets'];
|
|
61
|
+
readonly screens: Cfg['screens'] & PCfg['screens'];
|
|
62
|
+
}, Labels | BL, Groups | BG, AssetGroupNames | BAG, ReactiveQueryNames | BRQ>;
|
|
63
|
+
/**
|
|
64
|
+
* Add a subsequent plugin with type checking.
|
|
65
|
+
* This overload enforces plugin type compatibility and requirement satisfaction.
|
|
66
|
+
* Only merges the plugin's Provides (PCfg) into accumulated config, not its Requires (PReq).
|
|
67
|
+
*/
|
|
68
|
+
withPlugin<PCfg extends WorldConfig, PReq extends WorldConfig = EmptyConfig, BL extends string = never, BG extends string = never, BAG extends string = never, BRQ extends string = never>(plugin: ConfigsAreCompatible<Cfg, PCfg> extends true ? RequirementsSatisfied<Cfg, PReq> extends true ? Plugin<PCfg, PReq, BL, BG, BAG, BRQ> : never : never): ECSpressoBuilder<MergeConfigs<Cfg, PCfg>, Labels | BL, Groups | BG, AssetGroupNames | BAG, ReactiveQueryNames | BRQ>;
|
|
69
|
+
/**
|
|
70
|
+
* Add application-specific component types to the builder chain.
|
|
71
|
+
* This is a pure type-level operation with no runtime cost.
|
|
72
|
+
* Conflicts with existing component types (same key, different type) produce a `never` return.
|
|
73
|
+
*/
|
|
74
|
+
withComponentTypes<T extends Record<string, any>>(): TypesAreCompatible<Cfg['components'], T> extends true ? ECSpressoBuilder<WithComponents<Cfg, T>, Labels, Groups, AssetGroupNames, ReactiveQueryNames> : never;
|
|
75
|
+
/**
|
|
76
|
+
* Add application-specific event types to the builder chain.
|
|
77
|
+
* This is a pure type-level operation with no runtime cost.
|
|
78
|
+
* Conflicts with existing event types (same key, different type) produce a `never` return.
|
|
79
|
+
*/
|
|
80
|
+
withEventTypes<T extends Record<string, any>>(): TypesAreCompatible<Cfg['events'], T> extends true ? ECSpressoBuilder<WithEvents<Cfg, T>, Labels, Groups, AssetGroupNames, ReactiveQueryNames> : never;
|
|
81
|
+
/**
|
|
82
|
+
* Add application-specific resource types to the builder chain.
|
|
83
|
+
* This is a pure type-level operation with no runtime cost.
|
|
84
|
+
* Conflicts with existing resource types (same key, different type) produce a `never` return.
|
|
85
|
+
*/
|
|
86
|
+
withResourceTypes<T extends Record<string, any>>(): TypesAreCompatible<Cfg['resources'], T> extends true ? ECSpressoBuilder<WithResources<Cfg, T>, Labels, Groups, AssetGroupNames, ReactiveQueryNames> : never;
|
|
87
|
+
/**
|
|
88
|
+
* Add a resource during ECSpresso construction.
|
|
89
|
+
*
|
|
90
|
+
* When the key matches a pre-declared resource type (via `withResourceTypes`, `create<C,E,R>()`,
|
|
91
|
+
* or plugin resources), the value is validated against that type.
|
|
92
|
+
* For new keys, the value type is inferred as before.
|
|
93
|
+
*
|
|
94
|
+
* @param key The resource key
|
|
95
|
+
* @param resource The resource value, factory function, or factory with dependencies/disposal
|
|
96
|
+
* @returns This builder with updated resource types
|
|
97
|
+
*/
|
|
98
|
+
withResource<K extends keyof Cfg['resources'] & string>(key: K, resource: Cfg['resources'][K] | ((context: ECSpresso<Cfg>) => Cfg['resources'][K] | Promise<Cfg['resources'][K]>) | ResourceFactoryWithDeps<Cfg['resources'][K], ECSpresso<Cfg>, keyof Cfg['resources'] & string> | ResourceDirectValue<Cfg['resources'][K]>): ECSpressoBuilder<Cfg, Labels, Groups, AssetGroupNames, ReactiveQueryNames>;
|
|
99
|
+
withResource<K extends string, V>(key: K & ([K] extends [keyof Cfg['resources']] ? [V] extends [Cfg['resources'][K & keyof Cfg['resources']]] ? string : never : string), resource: V | ((context: ECSpresso<WithResources<Cfg, Record<K, V>>>) => V | Promise<V>) | ResourceFactoryWithDeps<V, ECSpresso<WithResources<Cfg, Record<K, V>>>, keyof (Cfg['resources'] & Record<K, V>) & string> | ResourceDirectValue<V>): ECSpressoBuilder<WithResources<Cfg, Record<K, V>>, Labels, Groups, AssetGroupNames, ReactiveQueryNames>;
|
|
100
|
+
/**
|
|
101
|
+
* Register a dispose callback for a component type during build.
|
|
102
|
+
* Called when a component is removed (explicit removal, entity destruction, or replacement).
|
|
103
|
+
* @param componentName The component type to register disposal for
|
|
104
|
+
* @param callback Function receiving the component value being disposed
|
|
105
|
+
* @returns This builder for method chaining
|
|
106
|
+
*/
|
|
107
|
+
withDispose<K extends keyof Cfg['components'] & string>(componentName: K, callback: (ctx: {
|
|
108
|
+
value: Cfg['components'][K];
|
|
109
|
+
entityId: number;
|
|
110
|
+
}) => void): this;
|
|
111
|
+
/**
|
|
112
|
+
* Register a required component relationship during build.
|
|
113
|
+
* When an entity gains `trigger`, the `required` component is auto-added
|
|
114
|
+
* (using `factory` for the default value) if not already present.
|
|
115
|
+
* @param trigger The component whose presence triggers auto-addition
|
|
116
|
+
* @param required The component to auto-add
|
|
117
|
+
* @param factory Function that creates the default value for the required component
|
|
118
|
+
* @returns This builder for method chaining
|
|
119
|
+
*/
|
|
120
|
+
withRequired<Trigger extends keyof Cfg['components'] & string, Required extends keyof Cfg['components'] & string>(trigger: Trigger, required: Required, factory: (triggerValue: Cfg['components'][Trigger]) => Cfg['components'][Required]): this;
|
|
121
|
+
/**
|
|
122
|
+
* Configure assets for this ECSpresso instance
|
|
123
|
+
* @param configurator Function that receives an AssetConfigurator and returns it after adding assets
|
|
124
|
+
* @returns This builder with updated asset types
|
|
125
|
+
*/
|
|
126
|
+
withAssets<NewA extends Record<string, unknown>, NewG extends string = never>(configurator: (assets: AssetConfigurator<{}, never>) => AssetConfigurator<NewA, NewG>): ECSpressoBuilder<{
|
|
127
|
+
readonly components: Cfg['components'];
|
|
128
|
+
readonly events: Cfg['events'];
|
|
129
|
+
readonly resources: Cfg['resources'] & {
|
|
130
|
+
$assets: AssetsResource<Cfg['assets'] & NewA, string>;
|
|
131
|
+
};
|
|
132
|
+
readonly assets: Cfg['assets'] & NewA;
|
|
133
|
+
readonly screens: Cfg['screens'];
|
|
134
|
+
}, Labels, Groups, AssetGroupNames | NewG, ReactiveQueryNames>;
|
|
135
|
+
/**
|
|
136
|
+
* Configure screens for this ECSpresso instance
|
|
137
|
+
* @param configurator Function that receives a ScreenConfigurator and returns it after adding screens
|
|
138
|
+
* @returns This builder with updated screen types
|
|
139
|
+
*/
|
|
140
|
+
withScreens<NewS extends Record<string, ScreenDefinition<any, any>>>(configurator: (screens: ScreenConfigurator<{}, ECSpresso<{
|
|
141
|
+
readonly components: Cfg['components'];
|
|
142
|
+
readonly events: Cfg['events'];
|
|
143
|
+
readonly resources: Cfg['resources'];
|
|
144
|
+
readonly assets: Cfg['assets'];
|
|
145
|
+
readonly screens: Record<string, ScreenDefinition>;
|
|
146
|
+
}>>) => ScreenConfigurator<NewS, ECSpresso<{
|
|
147
|
+
readonly components: Cfg['components'];
|
|
148
|
+
readonly events: Cfg['events'];
|
|
149
|
+
readonly resources: Cfg['resources'];
|
|
150
|
+
readonly assets: Cfg['assets'];
|
|
151
|
+
readonly screens: Record<string, ScreenDefinition>;
|
|
152
|
+
}>>): ECSpressoBuilder<{
|
|
153
|
+
readonly components: Cfg['components'];
|
|
154
|
+
readonly events: Cfg['events'];
|
|
155
|
+
readonly resources: Cfg['resources'] & {
|
|
156
|
+
$screen: ScreenResource<Cfg['screens'] & NewS>;
|
|
157
|
+
};
|
|
158
|
+
readonly assets: Cfg['assets'];
|
|
159
|
+
readonly screens: Cfg['screens'] & NewS;
|
|
160
|
+
}, Labels, Groups, AssetGroupNames, ReactiveQueryNames>;
|
|
161
|
+
/**
|
|
162
|
+
* Configure the fixed timestep interval for the fixedUpdate phase.
|
|
163
|
+
* @param dt The fixed timestep in seconds (e.g., 1/60 for 60Hz physics)
|
|
164
|
+
* @returns This builder for method chaining
|
|
165
|
+
*/
|
|
166
|
+
withFixedTimestep(dt: number): this;
|
|
167
|
+
/**
|
|
168
|
+
* Declare reactive query names that will be registered at runtime.
|
|
169
|
+
* This is a pure type-level operation with no runtime cost.
|
|
170
|
+
*/
|
|
171
|
+
withReactiveQueryNames<N extends string>(): ECSpressoBuilder<Cfg, Labels, Groups, AssetGroupNames, ReactiveQueryNames | N>;
|
|
172
|
+
/**
|
|
173
|
+
* Create a plugin factory from the builder's accumulated types.
|
|
174
|
+
* Returns a definePlugin equivalent with no manual type parameters.
|
|
175
|
+
*/
|
|
176
|
+
pluginFactory(): <PL extends string = never, PG extends string = never, PAG extends string = never, PRQ extends string = never>(config: {
|
|
177
|
+
id: string;
|
|
178
|
+
install: (world: ECSpresso<Cfg>) => void;
|
|
179
|
+
}) => Plugin<Cfg, EmptyConfig, PL, PG, PAG, PRQ>;
|
|
180
|
+
/**
|
|
181
|
+
* Complete the build process and return the built ECSpresso instance
|
|
182
|
+
*/
|
|
183
|
+
build(): ECSpresso<FinalizeBuiltinResources<Cfg, [AssetGroupNames] extends [never] ? string : AssetGroupNames>, [
|
|
184
|
+
Labels
|
|
185
|
+
] extends [never] ? string : Labels, [
|
|
186
|
+
Groups
|
|
187
|
+
] extends [never] ? string : Groups, [
|
|
188
|
+
AssetGroupNames
|
|
189
|
+
] extends [never] ? string : AssetGroupNames, [
|
|
190
|
+
ReactiveQueryNames
|
|
191
|
+
] extends [never] ? string : ReactiveQueryNames>;
|
|
192
|
+
}
|
|
193
|
+
export {};
|