@dcl/ecs 7.10.2 → 7.10.3-17918694201.commit-b983b3b

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.
@@ -17,6 +17,7 @@ import { MediaState } from './generated/pb/decentraland/sdk/components/common/me
17
17
  import { VirtualCameraComponentDefinitionExtended } from './extended/VirtualCamera';
18
18
  import { InputModifierComponentDefinitionExtended } from './extended/InputModifier';
19
19
  import { LightSourceComponentDefinitionExtended } from './extended/LightSource';
20
+ import { TagsComponentDefinitionExtended } from './manual/Tags';
20
21
  export * from './generated/index.gen';
21
22
  export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
22
23
  export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
@@ -34,6 +35,7 @@ export declare const LightSource: LwwComponentGetter<LightSourceComponentDefinit
34
35
  * @alpha
35
36
  */
36
37
  export declare const Name: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<NameType>;
38
+ export declare const Tags: (engine: Pick<IEngine, 'defineComponent'>) => TagsComponentDefinitionExtended;
37
39
  /**
38
40
  * @alpha
39
41
  */
@@ -14,6 +14,7 @@ import { MediaState } from './generated/pb/decentraland/sdk/components/common/me
14
14
  import { defineVirtualCameraComponent } from './extended/VirtualCamera';
15
15
  import { defineInputModifierComponent } from './extended/InputModifier';
16
16
  import { defineLightSourceComponent } from './extended/LightSource';
17
+ import defineTagsComponent from './manual/Tags';
17
18
  export * from './generated/index.gen';
18
19
  /* @__PURE__ */
19
20
  export const Transform = (engine) => defineTransformComponent(engine);
@@ -42,6 +43,8 @@ export const LightSource = (engine) => defineLightSourceComponent(engine);
42
43
  */
43
44
  /* @__PURE__ */
44
45
  export const Name = (engine) => defineNameComponent(engine);
46
+ /* @__PURE__ */
47
+ export const Tags = (engine) => defineTagsComponent(engine);
45
48
  /**
46
49
  * @alpha
47
50
  */
@@ -0,0 +1,34 @@
1
+ import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
2
+ import { Entity } from '../../engine';
3
+ export interface TagsType {
4
+ tags: string[];
5
+ }
6
+ export interface TagsComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition<TagsType> {
7
+ /**
8
+ * @public
9
+ *
10
+ * Add a tag to the entity's Tags component or create the component if it doesn't exist and add the tag
11
+ * @param entity - entity to add the tag to
12
+ * @param tagName - the tag name to add
13
+ * @returns true
14
+ */
15
+ add(entity: Entity, tagName: string): boolean;
16
+ /**
17
+ * @public
18
+ *
19
+ * Remove a tag from the entity's Tags component
20
+ * @param entity - entity to remove the tag from
21
+ * @param tagName - the tag name to remove
22
+ * @returns true if successful, false if the entity doesn't have a Tags component or the tag doesn't exist
23
+ */
24
+ remove(entity: Entity, tagName: string): boolean;
25
+ }
26
+ /**
27
+ * @public
28
+ *
29
+ * Define the Tags component
30
+ * @param engine - the engine to define the component on
31
+ * @returns the Tags component definition
32
+ */
33
+ declare function defineTagsComponent(engine: Pick<IEngine, 'defineComponent'>): TagsComponentDefinitionExtended;
34
+ export default defineTagsComponent;
@@ -0,0 +1,37 @@
1
+ import { Schemas } from '../../schemas';
2
+ /**
3
+ * @public
4
+ *
5
+ * Define the Tags component
6
+ * @param engine - the engine to define the component on
7
+ * @returns the Tags component definition
8
+ */
9
+ function defineTagsComponent(engine) {
10
+ const Tags = engine.defineComponent('core-schema::Tags', {
11
+ tags: Schemas.Array(Schemas.String)
12
+ });
13
+ return {
14
+ ...Tags,
15
+ add(entity, tagName) {
16
+ const tagsComponent = Tags.getMutableOrNull(entity);
17
+ if (tagsComponent) {
18
+ tagsComponent.tags.push(tagName);
19
+ }
20
+ else {
21
+ Tags.createOrReplace(entity, { tags: [tagName] });
22
+ }
23
+ return true;
24
+ },
25
+ remove(entity, tagName) {
26
+ const tagsComponent = Tags.getMutableOrNull(entity);
27
+ if (!tagsComponent || !tagsComponent.tags)
28
+ return false;
29
+ const newTags = tagsComponent.tags.filter((tag) => tag !== tagName);
30
+ if (newTags.length === tagsComponent.tags.length)
31
+ return false;
32
+ tagsComponent.tags = newTags;
33
+ return true;
34
+ }
35
+ };
36
+ }
37
+ export default defineTagsComponent;
@@ -8,6 +8,7 @@ export type { TweenHelper, TweenComponentDefinitionExtended } from './extended/T
8
8
  export type { CameraTransitionHelper, VirtualCameraComponentDefinitionExtended } from './extended/VirtualCamera';
9
9
  export type { TransformComponentExtended, TransformTypeWithOptionals } from './manual/Transform';
10
10
  export type { NameComponent, NameType } from './manual/Name';
11
+ export type { TagsComponentDefinitionExtended, TagsType } from './manual/Tags';
11
12
  export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents';
12
13
  export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity';
13
14
  export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent';
@@ -143,6 +143,14 @@ function preEngine(options) {
143
143
  const entity = getEntityOrNullByName(value);
144
144
  return entity;
145
145
  }
146
+ function* getEntitiesByTag(tagName) {
147
+ const TagComponent = components.Tags({ defineComponent });
148
+ for (const [entity, component] of getEntitiesWith(TagComponent)) {
149
+ if (entity !== 0 && component.tags?.some((tag) => tag === tagName)) {
150
+ yield entity;
151
+ }
152
+ }
153
+ }
146
154
  function* getComponentDefGroup(...args) {
147
155
  const [firstComponentDef, ...componentDefinitions] = args;
148
156
  for (const [entity] of firstComponentDef.iterator()) {
@@ -191,6 +199,7 @@ function preEngine(options) {
191
199
  getComponentOrNull: getComponentOrNull,
192
200
  getEntityOrNullByName,
193
201
  getEntityByName,
202
+ getEntitiesByTag,
194
203
  removeComponentDefinition,
195
204
  registerComponentDefinition,
196
205
  entityContainer,
@@ -246,6 +255,7 @@ export function Engine(options) {
246
255
  seal: partialEngine.seal,
247
256
  getEntityOrNullByName: partialEngine.getEntityOrNullByName,
248
257
  getEntityByName: partialEngine.getEntityByName,
258
+ getEntitiesByTag: partialEngine.getEntitiesByTag,
249
259
  update,
250
260
  RootEntity: 0,
251
261
  PlayerEntity: 1,
@@ -196,6 +196,13 @@ export interface IEngine {
196
196
  * @typeParam T - The type of the entity name value
197
197
  */
198
198
  getEntityByName<T = never, K = T>(value: K & (T extends never ? never : string)): Entity;
199
+ /**
200
+ * @public
201
+ * Get all entities that have a specific tag in their Tag component
202
+ * @param tag - Tag to search
203
+ * @returns Iterator of entities that have the given tag
204
+ */
205
+ getEntitiesByTag(tagName: string): Iterable<Entity>;
199
206
  /**
200
207
  * @public
201
208
  * @param deltaTime - deltaTime in seconds
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './engine/entity';
13
13
  export * from './components/types';
14
14
  import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended } from './components/types';
15
15
  import { NameComponent } from './components/manual/Name';
16
+ import { TagsComponentDefinitionExtended } from './components/manual/Tags';
16
17
  export declare const Transform: TransformComponentExtended;
17
18
  export declare const Animator: AnimatorComponentDefinitionExtended;
18
19
  export declare const AudioSource: AudioSourceComponentDefinitionExtended;
@@ -21,6 +22,7 @@ export declare const Material: MaterialComponentDefinitionExtended;
21
22
  export declare const MeshRenderer: MeshRendererComponentDefinitionExtended;
22
23
  export declare const MeshCollider: MeshColliderComponentDefinitionExtended;
23
24
  export declare const Name: NameComponent;
25
+ export declare const Tags: TagsComponentDefinitionExtended;
24
26
  export declare const Tween: TweenComponentDefinitionExtended;
25
27
  export declare const VirtualCamera: VirtualCameraComponentDefinitionExtended;
26
28
  export declare const InputModifier: InputModifierComponentDefinitionExtended;
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ export const Material = /* @__PURE__*/ components.Material(engine);
26
26
  export const MeshRenderer = /* @__PURE__*/ components.MeshRenderer(engine);
27
27
  export const MeshCollider = /* @__PURE__*/ components.MeshCollider(engine);
28
28
  export const Name = components.Name(engine);
29
+ export const Tags = components.Tags(engine);
29
30
  export const Tween = /* @__PURE__*/ components.Tween(engine);
30
31
  export const VirtualCamera = /* @__PURE__*/ components.VirtualCamera(engine);
31
32
  export const InputModifier = /* @__PURE__*/ components.InputModifier(engine);
@@ -17,6 +17,7 @@ import { MediaState } from './generated/pb/decentraland/sdk/components/common/me
17
17
  import { VirtualCameraComponentDefinitionExtended } from './extended/VirtualCamera';
18
18
  import { InputModifierComponentDefinitionExtended } from './extended/InputModifier';
19
19
  import { LightSourceComponentDefinitionExtended } from './extended/LightSource';
20
+ import { TagsComponentDefinitionExtended } from './manual/Tags';
20
21
  export * from './generated/index.gen';
21
22
  export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
22
23
  export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
@@ -34,6 +35,7 @@ export declare const LightSource: LwwComponentGetter<LightSourceComponentDefinit
34
35
  * @alpha
35
36
  */
36
37
  export declare const Name: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<NameType>;
38
+ export declare const Tags: (engine: Pick<IEngine, 'defineComponent'>) => TagsComponentDefinitionExtended;
37
39
  /**
38
40
  * @alpha
39
41
  */
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Name = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
20
+ exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
21
21
  const Animator_1 = require("./extended/Animator");
22
22
  const AudioSource_1 = require("./extended/AudioSource");
23
23
  const Material_1 = require("./extended/Material");
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "MediaState", { enumerable: true, get: function (
35
35
  const VirtualCamera_1 = require("./extended/VirtualCamera");
36
36
  const InputModifier_1 = require("./extended/InputModifier");
37
37
  const LightSource_1 = require("./extended/LightSource");
38
+ const Tags_1 = __importDefault(require("./manual/Tags"));
38
39
  __exportStar(require("./generated/index.gen"), exports);
39
40
  /* @__PURE__ */
40
41
  const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
@@ -75,6 +76,9 @@ exports.LightSource = LightSource;
75
76
  /* @__PURE__ */
76
77
  const Name = (engine) => (0, Name_1.default)(engine);
77
78
  exports.Name = Name;
79
+ /* @__PURE__ */
80
+ const Tags = (engine) => (0, Tags_1.default)(engine);
81
+ exports.Tags = Tags;
78
82
  /**
79
83
  * @alpha
80
84
  */
@@ -0,0 +1,34 @@
1
+ import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
2
+ import { Entity } from '../../engine';
3
+ export interface TagsType {
4
+ tags: string[];
5
+ }
6
+ export interface TagsComponentDefinitionExtended extends LastWriteWinElementSetComponentDefinition<TagsType> {
7
+ /**
8
+ * @public
9
+ *
10
+ * Add a tag to the entity's Tags component or create the component if it doesn't exist and add the tag
11
+ * @param entity - entity to add the tag to
12
+ * @param tagName - the tag name to add
13
+ * @returns true
14
+ */
15
+ add(entity: Entity, tagName: string): boolean;
16
+ /**
17
+ * @public
18
+ *
19
+ * Remove a tag from the entity's Tags component
20
+ * @param entity - entity to remove the tag from
21
+ * @param tagName - the tag name to remove
22
+ * @returns true if successful, false if the entity doesn't have a Tags component or the tag doesn't exist
23
+ */
24
+ remove(entity: Entity, tagName: string): boolean;
25
+ }
26
+ /**
27
+ * @public
28
+ *
29
+ * Define the Tags component
30
+ * @param engine - the engine to define the component on
31
+ * @returns the Tags component definition
32
+ */
33
+ declare function defineTagsComponent(engine: Pick<IEngine, 'defineComponent'>): TagsComponentDefinitionExtended;
34
+ export default defineTagsComponent;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schemas_1 = require("../../schemas");
4
+ /**
5
+ * @public
6
+ *
7
+ * Define the Tags component
8
+ * @param engine - the engine to define the component on
9
+ * @returns the Tags component definition
10
+ */
11
+ function defineTagsComponent(engine) {
12
+ const Tags = engine.defineComponent('core-schema::Tags', {
13
+ tags: schemas_1.Schemas.Array(schemas_1.Schemas.String)
14
+ });
15
+ return {
16
+ ...Tags,
17
+ add(entity, tagName) {
18
+ const tagsComponent = Tags.getMutableOrNull(entity);
19
+ if (tagsComponent) {
20
+ tagsComponent.tags.push(tagName);
21
+ }
22
+ else {
23
+ Tags.createOrReplace(entity, { tags: [tagName] });
24
+ }
25
+ return true;
26
+ },
27
+ remove(entity, tagName) {
28
+ const tagsComponent = Tags.getMutableOrNull(entity);
29
+ if (!tagsComponent || !tagsComponent.tags)
30
+ return false;
31
+ const newTags = tagsComponent.tags.filter((tag) => tag !== tagName);
32
+ if (newTags.length === tagsComponent.tags.length)
33
+ return false;
34
+ tagsComponent.tags = newTags;
35
+ return true;
36
+ }
37
+ };
38
+ }
39
+ exports.default = defineTagsComponent;
@@ -8,6 +8,7 @@ export type { TweenHelper, TweenComponentDefinitionExtended } from './extended/T
8
8
  export type { CameraTransitionHelper, VirtualCameraComponentDefinitionExtended } from './extended/VirtualCamera';
9
9
  export type { TransformComponentExtended, TransformTypeWithOptionals } from './manual/Transform';
10
10
  export type { NameComponent, NameType } from './manual/Name';
11
+ export type { TagsComponentDefinitionExtended, TagsType } from './manual/Tags';
11
12
  export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents';
12
13
  export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity';
13
14
  export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent';
@@ -172,6 +172,14 @@ function preEngine(options) {
172
172
  const entity = getEntityOrNullByName(value);
173
173
  return entity;
174
174
  }
175
+ function* getEntitiesByTag(tagName) {
176
+ const TagComponent = components.Tags({ defineComponent });
177
+ for (const [entity, component] of getEntitiesWith(TagComponent)) {
178
+ if (entity !== 0 && component.tags?.some((tag) => tag === tagName)) {
179
+ yield entity;
180
+ }
181
+ }
182
+ }
175
183
  function* getComponentDefGroup(...args) {
176
184
  const [firstComponentDef, ...componentDefinitions] = args;
177
185
  for (const [entity] of firstComponentDef.iterator()) {
@@ -220,6 +228,7 @@ function preEngine(options) {
220
228
  getComponentOrNull: getComponentOrNull,
221
229
  getEntityOrNullByName,
222
230
  getEntityByName,
231
+ getEntitiesByTag,
223
232
  removeComponentDefinition,
224
233
  registerComponentDefinition,
225
234
  entityContainer,
@@ -275,6 +284,7 @@ function Engine(options) {
275
284
  seal: partialEngine.seal,
276
285
  getEntityOrNullByName: partialEngine.getEntityOrNullByName,
277
286
  getEntityByName: partialEngine.getEntityByName,
287
+ getEntitiesByTag: partialEngine.getEntitiesByTag,
278
288
  update,
279
289
  RootEntity: 0,
280
290
  PlayerEntity: 1,
@@ -196,6 +196,13 @@ export interface IEngine {
196
196
  * @typeParam T - The type of the entity name value
197
197
  */
198
198
  getEntityByName<T = never, K = T>(value: K & (T extends never ? never : string)): Entity;
199
+ /**
200
+ * @public
201
+ * Get all entities that have a specific tag in their Tag component
202
+ * @param tag - Tag to search
203
+ * @returns Iterator of entities that have the given tag
204
+ */
205
+ getEntitiesByTag(tagName: string): Iterable<Entity>;
199
206
  /**
200
207
  * @public
201
208
  * @param deltaTime - deltaTime in seconds
@@ -13,6 +13,7 @@ export * from './engine/entity';
13
13
  export * from './components/types';
14
14
  import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended } from './components/types';
15
15
  import { NameComponent } from './components/manual/Name';
16
+ import { TagsComponentDefinitionExtended } from './components/manual/Tags';
16
17
  export declare const Transform: TransformComponentExtended;
17
18
  export declare const Animator: AnimatorComponentDefinitionExtended;
18
19
  export declare const AudioSource: AudioSourceComponentDefinitionExtended;
@@ -21,6 +22,7 @@ export declare const Material: MaterialComponentDefinitionExtended;
21
22
  export declare const MeshRenderer: MeshRendererComponentDefinitionExtended;
22
23
  export declare const MeshCollider: MeshColliderComponentDefinitionExtended;
23
24
  export declare const Name: NameComponent;
25
+ export declare const Tags: TagsComponentDefinitionExtended;
24
26
  export declare const Tween: TweenComponentDefinitionExtended;
25
27
  export declare const VirtualCamera: VirtualCameraComponentDefinitionExtended;
26
28
  export declare const InputModifier: InputModifierComponentDefinitionExtended;
package/dist-cjs/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
29
+ exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
30
30
  // The order of the following imports matters. Please do not auto-sort
31
31
  __exportStar(require("./engine"), exports);
32
32
  __exportStar(require("./schemas"), exports);
@@ -55,6 +55,7 @@ exports.Material = components.Material(initialization_1.engine);
55
55
  exports.MeshRenderer = components.MeshRenderer(initialization_1.engine);
56
56
  exports.MeshCollider = components.MeshCollider(initialization_1.engine);
57
57
  exports.Name = components.Name(initialization_1.engine);
58
+ exports.Tags = components.Tags(initialization_1.engine);
58
59
  exports.Tween = components.Tween(initialization_1.engine);
59
60
  exports.VirtualCamera = components.VirtualCamera(initialization_1.engine);
60
61
  exports.InputModifier = components.InputModifier(initialization_1.engine);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.10.2",
4
+ "version": "7.10.3-17918694201.commit-b983b3b",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "files": [
@@ -33,5 +33,5 @@
33
33
  },
34
34
  "types": "./dist/index.d.ts",
35
35
  "typings": "./dist/index.d.ts",
36
- "commit": "931de89979b7eca676af3d4e3ccbaa5dcf8ef300"
36
+ "commit": "b983b3b74a44f323355ad4aed6a0e25504d20eb1"
37
37
  }