Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions framework_crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bones::Ref<'_, bones::AssetServer>> {
self.0.shared_resource()
self.0.get_shared_resource()
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ impl BonesBevyRenderer {
}
app.init_resource::<BonesImageIds>();

if let Some(mut asset_server) = self.game.shared_resource_mut::<bones::AssetServer>() {
if let Some(mut asset_server) = self.game.get_shared_resource_mut::<bones::AssetServer>() {
asset_server.set_game_version(self.game_version);
asset_server.set_io(asset_io(&self.asset_dir, &self.packs_dir));

Expand Down Expand Up @@ -273,7 +273,7 @@ impl BonesBevyRenderer {
}

fn egui_ctx_initialized(game: Res<BonesGame>) -> bool {
game.shared_resource::<bones::EguiCtx>().is_some()
game.get_shared_resource::<bones::EguiCtx>().is_some()
}

fn assets_are_loaded(game: Res<BonesGame>) -> bool {
Expand Down Expand Up @@ -368,10 +368,9 @@ pub fn handle_asset_changes(
mut bevy_egui_textures: ResMut<bevy_egui::EguiUserTextures>,
mut bones_image_ids: ResMut<BonesImageIds>,
) {
if let Some(mut asset_server) = game.shared_resource_mut::<bones::AssetServer>() {
if let Some(mut asset_server) = game.get_shared_resource_mut::<bones::AssetServer>() {
asset_server.handle_asset_changes(|asset_server, handle| {
let mut bones_egui_textures =
game.shared_resource_mut::<bones::EguiTextures>().unwrap();
let mut bones_egui_textures = game.shared_resource_mut::<bones::EguiTextures>();
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;
Expand All @@ -394,7 +393,7 @@ pub fn handle_asset_changes(

#[cfg(not(target_arch = "wasm32"))]
fn handle_exits(game: Res<BonesGame>, mut exits: EventWriter<bevy::app::AppExit>) {
if **game.shared_resource::<bones::ExitBones>().unwrap() {
if **game.shared_resource::<bones::ExitBones>() {
exits.send(bevy::app::AppExit);
}
}
3 changes: 2 additions & 1 deletion framework_crates/bones_bevy_renderer/src/rumble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub fn handle_bones_rumble(
game: ResMut<BonesGame>,
mut rumble_requests: EventWriter<BevyGamepadRumbleRequest>,
) {
if let Some(mut bones_rumble_requests) = game.shared_resource_mut::<bones::GamepadsRumble>() {
if let Some(mut bones_rumble_requests) = game.get_shared_resource_mut::<bones::GamepadsRumble>()
{
while let Some(request) = bones_rumble_requests.requests.pop_front() {
match request {
bones::GamepadRumbleRequest::AddRumble {
Expand Down
18 changes: 16 additions & 2 deletions framework_crates/bones_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: HasSchema>(&self) -> Option<Ref<'_, T>> {
pub fn get_shared_resource<T: HasSchema>(&self) -> Option<Ref<'_, T>> {
let res = self
.shared_resources
.iter()
Expand Down Expand Up @@ -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<T: HasSchema>(&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<T: HasSchema>(&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<T: HasSchema>(&self) -> Option<AtomicResource<T>> {
let res = self
Expand All @@ -485,7 +499,7 @@ impl Game {
{
self.insert_shared_resource(T::default());
}
self.shared_resource_mut::<T>().unwrap()
self.shared_resource_mut::<T>()
}

/// Insert a resource that will be shared across all game sessions.
Expand Down
Loading