-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
0d8f328
commit dc43986
Showing
4 changed files
with
83 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
//! Asset management for the engine | ||
/// An error that can occur when loading an asset | ||
#[derive(Debug)] | ||
pub enum AssetError { | ||
/// The asset could not be found | ||
NotFound, | ||
/// The asset could not be loaded | ||
LoadFailed, | ||
/// The asset is not of the expected type | ||
TypeMismatch, | ||
} | ||
use crate::{FileSystemError, FromStream, ToVirtualPath}; | ||
|
||
/// Represents an asset that can be loaded and used by the engine | ||
pub trait Asset {} | ||
|
||
/// A manager for assets | ||
#[derive(Default)] | ||
pub struct AssetManager {} | ||
|
||
impl AssetManager { | ||
/// Loads an asset from the given path | ||
pub fn load<A: Asset + FromStream>(&self, path: impl ToVirtualPath) -> Result<A, AssetError> { | ||
let path = path.to_virtual_path(); | ||
let mut stream = path.open_input_stream().map_err(|_| AssetError::NotFound)?; | ||
|
||
A::from_stream(&mut stream).map_err(|_| AssetError::LoadFailed) | ||
} | ||
} | ||
|
||
/// An error that can occur when loading an asset | ||
#[derive(Debug)] | ||
pub enum AssetError { | ||
NotFound, | ||
LoadFailed, | ||
TypeMismatch, | ||
} |
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