From f10db47c9883806fb5b416f4c3d62de83c0e5b12 Mon Sep 17 00:00:00 2001 From: Matt Kleinschafer Date: Wed, 3 Apr 2024 14:03:10 +1100 Subject: [PATCH] Move asset components into common --- Cargo.lock | 9 - Cargo.toml | 1 - common/assets/test.ase | Bin 0 -> 950 bytes common/src/abstractions/assets.rs | 313 ++++++++++++++++++++++--- common/src/io/virtualfs.rs | 2 +- common/src/strings/names.rs | 1 + common/tests/asset-database.rs | 29 +++ modules/assets/Cargo.toml | 9 - modules/assets/assets/test.ase | 0 modules/assets/src/exporters.rs | 37 --- modules/assets/src/importers.rs | 37 --- modules/assets/src/lib.rs | 182 -------------- modules/assets/tests/asset-database.rs | 26 -- modules/graphics/src/animations.rs | 6 +- src/lib.rs | 2 - 15 files changed, 320 insertions(+), 334 deletions(-) create mode 100644 common/assets/test.ase create mode 100644 common/tests/asset-database.rs delete mode 100644 modules/assets/Cargo.toml delete mode 100644 modules/assets/assets/test.ase delete mode 100644 modules/assets/src/exporters.rs delete mode 100644 modules/assets/src/importers.rs delete mode 100644 modules/assets/src/lib.rs delete mode 100644 modules/assets/tests/asset-database.rs diff --git a/Cargo.lock b/Cargo.lock index 658aa49d..250f9b98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -597,7 +597,6 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" name = "surreal" version = "0.1.0" dependencies = [ - "surreal-assets", "surreal-audio", "surreal-backend-sdl", "surreal-common", @@ -608,14 +607,6 @@ dependencies = [ "surreal-scripting", ] -[[package]] -name = "surreal-assets" -version = "0.0.0" -dependencies = [ - "serde", - "surreal-common", -] - [[package]] name = "surreal-audio" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 8c970f2b..3e37842f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,6 @@ editor = { package = "surreal-editor", path = "./editor", optional = true } sdl = { package = "surreal-backend-sdl", path = "./backends/sdl", optional = true } # modules -assets = { package = "surreal-assets", path = "./modules/assets", optional = true } audio = { package = "surreal-audio", path = "./modules/audio", optional = true } graphics = { package = "surreal-graphics", path = "./modules/graphics", optional = true } input = { package = "surreal-input", path = "./modules/input", optional = true } diff --git a/common/assets/test.ase b/common/assets/test.ase new file mode 100644 index 0000000000000000000000000000000000000000..c1303f6b02a77631ad1317b479990446cac23f72 GIT binary patch literal 950 zcmdnS%)szqDGP%D5GpV*GB7Zt05JlvGBAP!!SV=E>alWxrvLiL4z`sYXsj3zvnznD zM6$#J$d*)Kg^I8s$sjTRGcf!I0tSW^D^>u>kdTo7l0az|kguRxfzm)ppo|f;b@%! z)&z+mgeHj7-cE4j0xDvuUef<%dbFI_G_D}4X$In@AuJa@L`pC&ePwV*Hf`Fh!}AKJ ztT``valPK(Q-8mdlt24-!}7o1=hpwSpRNBd`==!9BDh|@56!U>$c}|45JrYHJnn%8 zRZnB%1A8-{HF6R_AF^h3B&Onz{*9DSMCH;Jw`cCN5>~l3((&htH@k zncq>cRKt(mDwfxbhe0)hs;=QV=I}vYTrI5L!-K=eR$@)WMkYPC6EZWTfG+Y`Q(kJnkd2U;q6dQx}i*>R9sUys* literal 0 HcmV?d00001 diff --git a/common/src/abstractions/assets.rs b/common/src/abstractions/assets.rs index f9bf4483..8da1b431 100644 --- a/common/src/abstractions/assets.rs +++ b/common/src/abstractions/assets.rs @@ -1,6 +1,14 @@ -use std::future::Future; +//! Asset management for Surreal. -use crate::{Guid, StringName, VirtualPath}; +use std::{ + any::{Any, TypeId}, + future::Future, +}; + +pub use exporters::*; +pub use importers::*; + +use crate::{FastHashMap, FileSystemError, Guid, StreamError, StringName, ToVirtualPath, VirtualPath}; /// Represents a reference to an asset that can either be loaded or unloaded. /// @@ -12,7 +20,7 @@ use crate::{Guid, StringName, VirtualPath}; /// de-referenced. This will either return a reference to the asset data if the /// asset is loaded, or panic if the asset is not loaded. #[derive(Clone, Debug)] -pub struct AssetRef { +pub struct Asset { asset_id: AssetId, _marker: std::marker::PhantomData, } @@ -21,11 +29,11 @@ pub struct AssetRef { /// /// If the asset is not loaded, the asset identifier will be `None`, and /// attempting to de-reference the asset reference will panic. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum AssetId { - Name(StringName), Path(VirtualPath), + Name(StringName), Guid(Guid), } @@ -34,30 +42,10 @@ pub enum AssetId { enum AssetData { Unloaded, Pending, - Loaded(Box), -} - -#[cfg(feature = "serde")] -impl serde::Serialize for AssetRef { - fn serialize(&self, _serializer: S) -> Result { - todo!() - } -} - -#[cfg(feature = "serde")] -impl<'de, T> serde::Deserialize<'de> for AssetRef { - fn deserialize>(_deserializer: D) -> Result { - todo!() - } + Loaded(Box), } -/// A server capable of loading and unloading assets. -pub trait AssetServer { - /// Resolves the asset data for the given asset identifier. - fn resolve(&self, id: &AssetId) -> impl Future>; -} - -impl AssetRef { +impl Asset { /// Creates a new asset reference from a name. pub fn from_name(name: impl Into) -> Self { Self { @@ -90,3 +78,274 @@ impl AssetRef { }) } } + +#[cfg(feature = "serde")] +impl serde::Serialize for Asset { + fn serialize(&self, _serializer: S) -> Result { + todo!() + } +} + +#[cfg(feature = "serde")] +impl<'de, T> serde::Deserialize<'de> for Asset { + fn deserialize>(_deserializer: D) -> Result { + todo!() + } +} + +/// A server capable of loading and unloading assets. +pub trait AssetServer { + /// Resolves the asset data for the given asset identifier. + fn resolve(&self, id: &AssetId) -> impl Future>; +} + +/// A database for managing assets. +/// +/// This struct is the main interface for the asset management system. It +/// provides functionality for loading and unloading assets, and for querying +/// the state of assets. +/// +/// It works on flat-file system where all assets are stored on the file system. +/// Assets are loaded from the file system when they are first requested, and +/// are unloaded when they are no longer in use, or when asked to do so. +/// +/// Assets can be packed into 'Asset Bundles', which are files which contain +/// many other assets via some 'Asset Bundle Protocol'. Beyond being a composite +/// file, behaviour is identical to the flat-file system. +/// +/// Assets are identified by: +/// - A 'path', which is the full path of the asset in the virtual file system. +/// - A 'name', which is the name of the asset within the asset bundle. +/// - A 'guid', which is a globally unique identifier for the asset. +#[derive(Default)] +pub struct AssetDatabase { + // core asset storage + assets: FastHashMap, + + // lookup tables + _assets_by_path: FastHashMap, + _assets_by_name: FastHashMap, + _assets_by_guid: FastHashMap, + + // importers/exporters + importers: Vec>, + exporters: Vec>, +} + +/// A possible error when working with the asset database. +#[derive(Debug)] +pub enum AssetDatabaseError { + InvalidPath, + InvalidVersion, + NoImporterFound, + NoExporterFound, + FileSystemError(FileSystemError), + FailedToImport(AssetImportError), + FailedToExport(AssetExportError), +} + +impl From for AssetDatabaseError { + fn from(error: FileSystemError) -> Self { + Self::FileSystemError(error) + } +} + +impl From for AssetDatabaseError { + fn from(error: AssetImportError) -> Self { + Self::FailedToImport(error) + } +} + +impl From for AssetDatabaseError { + fn from(error: AssetExportError) -> Self { + Self::FailedToExport(error) + } +} + +/// Represents the internal state of an asset. +pub enum AssetState { + Unloaded, + Orphaned, + Loaded(Box), +} + +impl AssetDatabase { + /// Opens the asset database at the given path. + pub fn open(_path: impl ToVirtualPath) -> Result { + // TODO: make this actually open the database + Ok(Self::default()) + } + + /// Adds an importer to the database. + pub fn add_importer(&mut self, importer: impl UntypedAssetImporter + 'static) { + self.importers.push(Box::new(importer)); + } + + /// Adds an exporter to the database. + pub fn add_exporter(&mut self, exporter: impl UntypedAssetExporter + 'static) { + self.exporters.push(Box::new(exporter)); + } + + /// Gets an asset from the database, or loads it from the file system. + pub fn load(&mut self, path: impl ToVirtualPath) -> Result, AssetDatabaseError> { + let path = path.to_virtual_path(); + let type_id = TypeId::of::(); + + for importer in &self.importers { + if importer.can_import(type_id, path.clone()) { + let mut stream = path.open_input_stream()?; + + let asset = importer.import(&mut stream)?; + let asset_id = AssetId::Path(path.clone()); + let _asset_state = self.assets.insert(asset_id, AssetState::Loaded(asset)); + + return Ok(Asset::from_path(path)); + } + } + + Err(AssetDatabaseError::NoImporterFound) + } + + /// Exports an asset to the file system. + pub fn export(&mut self, asset: &A, path: impl ToVirtualPath) -> Result<(), AssetDatabaseError> { + let path = path.to_virtual_path(); + let type_id = TypeId::of::(); + + for exporter in &self.exporters { + if exporter.can_export(type_id, path.clone()) { + let mut stream = path.open_output_stream()?; + + exporter.export(asset, &mut stream)?; + + return Ok(()); + } + } + + Err(AssetDatabaseError::NoExporterFound) + } +} + +/// A bundle of assets. +/// +/// This struct represents a bundle of assets. It is used to load and unload +/// assets from an archive or compressed means. +/// +/// Bundles are hierarchical, and can contain other bundles, and the top-level +/// flat file system is a kind of 'bundle' which contains all other bundles. +pub struct AssetBundle {} + +/// A trait for asset bundle codecs. +/// +/// This trait is implemented by asset bundle codecs, which are responsible +/// for packing assets into asset bundles, and unpacking them later. +pub trait AssetBundleCodec {} + +mod exporters { + use crate::OutputStream; + + use super::*; + + /// An error that can occur when exporting an asset. + #[derive(Debug)] + pub enum AssetExportError { + FileSystemError(FileSystemError), + StreamError(StreamError), + } + + impl From for AssetExportError { + fn from(error: FileSystemError) -> Self { + Self::FileSystemError(error) + } + } + + impl From for AssetExportError { + fn from(error: StreamError) -> Self { + Self::StreamError(error) + } + } + + /// Exports assets to a specific format. + pub trait AssetExporter: Send + Sync + 'static { + type Asset: ?Sized; + + /// Returns whether this export can export the given asset type and path. + fn can_export(&self, _path: VirtualPath) -> bool { + true + } + + /// Exports an asset to the given stream. + fn export(&self, asset: &Self::Asset, stream: &mut dyn OutputStream) -> Result<(), AssetExportError>; + } + + /// A trait for exporting assets without knowing the asset type. + pub trait UntypedAssetExporter: Send + Sync + 'static { + fn can_export(&self, asset_type: TypeId, path: VirtualPath) -> bool; + fn export(&self, asset: &dyn Any, stream: &mut dyn OutputStream) -> Result<(), AssetExportError>; + } + + /// Allow any typed asset exporter to be used as an untyped asset exporter. + impl> UntypedAssetExporter for T { + fn can_export(&self, asset_type: TypeId, path: VirtualPath) -> bool { + asset_type == TypeId::of::() && self.can_export(path) + } + + fn export(&self, asset: &dyn Any, stream: &mut dyn OutputStream) -> Result<(), AssetExportError> { + self.export(asset.downcast_ref::().unwrap(), stream) + } + } +} + +mod importers { + use crate::InputStream; + + use super::*; + + /// An error that can occur when exporting an asset. + #[derive(Debug)] + pub enum AssetImportError { + FileSystemError(FileSystemError), + StreamError(StreamError), + } + + impl From for AssetImportError { + fn from(error: FileSystemError) -> Self { + Self::FileSystemError(error) + } + } + + impl From for AssetImportError { + fn from(error: StreamError) -> Self { + Self::StreamError(error) + } + } + + /// Imports assets from a specific format. + pub trait AssetImporter: Send + Sync + 'static { + type Asset: Sized; + + /// Returns whether this importer can import the given asset type and path. + fn can_import(&self, _path: VirtualPath) -> bool { + true + } + + /// Imports an asset from the given stream. + fn import(&self, data: &mut dyn InputStream) -> Result; + } + + /// A trait for importing assets without knowing the asset type. + pub trait UntypedAssetImporter: Send + Sync + 'static { + fn can_import(&self, asset_type: TypeId, path: VirtualPath) -> bool; + fn import(&self, data: &mut dyn InputStream) -> Result, AssetImportError>; + } + + /// Allow any typed asset importer to be used as an untyped asset importer. + impl> UntypedAssetImporter for T { + fn can_import(&self, asset_type: TypeId, path: VirtualPath) -> bool { + asset_type == TypeId::of::() && self.can_import(path) + } + + fn import(&self, data: &mut dyn InputStream) -> Result, AssetImportError> { + Ok(Box::new(self.import(data)?)) + } + } +} diff --git a/common/src/io/virtualfs.rs b/common/src/io/virtualfs.rs index 759ec12c..2b2c2fbc 100644 --- a/common/src/io/virtualfs.rs +++ b/common/src/io/virtualfs.rs @@ -107,7 +107,7 @@ impl FileSystemManager { /// For example, a path might be `file://Assets/Textures/Texture01.png`, or /// `zip://Assets.zip/Textures/Texture01.png`, or something more exotic like a /// packed storage scheme `packed://Assets.pak/Textures/Texture01.png`. -#[derive(Clone)] +#[derive(Clone, Hash, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct VirtualPath { scheme: StringName, diff --git a/common/src/strings/names.rs b/common/src/strings/names.rs index e8030e17..90821ee3 100644 --- a/common/src/strings/names.rs +++ b/common/src/strings/names.rs @@ -8,6 +8,7 @@ use crate::{Arena, Singleton}; crate::impl_arena_index!(StringId, "Identifies a string in a string pool."); /// Represents an interned string that can be used as a name. +#[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash)] pub struct StringName(StringId); diff --git a/common/tests/asset-database.rs b/common/tests/asset-database.rs new file mode 100644 index 00000000..d478a9f4 --- /dev/null +++ b/common/tests/asset-database.rs @@ -0,0 +1,29 @@ +use surreal_common::{AssetDatabase, AssetImporter, AssetImportError, InputStream}; + +fn build_database() -> AssetDatabase { + let mut database = AssetDatabase::open("assets").unwrap(); + database.add_importer(AsepriteFileImporter); + database +} + +#[test] +pub fn it_should_load_an_aseprite_file_and_export_it() { + let mut database = build_database(); + let _aseprite_file = database.load::("assets/test.ase").unwrap(); +} + +pub struct AsepriteFile; +pub struct AsepriteFileImporter; + +impl AssetImporter for AsepriteFileImporter { + type Asset = AsepriteFile; + + fn import(&self, data: &mut dyn InputStream) -> Result { + let _magic_number = data.read_u8()?; + let _frames = data.read_u16()?; + let _width = data.read_u16()?; + let _height = data.read_u16()?; + + Ok(AsepriteFile) + } +} diff --git a/modules/assets/Cargo.toml b/modules/assets/Cargo.toml deleted file mode 100644 index 12124fda..00000000 --- a/modules/assets/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "surreal-assets" -description = "Asset engine for Surreal" -authors.workspace = true -edition.workspace = true - -[dependencies] -common = { package = "surreal-common", path = "../../common" } -serde = { workspace = true, optional = true } diff --git a/modules/assets/assets/test.ase b/modules/assets/assets/test.ase deleted file mode 100644 index e69de29b..00000000 diff --git a/modules/assets/src/exporters.rs b/modules/assets/src/exporters.rs deleted file mode 100644 index 3b39f0e9..00000000 --- a/modules/assets/src/exporters.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::any::{Any, TypeId}; - -use common::{OutputStream, VirtualPath}; - -/// An error that can occur when exporting an asset. -#[derive(Debug)] -pub enum AssetExportError {} - -/// Exports assets to a specific format. -pub trait AssetExporter: Send + Sync + 'static { - type Asset; - - /// Returns whether this export can export the given asset type and path. - fn can_export(&self, _path: VirtualPath) -> bool { - true - } - - /// Exports an asset to the given stream. - fn export(&self, asset: &Self::Asset, stream: &mut dyn OutputStream) -> Result<(), AssetExportError>; -} - -/// A trait for exporting untyped assets. -pub trait UntypedAssetExporter: Send + Sync + 'static { - fn can_export(&self, asset_type: TypeId, path: VirtualPath) -> bool; - fn export(&self, asset: &dyn Any, stream: &mut dyn OutputStream) -> Result<(), AssetExportError>; -} - -/// Allow any typed asset importer to be used as an untyped asset importer. -impl> UntypedAssetExporter for T { - fn can_export(&self, asset_type: TypeId, path: VirtualPath) -> bool { - asset_type == TypeId::of::() && self.can_export(path) - } - - fn export(&self, asset: &dyn Any, stream: &mut dyn OutputStream) -> Result<(), AssetExportError> { - self.export(asset.downcast_ref::().unwrap(), stream) - } -} diff --git a/modules/assets/src/importers.rs b/modules/assets/src/importers.rs deleted file mode 100644 index 99bdfa56..00000000 --- a/modules/assets/src/importers.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::any::{Any, TypeId}; - -use common::{InputStream, VirtualPath}; - -/// An error that can occur when exporting an asset. -#[derive(Debug)] -pub enum AssetImportError {} - -/// Imports assets from a specific format. -pub trait AssetImporter: Send + Sync + 'static { - type Asset; - - /// Returns whether this importer can import the given asset type and path. - fn can_import(&self, _path: VirtualPath) -> bool { - true - } - - /// Imports an asset from the given stream. - fn import(&self, data: &mut dyn InputStream) -> Result; -} - -/// A trait for importing untyped assets. -pub trait UntypedAssetImporter: Send + Sync + 'static { - fn can_import(&self, asset_type: TypeId, path: VirtualPath) -> bool; - fn import(&self, data: &mut dyn InputStream) -> Result, AssetImportError>; -} - -/// Allow any typed asset importer to be used as an untyped asset importer. -impl> UntypedAssetImporter for T { - fn can_import(&self, asset_type: TypeId, path: VirtualPath) -> bool { - asset_type == TypeId::of::() && self.can_import(path) - } - - fn import(&self, data: &mut dyn InputStream) -> Result, AssetImportError> { - Ok(Box::new(self.import(data)?)) - } -} diff --git a/modules/assets/src/lib.rs b/modules/assets/src/lib.rs deleted file mode 100644 index 0b844265..00000000 --- a/modules/assets/src/lib.rs +++ /dev/null @@ -1,182 +0,0 @@ -//! Asset management for Surreal. - -use std::any::{Any, TypeId}; - -use common::{Arena, FastHashMap, FileSystemError, ToVirtualPath}; -pub use exporters::*; -pub use importers::*; - -mod exporters; -mod importers; - -common::impl_arena_index!(AssetId, "Identifies an asset in an asset database."); - -/// A database for managing assets. -/// -/// This struct is the main interface for the asset management system. It -/// provides functionality for loading and unloading assets, and for querying -/// the state of assets. -/// -/// It works on flat-file system where all assets are stored on the file system. -/// Assets are loaded from the file system when they are first requested, and -/// are unloaded when they are no longer in use, or when asked to do so. -/// -/// Assets can be packed into 'Asset Bundles', which are files which contain -/// many other assets via some 'Asset Bundle Protocol'. Beyond being a composite -/// file, behaviour is identical to the flat-file system. -/// -/// Assets are identified by: -/// - A 'path', which is the full path of the asset in the virtual file system. -/// - A 'key', which is the name of the asset within the asset bundle. -/// - A 'guid', which is a globally unique identifier for the asset. -#[derive(Default)] -pub struct AssetDatabase { - // core asset storage - assets: Arena, - - // lookup tables - _assets_by_path: FastHashMap, - _assets_by_key: FastHashMap, - _assets_by_guid: FastHashMap, - - // importers/exporters - importers: Vec>, - exporters: Vec>, -} - -/// A possible error when working with the asset database. -#[derive(Debug)] -pub enum AssetDatabaseError { - InvalidPath, - InvalidVersion, - NoImporterFound, - NoExporterFound, - FileSystemError(FileSystemError), - FailedToImport(AssetImportError), - FailedToExport(AssetExportError), -} - -impl From for AssetDatabaseError { - fn from(error: FileSystemError) -> Self { - Self::FileSystemError(error) - } -} - -impl From for AssetDatabaseError { - fn from(error: AssetImportError) -> Self { - Self::FailedToImport(error) - } -} - -impl From for AssetDatabaseError { - fn from(error: AssetExportError) -> Self { - Self::FailedToExport(error) - } -} - -/// Represents the internal state of an asset. -pub enum AssetState { - Unloaded, - Orphaned, - Loaded(Box), -} - -impl AssetDatabase { - /// Opens the asset database at the given path. - pub fn open(_path: impl ToVirtualPath) -> Result { - // TODO: make this actually open the database - Ok(Self::default()) - } - - /// Adds an importer to the database. - pub fn add_importer(&mut self, importer: impl UntypedAssetImporter + 'static) { - self.importers.push(Box::new(importer)); - } - - /// Adds an exporter to the database. - pub fn add_exporter(&mut self, exporter: impl UntypedAssetExporter + 'static) { - self.exporters.push(Box::new(exporter)); - } - - /// Gets an asset from the database, or loads it from the file system. - pub fn load(&mut self, path: impl ToVirtualPath) -> Result, AssetDatabaseError> { - let path = path.to_virtual_path(); - - for importer in &self.importers { - if importer.can_import(TypeId::of::(), path.clone()) { - let mut stream = path.open_input_stream()?; - - let asset = importer.import(&mut stream)?; - let asset_id = self.assets.insert(AssetState::Loaded(asset)); - - return Ok(Asset::from_id(asset_id)); - } - } - - Err(AssetDatabaseError::NoImporterFound) - } - - /// Exports an asset to the file system. - pub fn export(&mut self, asset: &A, path: impl ToVirtualPath) -> Result<(), AssetDatabaseError> { - let path = path.to_virtual_path(); - - for exporter in &self.exporters { - if exporter.can_export(TypeId::of::(), path.clone()) { - let mut stream = path.open_output_stream()?; - - exporter.export(asset, &mut stream)?; - - return Ok(()); - } - } - - Err(AssetDatabaseError::NoExporterFound) - } -} - -/// A reference to an asset in the database. -/// -/// This struct is a reference to an asset in the database. It is used to -/// reference an asset, and to query the state of the asset. -/// -/// Note that a reference to an asset does not guarantee that the asset is -/// loaded. If the asset is not loaded, then the reference will be invalid. -/// -/// This struct is a 'thin' wrapper around the asset, and is cheap to copy. -pub struct Asset { - id: AssetId, - kind: std::marker::PhantomData, -} - -impl Asset { - /// Creates a new asset reference from an asset ID. - pub const fn from_id(id: AssetId) -> Self { - Self { - id, - kind: std::marker::PhantomData, - } - } -} - -impl std::ops::Deref for Asset { - type Target = A; - - fn deref(&self) -> &Self::Target { - todo!() - } -} - -/// A bundle of assets. -/// -/// This struct represents a bundle of assets. It is used to load and unload -/// assets from an archive or compressed means. -/// -/// Bundles are hierarchical, and can contain other bundles, and the top-level -/// flat file system is a kind of 'bundle' which contains all other bundles. -pub struct AssetBundle {} - -/// A trait for asset bundle codecs. -/// -/// This trait is implemented by asset bundle codecs, which are responsible -/// for packing assets into asset bundles, and unpacking them later. -pub trait AssetBundleCodec {} diff --git a/modules/assets/tests/asset-database.rs b/modules/assets/tests/asset-database.rs deleted file mode 100644 index 725df8b6..00000000 --- a/modules/assets/tests/asset-database.rs +++ /dev/null @@ -1,26 +0,0 @@ -use common::{InputStream, VirtualPath}; -use surreal_assets::{AssetDatabase, AssetImporter, AssetImportError}; - -#[test] -pub fn it_should_build_a_valid_asset_database() { - let mut database = AssetDatabase::open("assets").unwrap(); - - database.add_importer(AsepriteFileImporter); - - let test = database.load::("assets/test.ase").unwrap(); -} - -pub struct AsepriteFile; -pub struct AsepriteFileImporter; - -impl AssetImporter for AsepriteFileImporter { - type Asset = AsepriteFile; - - fn can_import(&self, path: VirtualPath) -> bool { - return path.extension().ends_with("aseprite") || path.extension().ends_with("ase"); - } - - fn import(&self, data: &mut dyn InputStream) -> Result { - todo!() - } -} diff --git a/modules/graphics/src/animations.rs b/modules/graphics/src/animations.rs index 3b2dd320..523e3b5d 100644 --- a/modules/graphics/src/animations.rs +++ b/modules/graphics/src/animations.rs @@ -1,6 +1,6 @@ #![allow(unused_imports)] -use common::{AssetRef, FastHashMap, StringName, TimeSpan, Vec2}; +use common::{Asset, FastHashMap, StringName, TimeSpan, Vec2}; use crate::{Color, Texture}; @@ -70,7 +70,7 @@ pub enum AnimationTrack { Rotation(AnimationTrackData), Scale(AnimationTrackData), Color(AnimationTrackData), - // Texture(AnimationTrackData>), + Texture(AnimationTrackData>), } /// Data for a single animation track. @@ -165,7 +165,7 @@ impl AnimationTree { let AnimationTransition { condition, target } = transition; if condition(state, &self.state) { - self.current = Some(target.clone()); + self.current = Some(*target); break; } } diff --git a/src/lib.rs b/src/lib.rs index a2eb6213..063f5adf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,6 @@ #![no_std] -#[cfg(feature = "assets")] -pub extern crate assets; #[cfg(feature = "audio")] pub extern crate audio; pub extern crate common;