mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
handle::new now creates a new random handle
This commit is contained in:
parent
75614f5084
commit
e459b42418
3 changed files with 17 additions and 10 deletions
|
@ -23,7 +23,14 @@ pub struct Handle<T> {
|
|||
}
|
||||
|
||||
impl<T> Handle<T> {
|
||||
pub const fn new(id: HandleId) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Handle {
|
||||
id: HandleId::new(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn from_id(id: HandleId) -> Self {
|
||||
Handle {
|
||||
id,
|
||||
marker: PhantomData,
|
||||
|
@ -49,7 +56,7 @@ impl<T> Handle<T> {
|
|||
T: 'static,
|
||||
{
|
||||
if TypeId::of::<T>() == untyped_handle.type_id {
|
||||
Some(Handle::new(untyped_handle.id))
|
||||
Some(Handle::from_id(untyped_handle.id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<T> AssetStorage<T> {
|
|||
pub fn add(&mut self, asset: T) -> Handle<T> {
|
||||
let id = HandleId::new();
|
||||
self.assets.insert(id, asset);
|
||||
Handle::new(id)
|
||||
Handle::from_id(id)
|
||||
}
|
||||
|
||||
pub fn add_with_handle(&mut self, handle: Handle<T>, asset: T) {
|
||||
|
@ -61,7 +61,7 @@ impl<T> AssetStorage<T> {
|
|||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (Handle<T>, &T)> {
|
||||
self.assets.iter().map(|(k, v)| (Handle::new(*k), v))
|
||||
self.assets.iter().map(|(k, v)| (Handle::from_id(*k), v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Batch, BatchKey, Batcher};
|
||||
use bevy_asset::{Handle, HandleId, HandleUntyped};
|
||||
use bevy_asset::{Handle, HandleUntyped};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct A;
|
||||
|
@ -177,12 +177,12 @@ mod tests {
|
|||
let e2 = Entity(2);
|
||||
let e3 = Entity(3);
|
||||
|
||||
let a1: HandleUntyped = Handle::<A>::new(HandleId::new()).into();
|
||||
let b1: HandleUntyped = Handle::<B>::new(HandleId::new()).into();
|
||||
let c1: HandleUntyped = Handle::<C>::new(HandleId::new()).into();
|
||||
let a1: HandleUntyped = Handle::<A>::new().into();
|
||||
let b1: HandleUntyped = Handle::<B>::new().into();
|
||||
let c1: HandleUntyped = Handle::<C>::new().into();
|
||||
|
||||
let a2: HandleUntyped = Handle::<A>::new(HandleId::new()).into();
|
||||
let b2: HandleUntyped = Handle::<B>::new(HandleId::new()).into();
|
||||
let a2: HandleUntyped = Handle::<A>::new().into();
|
||||
let b2: HandleUntyped = Handle::<B>::new().into();
|
||||
|
||||
let a1_b1 = BatchKey::key2(a1, b1);
|
||||
let a2_b2 = BatchKey::key2(a2, b2);
|
||||
|
|
Loading…
Reference in a new issue