adrien-bon / bevy_ecs_tiled

Helpers for working with 2D tilemaps created with the Tiled map editor
MIT License
23 stars 5 forks source link

TSX files not loading in WASM #6

Open stevepryde opened 2 months ago

stevepryde commented 2 months ago

The current approach for loading TSX files relies on futures_lite which doesn't work in WASM builds.

We need a new approach for loading these assets in WASM

stevepryde commented 1 month ago

For anyone who encounters this, the workaround I used was to embed the tilesets in the tilemaps in Tiled.

There are two ways to do this:

  1. When creating a new tileset there is a checkbox on the right saying "Embed in map"
  2. OR, when editing a map, in the tileset pane at the bottom right, see the buttons along the bottom. The second button from the left says "Embed". If you click this, it will embed the tileset into the map. Make sure to only use the tiles from the embedded set.

This embeds the tileset info into the TMX file rather than just referencing a TSX file that contains the same info. The actual tile images are still separate regardless. But it just means Bevy doesn't need to load the TSX file separately, which is where the issue occurs.

It's related to the fact that the Tiled hook for fetching the TSX file is sync while the Bevy way to fetch asset data is async. So it needs to call an async method from a sync method, and currently it does this by using futures_lite. That works on most platforms but not WASM.

Niashi24 commented 2 weeks ago

Here is the issue in rs-tiled for async loading, which when closed should make closing this issue trivial: https://github.com/mapeditor/rs-tiled/issues/304

Amelia-Mowers commented 4 days ago

Hi,

I believe I am having the same problem. When I used this plugin, and attempt to serve my project with Trunk the wasm seems to fail and I get:

Uncaught TypeError: The specifier “env” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”. bevy_game-39230fd36e2500b.js:1:30

After searching around I found your (@stevepryde) post here and that you managed to get it working on your project dizzy-ducks, and successfully exported a working wasm build to itchio.

But when I cloned the dizzy ducks repo and tried to serve it locally using Trunk, I get the same issue:

Uncaught TypeError: The specifier “env” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”. dizzy-ducklings-46bff8eb8e30afb.js:1:30

Did you have the same issue, or is it a problem with my local dev environment? If so, how did you get a web build working for itchio/how did you test your web build locally?

Thank you in advance, and thank you for everything you have posted so far!