diff --git a/framework_crates/bones_bevy_renderer/src/lib.rs b/framework_crates/bones_bevy_renderer/src/lib.rs index 779099c030..ac29805497 100644 --- a/framework_crates/bones_bevy_renderer/src/lib.rs +++ b/framework_crates/bones_bevy_renderer/src/lib.rs @@ -68,7 +68,7 @@ pub struct BonesGame(pub bones::Game); impl BonesGame { /// Shorthand for [`bones::AssetServer`] typed access to the shared resource pub fn asset_server(&self) -> Option> { - self.0.shared_resource() + self.0.get_shared_resource() } } @@ -166,7 +166,7 @@ impl BonesBevyRenderer { } app.init_resource::(); - if let Some(mut asset_server) = self.game.shared_resource_mut::() { + if let Some(mut asset_server) = self.game.get_shared_resource_mut::() { asset_server.set_game_version(self.game_version); asset_server.set_io(asset_io(&self.asset_dir, &self.packs_dir)); @@ -273,7 +273,7 @@ impl BonesBevyRenderer { } fn egui_ctx_initialized(game: Res) -> bool { - game.shared_resource::().is_some() + game.get_shared_resource::().is_some() } fn assets_are_loaded(game: Res) -> bool { @@ -368,10 +368,9 @@ pub fn handle_asset_changes( mut bevy_egui_textures: ResMut, mut bones_image_ids: ResMut, ) { - if let Some(mut asset_server) = game.shared_resource_mut::() { + if let Some(mut asset_server) = game.get_shared_resource_mut::() { asset_server.handle_asset_changes(|asset_server, handle| { - let mut bones_egui_textures = - game.shared_resource_mut::().unwrap(); + let mut bones_egui_textures = game.shared_resource_mut::(); let Some(mut asset) = asset_server.get_asset_untyped_mut(handle) else { // There was an issue loading the asset. The error will have been logged. return; @@ -394,7 +393,7 @@ pub fn handle_asset_changes( #[cfg(not(target_arch = "wasm32"))] fn handle_exits(game: Res, mut exits: EventWriter) { - if **game.shared_resource::().unwrap() { + if **game.shared_resource::() { exits.send(bevy::app::AppExit); } } diff --git a/framework_crates/bones_bevy_renderer/src/rumble.rs b/framework_crates/bones_bevy_renderer/src/rumble.rs index 27b55437ef..4e7f5b3fa3 100644 --- a/framework_crates/bones_bevy_renderer/src/rumble.rs +++ b/framework_crates/bones_bevy_renderer/src/rumble.rs @@ -12,7 +12,8 @@ pub fn handle_bones_rumble( game: ResMut, mut rumble_requests: EventWriter, ) { - if let Some(mut bones_rumble_requests) = game.shared_resource_mut::() { + if let Some(mut bones_rumble_requests) = game.get_shared_resource_mut::() + { while let Some(request) = bones_rumble_requests.requests.pop_front() { match request { bones::GamepadRumbleRequest::AddRumble { diff --git a/framework_crates/bones_lib/src/lib.rs b/framework_crates/bones_lib/src/lib.rs index 234309e30f..887b12234f 100644 --- a/framework_crates/bones_lib/src/lib.rs +++ b/framework_crates/bones_lib/src/lib.rs @@ -430,7 +430,7 @@ impl Game { } #[track_caller] /// Get the shared resource of a given type out of this [`Game`]s shared resources. - pub fn shared_resource(&self) -> Option> { + pub fn get_shared_resource(&self) -> Option> { let res = self .shared_resources .iter() @@ -466,6 +466,20 @@ impl Game { } } + #[track_caller] + /// Get the shared resource of a given type out of this [`Game`]s shared resources. + pub fn shared_resource(&self) -> Ref<'_, T> { + self.get_shared_resource() + .expect("shared resource not found") + } + + #[track_caller] + /// Get the shared resource of a given type out of this [`Game`]s shared resources. + pub fn shared_resource_mut(&self) -> RefMut<'_, T> { + self.get_shared_resource_mut() + .expect("shared resource not found") + } + /// Get the shared resource cell of a given type out of this [`Game`]s shared resources. pub fn shared_resource_cell(&self) -> Option> { let res = self @@ -485,7 +499,7 @@ impl Game { { self.insert_shared_resource(T::default()); } - self.shared_resource_mut::().unwrap() + self.shared_resource_mut::() } /// Insert a resource that will be shared across all game sessions.