use std::{collections::HashMap, path::PathBuf};
use backtrace::Backtrace;
use serde::{Deserialize, Serialize};
use crate::asset_filter::AssetFilterOption;
pub trait AssetFilterError {}
#[derive(Debug)]
pub struct AssetError<E>
where
E: AssetFilterError,
{
pub error_type: AssetErrorType<E>,
pub backtrace: Backtrace,
}
impl<E> AssetError<E>
where
E: AssetFilterError,
{
pub fn new(error_type: AssetErrorType<E>) -> Self {
AssetError {
error_type,
backtrace: Backtrace::new(),
}
}
}
#[derive(Debug)]
pub enum AssetErrorType<E>
where
E: AssetFilterError,
{
IOError(std::io::Error),
JSONError(serde_json::Error),
FilterError(E),
AssetFilterNotFoundError(String),
AssetNotFoundInManifestError(String),
AssetPathError(PathBuf),
}
impl<E> From<std::io::Error> for AssetError<E>
where
E: AssetFilterError,
{
fn from(err: std::io::Error) -> Self {
AssetError {
error_type: AssetErrorType::IOError(err),
backtrace: Backtrace::new(),
}
}
}
impl<E> From<serde_json::Error> for AssetError<E>
where
E: AssetFilterError,
{
fn from(err: serde_json::Error) -> Self {
AssetError {
error_type: AssetErrorType::JSONError(err),
backtrace: Backtrace::new(),
}
}
}
impl<E> From<E> for AssetError<E>
where
E: AssetFilterError,
{
fn from(err: E) -> Self {
AssetError {
error_type: AssetErrorType::FilterError(err),
backtrace: Backtrace::new(),
}
}
}
pub type AssetResult<T, E> = Result<T, AssetError<E>>;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum AssetSource {
File(PathBuf),
Filtered(AssetFiltered),
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct AssetFiltered {
pub filter_name: String,
pub input_names: Vec<String>,
pub options: HashMap<String, AssetFilterOption>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct AssetData {
pub output_base_path: Option<PathBuf>,
pub extension: String,
pub source: AssetSource,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AssetManifest {
pub assets: HashMap<String, AssetData>,
pub public_assets: Vec<String>,
}