@unboxy/phaser-sdk 0.2.23 → 0.2.24

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.
@@ -2,6 +2,7 @@ import Phaser from 'phaser';
2
2
  import { getEntityRegistry } from '../scene/EntityRegistry.js';
3
3
  import { parseColor, spawnEntity } from '../scene/spawnEntity.js';
4
4
  import { resolveRenderScript } from '../scene/renderScripts.js';
5
+ import { getManifest } from '../scene/SceneLoader.js';
5
6
  import { EditorOverlayScene, EDITOR_OVERLAY_KEY } from './EditorOverlayScene.js';
6
7
  import { getEditorState, setEditorActive, setSelection, } from './EditorState.js';
7
8
  /**
@@ -384,23 +385,49 @@ async function createEntity(game, entity, manifestAsset) {
384
385
  console.warn('[unboxy/editor] createEntity: world scene has no entity registry');
385
386
  return;
386
387
  }
388
+ // Resolve which AssetRecord to use for the lazy-load probe. Three paths:
389
+ // 1. Host passed `manifestAsset` (asset is brand-new) — use that.
390
+ // 2. Already in manifest but not provided (re-drag of existing asset)
391
+ // — look it up via the cached manifest.
392
+ // 3. Non-sprite entity (no asset needed) — leave undefined.
393
+ let assetForLoad = manifestAsset;
394
+ if (!assetForLoad && entity.kind === 'sprite') {
395
+ const visual = entity.visual;
396
+ const assetId = visual?.assetId;
397
+ if (assetId) {
398
+ try {
399
+ const manifest = getManifest(scene);
400
+ assetForLoad = manifest.assets.find((a) => a.id === assetId);
401
+ }
402
+ catch {
403
+ /* manifest not in cache — should not happen in edit mode */
404
+ }
405
+ }
406
+ }
387
407
  // Lazy-load texture if needed (sprite + asset not yet in cache).
388
- if (manifestAsset &&
408
+ if (assetForLoad &&
389
409
  entity.kind === 'sprite' &&
390
- !scene.textures.exists(manifestAsset.textureKey)) {
391
- await loadAssetIntoScene(scene, manifestAsset);
410
+ !scene.textures.exists(assetForLoad.textureKey)) {
411
+ await loadAssetIntoScene(scene, assetForLoad);
392
412
  }
393
413
  const ctx = {
394
414
  scene,
395
415
  registry,
396
416
  resolveAsset: (id) => {
397
- // For ad-hoc creation we may not have full manifest access. Rely on
398
- // the host to have stamped the right textureKey/path into the asset
399
- // we received via manifestAsset; fallback to a synthetic record so
400
- // spawnEntity can still find a textureKey.
401
417
  if (manifestAsset && manifestAsset.id === id)
402
418
  return manifestAsset;
403
- throw new Error(`[unboxy/editor] createEntity: asset '${id}' not in manifest payload host must include manifestAsset`);
419
+ // Fallback: look up in the manifest cache. Covers re-drag of an
420
+ // already-in-manifest asset where the host omitted manifestAsset.
421
+ try {
422
+ const manifest = getManifest(scene);
423
+ const found = manifest.assets.find((a) => a.id === id);
424
+ if (found)
425
+ return found;
426
+ }
427
+ catch {
428
+ /* fall through to throw */
429
+ }
430
+ throw new Error(`[unboxy/editor] createEntity: asset '${id}' not found in manifest`);
404
431
  },
405
432
  resolveRenderScript: undefined,
406
433
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboxy/phaser-sdk",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "Unboxy Phaser 3 SDK — game infrastructure for the Unboxy platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",