@dcl/sdk 7.0.0-2875155444.commit-bb5e498 → 7.0.0-2884920754.commit-e7fba73
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/dist/ecs7/index.d.ts +209 -21
- package/dist/ecs7/index.js +182 -170
- package/dist/ecs7/index.min.js +1 -1
- package/dist/ecs7/index.min.js.map +1 -1
- package/package.json +4 -4
- package/types/ecs7/index.d.ts +203 -15
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dcl/sdk",
|
3
|
-
"version": "7.0.0-
|
3
|
+
"version": "7.0.0-2884920754.commit-e7fba73",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/src/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
@@ -27,8 +27,8 @@
|
|
27
27
|
"src/cli/**/*.js"
|
28
28
|
],
|
29
29
|
"dependencies": {
|
30
|
-
"@dcl/amd": "6.11.5-
|
31
|
-
"@dcl/build-ecs": "6.11.5-
|
30
|
+
"@dcl/amd": "6.11.5-2884920754.commit-e7fba73",
|
31
|
+
"@dcl/build-ecs": "6.11.5-2884920754.commit-e7fba73",
|
32
32
|
"@dcl/kernel": "1.0.0-2638443584.commit-696a74b",
|
33
33
|
"@dcl/posix": "^1.0.4",
|
34
34
|
"@dcl/schemas": "4.8.0",
|
@@ -38,5 +38,5 @@
|
|
38
38
|
"ignore": "^5.1.8"
|
39
39
|
},
|
40
40
|
"minCliVersion": "3.10.2",
|
41
|
-
"commit": "
|
41
|
+
"commit": "e7fba737c74d4e84e5261c4e026f454b0563b8e3"
|
42
42
|
}
|
package/types/ecs7/index.d.ts
CHANGED
@@ -70,21 +70,125 @@ declare interface Color3 {
|
|
70
70
|
*/
|
71
71
|
declare type ComponentDefinition<T extends ISchema = ISchema<any>> = {
|
72
72
|
_id: number;
|
73
|
+
/**
|
74
|
+
* Return the default value of the current component
|
75
|
+
*/
|
76
|
+
default(): DeepReadonly<ComponentType<T>>;
|
77
|
+
/**
|
78
|
+
* Get if the entity has this component
|
79
|
+
* @param entity
|
80
|
+
*
|
81
|
+
* Example:
|
82
|
+
* ```ts
|
83
|
+
* const myEntity = engine.addEntity()
|
84
|
+
* Transform.has(myEntity) // return false
|
85
|
+
* Transform.create(myEntity)
|
86
|
+
* Transform.has(myEntity) // return true
|
87
|
+
* ```
|
88
|
+
*/
|
73
89
|
has(entity: Entity): boolean;
|
74
|
-
|
90
|
+
/**
|
91
|
+
* Get the readonly component of the entity (to mutate it, use getMutable instead), throw an error if the entity doesn't have the component.
|
92
|
+
* @param entity
|
93
|
+
* @return
|
94
|
+
* Example:
|
95
|
+
* ```ts
|
96
|
+
* const myEntity = engine.addEntity()
|
97
|
+
* Transform.create(myEntity)
|
98
|
+
* const transform = Transform.get(myEntity) // return true
|
99
|
+
* log(transform.position.x === 0) // log 'true'
|
100
|
+
*
|
101
|
+
* transform.position.y = 10 // illegal statement, to mutate the component use getMutable
|
102
|
+
* ```
|
103
|
+
*
|
104
|
+
* ```ts
|
105
|
+
* const otherEntity = engine.addEntity()
|
106
|
+
* Transform.get(otherEntity) // throw an error!!
|
107
|
+
* ```
|
108
|
+
*/
|
109
|
+
get(entity: Entity): DeepReadonly<ComponentType<T>>;
|
110
|
+
/**
|
111
|
+
* Get the readonly component of the entity (to mutate it, use getMutable instead), or null if the entity doesn't have the component.
|
112
|
+
* @param entity
|
113
|
+
* @return
|
114
|
+
*
|
115
|
+
* Example:
|
116
|
+
* ```ts
|
117
|
+
* const otherEntity = engine.addEntity()
|
118
|
+
* log(Transform.get(otherEntity) === null) // log 'true'
|
119
|
+
* ```
|
120
|
+
*/
|
75
121
|
getOrNull(entity: Entity): DeepReadonly<ComponentType<T>> | null;
|
122
|
+
/**
|
123
|
+
* Add the current component to an entity, throw an error if the component already exists (use `createOrReplace` instead).
|
124
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
125
|
+
* @param entity
|
126
|
+
* @param val The initial value
|
127
|
+
*
|
128
|
+
* Example:
|
129
|
+
* ```ts
|
130
|
+
* const myEntity = engine.addEntity()
|
131
|
+
* Transform.create(myEntity, { ...Transform.default(), position: {x: 4, y: 0, z: 4} }) // ok!
|
132
|
+
* Transform.create(myEntity) // throw an error, the `Transform` component already exists in `myEntity`
|
133
|
+
* ````
|
134
|
+
*/
|
76
135
|
create(entity: Entity, val?: ComponentType<T>): ComponentType<T>;
|
77
|
-
|
136
|
+
/**
|
137
|
+
* Add the current component to an entity or replace the content if the entity already has the component
|
138
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
139
|
+
* @param entity
|
140
|
+
* @param val The initial or new value
|
141
|
+
*
|
142
|
+
* Example:
|
143
|
+
* ```ts
|
144
|
+
* const myEntity = engine.addEntity()
|
145
|
+
* Transform.create(myEntity) // ok!
|
146
|
+
* Transform.createOrReplace(myEntity, { ...Transform.default(), position: {x: 4, y: 0, z: 4} }) // ok!
|
147
|
+
* ````
|
148
|
+
*/
|
78
149
|
createOrReplace(entity: Entity, val?: ComponentType<T>): ComponentType<T>;
|
150
|
+
/**
|
151
|
+
* Delete the current component to an entity, return null if the entity doesn't have the current component.
|
152
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
153
|
+
* @param entity
|
154
|
+
*
|
155
|
+
* Example:
|
156
|
+
* ```ts
|
157
|
+
* const myEntity = engine.addEntity()
|
158
|
+
* Transform.create(myEntity) // ok!
|
159
|
+
* Transform.deleteFrom(myEntity) // return the component
|
160
|
+
* Transform.deleteFrom(myEntity) // return null
|
161
|
+
* ````
|
162
|
+
*/
|
79
163
|
deleteFrom(entity: Entity): ComponentType<T> | null;
|
80
|
-
|
81
|
-
|
82
|
-
|
164
|
+
/**
|
165
|
+
* Get the mutable component of the entity, throw an error if the entity doesn't have the component.
|
166
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
167
|
+
* @param entity
|
168
|
+
*
|
169
|
+
* Example:
|
170
|
+
* ```ts
|
171
|
+
* const myEntity = engine.addEntity()
|
172
|
+
* Transform.create(myEntity)
|
173
|
+
* Transform.getMutable(myEntity).position = {x: 4, y: 0, z: 4}
|
174
|
+
* ````
|
175
|
+
*/
|
176
|
+
getMutable(entity: Entity): ComponentType<T>;
|
177
|
+
/**
|
178
|
+
* Get the mutable component of the entity, return null if the entity doesn't have the component.
|
179
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
180
|
+
* @param entity
|
181
|
+
*
|
182
|
+
* Example:
|
183
|
+
* ```ts
|
184
|
+
* const transform = Transform.getMutableOrNull(myEntity)
|
185
|
+
* if (transform) {
|
186
|
+
* transform.position = {x: 4, y: 0, z: 4}
|
187
|
+
* }
|
188
|
+
* ````
|
189
|
+
*/
|
190
|
+
getMutableOrNull(entity: Entity): ComponentType<T> | null;
|
83
191
|
writeToByteBuffer(entity: Entity, buffer: ByteBuffer): void;
|
84
|
-
iterator(): Iterable<[Entity, ComponentType<T>]>;
|
85
|
-
dirtyIterator(): Iterable<Entity>;
|
86
|
-
clearDirty(): void;
|
87
|
-
isDirty(entity: Entity): boolean;
|
88
192
|
};
|
89
193
|
|
90
194
|
/** @public */
|
@@ -154,7 +258,7 @@ declare namespace Components {
|
|
154
258
|
* @public
|
155
259
|
*/
|
156
260
|
declare type ComponentSchema<T extends [ComponentDefinition, ...ComponentDefinition[]]> = {
|
157
|
-
[K in keyof T]: T[K] extends ComponentDefinition ? ReturnType<T[K]['
|
261
|
+
[K in keyof T]: T[K] extends ComponentDefinition ? ReturnType<T[K]['getMutable']> : never;
|
158
262
|
};
|
159
263
|
|
160
264
|
/**
|
@@ -311,7 +415,7 @@ declare type DeepReadonly<T> = {
|
|
311
415
|
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
312
416
|
};
|
313
417
|
|
314
|
-
declare function defineLibraryComponents({
|
418
|
+
declare function defineLibraryComponents({ defineComponentFromSchema }: Pick<IEngine, 'defineComponentFromSchema'>): {
|
315
419
|
Transform: ComponentDefinition<ISchema< {
|
316
420
|
position: {
|
317
421
|
x: number;
|
@@ -392,6 +496,8 @@ declare const entitySymbol: unique symbol;
|
|
392
496
|
*/
|
393
497
|
declare const Epsilon = 0.000001;
|
394
498
|
|
499
|
+
declare const error: (message: string | Error, data?: any) => void;
|
500
|
+
|
395
501
|
/** Excludes property keys from T where the property is assignable to U */
|
396
502
|
declare type ExcludeUndefined<T> = {
|
397
503
|
[P in keyof T]: undefined extends T[P] ? never : P;
|
@@ -415,16 +521,96 @@ declare function IArray<T>(type: ISchema<T>): ISchema<Array<T>>;
|
|
415
521
|
* @public
|
416
522
|
*/
|
417
523
|
declare type IEngine = {
|
524
|
+
/**
|
525
|
+
* Increment the used entity counter and return the next one.
|
526
|
+
* @param dynamic
|
527
|
+
* @return the next entity unused
|
528
|
+
*/
|
418
529
|
addEntity(dynamic?: boolean): Entity;
|
530
|
+
/**
|
531
|
+
* An alias of engine.addEntity(true)
|
532
|
+
*/
|
419
533
|
addDynamicEntity(): Entity;
|
534
|
+
/**
|
535
|
+
* Remove all components of an entity
|
536
|
+
* @param entity
|
537
|
+
*/
|
420
538
|
removeEntity(entity: Entity): void;
|
539
|
+
/**
|
540
|
+
* Add the system to the engine. It will be called every tick updated.
|
541
|
+
* @param system function that receives the delta time between last tick and current one.
|
542
|
+
* @param priority a number with the priority, big number are called before smaller ones
|
543
|
+
* @param name optional: a unique name to identify it
|
544
|
+
*
|
545
|
+
* Example:
|
546
|
+
* ```ts
|
547
|
+
* function mySystem(dt: number) {
|
548
|
+
* const entitiesWithBoxShapes = engine.getEntitiesWith(BoxShape, Transform)
|
549
|
+
* for (const [entity, _boxShape, _transform] of engine.getEntitiesWith(BoxShape, Transform)) {
|
550
|
+
* // do stuffs
|
551
|
+
* }
|
552
|
+
* }
|
553
|
+
* engine.addSystem(mySystem, 10)
|
554
|
+
* ```
|
555
|
+
*/
|
421
556
|
addSystem(system: Update, priority?: number, name?: string): void;
|
557
|
+
/**
|
558
|
+
* Remove a system from the engine.
|
559
|
+
* @param selector the function or the unique name to identify
|
560
|
+
* @returns if it was found and removed
|
561
|
+
*/
|
422
562
|
removeSystem(selector: string | Update): boolean;
|
423
|
-
|
424
|
-
|
425
|
-
|
563
|
+
/**
|
564
|
+
* Define a component and add it to the engine.
|
565
|
+
* @param spec An object with schema fields
|
566
|
+
* @param componentId unique id to identify the component, if the component id already exist, it will fail.
|
567
|
+
* @return The component definition
|
568
|
+
*
|
569
|
+
* ```ts
|
570
|
+
* const DoorComponentId = 10017
|
571
|
+
* const Door = engine.defineComponent({
|
572
|
+
* id: Schemas.Int,
|
573
|
+
* name: Schemas.String
|
574
|
+
* }, DoorComponentId)
|
575
|
+
*
|
576
|
+
* ```
|
577
|
+
*/
|
578
|
+
defineComponent<T extends Spec>(spec: Spec, componentId: number): ComponentDefinition<ISchema<Result<T>>>;
|
579
|
+
/**
|
580
|
+
* Define a component and add it to the engine.
|
581
|
+
* @param spec An object with schema fields
|
582
|
+
* @param componentId unique id to identify the component, if the component id already exist, it will fail.
|
583
|
+
* @return The component definition
|
584
|
+
*
|
585
|
+
* ```ts
|
586
|
+
* const StateComponentId = 10023
|
587
|
+
* const StateComponent = engine.defineComponent(Schemas.Bool, VisibleComponentId)
|
588
|
+
* ```
|
589
|
+
*/
|
590
|
+
defineComponentFromSchema<T extends ISchema>(spec: T, componentId: number): ComponentDefinition<T>;
|
591
|
+
/**
|
592
|
+
* Get the component definition from the component id.
|
593
|
+
* @param componentId
|
594
|
+
* @return the component definition, throw an error if it doesn't exist
|
595
|
+
* ```ts
|
596
|
+
* const StateComponentId = 10023
|
597
|
+
* const StateComponent = engine.getComponent(StateComponentId)
|
598
|
+
* ```
|
599
|
+
*/
|
426
600
|
getComponent<T extends ISchema>(componentId: number): ComponentDefinition<T>;
|
427
|
-
|
601
|
+
/**
|
602
|
+
* Get a iterator of entities that has all the component requested.
|
603
|
+
* @param components a list of component definitions
|
604
|
+
* @return An iterator of an array with the [entity, component1, component2, ...]
|
605
|
+
*
|
606
|
+
* Example:
|
607
|
+
* ```ts
|
608
|
+
* for (const [entity, boxShape, transform] of engine.getEntitiesWith(BoxShape, Transform)) {
|
609
|
+
* // the properties of boxShape and transform are read only
|
610
|
+
* }
|
611
|
+
* ```
|
612
|
+
*/
|
613
|
+
getEntitiesWith<T extends [ComponentDefinition, ...ComponentDefinition[]]>(...components: T): Iterable<[Entity, ...DeepReadonly<ComponentSchema<T>>]>;
|
428
614
|
baseComponents: SdkComponents;
|
429
615
|
};
|
430
616
|
|
@@ -479,6 +665,8 @@ declare interface ISize {
|
|
479
665
|
height: number;
|
480
666
|
}
|
481
667
|
|
668
|
+
declare const log: (...a: any[]) => void;
|
669
|
+
|
482
670
|
/**
|
483
671
|
* Class used to store matrix data (4x4)
|
484
672
|
* @public
|