-
Notifications
You must be signed in to change notification settings - Fork 32
/
lib.bevy.d.ts
78 lines (64 loc) · 1.64 KB
/
lib.bevy.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
declare namespace Deno {
namespace core {
function opSync(op: string, ...args: any[]): any;
}
}
// log.s
declare function trace(...args: any): void;
declare function debug(...args: any): void;
declare function info(...args: any): void;
declare function warn(...args: any): void;
declare function error(...args: any): void;
// ecs.js
declare interface BevyScript {
first?: () => void;
preUpdate?: () => void;
update?: () => void;
postUpdate?: () => void;
last?: () => void;
}
declare class ComponentId {
index: number;
}
type ComponentInfo = {
id: ComponentId;
name: string;
size: number;
};
type QueryDescriptor = {
components: ComponentId[];
};
type Primitive = number | string | boolean;
interface Value {
[path: string | number]: Value | Primitive | undefined;
}
type BevyType<T> = {
typeName: string;
};
type ExtractBevyType<T> = T extends BevyType<infer U>
? U
: T extends ComponentId
? Value
: never;
type MapQueryArgs<Q> = { [C in keyof Q]: ExtractBevyType<Q[C]> };
type QueryParameter = BevyType<unknown> | ComponentId;
type QueryItem<Q> = {
entity: Entity;
components: MapQueryArgs<Q>;
};
declare class QueryItems<Q> extends Array<QueryItem<Q>> {
get(entity: Entity): MapQueryArgs<Q> | undefined;
}
declare class World {
get components(): ComponentInfo[];
get resources(): ComponentInfo[];
get entities(): Entity[];
resource(componentId: ComponentId): Value | null;
resource<T>(type: BevyType<T>): T | null;
query<Q extends QueryParameter[]>(...query: Q): QueryItems<Q>;
get<Q extends QueryParameter[]>(
entity: Entity,
...components: Q
): MapQueryArgs<Q>;
}
declare let world: World;