@combos-fun/engine 0.0.11 → 0.0.13
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/agent-skill.md +144 -82
- package/dist/engine.cjs.js +17 -7
- package/dist/engine.cjs.js.map +1 -1
- package/dist/engine.cjs.prod.js +1 -1
- package/dist/engine.d.ts +324 -317
- package/dist/engine.esm.js +17 -7
- package/dist/engine.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/engine.d.ts
CHANGED
|
@@ -90,209 +90,80 @@ declare class Transform extends Component<TransformParams> {
|
|
|
90
90
|
clearChildren(): void;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
declare class Scene extends GameObject {
|
|
97
|
-
gameObjects: GameObject[];
|
|
98
|
-
canvas: HTMLCanvasElement;
|
|
99
|
-
constructor(name: any, obj?: TransformParams);
|
|
100
|
-
/**
|
|
101
|
-
* Add gameObject
|
|
102
|
-
* @param gameObject - game object
|
|
103
|
-
*/
|
|
104
|
-
addGameObject(gameObject: GameObject): void;
|
|
105
|
-
/**
|
|
106
|
-
* Remove gameObject
|
|
107
|
-
* @param gameObject - game object
|
|
108
|
-
*/
|
|
109
|
-
removeGameObject(gameObject: GameObject): void;
|
|
110
|
-
/**
|
|
111
|
-
* Destroy scene
|
|
112
|
-
*/
|
|
113
|
-
destroy(): void;
|
|
93
|
+
interface TickerOptions {
|
|
94
|
+
autoStart?: boolean;
|
|
95
|
+
frameRate?: number;
|
|
114
96
|
}
|
|
115
|
-
|
|
116
97
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @public
|
|
98
|
+
* Timeline tool
|
|
119
99
|
*/
|
|
120
|
-
declare class
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
private
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
* @returns transform component on this gameObject
|
|
142
|
-
* @readonly
|
|
143
|
-
*/
|
|
144
|
-
get transform(): Transform;
|
|
145
|
-
/**
|
|
146
|
-
* Get parent gameObject
|
|
147
|
-
* @returns parent gameObject
|
|
148
|
-
* @readonly
|
|
149
|
-
*/
|
|
150
|
-
get parent(): GameObject;
|
|
151
|
-
/**
|
|
152
|
-
* Get the name of this gameObject
|
|
153
|
-
* @readonly
|
|
154
|
-
*/
|
|
155
|
-
get name(): string;
|
|
156
|
-
set scene(val: Scene);
|
|
157
|
-
/**
|
|
158
|
-
* Get the scene which this gameObject added on
|
|
159
|
-
* @returns scene
|
|
160
|
-
* @readonly
|
|
161
|
-
*/
|
|
162
|
-
get scene(): Scene;
|
|
163
|
-
/**
|
|
164
|
-
* Add child gameObject
|
|
165
|
-
* @param gameObject - child gameobject
|
|
166
|
-
*/
|
|
167
|
-
addChild(gameObject: GameObject): void;
|
|
168
|
-
/**
|
|
169
|
-
* Remove child gameObject
|
|
170
|
-
* @param gameObject - child gameobject
|
|
171
|
-
*/
|
|
172
|
-
removeChild(gameObject: GameObject): GameObject;
|
|
173
|
-
/**
|
|
174
|
-
* Add component to this gameObject
|
|
175
|
-
* @remarks
|
|
176
|
-
* If component has already been added on a gameObject, it will throw an error
|
|
177
|
-
* @param C - component instance or Component class
|
|
178
|
-
*/
|
|
179
|
-
addComponent<T extends Component<ComponentParams>>(C: T): T;
|
|
180
|
-
addComponent<T extends Component<ComponentParams>>(C: ComponentConstructor<T>, obj?: ComponentParams): T;
|
|
181
|
-
/**
|
|
182
|
-
* Remove component on this gameObject
|
|
183
|
-
* @remarks
|
|
184
|
-
* default Transform component can not be removed, if the paramter represent a transform component, an error will be thrown.
|
|
185
|
-
* @param c - one of the compnoentName, component instance, component Class
|
|
186
|
-
* @returns
|
|
187
|
-
*/
|
|
188
|
-
removeComponent<T extends Component<ComponentParams>>(c: string): T;
|
|
189
|
-
removeComponent<T extends Component<ComponentParams>>(c: T): T;
|
|
190
|
-
removeComponent<T extends Component<ComponentParams>>(c: ComponentConstructor<T>): T;
|
|
191
|
-
private _removeComponent;
|
|
192
|
-
/**
|
|
193
|
-
* Get component on this gameObject
|
|
194
|
-
* @param c - one of the compnoentName, component instance, component Class
|
|
195
|
-
* @returns
|
|
196
|
-
*/
|
|
197
|
-
getComponent<T extends Component<ComponentParams>>(c: ComponentConstructor<T>): T;
|
|
198
|
-
getComponent<T extends Component>(c: string): T;
|
|
100
|
+
declare class Ticker {
|
|
101
|
+
/** Whether or not ticker should auto start */
|
|
102
|
+
autoStart: boolean;
|
|
103
|
+
/** FPS, The number of times that raf method is called per second */
|
|
104
|
+
frameRate: number;
|
|
105
|
+
/** Global Timeline **/
|
|
106
|
+
private timeline;
|
|
107
|
+
/** Time between two frame */
|
|
108
|
+
private _frameDuration;
|
|
109
|
+
/** Ticker is a function will called in each raf */
|
|
110
|
+
private _tickers;
|
|
111
|
+
/** raf handle id */
|
|
112
|
+
_requestId: number;
|
|
113
|
+
/** Last frame render time */
|
|
114
|
+
private _lastFrameTime;
|
|
115
|
+
/** Frame count since from ticker beigning */
|
|
116
|
+
private _frameCount;
|
|
117
|
+
/** Main ticker method handle */
|
|
118
|
+
private _ticker;
|
|
119
|
+
/** Represents the status of the Ticker, If ticker has started, the value is true */
|
|
120
|
+
private _started;
|
|
199
121
|
/**
|
|
200
|
-
*
|
|
201
|
-
* @
|
|
122
|
+
* @param autoStart - auto start game
|
|
123
|
+
* @param frameRate - game frame rate
|
|
202
124
|
*/
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
|
|
125
|
+
constructor(options?: TickerOptions);
|
|
126
|
+
/** Main loop, all _tickers will called in this method */
|
|
127
|
+
update(): void;
|
|
128
|
+
/** Add ticker function */
|
|
129
|
+
add(fn: (params: UpdateParams) => void): void;
|
|
130
|
+
/** Remove ticker function */
|
|
131
|
+
remove(fn: (params: UpdateParams) => void): void;
|
|
132
|
+
/** Start main loop */
|
|
133
|
+
start(): void;
|
|
134
|
+
/** Pause main loop */
|
|
135
|
+
pause(): void;
|
|
136
|
+
setPlaybackRate(rate: number): void;
|
|
206
137
|
}
|
|
207
138
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
frameCount: number;
|
|
214
|
-
/** current timestamp */
|
|
215
|
-
time: number;
|
|
216
|
-
/** current timestamp */
|
|
217
|
-
currentTime: number;
|
|
218
|
-
/** fps at current frame */
|
|
219
|
-
fps: number;
|
|
220
|
-
}
|
|
221
|
-
interface ComponentParams {
|
|
222
|
-
}
|
|
223
|
-
interface ComponentConstructor<T extends Component<ComponentParams>> {
|
|
224
|
-
componentName: string;
|
|
225
|
-
new (params?: ComponentParams): T;
|
|
139
|
+
/** Observer event type */
|
|
140
|
+
declare enum ObserverType {
|
|
141
|
+
ADD = "ADD",
|
|
142
|
+
REMOVE = "REMOVE",
|
|
143
|
+
CHANGE = "CHANGE"
|
|
226
144
|
}
|
|
227
145
|
/**
|
|
228
|
-
*
|
|
229
|
-
* @
|
|
146
|
+
* Observer property
|
|
147
|
+
* @remarks
|
|
148
|
+
* If `deep` is true then all descendants of `prop` will be observed
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* @observerComponent({
|
|
152
|
+
* Transform: [{ prop: 'size', deep: true }]
|
|
153
|
+
* })
|
|
154
|
+
* class TestSystem extends System {}
|
|
155
|
+
* ```
|
|
230
156
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
/** Name of this component */
|
|
235
|
-
readonly name: string;
|
|
236
|
-
/**
|
|
237
|
-
* Represents the status of the component, If component has started, the value is true
|
|
238
|
-
* @defaultValue false
|
|
239
|
-
*/
|
|
240
|
-
started: boolean;
|
|
241
|
-
/**
|
|
242
|
-
* gameObject which this component had added on
|
|
243
|
-
* @remarks
|
|
244
|
-
* Component can only be added on one gameObject, otherwise an error will be thrown,
|
|
245
|
-
* Component can only be attached to one game object at a time.
|
|
246
|
-
*/
|
|
247
|
-
gameObject: GameObject;
|
|
248
|
-
/** Default paramaters for this component */
|
|
249
|
-
__componentDefaultParams: T;
|
|
250
|
-
constructor(params?: T);
|
|
251
|
-
/**
|
|
252
|
-
* Called during component construction
|
|
253
|
-
* @param params - optional initial parameters
|
|
254
|
-
* @override
|
|
255
|
-
*/
|
|
256
|
-
init?(params?: T): void;
|
|
257
|
-
/**
|
|
258
|
-
* Called when component is added to a gameObject
|
|
259
|
-
* @override
|
|
260
|
-
*/
|
|
261
|
-
awake?(): void;
|
|
262
|
-
/**
|
|
263
|
-
* Called after all component's `awake` method has been called
|
|
264
|
-
* @override
|
|
265
|
-
*/
|
|
266
|
-
start?(): void;
|
|
267
|
-
/**
|
|
268
|
-
* Called in every tick, change self property or other component property
|
|
269
|
-
* @param frame - frame info about this tick
|
|
270
|
-
* @override
|
|
271
|
-
*/
|
|
272
|
-
update?(frame: UpdateParams): void;
|
|
273
|
-
/**
|
|
274
|
-
* Called after all gameObject's `update` method has been called
|
|
275
|
-
* @param frame - frame info about this tick
|
|
276
|
-
* @override
|
|
277
|
-
*/
|
|
278
|
-
lateUpdate?(frame: UpdateParams): void;
|
|
279
|
-
/**
|
|
280
|
-
* Called before game runing or every time game paused
|
|
281
|
-
* @virtual
|
|
282
|
-
* @override
|
|
283
|
-
*/
|
|
284
|
-
onResume?(): void;
|
|
285
|
-
/**
|
|
286
|
-
* Called while the game paused.
|
|
287
|
-
* @override
|
|
288
|
-
*/
|
|
289
|
-
onPause?(): void;
|
|
290
|
-
/**
|
|
291
|
-
* Called while component be destroyed.
|
|
292
|
-
* @override
|
|
293
|
-
*/
|
|
294
|
-
onDestroy?(): void;
|
|
157
|
+
interface PureObserverProp {
|
|
158
|
+
deep: boolean;
|
|
159
|
+
prop: string[];
|
|
295
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Observer Info
|
|
163
|
+
* @remarks
|
|
164
|
+
* The key of this map always be component's name, the value of this map is an array of `PureObserverProp`
|
|
165
|
+
*/
|
|
166
|
+
type PureObserverInfo = Record<string, PureObserverProp[]>;
|
|
296
167
|
|
|
297
168
|
interface ObserverEventParams {
|
|
298
169
|
type: ObserverType;
|
|
@@ -337,50 +208,99 @@ declare class ComponentObserver {
|
|
|
337
208
|
clear(): ObserverEvent[];
|
|
338
209
|
}
|
|
339
210
|
|
|
340
|
-
interface
|
|
341
|
-
|
|
342
|
-
|
|
211
|
+
interface SystemConstructor<T extends System = System> {
|
|
212
|
+
systemName: string;
|
|
213
|
+
observerInfo: PureObserverInfo;
|
|
214
|
+
new (params?: any): T;
|
|
343
215
|
}
|
|
344
216
|
/**
|
|
345
|
-
*
|
|
217
|
+
* Each System runs continuously and performs global actions on every Entity that possesses a Component of the same aspect as that System.
|
|
218
|
+
* @public
|
|
346
219
|
*/
|
|
347
|
-
declare class
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
frameRate: number;
|
|
352
|
-
/** Global Timeline **/
|
|
353
|
-
private timeline;
|
|
354
|
-
/** Time between two frame */
|
|
355
|
-
private _frameDuration;
|
|
356
|
-
/** Ticker is a function will called in each raf */
|
|
357
|
-
private _tickers;
|
|
358
|
-
/** raf handle id */
|
|
359
|
-
_requestId: number;
|
|
360
|
-
/** Last frame render time */
|
|
361
|
-
private _lastFrameTime;
|
|
362
|
-
/** Frame count since from ticker beigning */
|
|
363
|
-
private _frameCount;
|
|
364
|
-
/** Main ticker method handle */
|
|
365
|
-
private _ticker;
|
|
366
|
-
/** Represents the status of the Ticker, If ticker has started, the value is true */
|
|
367
|
-
private _started;
|
|
220
|
+
declare class System<T extends {} = {}> {
|
|
221
|
+
/** System name */
|
|
222
|
+
static systemName: string;
|
|
223
|
+
name: string;
|
|
368
224
|
/**
|
|
369
|
-
*
|
|
370
|
-
* @
|
|
225
|
+
* The collection of component properties observed by the System. System will respond to these changes
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // TestSystem will respond to changes of `size` and `position` property of the Transform component
|
|
229
|
+
* class TestSystem extends System {
|
|
230
|
+
* static observerInfo = {
|
|
231
|
+
* Transform: [{ prop: 'size', deep: true }, { prop: 'position', deep: true }]
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
static observerInfo: PureObserverInfo;
|
|
237
|
+
/** Component Observer */
|
|
238
|
+
componentObserver: ComponentObserver;
|
|
239
|
+
/** Game instance */
|
|
240
|
+
game: Game;
|
|
241
|
+
/** Represents the status of the component, if component has started, the value is true */
|
|
242
|
+
started: boolean;
|
|
243
|
+
/** Default paramaters for this system */
|
|
244
|
+
__systemDefaultParams: T;
|
|
245
|
+
constructor(params?: T);
|
|
246
|
+
/**
|
|
247
|
+
* Called when system is added to a gameObject
|
|
248
|
+
* @remarks
|
|
249
|
+
* The difference between init and awake is that `init` method recieves params.
|
|
250
|
+
* Both of those methods are called early than `start` method.
|
|
251
|
+
* Use this method to prepare data, ect.
|
|
252
|
+
* @param param - optional params
|
|
253
|
+
* @override
|
|
254
|
+
*/
|
|
255
|
+
init?(param?: T): void | Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Calleen system installed
|
|
258
|
+
* @override
|
|
259
|
+
*/
|
|
260
|
+
awake?(): void;
|
|
261
|
+
/**
|
|
262
|
+
* Called after all system `awake` method has been called
|
|
263
|
+
* @override
|
|
264
|
+
*/
|
|
265
|
+
start?(): void;
|
|
266
|
+
/**
|
|
267
|
+
* Called in each tick
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* // run TWEEN `update` method in main requestAnimationFrame loop
|
|
271
|
+
* class TransitionSystem extends System {
|
|
272
|
+
* update() {
|
|
273
|
+
* TWEEN.update()
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
* @param e - info about this tick
|
|
278
|
+
* @override
|
|
279
|
+
*/
|
|
280
|
+
update?(e: UpdateParams): void;
|
|
281
|
+
/**
|
|
282
|
+
* Called after all system have called the `update` method
|
|
283
|
+
* @param e - info about this tick
|
|
284
|
+
* @override
|
|
285
|
+
*/
|
|
286
|
+
lateUpdate?(e: UpdateParams): void;
|
|
287
|
+
/**
|
|
288
|
+
* Called before game runing or every time game paused
|
|
289
|
+
* @override
|
|
290
|
+
*/
|
|
291
|
+
onResume?(): void;
|
|
292
|
+
/**
|
|
293
|
+
* Called while the game paused
|
|
294
|
+
* @override
|
|
295
|
+
*/
|
|
296
|
+
onPause?(): void;
|
|
297
|
+
/**
|
|
298
|
+
* Called while the system be destroyed.
|
|
299
|
+
* @override
|
|
371
300
|
*/
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
|
|
375
|
-
/** Add ticker function */
|
|
376
|
-
add(fn: (params: UpdateParams) => void): void;
|
|
377
|
-
/** Remove ticker function */
|
|
378
|
-
remove(fn: (params: UpdateParams) => void): void;
|
|
379
|
-
/** Start main loop */
|
|
380
|
-
start(): void;
|
|
381
|
-
/** Pause main loop */
|
|
382
|
-
pause(): void;
|
|
383
|
-
setPlaybackRate(rate: number): void;
|
|
301
|
+
onDestroy?(): void;
|
|
302
|
+
/** Default destroy method */
|
|
303
|
+
destroy(): void;
|
|
384
304
|
}
|
|
385
305
|
|
|
386
306
|
/** Plugin registration shape */
|
|
@@ -506,129 +426,216 @@ declare class Game extends EventEmitter {
|
|
|
506
426
|
loadScene({ scene, mode, params, }: LoadSceneParams): void;
|
|
507
427
|
}
|
|
508
428
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
429
|
+
/**
|
|
430
|
+
* Scene is a gameObject container
|
|
431
|
+
*/
|
|
432
|
+
declare class Scene extends GameObject {
|
|
433
|
+
gameObjects: GameObject[];
|
|
434
|
+
canvas: HTMLCanvasElement;
|
|
435
|
+
game: Game;
|
|
436
|
+
constructor(name: string, obj?: TransformParams);
|
|
437
|
+
/**
|
|
438
|
+
* Add gameObject
|
|
439
|
+
* @param gameObject - game object
|
|
440
|
+
*/
|
|
441
|
+
addGameObject(gameObject: GameObject): void;
|
|
442
|
+
/**
|
|
443
|
+
* Remove gameObject
|
|
444
|
+
* @param gameObject - game object
|
|
445
|
+
*/
|
|
446
|
+
removeGameObject(gameObject: GameObject): void;
|
|
447
|
+
/**
|
|
448
|
+
* Destroy scene
|
|
449
|
+
*/
|
|
450
|
+
destroy(): void;
|
|
513
451
|
}
|
|
452
|
+
|
|
514
453
|
/**
|
|
515
|
-
*
|
|
454
|
+
* GameObject is a general purpose object. It consists of a unique id and components.
|
|
516
455
|
* @public
|
|
517
456
|
*/
|
|
518
|
-
declare class
|
|
519
|
-
/**
|
|
520
|
-
|
|
521
|
-
|
|
457
|
+
declare class GameObject {
|
|
458
|
+
/** Name of this gameObject */
|
|
459
|
+
private _name;
|
|
460
|
+
/** Scene is an abstraction, represent a canvas layer */
|
|
461
|
+
private _scene;
|
|
462
|
+
/** A key-value map for components on this gameObject */
|
|
463
|
+
private _componentCache;
|
|
464
|
+
/** Identifier of this gameObject */
|
|
465
|
+
id: number;
|
|
466
|
+
/** Components apply to this gameObject */
|
|
467
|
+
components: Component<ComponentParams>[];
|
|
468
|
+
/** GameObject has been destroyed */
|
|
469
|
+
destroyed: boolean;
|
|
522
470
|
/**
|
|
523
|
-
*
|
|
524
|
-
* @
|
|
525
|
-
*
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
|
|
471
|
+
* Consruct a new gameObject
|
|
472
|
+
* @param name - the name of this gameObject
|
|
473
|
+
* @param obj - optional transform parameters for default Transform component
|
|
474
|
+
*/
|
|
475
|
+
constructor(name: string, obj?: TransformParams);
|
|
476
|
+
/**
|
|
477
|
+
* Get default transform component
|
|
478
|
+
* @returns transform component on this gameObject
|
|
479
|
+
* @readonly
|
|
480
|
+
*/
|
|
481
|
+
get transform(): Transform;
|
|
482
|
+
/**
|
|
483
|
+
* Get parent gameObject
|
|
484
|
+
* @returns parent gameObject
|
|
485
|
+
* @readonly
|
|
486
|
+
*/
|
|
487
|
+
get parent(): GameObject;
|
|
488
|
+
/**
|
|
489
|
+
* Get the name of this gameObject
|
|
490
|
+
* @readonly
|
|
491
|
+
*/
|
|
492
|
+
get name(): string;
|
|
493
|
+
set scene(val: Scene);
|
|
494
|
+
/**
|
|
495
|
+
* Get the scene which this gameObject added on
|
|
496
|
+
* @returns scene
|
|
497
|
+
* @readonly
|
|
498
|
+
*/
|
|
499
|
+
get scene(): Scene;
|
|
500
|
+
/**
|
|
501
|
+
* Add child gameObject
|
|
502
|
+
* @param gameObject - child gameobject
|
|
503
|
+
*/
|
|
504
|
+
addChild(gameObject: GameObject): void;
|
|
505
|
+
/**
|
|
506
|
+
* Remove child gameObject
|
|
507
|
+
* @param gameObject - child gameobject
|
|
508
|
+
*/
|
|
509
|
+
removeChild(gameObject: GameObject): GameObject;
|
|
510
|
+
/**
|
|
511
|
+
* Add component to this gameObject
|
|
512
|
+
* @remarks
|
|
513
|
+
* If component has already been added on a gameObject, it will throw an error
|
|
514
|
+
* @param C - component instance or Component class
|
|
515
|
+
*/
|
|
516
|
+
addComponent<T extends Component>(C: T): T;
|
|
517
|
+
addComponent<T extends Component>(C: ComponentConstructor<T>, obj?: ComponentParams): T;
|
|
518
|
+
/**
|
|
519
|
+
* Remove component on this gameObject
|
|
520
|
+
* @remarks
|
|
521
|
+
* default Transform component can not be removed, if the paramter represent a transform component, an error will be thrown.
|
|
522
|
+
* @param c - one of the compnoentName, component instance, component Class
|
|
523
|
+
* @returns
|
|
524
|
+
*/
|
|
525
|
+
removeComponent<T extends Component>(c: string): T;
|
|
526
|
+
removeComponent<T extends Component>(c: T): T;
|
|
527
|
+
removeComponent<T extends Component>(c: ComponentConstructor<T>): T;
|
|
528
|
+
private _removeComponent;
|
|
529
|
+
/**
|
|
530
|
+
* Get component on this gameObject
|
|
531
|
+
* @param c - one of the compnoentName, component instance, component Class
|
|
532
|
+
* @returns
|
|
533
|
+
*/
|
|
534
|
+
getComponent<T extends Component>(c: ComponentConstructor<T>): T;
|
|
535
|
+
getComponent<T extends Component>(c: string): T;
|
|
536
|
+
/**
|
|
537
|
+
* Remove this gameObject on its parent
|
|
538
|
+
* @returns return this gameObject
|
|
539
|
+
*/
|
|
540
|
+
remove(): GameObject;
|
|
541
|
+
/** Destroy this gameObject */
|
|
542
|
+
destroy(): void;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/** frame info pass to `Component.update` method */
|
|
546
|
+
interface UpdateParams {
|
|
547
|
+
/** delta time from last frame */
|
|
548
|
+
deltaTime: number;
|
|
549
|
+
/** alias for deltaTime, matching common game framework conventions */
|
|
550
|
+
delta: number;
|
|
551
|
+
/** frame count since game begining */
|
|
552
|
+
frameCount: number;
|
|
553
|
+
/** current timestamp */
|
|
554
|
+
time: number;
|
|
555
|
+
/** current timestamp */
|
|
556
|
+
currentTime: number;
|
|
557
|
+
/** fps at current frame */
|
|
558
|
+
fps: number;
|
|
559
|
+
}
|
|
560
|
+
interface ComponentParams {
|
|
561
|
+
}
|
|
562
|
+
interface ComponentConstructor<T extends Component> {
|
|
563
|
+
componentName: string;
|
|
564
|
+
new (...args: any[]): T;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Component contain raw data apply to gameObject and how it interacts with the world
|
|
568
|
+
* @public
|
|
569
|
+
*/
|
|
570
|
+
declare class Component<T extends ComponentParams = {}> extends EventEmitter {
|
|
571
|
+
/** Name of this component */
|
|
572
|
+
static componentName: string;
|
|
573
|
+
/** Name of this component */
|
|
574
|
+
readonly name: string;
|
|
575
|
+
/**
|
|
576
|
+
* Represents the status of the component, If component has started, the value is true
|
|
577
|
+
* @defaultValue false
|
|
533
578
|
*/
|
|
534
|
-
static observerInfo: PureObserverInfo;
|
|
535
|
-
/** Component Observer */
|
|
536
|
-
componentObserver: ComponentObserver;
|
|
537
|
-
/** Game instance */
|
|
538
|
-
game: Game;
|
|
539
|
-
/** Represents the status of the component, if component has started, the value is true */
|
|
540
579
|
started: boolean;
|
|
541
|
-
/** Default paramaters for this system */
|
|
542
|
-
__systemDefaultParams: T;
|
|
543
|
-
constructor(params?: T);
|
|
544
580
|
/**
|
|
545
|
-
*
|
|
581
|
+
* gameObject which this component had added on
|
|
546
582
|
* @remarks
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
|
|
550
|
-
|
|
583
|
+
* Component can only be added on one gameObject, otherwise an error will be thrown,
|
|
584
|
+
* Component can only be attached to one game object at a time.
|
|
585
|
+
*/
|
|
586
|
+
gameObject: GameObject;
|
|
587
|
+
/**
|
|
588
|
+
* Get the game instance this component belongs to
|
|
589
|
+
*/
|
|
590
|
+
get game(): Game;
|
|
591
|
+
/** Default paramaters for this component */
|
|
592
|
+
__componentDefaultParams: T;
|
|
593
|
+
constructor(params?: T);
|
|
594
|
+
/**
|
|
595
|
+
* Called during component construction
|
|
596
|
+
* @param params - optional initial parameters
|
|
551
597
|
* @override
|
|
552
598
|
*/
|
|
553
|
-
init?(
|
|
599
|
+
init?(params?: T): void;
|
|
554
600
|
/**
|
|
555
|
-
*
|
|
601
|
+
* Called when component is added to a gameObject
|
|
556
602
|
* @override
|
|
557
603
|
*/
|
|
558
604
|
awake?(): void;
|
|
559
605
|
/**
|
|
560
|
-
* Called after all
|
|
606
|
+
* Called after all component's `awake` method has been called
|
|
561
607
|
* @override
|
|
562
608
|
*/
|
|
563
609
|
start?(): void;
|
|
564
610
|
/**
|
|
565
|
-
* Called in
|
|
566
|
-
* @
|
|
567
|
-
* ```typescript
|
|
568
|
-
* // run TWEEN `update` method in main requestAnimationFrame loop
|
|
569
|
-
* class TransitionSystem extends System {
|
|
570
|
-
* update() {
|
|
571
|
-
* TWEEN.update()
|
|
572
|
-
* }
|
|
573
|
-
* }
|
|
574
|
-
* ```
|
|
575
|
-
* @param e - info about this tick
|
|
611
|
+
* Called in every tick, change self property or other component property
|
|
612
|
+
* @param frame - frame info about this tick
|
|
576
613
|
* @override
|
|
577
614
|
*/
|
|
578
|
-
update?(
|
|
615
|
+
update?(frame: UpdateParams): void;
|
|
579
616
|
/**
|
|
580
|
-
* Called after all
|
|
581
|
-
* @param
|
|
617
|
+
* Called after all gameObject's `update` method has been called
|
|
618
|
+
* @param frame - frame info about this tick
|
|
582
619
|
* @override
|
|
583
620
|
*/
|
|
584
|
-
lateUpdate?(
|
|
621
|
+
lateUpdate?(frame: UpdateParams): void;
|
|
585
622
|
/**
|
|
586
|
-
* Called
|
|
623
|
+
* Called every time game resumed from pause
|
|
624
|
+
* @virtual
|
|
587
625
|
* @override
|
|
588
626
|
*/
|
|
589
627
|
onResume?(): void;
|
|
590
628
|
/**
|
|
591
|
-
* Called while the game paused
|
|
629
|
+
* Called while the game paused.
|
|
592
630
|
* @override
|
|
593
631
|
*/
|
|
594
632
|
onPause?(): void;
|
|
595
633
|
/**
|
|
596
|
-
* Called while
|
|
634
|
+
* Called while component be destroyed.
|
|
597
635
|
* @override
|
|
598
636
|
*/
|
|
599
637
|
onDestroy?(): void;
|
|
600
|
-
/** Default destory method */
|
|
601
|
-
destroy(): void;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/** Observer event type */
|
|
605
|
-
declare enum ObserverType {
|
|
606
|
-
ADD = "ADD",
|
|
607
|
-
REMOVE = "REMOVE",
|
|
608
|
-
CHANGE = "CHANGE"
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Observer property
|
|
612
|
-
* @remarks
|
|
613
|
-
* If `deep` is true then all descendants of `prop` will be observed
|
|
614
|
-
* @example
|
|
615
|
-
* ```typescript
|
|
616
|
-
* @observerComponent({
|
|
617
|
-
* Transform: [{ prop: 'size', deep: true }]
|
|
618
|
-
* })
|
|
619
|
-
* class TestSystem extends System {}
|
|
620
|
-
* ```
|
|
621
|
-
*/
|
|
622
|
-
interface PureObserverProp {
|
|
623
|
-
deep: boolean;
|
|
624
|
-
prop: string[];
|
|
625
638
|
}
|
|
626
|
-
/**
|
|
627
|
-
* Observer Info
|
|
628
|
-
* @remarks
|
|
629
|
-
* The key of this map always be component's name, the value of this map is an array of `PureObserverProp`
|
|
630
|
-
*/
|
|
631
|
-
type PureObserverInfo = Record<string, PureObserverProp[]>;
|
|
632
639
|
|
|
633
640
|
/**
|
|
634
641
|
* Collect property which react in Editor tooling
|
|
@@ -800,7 +807,7 @@ declare class Resource extends EventEmitter {
|
|
|
800
807
|
getResource(name: string): Promise<ResourceStruct>;
|
|
801
808
|
/** Make resource instance by resource type */
|
|
802
809
|
private instance;
|
|
803
|
-
/**
|
|
810
|
+
/** Destroy resource by name */
|
|
804
811
|
destroy(name: string): Promise<void>;
|
|
805
812
|
private _destroy;
|
|
806
813
|
/**
|