@relu-interactives/spatial-ecs 0.2.14 → 0.2.15

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
@@ -1,5 +1,5 @@
1
- import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-KDZ6VBRO.js';
2
- export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-KDZ6VBRO.js';
1
+ import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-D3AKP6QQ.js';
2
+ export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-D3AKP6QQ.js';
3
3
  import { registerDefaultFactories } from './chunk-7QBONTBW.js';
4
4
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-7QBONTBW.js';
5
5
  import { ObjectManagementSystem, applyTransform } from './chunk-27RBPOVO.js';
@@ -5317,6 +5317,8 @@ var _AudioSystem = class _AudioSystem {
5317
5317
  this.prevPlayingState = /* @__PURE__ */ new Map();
5318
5318
  /** Snapshot of options applied in the previous frame, for change detection. */
5319
5319
  this.prevOptions = /* @__PURE__ */ new Map();
5320
+ /** Tracks entities that were stopped due to invisibility. */
5321
+ this.stoppedDueToInvisibility = /* @__PURE__ */ new Set();
5320
5322
  this.isEditor = isEditor;
5321
5323
  }
5322
5324
  update(world, _deltaTime) {
@@ -5328,12 +5330,21 @@ var _AudioSystem = class _AudioSystem {
5328
5330
  if (!component?.audio) continue;
5329
5331
  const sound = component.audio;
5330
5332
  if (!world.isEntityVisible(entityId)) {
5331
- if (sound.isPlaying) sound.stop();
5333
+ if (sound.isPlaying) {
5334
+ sound.stop();
5335
+ this.stoppedDueToInvisibility.add(entityId);
5336
+ }
5332
5337
  continue;
5333
5338
  }
5339
+ if (this.stoppedDueToInvisibility.has(entityId)) {
5340
+ this.stoppedDueToInvisibility.delete(entityId);
5341
+ if (component.isPlaying && !sound.isPlaying && sound.buffer) {
5342
+ sound.play();
5343
+ }
5344
+ }
5334
5345
  this._syncOptions(entityId, component, sound);
5335
5346
  const prevWasPlaying = this.prevPlayingState.get(entityId) ?? false;
5336
- if (prevWasPlaying && !sound.isPlaying && component.isPlaying && !component.isPaused) {
5347
+ if (prevWasPlaying && !sound.isPlaying && component.isPlaying && !component.isPaused && !this.stoppedDueToInvisibility.has(entityId)) {
5337
5348
  component.isPlaying = false;
5338
5349
  }
5339
5350
  if (component.isPlaying && !sound.isPlaying) {
@@ -5353,6 +5364,7 @@ var _AudioSystem = class _AudioSystem {
5353
5364
  if (!liveEntityIds.has(entityId)) {
5354
5365
  this.prevPlayingState.delete(entityId);
5355
5366
  this.prevOptions.delete(entityId);
5367
+ this.stoppedDueToInvisibility.delete(entityId);
5356
5368
  }
5357
5369
  }
5358
5370
  }
@@ -5385,6 +5397,7 @@ var _AudioSystem = class _AudioSystem {
5385
5397
  dispose(_world) {
5386
5398
  this.prevPlayingState.clear();
5387
5399
  this.prevOptions.clear();
5400
+ this.stoppedDueToInvisibility.clear();
5388
5401
  }
5389
5402
  };
5390
5403
  __name(_AudioSystem, "AudioSystem");
@@ -5412,6 +5425,8 @@ var _VideoSystem = class _VideoSystem {
5412
5425
  this.prevIntent = /* @__PURE__ */ new Map();
5413
5426
  /** Snapshot of options applied in the previous frame, for change detection. */
5414
5427
  this.prevOptions = /* @__PURE__ */ new Map();
5428
+ /** Tracks entities that were manually paused due to invisibility. */
5429
+ this.pausedDueToInvisibility = /* @__PURE__ */ new Set();
5415
5430
  this.isEditor = isEditor;
5416
5431
  }
5417
5432
  update(world, _deltaTime) {
@@ -5423,12 +5438,22 @@ var _VideoSystem = class _VideoSystem {
5423
5438
  if (!component?.videoElement) continue;
5424
5439
  const video = component.videoElement;
5425
5440
  if (!world.isEntityVisible(entityId)) {
5426
- if (!video.paused) video.pause();
5441
+ if (!video.paused) {
5442
+ video.pause();
5443
+ this.pausedDueToInvisibility.add(entityId);
5444
+ }
5427
5445
  continue;
5428
5446
  }
5447
+ if (this.pausedDueToInvisibility.has(entityId)) {
5448
+ this.pausedDueToInvisibility.delete(entityId);
5449
+ if (component.isPlaying && video.paused) {
5450
+ video.play().catch(() => {
5451
+ });
5452
+ }
5453
+ }
5429
5454
  this._syncOptions(entityId, component, video);
5430
5455
  const prev = this.prevIntent.get(entityId) ?? { isPlaying: false, isPaused: false };
5431
- if (prev.isPlaying && video.paused && !video.seeking && component.isPlaying && !component.isPaused) {
5456
+ if (prev.isPlaying && video.paused && !video.seeking && component.isPlaying && !component.isPaused && !this.pausedDueToInvisibility.has(entityId)) {
5432
5457
  component.isPlaying = false;
5433
5458
  }
5434
5459
  const isStoppedNow = !component.isPlaying && !component.isPaused;
@@ -5460,6 +5485,7 @@ var _VideoSystem = class _VideoSystem {
5460
5485
  if (!liveEntityIds.has(entityId)) {
5461
5486
  this.prevIntent.delete(entityId);
5462
5487
  this.prevOptions.delete(entityId);
5488
+ this.pausedDueToInvisibility.delete(entityId);
5463
5489
  }
5464
5490
  }
5465
5491
  }
@@ -5512,6 +5538,7 @@ var _VideoSystem = class _VideoSystem {
5512
5538
  dispose(_world) {
5513
5539
  this.prevIntent.clear();
5514
5540
  this.prevOptions.clear();
5541
+ this.pausedDueToInvisibility.clear();
5515
5542
  }
5516
5543
  };
5517
5544
  __name(_VideoSystem, "VideoSystem");