-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
270 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ pub(crate) use registry::*; | |
pub(crate) use systems::*; | ||
|
||
mod manager; | ||
mod params; | ||
mod registry; | ||
mod systems; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::proto::{ProtoAssetEvent, ProtoError, Prototypical}; | ||
use bevy::asset::{Assets, Handle, HandleId}; | ||
use bevy::ecs::system::SystemParam; | ||
use bevy::prelude::{EventWriter, Res, ResMut}; | ||
|
||
#[derive(SystemParam)] | ||
pub(super) struct RegistryParams<'w, T: Prototypical> { | ||
prototypes: Res<'w, Assets<T>>, | ||
config: ResMut<'w, <T as Prototypical>::Config>, | ||
proto_events: EventWriter<'w, ProtoAssetEvent<T>>, | ||
} | ||
|
||
impl<'w, T: Prototypical> RegistryParams<'w, T> { | ||
pub fn prototypes(&self) -> &'w Assets<T> { | ||
Res::clone(&self.prototypes).into_inner() | ||
} | ||
|
||
pub fn config(&self) -> &T::Config { | ||
&self.config | ||
} | ||
|
||
pub fn config_mut(&mut self) -> &mut T::Config { | ||
&mut self.config | ||
} | ||
|
||
pub fn get_prototype(&self, handle: &Handle<T>) -> Result<&'w T, ProtoError> { | ||
self.prototypes() | ||
.get(handle) | ||
.ok_or_else(|| ProtoError::DoesNotExist(handle.clone_weak_untyped())) | ||
} | ||
|
||
pub fn get_strong_handle<H: Into<HandleId>>(&self, handle: H) -> Handle<T> { | ||
self.prototypes().get_handle(handle) | ||
} | ||
|
||
pub fn send_event(&mut self, event: ProtoAssetEvent<T>) { | ||
self.proto_events.send(event); | ||
} | ||
} |
Oops, something went wrong.