Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder as asset in web deployment #44

Closed
Troels51 opened this issue May 3, 2022 · 6 comments
Closed

Folder as asset in web deployment #44

Troels51 opened this issue May 3, 2022 · 6 comments

Comments

@Troels51
Copy link

Troels51 commented May 3, 2022

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
Copy link
Owner

NiklasEi commented May 3, 2022

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
Copy link
Author

Troels51 commented May 3, 2022

It seems related to this issue on bevy itself bevyengine/bevy#2916

@Troels51
Copy link
Author

Troels51 commented May 3, 2022

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.

@Troels51 Troels51 closed this as completed May 3, 2022
@NiklasEi
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

Troels51 commented Jun 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants