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

Fix embedded watcher to work with external crates #11370

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

shanecelis
Copy link
Contributor

@shanecelis shanecelis commented Jan 16, 2024

Objective

Tried using "embedded_watcher" feature and embedded_asset!() from another crate. The assets embedded fine but were not "watched." The problem appears to be that checking for the feature was done inside the macro, so rather than checking if "embedded_watcher" was enabled for bevy, it would check if it was enabled for the current crate.

Solution

I extracted the checks for the "embedded_watcher" feature into its own function called watched_path(). No external changes.

Alternative Solution

An alternative fix would be to not do any feature checking in embedded_asset!() or an extracted function and always send the full_path to insert_asset() where it's promptly dropped when the feature isn't turned on. That would be simpler.

    ($app: ident, $source_path: expr, $path: expr) => {{
        let mut embedded = $app
            .world
            .resource_mut::<$crate::io::embedded::EmbeddedAssetRegistry>();
        let path = $crate::embedded_path!($source_path, $path);
        //#[cfg(feature = "embedded_watcher")]
        let full_path = std::path::Path::new(file!()).parent().unwrap().join($path);
        //#[cfg(not(feature = "embedded_watcher"))]
        //let full_path = std::path::PathBuf::new();
        embedded.insert_asset(full_path, &path, include_bytes!($path));
    }};

Changelog

Fix embedded_watcher feature to work with external crates

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds labels Jan 16, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jan 16, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 16, 2024
Merged via the queue into bevyengine:main with commit b6e154f Jan 16, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants