forked from ecsyjs/ecsy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSystem.d.ts
90 lines (76 loc) · 1.87 KB
/
System.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
79
80
81
82
83
84
85
86
87
88
89
90
import {Component, ComponentConstructor} from "./Component";
import { Entity } from "./Entity";
import { World } from "./World";
interface Attributes {
priority?: number;
[propName: string]: any;
}
/**
* A system that manipulates entities in the world.
*/
export abstract class System {
/**
* Defines what Components the System will query for.
* This needs to be user defined.
*/
static queries: {
[queryName: string]: {
components: (ComponentConstructor<any> | NotComponent<any>)[],
listen?: {
added?: boolean,
removed?: boolean,
changed?: boolean | ComponentConstructor<any>[],
},
}
};
static isSystem: true;
constructor(world: World, attributes?: Attributes);
/**
* The results of the queries.
* Should be used inside of execute.
*/
queries: {
[queryName: string]: {
results: Entity[],
added?: Entity[],
removed?: Entity[],
changed?: Entity[],
}
}
world: World;
/**
* Whether the system will execute during the world tick.
*/
enabled: boolean;
/**
* Called when the system is added to the world.
*/
init(attributes?: Attributes): void
/**
* Resume execution of this system.
*/
play(): void;
/**
* Stop execution of this system.
*/
stop(): void;
/**
* This function is called for each run of world.
* All of the `queries` defined on the class are available here.
* @param delta
* @param time
*/
abstract execute(delta: number, time: number): void;
}
export interface SystemConstructor<T extends System> {
isSystem: true;
new (...args: any): T;
}
export interface NotComponent<C extends Component<any>> {
type: "not",
Component: ComponentConstructor<C>
}
/**
* Use the Not class to negate a component query.
*/
export function Not<C extends Component<any>>(Component: ComponentConstructor<C>): NotComponent<C>;