use nightshade::ecs::material::components::Material;
use nightshade::ecs::material::resources::material_registry_iter;
use nightshade::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize)]
pub struct MaterialEntry {
pub name: String,
pub material: Material,
}
pub fn list_materials(world: &World) -> Vec<MaterialEntry> {
let mut entries: Vec<MaterialEntry> =
material_registry_iter(&world.resources.assets.material_registry)
.map(|(name, material)| MaterialEntry {
name: name.clone(),
material: material.clone(),
})
.collect();
entries.sort_by(|a, b| a.name.cmp(&b.name));
entries
}
pub fn get_material(world: &World, name: &str) -> Option<Material> {
registry_entry_by_name(&world.resources.assets.material_registry.registry, name).cloned()
}
pub fn update_material(world: &mut World, name: &str, material: Material) {
queue_ecs_command(
world,
nightshade::ecs::world::commands::EcsCommand::ReloadMaterial {
name: name.to_string(),
material: Box::new(material),
},
);
}
pub fn set_material_variant(world: &mut World, variant: Option<&str>) -> usize {
nightshade::ecs::material::commands::material_variant_apply(world, variant)
}