@defold-typescript/types 0.56.0 → 0.58.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/ecs/debug.d.ts +57 -0
- package/ecs/hsm.d.ts +192 -0
- package/ecs/index.d.ts +1153 -0
- package/hsm/async.d.ts +1 -1
- package/hsm/debug.d.ts +1 -1
- package/hsm/defold.d.ts +1 -1
- package/hsm/index.d.ts +2 -2
- package/package.json +11 -1
package/ecs/index.d.ts
ADDED
|
@@ -0,0 +1,1153 @@
|
|
|
1
|
+
// Generated from packages/ecs/src/index.ts by `bun run --cwd packages/transpiler declarations`; do not edit.
|
|
2
|
+
declare const filterKeys: unique symbol;
|
|
3
|
+
interface FilterKeys<R extends string, U extends string> {
|
|
4
|
+
readonly required: R;
|
|
5
|
+
readonly used: U;
|
|
6
|
+
}
|
|
7
|
+
type FilterCall = {
|
|
8
|
+
bivariant(this: void, subject: unknown, candidate: unknown): boolean;
|
|
9
|
+
}["bivariant"];
|
|
10
|
+
/**
|
|
11
|
+
* Selects the entities a system sees, or the systems an `update` runs.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* A system calls it as `filter(system, entity)`, and `update` calls it as `filter(world, system)`.
|
|
15
|
+
* A filter built by `requireAll` and its siblings records the components it requires (`R`) and
|
|
16
|
+
* the components it names (`U`), so a system's callbacks see the required components as present
|
|
17
|
+
* and a name the entity type lacks is a compile error.
|
|
18
|
+
*
|
|
19
|
+
* @see requireAll
|
|
20
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#filters
|
|
21
|
+
*/
|
|
22
|
+
export type Filter<R extends string = string, U extends string = string> = FilterCall & {
|
|
23
|
+
readonly [filterKeys]?: FilterKeys<R, U>;
|
|
24
|
+
};
|
|
25
|
+
type FilterToken = string | Filter;
|
|
26
|
+
type KeysIn<F> = F extends {
|
|
27
|
+
readonly [filterKeys]?: infer K;
|
|
28
|
+
} ? NonNullable<K> extends FilterKeys<infer R, infer U> ? {
|
|
29
|
+
required: R;
|
|
30
|
+
used: U;
|
|
31
|
+
} : {
|
|
32
|
+
required: never;
|
|
33
|
+
used: never;
|
|
34
|
+
} : {
|
|
35
|
+
required: never;
|
|
36
|
+
used: never;
|
|
37
|
+
};
|
|
38
|
+
type RequiredBy<T> = T extends string ? T : KeysIn<T>["required"];
|
|
39
|
+
type UsedBy<T> = T extends string ? T : KeysIn<T>["used"];
|
|
40
|
+
type KnownKeys<E, F> = string extends KeysIn<F>["used"] ? unknown : [Exclude<KeysIn<F>["used"], keyof E>] extends [never] ? unknown : {
|
|
41
|
+
readonly "unknown components": Exclude<KeysIn<F>["used"], keyof E>;
|
|
42
|
+
};
|
|
43
|
+
type PatternOperator = "&" | "|" | "!" | "(" | ")";
|
|
44
|
+
type PatternNames<P extends string, Name extends string = "", Names extends string = never> = string extends P ? string : P extends `${infer C}${infer Rest}` ? C extends PatternOperator ? PatternNames<Rest, "", Names | (Name extends "" ? never : Name)> : PatternNames<Rest, `${Name}${C}`, Names> : Names | (Name extends "" ? never : Name);
|
|
45
|
+
/** `E` with the components `K` present. */
|
|
46
|
+
export type With<E, K> = [K] extends [never] ? E : E & {
|
|
47
|
+
[P in K & keyof E]-?: Exclude<E[P], undefined>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The fields every system carries.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* ecs sets `world`, `entities`, `indices`, `index`, `modified` and `bufferedTime`. A definition
|
|
54
|
+
* may set `active`, `interval`, `nocache` and its own fields, and the factory sets `filter`.
|
|
55
|
+
*/
|
|
56
|
+
export interface SystemFields<E> {
|
|
57
|
+
/**
|
|
58
|
+
* The world the system belongs to.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* `addSystem` sets it at once, and it is cleared when the system leaves at a `refresh` or
|
|
62
|
+
* `update`.
|
|
63
|
+
*/
|
|
64
|
+
readonly world?: World<E> | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Whether `update` and `refresh` run the system.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Defaults to `true`. An inactive system still gains and loses entities, with `onAdd` and
|
|
70
|
+
* `onRemove`.
|
|
71
|
+
*/
|
|
72
|
+
active?: boolean | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The entities the system holds, in the order it processes them.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* A `nocache` system has none.
|
|
78
|
+
*/
|
|
79
|
+
readonly entities?: readonly E[] | undefined;
|
|
80
|
+
/** Each held entity's position in `entities`, keyed by the entity's id in the system's world. */
|
|
81
|
+
readonly indices?: Readonly<Record<number, number | undefined>> | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The system's 1-based position in its world.
|
|
84
|
+
*
|
|
85
|
+
* @see World.setSystemIndex
|
|
86
|
+
*/
|
|
87
|
+
readonly index?: number | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the system's entities changed since its last update.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* `onModify` runs while it is set. An `update` whose system filter leaves the system out keeps
|
|
93
|
+
* it set.
|
|
94
|
+
*/
|
|
95
|
+
modified?: boolean | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* When set, `update` runs once per `interval` of buffered time instead of once per frame.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* The system buffers each update's `dt` and runs `update` once for each whole `interval` it
|
|
101
|
+
* holds, with `interval` as `dt`: zero, one or several times a frame.
|
|
102
|
+
*/
|
|
103
|
+
interval?: number | undefined;
|
|
104
|
+
/** The time an interval system has buffered toward its next update. */
|
|
105
|
+
bufferedTime?: number | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* When `true`, a processing system keeps no `entities` list.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* A `nocache` system filters the world's entities on every update and gets no `onAdd` or
|
|
111
|
+
* `onRemove`. A keyed reload cannot change it.
|
|
112
|
+
*/
|
|
113
|
+
nocache?: boolean | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Selects the system's entities.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* The factory sets it from its first argument. A system built without one holds no entities.
|
|
119
|
+
*/
|
|
120
|
+
filter?: Filter | undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The callbacks every system may define.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* `this` is the system in each.
|
|
127
|
+
*
|
|
128
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#one-frame
|
|
129
|
+
*/
|
|
130
|
+
export interface SystemCallbacks<E, X = E> {
|
|
131
|
+
/**
|
|
132
|
+
* Runs when an entity joins the system.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* Runs while the `refresh` or `update` that applies the add runs, before any `onModify`.
|
|
136
|
+
*
|
|
137
|
+
* @param entity The entity, which has the filter's components.
|
|
138
|
+
*/
|
|
139
|
+
onAdd?(entity: X): void;
|
|
140
|
+
/**
|
|
141
|
+
* Runs when an entity leaves the system.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Runs while the `refresh` or `update` that applies the change runs, and for every entity the
|
|
145
|
+
* system holds when the system leaves its world.
|
|
146
|
+
*
|
|
147
|
+
* @param entity The entity, which may have lost the filter's components.
|
|
148
|
+
*/
|
|
149
|
+
onRemove?(entity: E): void;
|
|
150
|
+
/**
|
|
151
|
+
* Runs before the next update after the system's entities changed.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* `update` runs `onModify` and `preWrap` together from the last system to the first: system N
|
|
155
|
+
* runs both before system N-1 runs either. A system that just joined counts as changed.
|
|
156
|
+
*
|
|
157
|
+
* @param dt The update's `dt`, or `0` from `refresh`.
|
|
158
|
+
*/
|
|
159
|
+
onModify?(dt: number): void;
|
|
160
|
+
/**
|
|
161
|
+
* Runs when the system joins a world, before it takes the world's entities.
|
|
162
|
+
*
|
|
163
|
+
* @param world The world the system joined.
|
|
164
|
+
*/
|
|
165
|
+
onAddToWorld?(world: World<E>): void;
|
|
166
|
+
/**
|
|
167
|
+
* Runs when the system leaves a world, after its entities left it.
|
|
168
|
+
*
|
|
169
|
+
* @param world The world the system left.
|
|
170
|
+
*/
|
|
171
|
+
onRemoveFromWorld?(world: World<E>): void;
|
|
172
|
+
/**
|
|
173
|
+
* Runs before any system updates.
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* `update` runs `onModify` and `preWrap` together from the last system to the first: system N
|
|
177
|
+
* runs both before system N-1 runs either.
|
|
178
|
+
*
|
|
179
|
+
* @param dt The update's `dt`.
|
|
180
|
+
*/
|
|
181
|
+
preWrap?(dt: number): void;
|
|
182
|
+
/**
|
|
183
|
+
* Runs after every system updated.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* `update` runs `postWrap` from the first system to the last.
|
|
187
|
+
*
|
|
188
|
+
* @param dt The update's `dt`.
|
|
189
|
+
*/
|
|
190
|
+
postWrap?(dt: number): void;
|
|
191
|
+
}
|
|
192
|
+
/** The callbacks of a system built by `system`. */
|
|
193
|
+
export interface PlainSystemCallbacks<E, X = E> extends SystemCallbacks<E, X> {
|
|
194
|
+
/**
|
|
195
|
+
* Runs once per world update, or once per `interval`.
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* The world runs `update` from the first system to the last.
|
|
199
|
+
*
|
|
200
|
+
* @param dt The update's `dt`, or the system's `interval`.
|
|
201
|
+
*/
|
|
202
|
+
update?(dt: number): void;
|
|
203
|
+
}
|
|
204
|
+
/** The callbacks of a system built by `processingSystem`. */
|
|
205
|
+
export interface ProcessingSystemCallbacks<E, X = E> extends SystemCallbacks<E, X> {
|
|
206
|
+
/**
|
|
207
|
+
* Runs before the system processes its entities.
|
|
208
|
+
*
|
|
209
|
+
* @param dt The update's `dt`, or the system's `interval`.
|
|
210
|
+
*/
|
|
211
|
+
preProcess?(dt: number): void;
|
|
212
|
+
/**
|
|
213
|
+
* Runs once for each entity the system holds.
|
|
214
|
+
*
|
|
215
|
+
* @param entity The entity, which has the filter's components.
|
|
216
|
+
* @param dt The update's `dt`, or the system's `interval`.
|
|
217
|
+
*/
|
|
218
|
+
process?(entity: X, dt: number): void;
|
|
219
|
+
/**
|
|
220
|
+
* Runs after the system processed its entities.
|
|
221
|
+
*
|
|
222
|
+
* @param dt The update's `dt`, or the system's `interval`.
|
|
223
|
+
*/
|
|
224
|
+
postProcess?(dt: number): void;
|
|
225
|
+
/** A processing system's `update` runs `preProcess`, `process` and `postProcess`. */
|
|
226
|
+
update?: never;
|
|
227
|
+
}
|
|
228
|
+
/** What a sorted system's definition adds to its callbacks. */
|
|
229
|
+
export interface SortedDefinition<X> {
|
|
230
|
+
/**
|
|
231
|
+
* Whether `e1` goes before `e2`.
|
|
232
|
+
*
|
|
233
|
+
* @remarks
|
|
234
|
+
* Read at the system's first sort, and again after a keyed reload. The sort is stable: two
|
|
235
|
+
* entities where neither goes before the other keep their order.
|
|
236
|
+
*
|
|
237
|
+
* @param e1 An entity the system holds.
|
|
238
|
+
* @param e2 Another entity the system holds.
|
|
239
|
+
* @returns `true` when `e1` goes first.
|
|
240
|
+
*/
|
|
241
|
+
compare(e1: X, e2: X): boolean;
|
|
242
|
+
/** A sorted system keeps its entities, so it cannot be `nocache`. */
|
|
243
|
+
nocache?: false | undefined;
|
|
244
|
+
}
|
|
245
|
+
/** The callbacks of a system built by `sortedSystem`. */
|
|
246
|
+
export interface SortedSystemCallbacks<E, X = E> extends PlainSystemCallbacks<E, X>, SortedDefinition<X> {
|
|
247
|
+
/** A sorted system's `onModify` sorts its entities. */
|
|
248
|
+
onModify?: never;
|
|
249
|
+
}
|
|
250
|
+
/** The callbacks of a system built by `sortedProcessingSystem`. */
|
|
251
|
+
export interface SortedProcessingSystemCallbacks<E, X = E> extends ProcessingSystemCallbacks<E, X>, SortedDefinition<X> {
|
|
252
|
+
/** A sorted system's `onModify` sorts its entities. */
|
|
253
|
+
onModify?: never;
|
|
254
|
+
}
|
|
255
|
+
/** A system: its definition `D` plus the fields ecs manages. */
|
|
256
|
+
export type System<E, D = unknown> = D & SystemFields<E>;
|
|
257
|
+
/** The fields a sorted system adds to those every system carries. */
|
|
258
|
+
export interface SortedSystemFields<X> {
|
|
259
|
+
/** A sorted system keeps its entities, so it cannot be `nocache`. */
|
|
260
|
+
nocache?: false | undefined;
|
|
261
|
+
/** `compare` bound to the system, built at the first sort and kept until a keyed reload. */
|
|
262
|
+
readonly sortDelegate?: ((this: void, e1: X, e2: X) => boolean) | undefined;
|
|
263
|
+
}
|
|
264
|
+
/** A sorted system over entities `E` whose `compare` takes `X`. */
|
|
265
|
+
export type SortedSystem<E, D = unknown, X = E> = System<E, D> & SortedSystemFields<X>;
|
|
266
|
+
type Definition<D, C> = {
|
|
267
|
+
[K in keyof D]: K extends keyof C ? C[K] : D[K];
|
|
268
|
+
} & C;
|
|
269
|
+
/**
|
|
270
|
+
* Builds a system from a definition, with or without a filter.
|
|
271
|
+
*
|
|
272
|
+
* @see system
|
|
273
|
+
*/
|
|
274
|
+
export interface SystemFactory<E> {
|
|
275
|
+
/**
|
|
276
|
+
* Builds a system that holds no entities.
|
|
277
|
+
*
|
|
278
|
+
* @param def The system's fields and callbacks; `this` in each callback is the system.
|
|
279
|
+
* @returns `def` as a system, or under a key the system the key built first.
|
|
280
|
+
* @throws When a keyed reload changes `nocache`.
|
|
281
|
+
*/
|
|
282
|
+
<D extends object>(this: void, def: Definition<D, PlainSystemCallbacks<E>> & ThisType<System<E, D>>): System<E, D>;
|
|
283
|
+
/**
|
|
284
|
+
* Builds a system over the entities `filter` selects.
|
|
285
|
+
*
|
|
286
|
+
* @param filter Selects the system's entities; its required components are present in each
|
|
287
|
+
* callback.
|
|
288
|
+
* @param def The system's fields and callbacks; `this` in each callback is the system.
|
|
289
|
+
* @returns `def` as a system, or under a key the system the key built first.
|
|
290
|
+
* @throws When a keyed reload changes `nocache`.
|
|
291
|
+
*/
|
|
292
|
+
<F extends Filter, D extends object>(this: void, filter: F & KnownKeys<E, F>, def: Definition<D, PlainSystemCallbacks<E, With<E, KeysIn<F>["required"]>>> & ThisType<System<E, D>>): System<E, D>;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Builds a processing system from a filter and a definition.
|
|
296
|
+
*
|
|
297
|
+
* @remarks
|
|
298
|
+
* `filter`'s required components are present in each callback, and `this` in each is the system.
|
|
299
|
+
* Under a key it returns the system the key built first, and throws when the reload changes
|
|
300
|
+
* `nocache`.
|
|
301
|
+
*
|
|
302
|
+
* @see processingSystem
|
|
303
|
+
*/
|
|
304
|
+
export type ProcessingSystemFactory<E> = <F extends Filter, D extends object>(this: void, filter: F & KnownKeys<E, F>, def: Definition<D, ProcessingSystemCallbacks<E, With<E, KeysIn<F>["required"]>>> & ThisType<System<E, D>>) => System<E, D>;
|
|
305
|
+
/**
|
|
306
|
+
* Builds a sorted system from a definition, with or without a filter.
|
|
307
|
+
*
|
|
308
|
+
* @see sortedSystem
|
|
309
|
+
*/
|
|
310
|
+
export interface SortedSystemFactory<E> {
|
|
311
|
+
/**
|
|
312
|
+
* Builds a sorted system that holds no entities.
|
|
313
|
+
*
|
|
314
|
+
* @param def The system's fields, callbacks and `compare`; `this` in each is the system.
|
|
315
|
+
* @returns `def` as a system, or under a key the system the key built first.
|
|
316
|
+
* @throws When a keyed reload changes `nocache`.
|
|
317
|
+
*/
|
|
318
|
+
<D extends object>(this: void, def: Definition<D, SortedSystemCallbacks<E>> & ThisType<SortedSystem<E, D>>): SortedSystem<E, D>;
|
|
319
|
+
/**
|
|
320
|
+
* Builds a sorted system over the entities `filter` selects.
|
|
321
|
+
*
|
|
322
|
+
* @param filter Selects the system's entities; its required components are present in each
|
|
323
|
+
* callback and in `compare`.
|
|
324
|
+
* @param def The system's fields, callbacks and `compare`; `this` in each is the system.
|
|
325
|
+
* @returns `def` as a system, or under a key the system the key built first.
|
|
326
|
+
* @throws When a keyed reload changes `nocache`.
|
|
327
|
+
*/
|
|
328
|
+
<F extends Filter, D extends object>(this: void, filter: F & KnownKeys<E, F>, def: Definition<D, SortedSystemCallbacks<E, With<E, KeysIn<F>["required"]>>> & ThisType<SortedSystem<E, D, With<E, KeysIn<F>["required"]>>>): SortedSystem<E, D, With<E, KeysIn<F>["required"]>>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Builds a sorted processing system from a filter and a definition.
|
|
332
|
+
*
|
|
333
|
+
* @remarks
|
|
334
|
+
* `filter`'s required components are present in each callback and in `compare`, and `this` in
|
|
335
|
+
* each is the system. Under a key it returns the system the key built first, and throws when the
|
|
336
|
+
* reload changes `nocache`.
|
|
337
|
+
*
|
|
338
|
+
* @see sortedProcessingSystem
|
|
339
|
+
*/
|
|
340
|
+
export type SortedProcessingSystemFactory<E> = <F extends Filter, D extends object>(this: void, filter: F & KnownKeys<E, F>, def: Definition<D, SortedProcessingSystemCallbacks<E, With<E, KeysIn<F>["required"]>>> & ThisType<SortedSystem<E, D, With<E, KeysIn<F>["required"]>>>) => SortedSystem<E, D, With<E, KeysIn<F>["required"]>>;
|
|
341
|
+
/**
|
|
342
|
+
* Holds entities and systems.
|
|
343
|
+
*
|
|
344
|
+
* @remarks
|
|
345
|
+
* Adding and removing take effect at the next `refresh` or `update`, so no system sees its
|
|
346
|
+
* entities change in the middle of a loop. Each method is also a function that takes the world
|
|
347
|
+
* first: `update(w, dt)` is `w.update(dt)`.
|
|
348
|
+
*
|
|
349
|
+
* @see world
|
|
350
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#the-world
|
|
351
|
+
*/
|
|
352
|
+
export interface World<E> {
|
|
353
|
+
/** The world's systems, in index order. */
|
|
354
|
+
readonly systems: readonly SystemFields<E>[];
|
|
355
|
+
/** The entities the world holds, as of its last `refresh` or `update`. */
|
|
356
|
+
readonly entities: readonly E[];
|
|
357
|
+
/**
|
|
358
|
+
* Adds each item as a system or an entity.
|
|
359
|
+
*
|
|
360
|
+
* @remarks
|
|
361
|
+
* Takes effect at the next `refresh` or `update`.
|
|
362
|
+
*
|
|
363
|
+
* @param items Systems and entities, in any mix.
|
|
364
|
+
* @throws When a system already belongs to a world.
|
|
365
|
+
*/
|
|
366
|
+
add(this: World<E>, ...items: (E | SystemFields<E>)[]): void;
|
|
367
|
+
/**
|
|
368
|
+
* Adds an entity, or re-checks one whose components changed.
|
|
369
|
+
*
|
|
370
|
+
* @remarks
|
|
371
|
+
* Takes effect at the next `refresh` or `update`, when each system checks the entity against
|
|
372
|
+
* its filter.
|
|
373
|
+
*
|
|
374
|
+
* @param entity The entity.
|
|
375
|
+
* @returns `entity`.
|
|
376
|
+
*/
|
|
377
|
+
addEntity<T extends E>(this: World<E>, entity: T): T;
|
|
378
|
+
/**
|
|
379
|
+
* Re-checks an entity whose components changed; the same as `addEntity`.
|
|
380
|
+
*
|
|
381
|
+
* @remarks
|
|
382
|
+
* Each system checks the entity against its filter at the next `refresh` or `update`.
|
|
383
|
+
*
|
|
384
|
+
* @param entity The entity whose components changed.
|
|
385
|
+
* @returns `entity`.
|
|
386
|
+
*/
|
|
387
|
+
changed<T extends E>(this: World<E>, entity: T): T;
|
|
388
|
+
/**
|
|
389
|
+
* Adds a system.
|
|
390
|
+
*
|
|
391
|
+
* @remarks
|
|
392
|
+
* Takes effect at the next `refresh` or `update`, and sets the system's `world` at once.
|
|
393
|
+
*
|
|
394
|
+
* @param system The system.
|
|
395
|
+
* @returns `system`.
|
|
396
|
+
* @throws When the system already belongs to a world.
|
|
397
|
+
*/
|
|
398
|
+
addSystem<S extends SystemFields<E>>(this: World<E>, system: S): S;
|
|
399
|
+
/**
|
|
400
|
+
* Removes each item as a system or an entity.
|
|
401
|
+
*
|
|
402
|
+
* @remarks
|
|
403
|
+
* Takes effect at the next `refresh` or `update`.
|
|
404
|
+
*
|
|
405
|
+
* @param items Systems and entities, in any mix.
|
|
406
|
+
* @throws When a system belongs to another world or to none.
|
|
407
|
+
*/
|
|
408
|
+
remove(this: World<E>, ...items: (E | SystemFields<E>)[]): void;
|
|
409
|
+
/**
|
|
410
|
+
* Removes an entity.
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* Takes effect at the next `refresh` or `update`.
|
|
414
|
+
*
|
|
415
|
+
* @param entity The entity.
|
|
416
|
+
* @returns `entity`.
|
|
417
|
+
*/
|
|
418
|
+
removeEntity<T extends E>(this: World<E>, entity: T): T;
|
|
419
|
+
/**
|
|
420
|
+
* Removes a system.
|
|
421
|
+
*
|
|
422
|
+
* @remarks
|
|
423
|
+
* Takes effect at the next `refresh` or `update`.
|
|
424
|
+
*
|
|
425
|
+
* @param system The system.
|
|
426
|
+
* @returns `system`.
|
|
427
|
+
* @throws When the system belongs to another world or to none.
|
|
428
|
+
*/
|
|
429
|
+
removeSystem<S extends SystemFields<E>>(this: World<E>, system: S): S;
|
|
430
|
+
/**
|
|
431
|
+
* Applies pending changes and runs `onModify` with `0` on each modified system.
|
|
432
|
+
*
|
|
433
|
+
* @remarks
|
|
434
|
+
* Only active systems run `onModify`, from the last system to the first.
|
|
435
|
+
*/
|
|
436
|
+
refresh(this: World<E>): void;
|
|
437
|
+
/**
|
|
438
|
+
* Applies pending changes and updates every active system, or those `systemFilter` selects.
|
|
439
|
+
*
|
|
440
|
+
* @remarks
|
|
441
|
+
* One update runs four passes. Systems waiting to join or leave do so, then entities. From the
|
|
442
|
+
* last system to the first, each active system runs `onModify` if its entities changed, then
|
|
443
|
+
* `preWrap`. From the first to the last, each runs `update`, and then each runs `postWrap`.
|
|
444
|
+
* `onModify` runs on every active system whatever `systemFilter` selects.
|
|
445
|
+
*
|
|
446
|
+
* @param dt The time since the last update.
|
|
447
|
+
* @param systemFilter Selects the systems that run `preWrap`, `update` and `postWrap`, called
|
|
448
|
+
* as `filter(world, system)`.
|
|
449
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#one-frame
|
|
450
|
+
*/
|
|
451
|
+
update(this: World<E>, dt: number, systemFilter?: Filter): void;
|
|
452
|
+
/**
|
|
453
|
+
* Removes every entity.
|
|
454
|
+
*
|
|
455
|
+
* @remarks
|
|
456
|
+
* Takes effect at the next `refresh` or `update`.
|
|
457
|
+
*/
|
|
458
|
+
clearEntities(this: World<E>): void;
|
|
459
|
+
/**
|
|
460
|
+
* Removes every system.
|
|
461
|
+
*
|
|
462
|
+
* @remarks
|
|
463
|
+
* Takes effect at the next `refresh` or `update`.
|
|
464
|
+
*/
|
|
465
|
+
clearSystems(this: World<E>): void;
|
|
466
|
+
/**
|
|
467
|
+
* The number of entities the world holds.
|
|
468
|
+
*
|
|
469
|
+
* @returns The length of `entities`, as of the last `refresh` or `update`.
|
|
470
|
+
*/
|
|
471
|
+
getEntityCount(this: World<E>): number;
|
|
472
|
+
/**
|
|
473
|
+
* The number of systems the world holds.
|
|
474
|
+
*
|
|
475
|
+
* @returns The length of `systems`, as of the last `refresh` or `update`.
|
|
476
|
+
*/
|
|
477
|
+
getSystemCount(this: World<E>): number;
|
|
478
|
+
/**
|
|
479
|
+
* Moves a system to a 1-based index (negative counts from the end) and returns its old index.
|
|
480
|
+
*
|
|
481
|
+
* @remarks
|
|
482
|
+
* Applies pending system changes first, so a system added since the last update can move.
|
|
483
|
+
*
|
|
484
|
+
* @param system A system of this world.
|
|
485
|
+
* @param index The new index, where `1` is the first and `-1` the last.
|
|
486
|
+
* @returns The system's old index.
|
|
487
|
+
* @throws When the system does not belong to this world.
|
|
488
|
+
*/
|
|
489
|
+
setSystemIndex(this: World<E>, system: SystemFields<E>, index: number): number;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Builds a filter that selects an entity with every component and passing every filter given.
|
|
493
|
+
*
|
|
494
|
+
* @remarks
|
|
495
|
+
* A system built with it sees each named component as present in its callbacks, along with the
|
|
496
|
+
* components a nested `requireAll` requires.
|
|
497
|
+
*
|
|
498
|
+
* @param tokens Component names and filters.
|
|
499
|
+
* @returns The filter.
|
|
500
|
+
* @throws When a token is neither a component name nor a filter.
|
|
501
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#filters
|
|
502
|
+
* @example
|
|
503
|
+
* ```ts
|
|
504
|
+
* import { processingSystem, requireAll } from "@defold-typescript/types/ecs";
|
|
505
|
+
*
|
|
506
|
+
* interface Ent {
|
|
507
|
+
* position?: { x: number };
|
|
508
|
+
* velocity?: { x: number };
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* export const move = processingSystem<Ent>()(requireAll("position", "velocity"), {
|
|
512
|
+
* process(e, dt) {
|
|
513
|
+
* e.position.x += e.velocity.x * dt;
|
|
514
|
+
* },
|
|
515
|
+
* });
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
export declare function requireAll<const T extends readonly FilterToken[]>(...tokens: T): Filter<RequiredBy<T[number]>, UsedBy<T[number]>>;
|
|
519
|
+
/**
|
|
520
|
+
* Builds a filter that selects an entity with at least one component or passing at least one
|
|
521
|
+
* filter given.
|
|
522
|
+
*
|
|
523
|
+
* @remarks
|
|
524
|
+
* It narrows no component, since no single one is certain.
|
|
525
|
+
*
|
|
526
|
+
* @param tokens Component names and filters.
|
|
527
|
+
* @returns The filter.
|
|
528
|
+
* @throws When a token is neither a component name nor a filter.
|
|
529
|
+
* @example
|
|
530
|
+
* ```ts
|
|
531
|
+
* import { processingSystem, requireAny } from "@defold-typescript/types/ecs";
|
|
532
|
+
*
|
|
533
|
+
* interface Ent {
|
|
534
|
+
* sprite?: Url;
|
|
535
|
+
* label?: Url;
|
|
536
|
+
* }
|
|
537
|
+
*
|
|
538
|
+
* export const visible = processingSystem<Ent>()(requireAny("sprite", "label"), {
|
|
539
|
+
* process(e) {
|
|
540
|
+
* if (e.sprite !== undefined) {
|
|
541
|
+
* msg.post(e.sprite, "enable");
|
|
542
|
+
* }
|
|
543
|
+
* },
|
|
544
|
+
* });
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
export declare function requireAny<const T extends readonly FilterToken[]>(...tokens: T): Filter<never, UsedBy<T[number]>>;
|
|
548
|
+
/**
|
|
549
|
+
* Builds a filter that rejects an entity with every component and passing every filter given.
|
|
550
|
+
*
|
|
551
|
+
* @param tokens Component names and filters.
|
|
552
|
+
* @returns The filter.
|
|
553
|
+
* @throws When a token is neither a component name nor a filter.
|
|
554
|
+
* @example
|
|
555
|
+
* ```ts
|
|
556
|
+
* import { processingSystem, rejectAll, requireAll } from "@defold-typescript/types/ecs";
|
|
557
|
+
*
|
|
558
|
+
* interface Ent {
|
|
559
|
+
* position?: { y: number };
|
|
560
|
+
* frozen?: true;
|
|
561
|
+
* pinned?: true;
|
|
562
|
+
* }
|
|
563
|
+
*
|
|
564
|
+
* export const sink = processingSystem<Ent>()(
|
|
565
|
+
* requireAll("position", rejectAll("frozen", "pinned")),
|
|
566
|
+
* {
|
|
567
|
+
* process(e, dt) {
|
|
568
|
+
* e.position.y -= dt;
|
|
569
|
+
* },
|
|
570
|
+
* },
|
|
571
|
+
* );
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
export declare function rejectAll<const T extends readonly FilterToken[]>(...tokens: T): Filter<never, UsedBy<T[number]>>;
|
|
575
|
+
/**
|
|
576
|
+
* Builds a filter that rejects an entity with at least one component or passing at least one
|
|
577
|
+
* filter given.
|
|
578
|
+
*
|
|
579
|
+
* @param tokens Component names and filters.
|
|
580
|
+
* @returns The filter.
|
|
581
|
+
* @throws When a token is neither a component name nor a filter.
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* import { processingSystem, rejectAny, requireAll } from "@defold-typescript/types/ecs";
|
|
585
|
+
*
|
|
586
|
+
* interface Ent {
|
|
587
|
+
* velocity?: { y: number };
|
|
588
|
+
* frozen?: true;
|
|
589
|
+
* }
|
|
590
|
+
*
|
|
591
|
+
* export const fall = processingSystem<Ent>()(requireAll("velocity", rejectAny("frozen")), {
|
|
592
|
+
* process(e, dt) {
|
|
593
|
+
* e.velocity.y -= 9.8 * dt;
|
|
594
|
+
* },
|
|
595
|
+
* });
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
export declare function rejectAny<const T extends readonly FilterToken[]>(...tokens: T): Filter<never, UsedBy<T[number]>>;
|
|
599
|
+
/**
|
|
600
|
+
* Builds a filter from a tiny-ecs pattern such as `"a&!b"`.
|
|
601
|
+
*
|
|
602
|
+
* @remarks
|
|
603
|
+
* A pattern holds component names of letters, digits and `_`, joined by `&` (and) and `|` (or),
|
|
604
|
+
* each optionally prefixed by `!` (not) and grouped with parentheses. `&` binds tighter than `|`,
|
|
605
|
+
* so `a|b&c` is `a|(b&c)`. A pattern filter narrows no component, but a name the entity type
|
|
606
|
+
* lacks is still a compile error.
|
|
607
|
+
*
|
|
608
|
+
* @param pattern The pattern, with no whitespace.
|
|
609
|
+
* @returns The filter.
|
|
610
|
+
* @throws When the pattern breaks this syntax; the message names the 1-based position where it
|
|
611
|
+
* stops.
|
|
612
|
+
* @see tryFilter
|
|
613
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#string-filters
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* import { filter, processingSystem } from "@defold-typescript/types/ecs";
|
|
617
|
+
*
|
|
618
|
+
* interface Ent {
|
|
619
|
+
* readonly name: string;
|
|
620
|
+
* position?: { x: number };
|
|
621
|
+
* frozen?: true;
|
|
622
|
+
* }
|
|
623
|
+
*
|
|
624
|
+
* export const awake = processingSystem<Ent>()(filter("position&!frozen"), {
|
|
625
|
+
* process(e) {
|
|
626
|
+
* print(e.name);
|
|
627
|
+
* },
|
|
628
|
+
* });
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
export declare function filter<const P extends string>(pattern: P): Filter<never, PatternNames<P>>;
|
|
632
|
+
/**
|
|
633
|
+
* Builds a filter as `filter` does, returning the error instead of throwing it.
|
|
634
|
+
*
|
|
635
|
+
* @param pattern A tiny-ecs pattern, as `filter` takes.
|
|
636
|
+
* @returns `{ ok: true, filter }`, or `{ ok: false, error }` with the message `filter` throws.
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* import { tryFilter } from "@defold-typescript/types/ecs";
|
|
640
|
+
*
|
|
641
|
+
* export function check(pattern: string): void {
|
|
642
|
+
* const result = tryFilter(pattern);
|
|
643
|
+
* if (!result.ok) {
|
|
644
|
+
* print(result.error);
|
|
645
|
+
* }
|
|
646
|
+
* }
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
export declare function tryFilter<const P extends string>(pattern: P): {
|
|
650
|
+
ok: true;
|
|
651
|
+
filter: Filter<never, PatternNames<P>>;
|
|
652
|
+
} | {
|
|
653
|
+
ok: false;
|
|
654
|
+
error: string;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* Returns a factory for plain systems over entities of type `E`.
|
|
658
|
+
*
|
|
659
|
+
* @remarks
|
|
660
|
+
* The factory takes a definition, or a filter and a definition. With a `key`, a later factory
|
|
661
|
+
* call under it puts the new definition into the system built first and returns that system, so
|
|
662
|
+
* a hot reload keeps the system running with its entities.
|
|
663
|
+
*
|
|
664
|
+
* @param key Names the system across hot reloads.
|
|
665
|
+
* @returns The factory.
|
|
666
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#hot-reload
|
|
667
|
+
* @example
|
|
668
|
+
* ```ts
|
|
669
|
+
* import { system, world } from "@defold-typescript/types/ecs";
|
|
670
|
+
*
|
|
671
|
+
* interface Ent {
|
|
672
|
+
* readonly name: string;
|
|
673
|
+
* }
|
|
674
|
+
*
|
|
675
|
+
* const clock = system<Ent>("clock")({
|
|
676
|
+
* elapsed: 0,
|
|
677
|
+
* update(dt) {
|
|
678
|
+
* this.elapsed += dt;
|
|
679
|
+
* },
|
|
680
|
+
* });
|
|
681
|
+
*
|
|
682
|
+
* export const w = world<Ent>(clock);
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
export declare function system<E>(key?: string): SystemFactory<E>;
|
|
686
|
+
/**
|
|
687
|
+
* Returns a factory for processing systems over entities of type `E`.
|
|
688
|
+
*
|
|
689
|
+
* @remarks
|
|
690
|
+
* The factory takes a filter and a definition. The system's `update` runs `preProcess`, then
|
|
691
|
+
* `process` once for each entity it holds, then `postProcess`. With a `key`, a later factory call
|
|
692
|
+
* under it reloads the system built first, as `system` does.
|
|
693
|
+
*
|
|
694
|
+
* @param key Names the system across hot reloads.
|
|
695
|
+
* @returns The factory.
|
|
696
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#systems
|
|
697
|
+
* @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* import { processingSystem, requireAll } from "@defold-typescript/types/ecs";
|
|
700
|
+
*
|
|
701
|
+
* interface Ent {
|
|
702
|
+
* position?: { x: number };
|
|
703
|
+
* velocity?: { x: number };
|
|
704
|
+
* }
|
|
705
|
+
*
|
|
706
|
+
* export const move = processingSystem<Ent>("move")(requireAll("position", "velocity"), {
|
|
707
|
+
* process(e, dt) {
|
|
708
|
+
* e.position.x += e.velocity.x * dt;
|
|
709
|
+
* },
|
|
710
|
+
* });
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
export declare function processingSystem<E>(key?: string): ProcessingSystemFactory<E>;
|
|
714
|
+
/**
|
|
715
|
+
* Returns a factory for plain systems that keep their entities in `compare` order.
|
|
716
|
+
*
|
|
717
|
+
* @remarks
|
|
718
|
+
* The system sorts at the first `refresh` or `update` after its entities change. With a `key`, a
|
|
719
|
+
* later factory call under it reloads the system built first, which sorts with the new `compare`
|
|
720
|
+
* at its next `refresh` or `update`.
|
|
721
|
+
*
|
|
722
|
+
* @param key Names the system across hot reloads.
|
|
723
|
+
* @returns The factory.
|
|
724
|
+
* @example
|
|
725
|
+
* ```ts
|
|
726
|
+
* import { requireAll, sortedSystem } from "@defold-typescript/types/ecs";
|
|
727
|
+
*
|
|
728
|
+
* interface Ent {
|
|
729
|
+
* readonly name: string;
|
|
730
|
+
* score?: number;
|
|
731
|
+
* }
|
|
732
|
+
*
|
|
733
|
+
* export const leaders = sortedSystem<Ent>()(requireAll("score"), {
|
|
734
|
+
* compare(a, b) {
|
|
735
|
+
* return a.score > b.score;
|
|
736
|
+
* },
|
|
737
|
+
* update() {
|
|
738
|
+
* const first = this.entities?.[0];
|
|
739
|
+
* if (first !== undefined) {
|
|
740
|
+
* print(first.name);
|
|
741
|
+
* }
|
|
742
|
+
* },
|
|
743
|
+
* });
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
export declare function sortedSystem<E>(key?: string): SortedSystemFactory<E>;
|
|
747
|
+
/**
|
|
748
|
+
* Returns a factory for processing systems that process their entities in `compare` order.
|
|
749
|
+
*
|
|
750
|
+
* @remarks
|
|
751
|
+
* With a `key`, a later factory call under it reloads the system built first, as `sortedSystem`
|
|
752
|
+
* does.
|
|
753
|
+
*
|
|
754
|
+
* @param key Names the system across hot reloads.
|
|
755
|
+
* @returns The factory.
|
|
756
|
+
* @example
|
|
757
|
+
* ```ts
|
|
758
|
+
* import { requireAll, sortedProcessingSystem } from "@defold-typescript/types/ecs";
|
|
759
|
+
*
|
|
760
|
+
* interface Ent {
|
|
761
|
+
* depth?: number;
|
|
762
|
+
* sprite?: Url;
|
|
763
|
+
* }
|
|
764
|
+
*
|
|
765
|
+
* export const layers = sortedProcessingSystem<Ent>()(requireAll("depth", "sprite"), {
|
|
766
|
+
* compare(a, b) {
|
|
767
|
+
* return a.depth < b.depth;
|
|
768
|
+
* },
|
|
769
|
+
* process(e) {
|
|
770
|
+
* msg.post(e.sprite, "enable");
|
|
771
|
+
* },
|
|
772
|
+
* });
|
|
773
|
+
* ```
|
|
774
|
+
*/
|
|
775
|
+
export declare function sortedProcessingSystem<E>(key?: string): SortedProcessingSystemFactory<E>;
|
|
776
|
+
/**
|
|
777
|
+
* Creates a world holding `items`, applied at once.
|
|
778
|
+
*
|
|
779
|
+
* @remarks
|
|
780
|
+
* Creating the world runs `onAddToWorld` and `onAdd`, but no `onModify`: the first `update` or
|
|
781
|
+
* `refresh` runs it, since a system that just joined counts as changed.
|
|
782
|
+
*
|
|
783
|
+
* @param items Systems and entities, in any mix.
|
|
784
|
+
* @returns The world.
|
|
785
|
+
* @throws When a system already belongs to a world.
|
|
786
|
+
* @see https://defold-typescript.github.io/toolchain/entity-systems#the-world
|
|
787
|
+
* @example
|
|
788
|
+
* ```ts
|
|
789
|
+
* import { processingSystem, requireAll, world } from "@defold-typescript/types/ecs";
|
|
790
|
+
*
|
|
791
|
+
* interface Ent {
|
|
792
|
+
* position?: { x: number };
|
|
793
|
+
* }
|
|
794
|
+
*
|
|
795
|
+
* const drift = processingSystem<Ent>()(requireAll("position"), {
|
|
796
|
+
* process(e, dt) {
|
|
797
|
+
* e.position.x += dt;
|
|
798
|
+
* },
|
|
799
|
+
* });
|
|
800
|
+
*
|
|
801
|
+
* export const w = world<Ent>(drift, { position: { x: 0 } });
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
export declare function world<E>(...items: (E | SystemFields<E>)[]): World<E>;
|
|
805
|
+
/**
|
|
806
|
+
* Adds each item as a system or an entity; the same as `target.add(...items)`.
|
|
807
|
+
*
|
|
808
|
+
* @remarks
|
|
809
|
+
* Takes effect at the next `refresh` or `update`.
|
|
810
|
+
*
|
|
811
|
+
* @param target The world.
|
|
812
|
+
* @param items Systems and entities, in any mix.
|
|
813
|
+
* @throws When a system already belongs to a world.
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* import { add, world } from "@defold-typescript/types/ecs";
|
|
817
|
+
*
|
|
818
|
+
* interface Ent {
|
|
819
|
+
* readonly name: string;
|
|
820
|
+
* }
|
|
821
|
+
*
|
|
822
|
+
* const w = world<Ent>();
|
|
823
|
+
* add(w, { name: "ball" }, { name: "wall" });
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
export declare function add<E>(target: World<E>, ...items: (E | SystemFields<E>)[]): void;
|
|
827
|
+
/**
|
|
828
|
+
* Adds an entity, or re-checks one whose components changed; the same as `target.addEntity`.
|
|
829
|
+
*
|
|
830
|
+
* @remarks
|
|
831
|
+
* Takes effect at the next `refresh` or `update`.
|
|
832
|
+
*
|
|
833
|
+
* @param target The world.
|
|
834
|
+
* @param entity The entity.
|
|
835
|
+
* @returns `entity`.
|
|
836
|
+
* @example
|
|
837
|
+
* ```ts
|
|
838
|
+
* import { addEntity, world } from "@defold-typescript/types/ecs";
|
|
839
|
+
*
|
|
840
|
+
* interface Ent {
|
|
841
|
+
* readonly name: string;
|
|
842
|
+
* }
|
|
843
|
+
*
|
|
844
|
+
* const w = world<Ent>();
|
|
845
|
+
* export const ball = addEntity(w, { name: "ball" });
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
export declare function addEntity<E, T extends E>(target: World<E>, entity: T): T;
|
|
849
|
+
/**
|
|
850
|
+
* Re-checks an entity whose components changed; the same as `target.changed`.
|
|
851
|
+
*
|
|
852
|
+
* @remarks
|
|
853
|
+
* Each system checks the entity against its filter at the next `refresh` or `update`.
|
|
854
|
+
*
|
|
855
|
+
* @param target The world.
|
|
856
|
+
* @param entity The entity whose components changed.
|
|
857
|
+
* @returns `entity`.
|
|
858
|
+
* @example
|
|
859
|
+
* ```ts
|
|
860
|
+
* import { changed, world } from "@defold-typescript/types/ecs";
|
|
861
|
+
*
|
|
862
|
+
* interface Ent {
|
|
863
|
+
* readonly name: string;
|
|
864
|
+
* frozen?: true;
|
|
865
|
+
* }
|
|
866
|
+
*
|
|
867
|
+
* const w = world<Ent>();
|
|
868
|
+
*
|
|
869
|
+
* export function freeze(e: Ent): void {
|
|
870
|
+
* e.frozen = true;
|
|
871
|
+
* changed(w, e);
|
|
872
|
+
* }
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
875
|
+
export declare function changed<E, T extends E>(target: World<E>, entity: T): T;
|
|
876
|
+
/**
|
|
877
|
+
* Adds a system; the same as `target.addSystem`.
|
|
878
|
+
*
|
|
879
|
+
* @remarks
|
|
880
|
+
* Takes effect at the next `refresh` or `update`, and sets the system's `world` at once.
|
|
881
|
+
*
|
|
882
|
+
* @param target The world.
|
|
883
|
+
* @param system The system.
|
|
884
|
+
* @returns `system`.
|
|
885
|
+
* @throws When the system already belongs to a world.
|
|
886
|
+
* @example
|
|
887
|
+
* ```ts
|
|
888
|
+
* import { addSystem, system, world } from "@defold-typescript/types/ecs";
|
|
889
|
+
*
|
|
890
|
+
* interface Ent {
|
|
891
|
+
* readonly name: string;
|
|
892
|
+
* }
|
|
893
|
+
*
|
|
894
|
+
* const w = world<Ent>();
|
|
895
|
+
* export const ticker = addSystem(
|
|
896
|
+
* w,
|
|
897
|
+
* system<Ent>()({
|
|
898
|
+
* update(dt) {
|
|
899
|
+
* print(dt);
|
|
900
|
+
* },
|
|
901
|
+
* }),
|
|
902
|
+
* );
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
export declare function addSystem<E, S extends SystemFields<E>>(target: World<E>, system: S): S;
|
|
906
|
+
/**
|
|
907
|
+
* Removes each item as a system or an entity; the same as `target.remove(...items)`.
|
|
908
|
+
*
|
|
909
|
+
* @remarks
|
|
910
|
+
* Takes effect at the next `refresh` or `update`.
|
|
911
|
+
*
|
|
912
|
+
* @param target The world.
|
|
913
|
+
* @param items Systems and entities, in any mix.
|
|
914
|
+
* @throws When a system belongs to another world or to none.
|
|
915
|
+
* @example
|
|
916
|
+
* ```ts
|
|
917
|
+
* import { remove, world } from "@defold-typescript/types/ecs";
|
|
918
|
+
*
|
|
919
|
+
* interface Ent {
|
|
920
|
+
* readonly name: string;
|
|
921
|
+
* }
|
|
922
|
+
*
|
|
923
|
+
* const ball: Ent = { name: "ball" };
|
|
924
|
+
* const w = world<Ent>(ball);
|
|
925
|
+
* remove(w, ball);
|
|
926
|
+
* ```
|
|
927
|
+
*/
|
|
928
|
+
export declare function remove<E>(target: World<E>, ...items: (E | SystemFields<E>)[]): void;
|
|
929
|
+
/**
|
|
930
|
+
* Removes an entity; the same as `target.removeEntity`.
|
|
931
|
+
*
|
|
932
|
+
* @remarks
|
|
933
|
+
* Takes effect at the next `refresh` or `update`.
|
|
934
|
+
*
|
|
935
|
+
* @param target The world.
|
|
936
|
+
* @param entity The entity.
|
|
937
|
+
* @returns `entity`.
|
|
938
|
+
* @example
|
|
939
|
+
* ```ts
|
|
940
|
+
* import { removeEntity, world } from "@defold-typescript/types/ecs";
|
|
941
|
+
*
|
|
942
|
+
* interface Ent {
|
|
943
|
+
* readonly name: string;
|
|
944
|
+
* }
|
|
945
|
+
*
|
|
946
|
+
* const ball: Ent = { name: "ball" };
|
|
947
|
+
* const w = world<Ent>(ball);
|
|
948
|
+
* removeEntity(w, ball);
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
export declare function removeEntity<E, T extends E>(target: World<E>, entity: T): T;
|
|
952
|
+
/**
|
|
953
|
+
* Removes a system; the same as `target.removeSystem`.
|
|
954
|
+
*
|
|
955
|
+
* @remarks
|
|
956
|
+
* Takes effect at the next `refresh` or `update`.
|
|
957
|
+
*
|
|
958
|
+
* @param target The world.
|
|
959
|
+
* @param system The system.
|
|
960
|
+
* @returns `system`.
|
|
961
|
+
* @throws When the system belongs to another world or to none.
|
|
962
|
+
* @example
|
|
963
|
+
* ```ts
|
|
964
|
+
* import { removeSystem, system, world } from "@defold-typescript/types/ecs";
|
|
965
|
+
*
|
|
966
|
+
* interface Ent {
|
|
967
|
+
* readonly name: string;
|
|
968
|
+
* }
|
|
969
|
+
*
|
|
970
|
+
* const ticker = system<Ent>()({});
|
|
971
|
+
* const w = world<Ent>(ticker);
|
|
972
|
+
* removeSystem(w, ticker);
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
export declare function removeSystem<E, S extends SystemFields<E>>(target: World<E>, system: S): S;
|
|
976
|
+
/**
|
|
977
|
+
* Applies pending changes and runs `onModify` with `0` on each modified system; the same as
|
|
978
|
+
* `target.refresh()`.
|
|
979
|
+
*
|
|
980
|
+
* @param target The world.
|
|
981
|
+
* @example
|
|
982
|
+
* ```ts
|
|
983
|
+
* import { hasEntity, refresh, world } from "@defold-typescript/types/ecs";
|
|
984
|
+
*
|
|
985
|
+
* interface Ent {
|
|
986
|
+
* readonly name: string;
|
|
987
|
+
* }
|
|
988
|
+
*
|
|
989
|
+
* const w = world<Ent>();
|
|
990
|
+
* const wall: Ent = { name: "wall" };
|
|
991
|
+
* w.add(wall);
|
|
992
|
+
* refresh(w);
|
|
993
|
+
* print(hasEntity(w, wall));
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
export declare function refresh<E>(target: World<E>): void;
|
|
997
|
+
/**
|
|
998
|
+
* Applies pending changes and updates every active system, or those `systemFilter` selects; the
|
|
999
|
+
* same as `target.update(dt, systemFilter)`.
|
|
1000
|
+
*
|
|
1001
|
+
* @param target The world.
|
|
1002
|
+
* @param dt The time since the last update.
|
|
1003
|
+
* @param systemFilter Selects the systems that run `preWrap`, `update` and `postWrap`, called as
|
|
1004
|
+
* `filter(world, system)`.
|
|
1005
|
+
* @see World.update
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* import { rejectAny, update, world } from "@defold-typescript/types/ecs";
|
|
1009
|
+
*
|
|
1010
|
+
* interface Ent {
|
|
1011
|
+
* readonly name: string;
|
|
1012
|
+
* }
|
|
1013
|
+
*
|
|
1014
|
+
* const w = world<Ent>();
|
|
1015
|
+
*
|
|
1016
|
+
* export function step(dt: number, paused: boolean): void {
|
|
1017
|
+
* update(w, dt, paused ? rejectAny("gameplay") : undefined);
|
|
1018
|
+
* }
|
|
1019
|
+
* ```
|
|
1020
|
+
*/
|
|
1021
|
+
export declare function update<E>(target: World<E>, dt: number, systemFilter?: Filter): void;
|
|
1022
|
+
/**
|
|
1023
|
+
* Removes every entity; the same as `target.clearEntities()`.
|
|
1024
|
+
*
|
|
1025
|
+
* @remarks
|
|
1026
|
+
* Takes effect at the next `refresh` or `update`.
|
|
1027
|
+
*
|
|
1028
|
+
* @param target The world.
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```ts
|
|
1031
|
+
* import { clearEntities, world } from "@defold-typescript/types/ecs";
|
|
1032
|
+
*
|
|
1033
|
+
* interface Ent {
|
|
1034
|
+
* readonly name: string;
|
|
1035
|
+
* }
|
|
1036
|
+
*
|
|
1037
|
+
* const w = world<Ent>({ name: "ball" });
|
|
1038
|
+
* clearEntities(w);
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
export declare function clearEntities<E>(target: World<E>): void;
|
|
1042
|
+
/**
|
|
1043
|
+
* Removes every system; the same as `target.clearSystems()`.
|
|
1044
|
+
*
|
|
1045
|
+
* @remarks
|
|
1046
|
+
* Takes effect at the next `refresh` or `update`.
|
|
1047
|
+
*
|
|
1048
|
+
* @param target The world.
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* import { clearSystems, system, world } from "@defold-typescript/types/ecs";
|
|
1052
|
+
*
|
|
1053
|
+
* interface Ent {
|
|
1054
|
+
* readonly name: string;
|
|
1055
|
+
* }
|
|
1056
|
+
*
|
|
1057
|
+
* const w = world<Ent>(system<Ent>()({}));
|
|
1058
|
+
* clearSystems(w);
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
1061
|
+
export declare function clearSystems<E>(target: World<E>): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* The number of entities the world holds; the same as `target.getEntityCount()`.
|
|
1064
|
+
*
|
|
1065
|
+
* @param target The world.
|
|
1066
|
+
* @returns The length of the world's `entities`, as of its last `refresh` or `update`.
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* import { getEntityCount, world } from "@defold-typescript/types/ecs";
|
|
1070
|
+
*
|
|
1071
|
+
* interface Ent {
|
|
1072
|
+
* readonly name: string;
|
|
1073
|
+
* }
|
|
1074
|
+
*
|
|
1075
|
+
* const w = world<Ent>({ name: "ball" });
|
|
1076
|
+
* print(getEntityCount(w));
|
|
1077
|
+
* ```
|
|
1078
|
+
*/
|
|
1079
|
+
export declare function getEntityCount<E>(target: World<E>): number;
|
|
1080
|
+
/**
|
|
1081
|
+
* The number of systems the world holds; the same as `target.getSystemCount()`.
|
|
1082
|
+
*
|
|
1083
|
+
* @param target The world.
|
|
1084
|
+
* @returns The length of the world's `systems`, as of its last `refresh` or `update`.
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```ts
|
|
1087
|
+
* import { getSystemCount, system, world } from "@defold-typescript/types/ecs";
|
|
1088
|
+
*
|
|
1089
|
+
* interface Ent {
|
|
1090
|
+
* readonly name: string;
|
|
1091
|
+
* }
|
|
1092
|
+
*
|
|
1093
|
+
* const w = world<Ent>(system<Ent>()({}));
|
|
1094
|
+
* print(getSystemCount(w));
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
export declare function getSystemCount<E>(target: World<E>): number;
|
|
1098
|
+
/**
|
|
1099
|
+
* Whether the world holds `entity` as of its last `refresh` or `update`.
|
|
1100
|
+
*
|
|
1101
|
+
* @remarks
|
|
1102
|
+
* It reads `false` while the entity's add is pending, and `true` while its removal is. It has no
|
|
1103
|
+
* method form on the world.
|
|
1104
|
+
*
|
|
1105
|
+
* @param target The world.
|
|
1106
|
+
* @param entity The entity.
|
|
1107
|
+
* @returns `true` when the world held `entity` at its last `refresh` or `update`.
|
|
1108
|
+
* @example
|
|
1109
|
+
* ```ts
|
|
1110
|
+
* import { hasEntity, world } from "@defold-typescript/types/ecs";
|
|
1111
|
+
*
|
|
1112
|
+
* interface Ent {
|
|
1113
|
+
* readonly name: string;
|
|
1114
|
+
* }
|
|
1115
|
+
*
|
|
1116
|
+
* const w = world<Ent>();
|
|
1117
|
+
* const wall: Ent = { name: "wall" };
|
|
1118
|
+
* w.add(wall);
|
|
1119
|
+
* print(hasEntity(w, wall));
|
|
1120
|
+
* w.refresh();
|
|
1121
|
+
* print(hasEntity(w, wall));
|
|
1122
|
+
* ```
|
|
1123
|
+
*/
|
|
1124
|
+
export declare function hasEntity<E>(target: World<E>, entity: E): boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* Moves a system to a 1-based index and returns its old index; the same as
|
|
1127
|
+
* `target.setSystemIndex(system, index)`.
|
|
1128
|
+
*
|
|
1129
|
+
* @remarks
|
|
1130
|
+
* A negative index counts from the end. Pending system changes apply first, so a system added
|
|
1131
|
+
* since the last update can move.
|
|
1132
|
+
*
|
|
1133
|
+
* @param target The world.
|
|
1134
|
+
* @param system A system of `target`.
|
|
1135
|
+
* @param index The new index, where `1` is the first and `-1` the last.
|
|
1136
|
+
* @returns The system's old index.
|
|
1137
|
+
* @throws When the system does not belong to `target`.
|
|
1138
|
+
* @example
|
|
1139
|
+
* ```ts
|
|
1140
|
+
* import { setSystemIndex, system, world } from "@defold-typescript/types/ecs";
|
|
1141
|
+
*
|
|
1142
|
+
* interface Ent {
|
|
1143
|
+
* readonly name: string;
|
|
1144
|
+
* }
|
|
1145
|
+
*
|
|
1146
|
+
* const first = system<Ent>()({});
|
|
1147
|
+
* const last = system<Ent>()({});
|
|
1148
|
+
* const w = world<Ent>(first, last);
|
|
1149
|
+
* setSystemIndex(w, last, 1);
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1152
|
+
export declare function setSystemIndex<E>(target: World<E>, system: SystemFields<E>, index: number): number;
|
|
1153
|
+
export {};
|