DEV Community

Cover image for Bevy Minesweeper: Tiles and Components

Bevy Minesweeper: Tiles and Components

Qongzi on February 21, 2022

Check the repository Assets Let's complete our board, for this we will need assets: A bomb png texture A font (You can use the as...
Collapse
 
tomuxmon profile image
Tomas Dambrauskas • Edited

When I run using "cargo run" assets are loaded correctly. But when I try to launch debugger with visual studio code it fails loading assets.
my configuration looks like this:

{
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'minesweeper-tutorial'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=minesweeper-tutorial",
                    "--package=minesweeper-tutorial",
                    "--features",
                    "debug"
                ],
                "filter": {
                    "name": "minesweeper-tutorial",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
Enter fullscreen mode Exit fullscreen mode

should "cwd" (program working directory) be changed to something else?

Oh and also had to change BoardPlugin build debug section to use registry instead to make it work.:

        #[cfg(feature = "debug")]
        {
            let mut registry = app
                .world
                .get_resource_or_insert_with(InspectableRegistry::default);
            // registering custom component to be able to edit it in inspector
            registry.register::<Coordinates>();
            registry.register::<BombNeighbor>();
            registry.register::<Bomb>();
            registry.register::<Uncover>();
        }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tomuxmon profile image
Tomas Dambrauskas • Edited

Had to add environment variable in launch json :

"env": {
    "CARGO_MANIFEST_DIR": "${workspaceFolder}"
}
Enter fullscreen mode Exit fullscreen mode

a clue found in : docs.rs/bevy_asset/0.6.0/bevy_asse...

Collapse
 
qongzi profile image
Qongzi

I don't use VS Code so I don't know about the issues with the built in debugger.

About the registry, you are using the old way of registering the components
Are you using the latest version of bevy_inspector_egui ? It should be 0.8.x.
Accessing the inspectable registry is no longer required

Collapse
 
tomuxmon profile image
Tomas Dambrauskas • Edited

hmm. set the version in cargo to version = "~0.8". checked to see that version 0.8.2 is being downloaded. still had the same issue. Got panic:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/tomas/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-inspector-egui-0.8.2/src/lib.rs:375:14
Enter fullscreen mode Exit fullscreen mode

bevy inspector egui panicked when unwrapping:

impl RegisterInspectable for App {
    fn register_inspectable<T: Inspectable + 'static>(&mut self) -> &mut Self {
        self.world
            .get_resource_mut::<InspectableRegistry>()
            .unwrap() // <-- panic here
            .register::<T>();
        self
    }
}
//..
Enter fullscreen mode Exit fullscreen mode

also. it seems that order of adding world inspector plugin matters (somehow expecting it to be strictly declarative). If I register the plugin at the start like this:

let mut app = App::new();
// Debug hierarchy inspector
#[cfg(feature = "debug")]
app.add_plugin(WorldInspectorPlugin::new());
Enter fullscreen mode Exit fullscreen mode

I get no panic, but sadly I also do not get any world inspector plugin.
If I add the world inspector plugin just before the app run it ends up panicking.

 // Debug hierarchy inspector
#[cfg(feature = "debug")]
app.add_plugin(WorldInspectorPlugin::new());

app.run();
Enter fullscreen mode Exit fullscreen mode

but anyways... registry.register::<T>() work for me so I do not really care at this point :P. Thanks for your time!

Collapse
 
leonidv profile image
Leonid Vygovskiy

github.com/leonidv/bevy-minesweepe... - full tutorial updated to 12.1. One chapter per commit.