@dcl/ecs 7.1.18-5157707330.commit-091fce4 → 7.1.18-5158337338.commit-735bf67

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.
@@ -33,6 +33,15 @@ export interface PointerEventsSystem {
33
33
  /**
34
34
  * @public
35
35
  * Execute callback when the user press the InputButton pointing at the entity
36
+ * @param pointerData - Entity to attach the callback, Opts to trigger Feedback and Button
37
+ * @param cb - Function to execute when click fires
38
+ */
39
+ onPointerDown(pointerData: {
40
+ entity: Entity;
41
+ opts?: Partial<EventSystemOptions>;
42
+ }, cb: EventSystemCallback): void;
43
+ /**
44
+ * @deprecated Use onPointerDown with (pointerData, cb)
36
45
  * @param entity - Entity to attach the callback
37
46
  * @param cb - Function to execute when click fires
38
47
  * @param opts - Opts to trigger Feedback and Button
@@ -41,6 +50,15 @@ export interface PointerEventsSystem {
41
50
  /**
42
51
  * @public
43
52
  * Execute callback when the user releases the InputButton pointing at the entity
53
+ * @param pointerData - Entity to attach the callback - Opts to trigger Feedback and Button
54
+ * @param cb - Function to execute when click fires
55
+ */
56
+ onPointerUp(pointerData: {
57
+ entity: Entity;
58
+ opts?: Partial<EventSystemOptions>;
59
+ }, cb: EventSystemCallback): void;
60
+ /**
61
+ * @deprecated Use onPointerUp with (pointerData, cb)
44
62
  * @param entity - Entity to attach the callback
45
63
  * @param cb - Function to execute when click fires
46
64
  * @param opts - Opts to trigger Feedback and Button
@@ -76,6 +76,28 @@ export function createPointerEventsSystem(engine, inputSystem) {
76
76
  }
77
77
  }
78
78
  });
79
+ const onPointerDown = (...args) => {
80
+ const [data, cb, maybeOpts] = args;
81
+ if (typeof data === 'number') {
82
+ return onPointerDown({ entity: data, opts: maybeOpts ?? {} }, cb);
83
+ }
84
+ const { entity, opts } = data;
85
+ const options = getDefaultOpts(opts);
86
+ removeEvent(entity, EventType.Down);
87
+ getEvent(entity).set(EventType.Down, { cb, opts: options });
88
+ setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
89
+ };
90
+ const onPointerUp = (...args) => {
91
+ const [data, cb, maybeOpts] = args;
92
+ if (typeof data === 'number') {
93
+ return onPointerUp({ entity: data, opts: maybeOpts ?? {} }, cb);
94
+ }
95
+ const { entity, opts } = data;
96
+ const options = getDefaultOpts(opts);
97
+ removeEvent(entity, EventType.Up);
98
+ getEvent(entity).set(EventType.Up, { cb, opts: options });
99
+ setPointerEvent(entity, 0 /* PointerEventType.PET_UP */, options);
100
+ };
79
101
  return {
80
102
  removeOnClick(entity) {
81
103
  removeEvent(entity, EventType.Click);
@@ -86,25 +108,16 @@ export function createPointerEventsSystem(engine, inputSystem) {
86
108
  removeOnPointerUp(entity) {
87
109
  removeEvent(entity, EventType.Up);
88
110
  },
89
- onClick(entity, cb, opts) {
90
- const options = getDefaultOpts(opts);
111
+ onClick(value, cb) {
112
+ const { entity } = value;
113
+ const options = getDefaultOpts(value.opts);
91
114
  // Clear previous event with over feedback included
92
115
  removeEvent(entity, EventType.Click);
93
116
  // Set new event
94
117
  getEvent(entity).set(EventType.Click, { cb, opts: options });
95
118
  setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
96
119
  },
97
- onPointerDown(entity, cb, opts) {
98
- const options = getDefaultOpts(opts);
99
- removeEvent(entity, EventType.Down);
100
- getEvent(entity).set(EventType.Down, { cb, opts: options });
101
- setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
102
- },
103
- onPointerUp(entity, cb, opts) {
104
- const options = getDefaultOpts(opts);
105
- removeEvent(entity, EventType.Up);
106
- getEvent(entity).set(EventType.Up, { cb, opts: options });
107
- setPointerEvent(entity, 0 /* PointerEventType.PET_UP */, options);
108
- }
120
+ onPointerDown,
121
+ onPointerUp
109
122
  };
110
123
  }
@@ -45,6 +45,15 @@ export interface RaycastSystem {
45
45
  * @public
46
46
  * Execute callback when the entity receives a RaycastResult component update.
47
47
  * Uses a Vector3 entity-local direction value to calculate the ray direction
48
+ * @param raycastData - Entity to attach the callback and Raycast configuration options
49
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
50
+ */
51
+ registerLocalDirectionRaycast(raycastData: {
52
+ entity: Entity;
53
+ opts?: Partial<LocalDirectionRaycastOptions>;
54
+ }, callback: RaycastSystemCallback): void;
55
+ /**
56
+ * @deprecated use registerLocalDirectionRaycast(raycastData, cb) instead
48
57
  * @param entity - Entity to attach the callback
49
58
  * @param callback - Function to execute when the entity's RaycastResult component is updated
50
59
  * @param options - Raycast configuration options
@@ -54,6 +63,15 @@ export interface RaycastSystem {
54
63
  * @public
55
64
  * Execute callback when the entity receives a RaycastResult component update.
56
65
  * Uses a Vector3 global direction value to calculate the ray direction
66
+ * @param raycastData - Entity to attach the callback
67
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
68
+ */
69
+ registerGlobalDirectionRaycast(raycastData: {
70
+ entity: Entity;
71
+ opts?: Partial<GlobalDirectionRaycastOptions>;
72
+ }, callback: RaycastSystemCallback): void;
73
+ /**
74
+ * @deprecated use registerGlobalDirectionRaycast(raycastData, cb) instead
57
75
  * @param entity - Entity to attach the callback
58
76
  * @param callback - Function to execute when the entity's RaycastResult component is updated
59
77
  * @param options - Raycast configuration options
@@ -63,6 +81,15 @@ export interface RaycastSystem {
63
81
  * @public
64
82
  * Execute callback when the entity receives a RaycastResult component update.
65
83
  * Uses a Vector3 global target position to calculate the ray direction
84
+ * @param raycastData - Entity to attach the callback and Raycast configuration options
85
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
86
+ */
87
+ registerGlobalTargetRaycast(raycastData: {
88
+ entity: Entity;
89
+ opts?: Partial<GlobalTargetRaycastOptions>;
90
+ }, callback: RaycastSystemCallback): void;
91
+ /**
92
+ * @deprecated use registerGlobalTargetRaycast(raycastData, cb) instead
66
93
  * @param entity - Entity to attach the callback
67
94
  * @param callback - Function to execute when the entity's RaycastResult component is updated
68
95
  * @param options - Raycast configuration options
@@ -72,9 +99,46 @@ export interface RaycastSystem {
72
99
  * @public
73
100
  * Execute callback when the entity receives a RaycastResult component update.
74
101
  * Uses an target Entity value to calculate the ray direction
102
+ * @param raycastData - Entity to attach the callback
103
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
104
+ * @param options - Raycast configuration options
105
+ */
106
+ registerTargetEntityRaycast(raycastData: {
107
+ entity: Entity;
108
+ opts?: Partial<TargetEntityRaycastOptions>;
109
+ }, callback: RaycastSystemCallback): void;
110
+ /**
111
+ * @deprecated use registerTargetEntityRaycast(raycastData, cb) instead
75
112
  * @param entity - Entity to attach the callback
76
113
  * @param callback - Function to execute when the entity's RaycastResult component is updated
77
114
  * @param options - Raycast configuration options
78
115
  */
79
116
  registerTargetEntityRaycast(entity: Entity, callback: RaycastSystemCallback, options?: Partial<TargetEntityRaycastOptions>): void;
117
+ /**
118
+ * @public
119
+ * Creates Raycast local direction opts with defaults
120
+ */
121
+ localDirectionOptions(options?: Partial<LocalDirectionRaycastOptions>): RaycastSystemOptions;
122
+ /**
123
+ * @public
124
+ * Creates Raycast global direction opts with defaults
125
+ */
126
+ globalDirectionOptions(options?: Partial<GlobalDirectionRaycastOptions>): RaycastSystemOptions;
127
+ /**
128
+ * @public
129
+ * Creates Raycast global target direction opts with defaults
130
+ */
131
+ globalTargetOptions(options?: Partial<GlobalTargetRaycastOptions>): RaycastSystemOptions;
132
+ /**
133
+ * @public
134
+ * Creates Raycast target entity opts with defaults
135
+ */
136
+ targetEntitytOptions(options?: Partial<TargetEntityRaycastOptions>): RaycastSystemOptions;
137
+ /**
138
+ * @public
139
+ * Immediate mode Raycast to be used on a sytem rather than callbacks
140
+ *
141
+ * Use the options helper to create the specified raycast i.e. localDirectionOptions(opts)
142
+ */
143
+ registerRaycast(entity: Entity, options: RaycastSystemOptions): DeepReadonlyObject<PBRaycastResult> | null;
80
144
  }
@@ -4,8 +4,8 @@ import { EntityState } from '../engine/entity';
4
4
  * @internal
5
5
  */
6
6
  export function createRaycastSystem(engine) {
7
- const raycastComponent = components.Raycast(engine);
8
- const raycastResultComponent = components.RaycastResult(engine);
7
+ const Raycast = components.Raycast(engine);
8
+ const RaycastResult = components.RaycastResult(engine);
9
9
  const entitiesCallbackResultMap = new Map();
10
10
  const defaultOptions = {
11
11
  maxDistance: 16,
@@ -46,30 +46,30 @@ export function createRaycastSystem(engine) {
46
46
  targetEntity: options.targetEntity || 0
47
47
  }
48
48
  });
49
- function registerRaycast(entity, callback, options) {
50
- const raycast = raycastComponent.getOrCreateMutable(entity);
51
- raycast.maxDistance = options.maxDistance;
52
- raycast.originOffset = options.originOffset;
53
- raycast.collisionMask = options.collisionMask;
54
- raycast.direction = options.directionRawValue;
55
- raycast.continuous = options.continuous;
56
- raycast.queryType = options.queryType;
49
+ function registerRaycastWithCallback(entity, raycastValue, callback) {
50
+ const raycast = Raycast.getOrCreateMutable(entity);
51
+ raycast.maxDistance = raycastValue.maxDistance;
52
+ raycast.originOffset = raycastValue.originOffset;
53
+ raycast.collisionMask = raycastValue.collisionMask;
54
+ raycast.direction = raycastValue.directionRawValue;
55
+ raycast.continuous = raycastValue.continuous;
56
+ raycast.queryType = raycastValue.queryType;
57
57
  entitiesCallbackResultMap.set(entity, { callback: callback });
58
58
  }
59
59
  function removeRaycast(entity) {
60
- raycastComponent.deleteFrom(entity);
61
- raycastResultComponent.deleteFrom(entity);
60
+ Raycast.deleteFrom(entity);
61
+ RaycastResult.deleteFrom(entity);
62
62
  entitiesCallbackResultMap.delete(entity);
63
63
  }
64
64
  // @internal
65
65
  engine.addSystem(function EventSystem() {
66
66
  for (const [entity, data] of entitiesCallbackResultMap) {
67
- const raycast = raycastComponent.getOrNull(entity);
67
+ const raycast = Raycast.getOrNull(entity);
68
68
  if (engine.getEntityState(entity) === EntityState.Removed || !raycast) {
69
69
  entitiesCallbackResultMap.delete(entity);
70
70
  continue;
71
71
  }
72
- const currentResult = raycastResultComponent.getOrNull(entity);
72
+ const currentResult = RaycastResult.getOrNull(entity);
73
73
  if (!currentResult)
74
74
  continue;
75
75
  data.callback(currentResult);
@@ -77,21 +77,62 @@ export function createRaycastSystem(engine) {
77
77
  removeRaycast(entity);
78
78
  }
79
79
  });
80
+ const registerLocalDirectionRaycast = (...args) => {
81
+ const [data, cb, maybeOpts] = args;
82
+ if (typeof data === 'number') {
83
+ return registerLocalDirectionRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
84
+ }
85
+ const { entity, opts } = data;
86
+ registerRaycastWithCallback(entity, getLocalDirectionRaycastDefaultOptions(opts), cb);
87
+ };
88
+ const registerGlobalDirectionRaycast = (...args) => {
89
+ const [data, cb, maybeOpts] = args;
90
+ if (typeof data === 'number') {
91
+ return registerGlobalDirectionRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
92
+ }
93
+ const { entity, opts } = data;
94
+ registerRaycastWithCallback(entity, getGlobalDirectionRaycastDefaultOptions(opts), cb);
95
+ };
96
+ const registerGlobalTargetRaycast = (...args) => {
97
+ const [data, cb, maybeOpts] = args;
98
+ if (typeof data === 'number') {
99
+ return registerGlobalTargetRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
100
+ }
101
+ const { entity, opts } = data;
102
+ registerRaycastWithCallback(entity, getGlobalTargetRaycastDefaultOptions(opts), cb);
103
+ };
104
+ const registerTargetEntityRaycast = (...args) => {
105
+ const [data, cb, maybeOpts] = args;
106
+ if (typeof data === 'number') {
107
+ return registerTargetEntityRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
108
+ }
109
+ const { entity, opts } = data;
110
+ registerRaycastWithCallback(entity, getTargetEntityRaycastDefaultOptions(opts), cb);
111
+ };
80
112
  return {
81
113
  removeRaycasterEntity(entity) {
82
114
  removeRaycast(entity);
83
115
  },
84
- registerLocalDirectionRaycast(entity, callback, opts) {
85
- registerRaycast(entity, callback, getLocalDirectionRaycastDefaultOptions(opts));
86
- },
87
- registerGlobalDirectionRaycast(entity, callback, opts) {
88
- registerRaycast(entity, callback, getGlobalDirectionRaycastDefaultOptions(opts));
89
- },
90
- registerGlobalTargetRaycast(entity, callback, opts) {
91
- registerRaycast(entity, callback, getGlobalTargetRaycastDefaultOptions(opts));
116
+ registerLocalDirectionRaycast,
117
+ registerGlobalDirectionRaycast,
118
+ registerGlobalTargetRaycast,
119
+ registerTargetEntityRaycast,
120
+ registerRaycast(entity, opts) {
121
+ const raycast = Raycast.getOrNull(entity);
122
+ if (!raycast)
123
+ Raycast.create(entity, { ...opts, direction: opts.directionRawValue });
124
+ const value = RaycastResult.getOrNull(entity);
125
+ if (value) {
126
+ if (!opts.continuous) {
127
+ RaycastResult.deleteFrom(entity);
128
+ Raycast.deleteFrom(entity);
129
+ }
130
+ }
131
+ return value;
92
132
  },
93
- registerTargetEntityRaycast(entity, callback, opts) {
94
- registerRaycast(entity, callback, getTargetEntityRaycastDefaultOptions(opts));
95
- }
133
+ localDirectionOptions: getLocalDirectionRaycastDefaultOptions,
134
+ globalDirectionOptions: getGlobalDirectionRaycastDefaultOptions,
135
+ globalTargetOptions: getGlobalTargetRaycastDefaultOptions,
136
+ targetEntitytOptions: getTargetEntityRaycastDefaultOptions
96
137
  };
97
138
  }
@@ -11,4 +11,9 @@ export interface VideoEventsSystem {
11
11
  removeVideoEventsEntity(entity: Entity): void;
12
12
  registerVideoEventsEntity(entity: Entity, callback: VideoEventsSystemCallback): void;
13
13
  hasVideoEventsEntity(entity: Entity): boolean;
14
+ /**
15
+ * Returns the latest state of the VideoEvent
16
+ * @param entity - Entity to retrieve the video status
17
+ */
18
+ getVideoState(entity: Entity): DeepReadonlyObject<PBVideoEvent> | undefined;
14
19
  }
@@ -28,23 +28,14 @@ export function createVideoEventsSystem(engine) {
28
28
  }
29
29
  // Compare with last state
30
30
  const videoEvent = videoEventComponent.get(entity);
31
- const values = videoEvent.values();
32
- const valuesAmount = videoEvent.size;
33
- let latestVideoEventComponentState = undefined;
34
- // get latest component state
35
- let index = 0;
36
- for (const value of values) {
37
- if (index === valuesAmount - 1)
38
- latestVideoEventComponentState = value;
39
- index++;
40
- }
41
- if (latestVideoEventComponentState === undefined ||
42
- (data.lastVideoState !== undefined && data.lastVideoState === latestVideoEventComponentState.state))
31
+ const values = Array.from(videoEvent.values());
32
+ const lastValue = values[videoEvent.size - 1];
33
+ if (lastValue === undefined || (data.lastVideoState !== undefined && data.lastVideoState === lastValue.state))
43
34
  continue;
44
- data.callback(latestVideoEventComponentState);
35
+ data.callback(lastValue);
45
36
  entitiesCallbackVideoStateMap.set(entity, {
46
37
  callback: data.callback,
47
- lastVideoState: latestVideoEventComponentState.state
38
+ lastVideoState: lastValue.state
48
39
  });
49
40
  }
50
41
  });
@@ -57,6 +48,12 @@ export function createVideoEventsSystem(engine) {
57
48
  },
58
49
  hasVideoEventsEntity(entity) {
59
50
  return hasVideoEventsEntity(entity);
51
+ },
52
+ getVideoState(entity) {
53
+ const videoEvent = videoEventComponent.get(entity);
54
+ const values = Array.from(videoEvent.values());
55
+ const lastValue = values[videoEvent.size - 1];
56
+ return lastValue;
60
57
  }
61
58
  };
62
59
  }
@@ -33,6 +33,15 @@ export interface PointerEventsSystem {
33
33
  /**
34
34
  * @public
35
35
  * Execute callback when the user press the InputButton pointing at the entity
36
+ * @param pointerData - Entity to attach the callback, Opts to trigger Feedback and Button
37
+ * @param cb - Function to execute when click fires
38
+ */
39
+ onPointerDown(pointerData: {
40
+ entity: Entity;
41
+ opts?: Partial<EventSystemOptions>;
42
+ }, cb: EventSystemCallback): void;
43
+ /**
44
+ * @deprecated Use onPointerDown with (pointerData, cb)
36
45
  * @param entity - Entity to attach the callback
37
46
  * @param cb - Function to execute when click fires
38
47
  * @param opts - Opts to trigger Feedback and Button
@@ -41,6 +50,15 @@ export interface PointerEventsSystem {
41
50
  /**
42
51
  * @public
43
52
  * Execute callback when the user releases the InputButton pointing at the entity
53
+ * @param pointerData - Entity to attach the callback - Opts to trigger Feedback and Button
54
+ * @param cb - Function to execute when click fires
55
+ */
56
+ onPointerUp(pointerData: {
57
+ entity: Entity;
58
+ opts?: Partial<EventSystemOptions>;
59
+ }, cb: EventSystemCallback): void;
60
+ /**
61
+ * @deprecated Use onPointerUp with (pointerData, cb)
44
62
  * @param entity - Entity to attach the callback
45
63
  * @param cb - Function to execute when click fires
46
64
  * @param opts - Opts to trigger Feedback and Button
@@ -102,6 +102,28 @@ function createPointerEventsSystem(engine, inputSystem) {
102
102
  }
103
103
  }
104
104
  });
105
+ const onPointerDown = (...args) => {
106
+ const [data, cb, maybeOpts] = args;
107
+ if (typeof data === 'number') {
108
+ return onPointerDown({ entity: data, opts: maybeOpts ?? {} }, cb);
109
+ }
110
+ const { entity, opts } = data;
111
+ const options = getDefaultOpts(opts);
112
+ removeEvent(entity, EventType.Down);
113
+ getEvent(entity).set(EventType.Down, { cb, opts: options });
114
+ setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
115
+ };
116
+ const onPointerUp = (...args) => {
117
+ const [data, cb, maybeOpts] = args;
118
+ if (typeof data === 'number') {
119
+ return onPointerUp({ entity: data, opts: maybeOpts ?? {} }, cb);
120
+ }
121
+ const { entity, opts } = data;
122
+ const options = getDefaultOpts(opts);
123
+ removeEvent(entity, EventType.Up);
124
+ getEvent(entity).set(EventType.Up, { cb, opts: options });
125
+ setPointerEvent(entity, 0 /* PointerEventType.PET_UP */, options);
126
+ };
105
127
  return {
106
128
  removeOnClick(entity) {
107
129
  removeEvent(entity, EventType.Click);
@@ -112,26 +134,17 @@ function createPointerEventsSystem(engine, inputSystem) {
112
134
  removeOnPointerUp(entity) {
113
135
  removeEvent(entity, EventType.Up);
114
136
  },
115
- onClick(entity, cb, opts) {
116
- const options = getDefaultOpts(opts);
137
+ onClick(value, cb) {
138
+ const { entity } = value;
139
+ const options = getDefaultOpts(value.opts);
117
140
  // Clear previous event with over feedback included
118
141
  removeEvent(entity, EventType.Click);
119
142
  // Set new event
120
143
  getEvent(entity).set(EventType.Click, { cb, opts: options });
121
144
  setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
122
145
  },
123
- onPointerDown(entity, cb, opts) {
124
- const options = getDefaultOpts(opts);
125
- removeEvent(entity, EventType.Down);
126
- getEvent(entity).set(EventType.Down, { cb, opts: options });
127
- setPointerEvent(entity, 1 /* PointerEventType.PET_DOWN */, options);
128
- },
129
- onPointerUp(entity, cb, opts) {
130
- const options = getDefaultOpts(opts);
131
- removeEvent(entity, EventType.Up);
132
- getEvent(entity).set(EventType.Up, { cb, opts: options });
133
- setPointerEvent(entity, 0 /* PointerEventType.PET_UP */, options);
134
- }
146
+ onPointerDown,
147
+ onPointerUp
135
148
  };
136
149
  }
137
150
  exports.createPointerEventsSystem = createPointerEventsSystem;
@@ -45,6 +45,15 @@ export interface RaycastSystem {
45
45
  * @public
46
46
  * Execute callback when the entity receives a RaycastResult component update.
47
47
  * Uses a Vector3 entity-local direction value to calculate the ray direction
48
+ * @param raycastData - Entity to attach the callback and Raycast configuration options
49
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
50
+ */
51
+ registerLocalDirectionRaycast(raycastData: {
52
+ entity: Entity;
53
+ opts?: Partial<LocalDirectionRaycastOptions>;
54
+ }, callback: RaycastSystemCallback): void;
55
+ /**
56
+ * @deprecated use registerLocalDirectionRaycast(raycastData, cb) instead
48
57
  * @param entity - Entity to attach the callback
49
58
  * @param callback - Function to execute when the entity's RaycastResult component is updated
50
59
  * @param options - Raycast configuration options
@@ -54,6 +63,15 @@ export interface RaycastSystem {
54
63
  * @public
55
64
  * Execute callback when the entity receives a RaycastResult component update.
56
65
  * Uses a Vector3 global direction value to calculate the ray direction
66
+ * @param raycastData - Entity to attach the callback
67
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
68
+ */
69
+ registerGlobalDirectionRaycast(raycastData: {
70
+ entity: Entity;
71
+ opts?: Partial<GlobalDirectionRaycastOptions>;
72
+ }, callback: RaycastSystemCallback): void;
73
+ /**
74
+ * @deprecated use registerGlobalDirectionRaycast(raycastData, cb) instead
57
75
  * @param entity - Entity to attach the callback
58
76
  * @param callback - Function to execute when the entity's RaycastResult component is updated
59
77
  * @param options - Raycast configuration options
@@ -63,6 +81,15 @@ export interface RaycastSystem {
63
81
  * @public
64
82
  * Execute callback when the entity receives a RaycastResult component update.
65
83
  * Uses a Vector3 global target position to calculate the ray direction
84
+ * @param raycastData - Entity to attach the callback and Raycast configuration options
85
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
86
+ */
87
+ registerGlobalTargetRaycast(raycastData: {
88
+ entity: Entity;
89
+ opts?: Partial<GlobalTargetRaycastOptions>;
90
+ }, callback: RaycastSystemCallback): void;
91
+ /**
92
+ * @deprecated use registerGlobalTargetRaycast(raycastData, cb) instead
66
93
  * @param entity - Entity to attach the callback
67
94
  * @param callback - Function to execute when the entity's RaycastResult component is updated
68
95
  * @param options - Raycast configuration options
@@ -72,9 +99,46 @@ export interface RaycastSystem {
72
99
  * @public
73
100
  * Execute callback when the entity receives a RaycastResult component update.
74
101
  * Uses an target Entity value to calculate the ray direction
102
+ * @param raycastData - Entity to attach the callback
103
+ * @param callback - Function to execute when the entity's RaycastResult component is updated
104
+ * @param options - Raycast configuration options
105
+ */
106
+ registerTargetEntityRaycast(raycastData: {
107
+ entity: Entity;
108
+ opts?: Partial<TargetEntityRaycastOptions>;
109
+ }, callback: RaycastSystemCallback): void;
110
+ /**
111
+ * @deprecated use registerTargetEntityRaycast(raycastData, cb) instead
75
112
  * @param entity - Entity to attach the callback
76
113
  * @param callback - Function to execute when the entity's RaycastResult component is updated
77
114
  * @param options - Raycast configuration options
78
115
  */
79
116
  registerTargetEntityRaycast(entity: Entity, callback: RaycastSystemCallback, options?: Partial<TargetEntityRaycastOptions>): void;
117
+ /**
118
+ * @public
119
+ * Creates Raycast local direction opts with defaults
120
+ */
121
+ localDirectionOptions(options?: Partial<LocalDirectionRaycastOptions>): RaycastSystemOptions;
122
+ /**
123
+ * @public
124
+ * Creates Raycast global direction opts with defaults
125
+ */
126
+ globalDirectionOptions(options?: Partial<GlobalDirectionRaycastOptions>): RaycastSystemOptions;
127
+ /**
128
+ * @public
129
+ * Creates Raycast global target direction opts with defaults
130
+ */
131
+ globalTargetOptions(options?: Partial<GlobalTargetRaycastOptions>): RaycastSystemOptions;
132
+ /**
133
+ * @public
134
+ * Creates Raycast target entity opts with defaults
135
+ */
136
+ targetEntitytOptions(options?: Partial<TargetEntityRaycastOptions>): RaycastSystemOptions;
137
+ /**
138
+ * @public
139
+ * Immediate mode Raycast to be used on a sytem rather than callbacks
140
+ *
141
+ * Use the options helper to create the specified raycast i.e. localDirectionOptions(opts)
142
+ */
143
+ registerRaycast(entity: Entity, options: RaycastSystemOptions): DeepReadonlyObject<PBRaycastResult> | null;
80
144
  }
@@ -30,8 +30,8 @@ const entity_1 = require("../engine/entity");
30
30
  * @internal
31
31
  */
32
32
  function createRaycastSystem(engine) {
33
- const raycastComponent = components.Raycast(engine);
34
- const raycastResultComponent = components.RaycastResult(engine);
33
+ const Raycast = components.Raycast(engine);
34
+ const RaycastResult = components.RaycastResult(engine);
35
35
  const entitiesCallbackResultMap = new Map();
36
36
  const defaultOptions = {
37
37
  maxDistance: 16,
@@ -72,30 +72,30 @@ function createRaycastSystem(engine) {
72
72
  targetEntity: options.targetEntity || 0
73
73
  }
74
74
  });
75
- function registerRaycast(entity, callback, options) {
76
- const raycast = raycastComponent.getOrCreateMutable(entity);
77
- raycast.maxDistance = options.maxDistance;
78
- raycast.originOffset = options.originOffset;
79
- raycast.collisionMask = options.collisionMask;
80
- raycast.direction = options.directionRawValue;
81
- raycast.continuous = options.continuous;
82
- raycast.queryType = options.queryType;
75
+ function registerRaycastWithCallback(entity, raycastValue, callback) {
76
+ const raycast = Raycast.getOrCreateMutable(entity);
77
+ raycast.maxDistance = raycastValue.maxDistance;
78
+ raycast.originOffset = raycastValue.originOffset;
79
+ raycast.collisionMask = raycastValue.collisionMask;
80
+ raycast.direction = raycastValue.directionRawValue;
81
+ raycast.continuous = raycastValue.continuous;
82
+ raycast.queryType = raycastValue.queryType;
83
83
  entitiesCallbackResultMap.set(entity, { callback: callback });
84
84
  }
85
85
  function removeRaycast(entity) {
86
- raycastComponent.deleteFrom(entity);
87
- raycastResultComponent.deleteFrom(entity);
86
+ Raycast.deleteFrom(entity);
87
+ RaycastResult.deleteFrom(entity);
88
88
  entitiesCallbackResultMap.delete(entity);
89
89
  }
90
90
  // @internal
91
91
  engine.addSystem(function EventSystem() {
92
92
  for (const [entity, data] of entitiesCallbackResultMap) {
93
- const raycast = raycastComponent.getOrNull(entity);
93
+ const raycast = Raycast.getOrNull(entity);
94
94
  if (engine.getEntityState(entity) === entity_1.EntityState.Removed || !raycast) {
95
95
  entitiesCallbackResultMap.delete(entity);
96
96
  continue;
97
97
  }
98
- const currentResult = raycastResultComponent.getOrNull(entity);
98
+ const currentResult = RaycastResult.getOrNull(entity);
99
99
  if (!currentResult)
100
100
  continue;
101
101
  data.callback(currentResult);
@@ -103,22 +103,63 @@ function createRaycastSystem(engine) {
103
103
  removeRaycast(entity);
104
104
  }
105
105
  });
106
+ const registerLocalDirectionRaycast = (...args) => {
107
+ const [data, cb, maybeOpts] = args;
108
+ if (typeof data === 'number') {
109
+ return registerLocalDirectionRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
110
+ }
111
+ const { entity, opts } = data;
112
+ registerRaycastWithCallback(entity, getLocalDirectionRaycastDefaultOptions(opts), cb);
113
+ };
114
+ const registerGlobalDirectionRaycast = (...args) => {
115
+ const [data, cb, maybeOpts] = args;
116
+ if (typeof data === 'number') {
117
+ return registerGlobalDirectionRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
118
+ }
119
+ const { entity, opts } = data;
120
+ registerRaycastWithCallback(entity, getGlobalDirectionRaycastDefaultOptions(opts), cb);
121
+ };
122
+ const registerGlobalTargetRaycast = (...args) => {
123
+ const [data, cb, maybeOpts] = args;
124
+ if (typeof data === 'number') {
125
+ return registerGlobalTargetRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
126
+ }
127
+ const { entity, opts } = data;
128
+ registerRaycastWithCallback(entity, getGlobalTargetRaycastDefaultOptions(opts), cb);
129
+ };
130
+ const registerTargetEntityRaycast = (...args) => {
131
+ const [data, cb, maybeOpts] = args;
132
+ if (typeof data === 'number') {
133
+ return registerTargetEntityRaycast({ entity: data, opts: maybeOpts ?? {} }, cb);
134
+ }
135
+ const { entity, opts } = data;
136
+ registerRaycastWithCallback(entity, getTargetEntityRaycastDefaultOptions(opts), cb);
137
+ };
106
138
  return {
107
139
  removeRaycasterEntity(entity) {
108
140
  removeRaycast(entity);
109
141
  },
110
- registerLocalDirectionRaycast(entity, callback, opts) {
111
- registerRaycast(entity, callback, getLocalDirectionRaycastDefaultOptions(opts));
112
- },
113
- registerGlobalDirectionRaycast(entity, callback, opts) {
114
- registerRaycast(entity, callback, getGlobalDirectionRaycastDefaultOptions(opts));
115
- },
116
- registerGlobalTargetRaycast(entity, callback, opts) {
117
- registerRaycast(entity, callback, getGlobalTargetRaycastDefaultOptions(opts));
142
+ registerLocalDirectionRaycast,
143
+ registerGlobalDirectionRaycast,
144
+ registerGlobalTargetRaycast,
145
+ registerTargetEntityRaycast,
146
+ registerRaycast(entity, opts) {
147
+ const raycast = Raycast.getOrNull(entity);
148
+ if (!raycast)
149
+ Raycast.create(entity, { ...opts, direction: opts.directionRawValue });
150
+ const value = RaycastResult.getOrNull(entity);
151
+ if (value) {
152
+ if (!opts.continuous) {
153
+ RaycastResult.deleteFrom(entity);
154
+ Raycast.deleteFrom(entity);
155
+ }
156
+ }
157
+ return value;
118
158
  },
119
- registerTargetEntityRaycast(entity, callback, opts) {
120
- registerRaycast(entity, callback, getTargetEntityRaycastDefaultOptions(opts));
121
- }
159
+ localDirectionOptions: getLocalDirectionRaycastDefaultOptions,
160
+ globalDirectionOptions: getGlobalDirectionRaycastDefaultOptions,
161
+ globalTargetOptions: getGlobalTargetRaycastDefaultOptions,
162
+ targetEntitytOptions: getTargetEntityRaycastDefaultOptions
122
163
  };
123
164
  }
124
165
  exports.createRaycastSystem = createRaycastSystem;
@@ -11,4 +11,9 @@ export interface VideoEventsSystem {
11
11
  removeVideoEventsEntity(entity: Entity): void;
12
12
  registerVideoEventsEntity(entity: Entity, callback: VideoEventsSystemCallback): void;
13
13
  hasVideoEventsEntity(entity: Entity): boolean;
14
+ /**
15
+ * Returns the latest state of the VideoEvent
16
+ * @param entity - Entity to retrieve the video status
17
+ */
18
+ getVideoState(entity: Entity): DeepReadonlyObject<PBVideoEvent> | undefined;
14
19
  }
@@ -54,23 +54,14 @@ function createVideoEventsSystem(engine) {
54
54
  }
55
55
  // Compare with last state
56
56
  const videoEvent = videoEventComponent.get(entity);
57
- const values = videoEvent.values();
58
- const valuesAmount = videoEvent.size;
59
- let latestVideoEventComponentState = undefined;
60
- // get latest component state
61
- let index = 0;
62
- for (const value of values) {
63
- if (index === valuesAmount - 1)
64
- latestVideoEventComponentState = value;
65
- index++;
66
- }
67
- if (latestVideoEventComponentState === undefined ||
68
- (data.lastVideoState !== undefined && data.lastVideoState === latestVideoEventComponentState.state))
57
+ const values = Array.from(videoEvent.values());
58
+ const lastValue = values[videoEvent.size - 1];
59
+ if (lastValue === undefined || (data.lastVideoState !== undefined && data.lastVideoState === lastValue.state))
69
60
  continue;
70
- data.callback(latestVideoEventComponentState);
61
+ data.callback(lastValue);
71
62
  entitiesCallbackVideoStateMap.set(entity, {
72
63
  callback: data.callback,
73
- lastVideoState: latestVideoEventComponentState.state
64
+ lastVideoState: lastValue.state
74
65
  });
75
66
  }
76
67
  });
@@ -83,6 +74,12 @@ function createVideoEventsSystem(engine) {
83
74
  },
84
75
  hasVideoEventsEntity(entity) {
85
76
  return hasVideoEventsEntity(entity);
77
+ },
78
+ getVideoState(entity) {
79
+ const videoEvent = videoEventComponent.get(entity);
80
+ const values = Array.from(videoEvent.values());
81
+ const lastValue = values[videoEvent.size - 1];
82
+ return lastValue;
86
83
  }
87
84
  };
88
85
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.1.18-5157707330.commit-091fce4",
4
+ "version": "7.1.18-5158337338.commit-735bf67",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "dependencies": {
8
- "@dcl/js-runtime": "7.1.18-5157707330.commit-091fce4"
8
+ "@dcl/js-runtime": "7.1.18-5158337338.commit-735bf67"
9
9
  },
10
10
  "files": [
11
11
  "dist",
@@ -25,7 +25,8 @@
25
25
  "directory": "packages/@dcl/ecs"
26
26
  },
27
27
  "scripts": {
28
- "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json"
28
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
29
+ "watch": "tsc -p tsconfig.json --watch"
29
30
  },
30
31
  "typedoc": {
31
32
  "entryPoint": "./src/index.ts",
@@ -35,5 +36,5 @@
35
36
  },
36
37
  "types": "./dist/index.d.ts",
37
38
  "typings": "./dist/index.d.ts",
38
- "commit": "091fce4615f18681efcef4556b5fc76652a79639"
39
+ "commit": "735bf678b8390821dd0fdd6046e78963212bed6c"
39
40
  }