mirror of
https://codeberg.org/icewind/vmt-parser.git
synced 2026-08-02 12:24:46 +02:00
Make patch materials more flexible
This commit is contained in:
parent
b8dfe4e117
commit
cc19fe323e
2 changed files with 12 additions and 4 deletions
|
|
@ -196,9 +196,9 @@ impl Material {
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PatchMaterial {
|
pub struct PatchMaterial {
|
||||||
#[serde(deserialize_with = "deserialize_path")]
|
#[serde(deserialize_with = "deserialize_path")]
|
||||||
include: String,
|
pub include: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
replace: Table,
|
pub replace: Table,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PatchMaterial {
|
impl PatchMaterial {
|
||||||
|
|
@ -209,7 +209,14 @@ impl PatchMaterial {
|
||||||
E: From<VdfError>,
|
E: From<VdfError>,
|
||||||
{
|
{
|
||||||
let base = loader(&self.include)?.to_ascii_lowercase();
|
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<Material, VdfError> {
|
||||||
|
let mut material = Table::load_from_str(base)?;
|
||||||
|
|
||||||
let material_values = match material.iter_mut().next() {
|
let material_values = match material.iter_mut().next() {
|
||||||
Some((_, Entry::Table(table))) => table,
|
Some((_, Entry::Table(table))) => table,
|
||||||
|
|
@ -224,7 +231,7 @@ impl PatchMaterial {
|
||||||
material_values.insert(key.clone(), value.clone());
|
material_values.insert(key.clone(), value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(from_entry(Entry::Table(material))?)
|
from_entry(Entry::Table(material))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ pub struct ModulateMaterial {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
|
#[allow(unused)]
|
||||||
pub enum SpriteOrientation {
|
pub enum SpriteOrientation {
|
||||||
ParallelUpright,
|
ParallelUpright,
|
||||||
#[default]
|
#[default]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue