summaryrefslogtreecommitdiff
path: root/engine/src/material/asset.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-09-27 20:28:24 +0200
committerHampusM <hampus@hampusmat.com>2026-09-27 20:46:16 +0200
commitee6e010611433f0aad53e3c99571b8a8c6ca13f4 (patch)
tree06ff656f764114361ae07f42d4be208d42d5c1c1 /engine/src/material/asset.rs
parent749303f2bab1b2b374f7b837cc75acf65067699e (diff)
refactor(engine): make asset importers per asset type
Diffstat (limited to 'engine/src/material/asset.rs')
-rw-r--r--engine/src/material/asset.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/engine/src/material/asset.rs b/engine/src/material/asset.rs
index f87b768..f452f54 100644
--- a/engine/src/material/asset.rs
+++ b/engine/src/material/asset.rs
@@ -1,17 +1,9 @@
-use std::borrow::Cow;
-use std::collections::HashMap;
use std::fs::read_to_string;
use std::path::{Path, PathBuf};
-use crate::asset::{Assets, Handle as AssetHandle, Submitter as AssetSubmitter};
+use crate::asset::{Assets, Submitter as AssetSubmitter};
use crate::material::Material;
-#[derive(Debug, Clone)]
-pub struct Map
-{
- pub assets: HashMap<Cow<'static, str>, AssetHandle<Material>>,
-}
-
/// Material asset import settings.
#[derive(Debug)]
#[non_exhaustive]
@@ -19,15 +11,19 @@ pub struct Settings {}
pub fn add_importers(assets: &mut Assets)
{
- assets.set_importer(["mtl"], import_wavefront_mtl_asset);
+ assets.set_importer::<Material, Settings, Error>(import);
}
-fn import_wavefront_mtl_asset(
+fn import(
asset_submitter: &mut AssetSubmitter<'_>,
path: &Path,
_settings: Option<&'_ Settings>,
) -> Result<(), Error>
{
+ if path.extension().is_none_or(|ext| ext != "mtl") {
+ return Err(Error::UnsupportedFileType);
+ }
+
let parent_path = path
.parent()
.ok_or_else(|| Error::InvalidPath(path.to_path_buf()))?;
@@ -71,6 +67,9 @@ fn import_wavefront_mtl_asset(
#[derive(Debug, thiserror::Error)]
enum Error
{
+ #[error("File type is unsupported")]
+ UnsupportedFileType,
+
#[error("Invalid path '{}'", .0.display())]
InvalidPath(PathBuf),