-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PrototypesMut::load_folder #36
Conversation
let handles: Vec<_> = handles.iter().map(|handle| handle.clone().typed::<T>()).collect(); | ||
|
||
handles.iter().for_each(|handle| { | ||
let path = self.asset_server.get_handle_path(handle).unwrap().path().to_str().unwrap().to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit gross, we should probably handle the error cases instead of calling unwrap
.
Perhaps I should add PrototypesError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically this should always return a path, right? If so, I think we can go ahead and just unwrap it (maybe with an .expect()
instead).
Same for the call to to_str
(which we could replace with to_str_lossy
but that could break the mapping).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some errors for this, let me know what you think
let handles: Vec<_> = handles.iter().map(|handle| handle.clone().typed::<T>()).collect(); | ||
|
||
handles.iter().for_each(|handle| { | ||
let path = self.asset_server.get_handle_path(handle).unwrap().path().to_str().unwrap().to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically this should always return a path, right? If so, I think we can go ahead and just unwrap it (maybe with an .expect()
instead).
Same for the call to to_str
(which we could replace with to_str_lossy
but that could break the mapping).
bevy_proto_backend/src/path/error.rs
Outdated
/// The path cannot be converted to a string. | ||
#[error("cannot convert path to a string")] | ||
ConversionError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I wonder if this should give more info regarding why it failed. Like maybe it should be called NotUtf8
or maybe the error message should indicate that the path was not valid UTF-8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think NotUtf8
works
.path() | ||
.to_str() | ||
.ok_or(PathError::ConversionError)? | ||
.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, what if we took in P: Into<PathBuf>
and then stored the PathBuf
in ProtoStorage
instead of Cow<'static, str>
?
This way we don't need to worry about conversions (we can remove the ConversionError
) and it's a little more clear we're looking for paths to files and not just their ID or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! I think it really helps bridge the gap between these system parameters and the AssetServer
for new users when we have similar methods between the two.
Add
PrototypesMut::load_folder
so that it mirrorsAssetServer::load_folder
, with the exception that the returned handles are typed.