refactor(): made the various gltf assets loaded by bevy_asset_loader optional (to handle the case where they are not present)

* updated all examples accordingly
This commit is contained in:
kaosat.dev 2024-03-12 23:43:56 +01:00
parent ea41c3c9cb
commit 5192518b12
8 changed files with 11 additions and 11 deletions

View File

@ -30,7 +30,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -20,7 +20,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -20,7 +20,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -21,7 +21,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -21,7 +21,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -76,7 +76,7 @@ pub fn trigger_level_transition(
} else if target_level == "Level2" { } else if target_level == "Level2" {
level = game_assets.level2.clone().unwrap(); level = game_assets.level2.clone().unwrap();
} else { } else {
level = game_assets.world.clone(); level = game_assets.world.clone().unwrap();
} }
info!("spawning new level"); info!("spawning new level");
commands.spawn(( commands.spawn((

View File

@ -21,7 +21,7 @@ pub fn setup_game(
SceneBundle { SceneBundle {
// note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene // note: because of this issue https://github.com/bevyengine/bevy/issues/10436, "world" is now a gltf file instead of a scene
scene: models scene: models
.get(game_assets.world.id()) .get(game_assets.world.clone().unwrap().id())
.expect("main level should have been loaded") .expect("main level should have been loaded")
.scenes[0] .scenes[0]
.clone(), .clone(),

View File

@ -5,8 +5,8 @@ use bevy_asset_loader::prelude::*;
#[derive(AssetCollection, Resource)] #[derive(AssetCollection, Resource)]
pub struct GameAssets { pub struct GameAssets {
#[asset(key = "world")] #[asset(key = "world", optional)]
pub world: Handle<Gltf>, pub world: Option<Handle<Gltf>>,
#[asset(key = "world_dynamic", optional)] #[asset(key = "world_dynamic", optional)]
pub world_dynamic: Option<Handle<Gltf>>, pub world_dynamic: Option<Handle<Gltf>>,
@ -16,8 +16,8 @@ pub struct GameAssets {
#[asset(key = "level2", optional)] #[asset(key = "level2", optional)]
pub level2: Option<Handle<Gltf>>, pub level2: Option<Handle<Gltf>>,
#[asset(key = "models", collection(typed, mapped))] #[asset(key = "models", collection(typed, mapped), optional)]
pub models: HashMap<String, Handle<Gltf>>, pub models: Option<HashMap<String, Handle<Gltf>>>,
#[asset(key = "materials", collection(typed, mapped), optional)] #[asset(key = "materials", collection(typed, mapped), optional)]
pub materials: Option<HashMap<String, Handle<Gltf>>>, pub materials: Option<HashMap<String, Handle<Gltf>>>,