From cc19fe323e7d27c8003c2361c7742c493b1ce4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Sat, 11 Jul 2026 01:05:18 +0200 Subject: [PATCH] Make patch materials more flexible --- src/material/mod.rs | 15 +++++++++++---- src/material/modulate.rs | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/material/mod.rs b/src/material/mod.rs index 951a245..ed9d20d 100644 --- a/src/material/mod.rs +++ b/src/material/mod.rs @@ -196,9 +196,9 @@ impl Material { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PatchMaterial { #[serde(deserialize_with = "deserialize_path")] - include: String, + pub include: String, #[serde(default)] - replace: Table, + pub replace: Table, } impl PatchMaterial { @@ -209,7 +209,14 @@ impl PatchMaterial { E: From, { let base = loader(&self.include)?.to_ascii_lowercase(); - let mut material = Table::load_from_str(&base)?; + Ok(self.apply(&base)?) + } + + /// Parse the base material and apply the patch + /// + /// The base material needs to be lowercase. + pub fn apply(&self, base: &str) -> Result { + let mut material = Table::load_from_str(base)?; let material_values = match material.iter_mut().next() { Some((_, Entry::Table(table))) => table, @@ -224,7 +231,7 @@ impl PatchMaterial { material_values.insert(key.clone(), value.clone()); } - Ok(from_entry(Entry::Table(material))?) + from_entry(Entry::Table(material)) } } diff --git a/src/material/modulate.rs b/src/material/modulate.rs index ad9e55d..ab0d699 100644 --- a/src/material/modulate.rs +++ b/src/material/modulate.rs @@ -16,6 +16,7 @@ pub struct ModulateMaterial { #[derive(Debug, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "snake_case")] +#[allow(unused)] pub enum SpriteOrientation { ParallelUpright, #[default]