NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
474 stars 52 forks source link

Folder as asset in web deployment #44

Closed Troels51 closed 2 years ago

Troels51 commented 2 years ago

I am having trouble getting a folder loaded when running on the web. I am using your template for building and deploying my stuff to github pages, but a folder that is loading fine on windows is panicking on the web.

You should see the problem on this deployment: (https://troels51.github.io/hex_map_bevy/) And it is panicking like this in the log panicked at 'called `Result::unwrap()` on an `Err` value: AssetFolderNotADirectory("hexes")', src\loading\hex.rs:20:10

NiklasEi commented 2 years ago

Yes. Folders do not work on the web. Usually, websites do not offer the possibility to get all content under a certain path. If you want to support web, you will have to load your asset files from full paths.

See bevyengine/bevy#2916

Troels51 commented 2 years ago

It seems related to this issue on bevy itself https://github.com/bevyengine/bevy/issues/2916

Troels51 commented 2 years ago

I see we found the same issue. I will have to figure out a way to get around this because it would be nice to easily add new hexes without having to recompile.

NiklasEi commented 2 years ago

I see we found the same issue. I will have to figure out a way to get around this because it would be nice to easily add new hexes without having to recompile.

I guess this could be solved by supporting more ways to load folders in dynamic asset collections? For example, I could add support for listing files to be loaded as a Vec<Handle<T>>:

({
    "hexes": Folder (
        paths: [
            "images/hex_1.png",
            "images/hex_2.png",
            "images/hex_3.png",
            "images/hex_4.png",
            "images/hex_5.png"
        ],
    ),
})

In you code:

#[derive(AssetCollection)]
struct ImageAssets {
  #[asset(key = "hexes", folder(typed))]
  hexes: Vec<Handle<Image>>,
}

Would that help? That should work on the web and not require a recompile when adding new file paths.

Troels51 commented 2 years ago

That would be a good tool to have. Then a new hex can be added by adding the asset and updating the index file

I was thinking I could use trunk.rs to generate the file list as part of the web build. Then I wouldn't have to maintain that file as well.

Troels51 commented 2 years ago

I see you implemented the change. I really appreciate that, and thanks for the hard work 🙂