Skip to content

Commit

Permalink
Convert UntypedHandles to Handle<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Jan 21, 2024
1 parent 3b56102 commit 5c5a959
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/level_instantiation/spawning/objects/orb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use bevy::prelude::*;
use bevy::reflect::TypeUuid;

fn get_or_add_mesh_handle(mesh_assets: &mut Assets<Mesh>) -> Handle<Mesh> {
const MESH_HANDLE: UntypedHandle =
UntypedHandle::weak_from_u64(Mesh::TYPE_UUID, 0x1f40128bac02a9b);
const MESH_HANDLE: Handle<Mesh> = Handle::weak_from_u128(0x1f40128bac02a9b);
mesh_assets.get_or_add(MESH_HANDLE, || {
Mesh::from(shape::UVSphere {
radius: 1.0,
Expand Down
3 changes: 1 addition & 2 deletions src/level_instantiation/spawning/objects/skydome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use serde::{Deserialize, Serialize};
pub(crate) struct Skydome;

fn get_or_add_mesh_handle(mesh_assets: &mut Assets<Mesh>) -> Handle<Mesh> {
const MESH_HANDLE: UntypedHandle =
UntypedHandle::weak_from_u64(Mesh::TYPE_UUID, 0x1f40128bac02a9a);
const MESH_HANDLE: Handle<Mesh> = Handle::weak_from_u128(0x1f40128bac02a9a);
mesh_assets.get_or_add(MESH_HANDLE, || {
Mesh::from(shape::UVSphere {
radius: 150.0,
Expand Down
11 changes: 7 additions & 4 deletions src/level_instantiation/spawning/objects/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use bevy::prelude::*;

pub(crate) trait MeshAssetsExt {
fn get_or_add(&mut self, handle: UntypedHandle, create_mesh: impl Fn() -> Mesh)
-> Handle<Mesh>;
fn get_or_add<T: Asset>(
&mut self,
handle: Handle<T>,
create_mesh: impl Fn() -> Mesh,
) -> Handle<Mesh>;
}

impl MeshAssetsExt for Assets<Mesh> {
fn get_or_add(
fn get_or_add<T: Asset>(
&mut self,
handle: UntypedHandle,
handle: Handle<T>,
create_mesh: impl Fn() -> Mesh,
) -> Handle<Mesh> {
let handle = handle.typed();
Expand Down

0 comments on commit 5c5a959

Please sign in to comment.