phaserjs / phaser-editor-issues

Phaser Editor's bug tracker.
0 stars 0 forks source link

Preload Pack Files property for Scenes is broken. #31

Closed virtualarkansas closed 2 weeks ago

virtualarkansas commented 1 month ago

Version

Description

I'm writing a course using Phaser Editor, and I noticed this when making a section about creating preloading screens.

The default template has the following in Preload.ts:

/* START-USER-IMPORTS */
import assetPackUrl from "../../static/assets/asset-pack.json";
/* END-USER-IMPORTS */

and further down

preload() {

    this.editorCreate();

    console.log(assetPackUrl);
    this.load.pack("asset-pack", assetPackUrl);
}

This does work. However, if the user tries to use the editor feature where they assign an asset pack to be preloaded on a scene:

Screenshot 2024-08-08 at 1 50 28 PM

Only this code is generated:

preload(): void {
    this.load.pack("game-asset-pack", "assets/game-asset-pack.json");
}

This does not work. Webpack bundles the asset packs in this format: asset-packs/[name]-[hash][ext][query]. So the browser just 404s when it attempts to get the asset pack.

What the browser is trying to load: http://localhost:8080/assets/preload-asset-pack.json

What the browser should be loading: http://localhost:8080/asset-packs/preload-asset-pack-322e64b4e68337cc0915.json

Possible solution

The fix would be for the editor to add the correct asset pack import statements to the non-user edited section at the top of the scene file and use that in the auto-generated this.load.pack call.

Additional

I haven't tested the scenario where the user chooses to have multiple asset packs loaded with the scene. So I'm not sure if there's any additional issues there.

PhaserEditor2D commented 1 month ago

Yes, for the moment I think the best, in webpack templates, is writing the loading code by hand.

Thanks

virtualarkansas commented 1 month ago

Yes, that's what I intend to do in the near term. Thanks for the response.