archetype-ecs 1.4.2 → 1.4.3
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 +1 -1
- package/dist/src/ComponentRegistry.d.ts +8 -3
- package/dist/src/EntityManager.d.ts +2 -5
- package/dist/src/index.d.ts +4 -7
- package/package.json +1 -1
- package/src/ComponentRegistry.ts +7 -3
- package/src/EntityManager.ts +2 -6
- package/src/index.ts +2 -3
package/README.md
CHANGED
|
@@ -261,7 +261,7 @@ Supports stripping components, skipping entities, and custom serializers.
|
|
|
261
261
|
Component types are inferred from their definition. Field names autocomplete, wrong fields are compile errors.
|
|
262
262
|
|
|
263
263
|
```ts
|
|
264
|
-
//
|
|
264
|
+
// Schema is inferred — Position becomes ComponentDef<{ x: 'f32'; y: 'f32' }>
|
|
265
265
|
const Position = component('Position', 'f32', ['x', 'y'])
|
|
266
266
|
|
|
267
267
|
Position.x // FieldRef — autocompletes to .x and .y
|
|
@@ -4,10 +4,15 @@ export declare const TYPE_MAP: Record<string, TypedArrayConstructor>;
|
|
|
4
4
|
export type TypeSpec = TypedArrayConstructor | [TypedArrayConstructor, number];
|
|
5
5
|
export declare function parseTypeSpec(typeStr: string): TypeSpec;
|
|
6
6
|
export declare const componentSchemas: Map<symbol, Record<string, TypeSpec>>;
|
|
7
|
-
export interface
|
|
7
|
+
export interface FieldRef {
|
|
8
8
|
readonly _sym: symbol;
|
|
9
|
-
readonly
|
|
10
|
-
[key: string]: unknown;
|
|
9
|
+
readonly _field: string;
|
|
11
10
|
}
|
|
11
|
+
export type ComponentDef<S extends Record<string, string> = {}> = {
|
|
12
|
+
readonly _sym: symbol;
|
|
13
|
+
readonly _name: string;
|
|
14
|
+
} & {
|
|
15
|
+
readonly [K in keyof S]: FieldRef;
|
|
16
|
+
};
|
|
12
17
|
export declare function toSym(type: ComponentDef | symbol): symbol;
|
|
13
18
|
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { type ComponentDef } from './ComponentRegistry.js';
|
|
1
|
+
import { type ComponentDef, type FieldRef } from './ComponentRegistry.js';
|
|
2
|
+
export type { FieldRef } from './ComponentRegistry.js';
|
|
2
3
|
export type EntityId = number;
|
|
3
|
-
export interface FieldRef {
|
|
4
|
-
readonly _sym: symbol;
|
|
5
|
-
readonly _field: string;
|
|
6
|
-
}
|
|
7
4
|
export interface ArchetypeView {
|
|
8
5
|
readonly id: number;
|
|
9
6
|
readonly entityIds: EntityId[];
|
package/dist/src/index.d.ts
CHANGED
|
@@ -7,11 +7,8 @@ export type { Profiler, ProfilerEntry } from './Profiler.js';
|
|
|
7
7
|
export { TYPED, componentSchemas, parseTypeSpec } from './ComponentRegistry.js';
|
|
8
8
|
export type { ComponentDef, TypeSpec } from './ComponentRegistry.js';
|
|
9
9
|
import { type ComponentDef } from './ComponentRegistry.js';
|
|
10
|
-
import type { FieldRef } from './EntityManager.js';
|
|
11
10
|
export declare function component(name: string): ComponentDef;
|
|
12
|
-
export declare function component<F extends readonly string[]>(name: string, type:
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
export declare function component<S extends Record<string, string>>(name: string, schema: S): ComponentDef
|
|
16
|
-
readonly [K in keyof S]: FieldRef;
|
|
17
|
-
};
|
|
11
|
+
export declare function component<F extends readonly string[], T extends string>(name: string, type: T, fields: F): ComponentDef<{
|
|
12
|
+
[K in F[number]]: T;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function component<S extends Record<string, string>>(name: string, schema: S): ComponentDef<S>;
|
package/package.json
CHANGED
package/src/ComponentRegistry.ts
CHANGED
|
@@ -34,12 +34,16 @@ export function parseTypeSpec(typeStr: string): TypeSpec {
|
|
|
34
34
|
|
|
35
35
|
export const componentSchemas = new Map<symbol, Record<string, TypeSpec>>();
|
|
36
36
|
|
|
37
|
-
export interface
|
|
37
|
+
export interface FieldRef {
|
|
38
38
|
readonly _sym: symbol;
|
|
39
|
-
readonly
|
|
40
|
-
[key: string]: unknown;
|
|
39
|
+
readonly _field: string;
|
|
41
40
|
}
|
|
42
41
|
|
|
42
|
+
export type ComponentDef<S extends Record<string, string> = {}> = {
|
|
43
|
+
readonly _sym: symbol;
|
|
44
|
+
readonly _name: string;
|
|
45
|
+
} & { readonly [K in keyof S]: FieldRef };
|
|
46
|
+
|
|
43
47
|
export function toSym(type: ComponentDef | symbol): symbol {
|
|
44
48
|
return (type as ComponentDef)._sym || (type as symbol);
|
|
45
49
|
}
|
package/src/EntityManager.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { TYPED, componentSchemas, toSym, type ComponentDef, type TypeSpec } from './ComponentRegistry.js';
|
|
1
|
+
import { TYPED, componentSchemas, toSym, type ComponentDef, type TypeSpec, type FieldRef } from './ComponentRegistry.js';
|
|
2
|
+
export type { FieldRef } from './ComponentRegistry.js';
|
|
2
3
|
|
|
3
4
|
export type EntityId = number;
|
|
4
5
|
|
|
5
|
-
export interface FieldRef {
|
|
6
|
-
readonly _sym: symbol;
|
|
7
|
-
readonly _field: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
export interface ArchetypeView {
|
|
11
7
|
readonly id: number;
|
|
12
8
|
readonly entityIds: EntityId[];
|
package/src/index.ts
CHANGED
|
@@ -8,11 +8,10 @@ export { TYPED, componentSchemas, parseTypeSpec } from './ComponentRegistry.js';
|
|
|
8
8
|
export type { ComponentDef, TypeSpec } from './ComponentRegistry.js';
|
|
9
9
|
|
|
10
10
|
import { parseTypeSpec, componentSchemas, type ComponentDef, type TypeSpec } from './ComponentRegistry.js';
|
|
11
|
-
import type { FieldRef } from './EntityManager.js';
|
|
12
11
|
|
|
13
12
|
export function component(name: string): ComponentDef;
|
|
14
|
-
export function component<F extends readonly string[]>(name: string, type:
|
|
15
|
-
export function component<S extends Record<string, string>>(name: string, schema: S): ComponentDef
|
|
13
|
+
export function component<F extends readonly string[], T extends string>(name: string, type: T, fields: F): ComponentDef<{ [K in F[number]]: T }>;
|
|
14
|
+
export function component<S extends Record<string, string>>(name: string, schema: S): ComponentDef<S>;
|
|
16
15
|
export function component(name: string, typeOrSchema?: string | Record<string, string>, fields?: string[]): ComponentDef {
|
|
17
16
|
const sym = Symbol(name);
|
|
18
17
|
const comp: any = { _sym: sym, _name: name };
|