@dcl/playground-assets 7.1.0 → 7.1.1-4386019452.commit-8b1daa0

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/index.js CHANGED
@@ -42112,11 +42112,19 @@
42112
42112
  }
42113
42113
  };
42114
42114
 
42115
+ function getPointerEnum(pointerKey) {
42116
+ const pointers = {
42117
+ onMouseDown: 1 /* PointerEventType.PET_DOWN */,
42118
+ onMouseUp: 0 /* PointerEventType.PET_UP */
42119
+ };
42120
+ return pointers[pointerKey];
42121
+ }
42115
42122
  function createReconciler(engine, pointerEvents) {
42116
42123
  // Store all the entities so when we destroy the UI we can also destroy them
42117
42124
  const entities = new Set();
42118
42125
  // Store the onChange callbacks to be runned every time a Result has changed
42119
42126
  const changeEvents = new Map();
42127
+ const clickEvents = new Map();
42120
42128
  // Initialize components
42121
42129
  const UiTransform = UiTransform$1(engine);
42122
42130
  const UiText = UiText$1(engine);
@@ -42133,11 +42141,18 @@
42133
42141
  uiInput: UiInput.componentId,
42134
42142
  uiDropdown: UiDropdown.componentId
42135
42143
  };
42144
+ function pointerEventCallback(entity, pointerEvent) {
42145
+ const callback = clickEvents.get(entity)?.get(pointerEvent);
42146
+ if (callback)
42147
+ callback();
42148
+ return;
42149
+ }
42136
42150
  function updateTree(instance, props) {
42137
42151
  upsertComponent(instance, props, 'uiTransform');
42138
42152
  }
42139
42153
  function upsertListener(instance, update) {
42140
42154
  if (update.type === 'delete' || !update.props) {
42155
+ clickEvents.get(instance.entity)?.delete(getPointerEnum(update.component));
42141
42156
  if (update.component === 'onMouseDown') {
42142
42157
  pointerEvents.removeOnPointerDown(instance.entity);
42143
42158
  }
@@ -42147,8 +42162,14 @@
42147
42162
  return;
42148
42163
  }
42149
42164
  if (update.props) {
42150
- const pointerEvent = update.component === 'onMouseDown' ? pointerEvents.onPointerDown : pointerEvents.onPointerUp;
42151
- pointerEvent(instance.entity, update.props, {
42165
+ const pointerEvent = getPointerEnum(update.component);
42166
+ const entityEvent = clickEvents.get(instance.entity) || clickEvents.set(instance.entity, new Map()).get(instance.entity);
42167
+ const alreadyHasPointerEvent = entityEvent.get(pointerEvent);
42168
+ entityEvent.set(pointerEvent, update.props);
42169
+ if (alreadyHasPointerEvent)
42170
+ return;
42171
+ const pointerEventSystem = update.component === 'onMouseDown' ? pointerEvents.onPointerDown : pointerEvents.onPointerUp;
42172
+ pointerEventSystem(instance.entity, () => pointerEventCallback(instance.entity, pointerEvent), {
42152
42173
  button: 0 /* InputAction.IA_POINTER */,
42153
42174
  // We add this showFeedBack so the pointerEventSystem creates a PointerEvent component with our entity
42154
42175
  // This is needed for the renderer to know which entities are clickeables
@@ -42161,19 +42182,22 @@
42161
42182
  const Component = engine.getComponent(componentId);
42162
42183
  Component.deleteFrom(instance.entity);
42163
42184
  }
42164
- function upsertComponent(instance, props, componentName) {
42185
+ function upsertComponent(instance, props = {}, componentName) {
42165
42186
  const componentId = getComponentId[componentName];
42166
- const Component = engine.getComponent(componentId);
42167
- const component = Component.getMutableOrNull(instance.entity) || Component.create(instance.entity);
42187
+ if ('onChange' in props) {
42188
+ const onChange = props['onChange'];
42189
+ updateOnChange(instance.entity, componentId, { fn: onChange });
42190
+ delete props['onChange'];
42191
+ }
42192
+ // We check if there is any key pending to be changed to avoid updating the existing component
42193
+ if (!Object.keys(props).length) {
42194
+ return;
42195
+ }
42196
+ const ComponentDef = engine.getComponent(componentId);
42197
+ const component = ComponentDef.getMutableOrNull(instance.entity) || ComponentDef.create(instance.entity);
42168
42198
  for (const key in props) {
42169
42199
  const keyProp = key;
42170
- if (key === 'onChange') {
42171
- const onChange = props[keyProp];
42172
- updateOnChange(instance.entity, componentId, { fn: onChange });
42173
- }
42174
- else {
42175
- component[keyProp] = props[keyProp];
42176
- }
42200
+ component[keyProp] = props[keyProp];
42177
42201
  }
42178
42202
  }
42179
42203
  function removeChildEntity(instance) {
@@ -42277,7 +42301,7 @@
42277
42301
  if (update.type === 'delete') {
42278
42302
  removeComponent(instance, update.component);
42279
42303
  }
42280
- else {
42304
+ else if (update.props) {
42281
42305
  upsertComponent(instance, update.props, update.component);
42282
42306
  }
42283
42307
  }