patch resolving

This commit is contained in:
Robin Appelman 2023-12-19 01:16:46 +01:00
commit 1e1733f5f7
7 changed files with 106 additions and 13 deletions

View file

@ -4,7 +4,7 @@
"$basetexture2" "cp_mountainlab/nature/grass001"
"$blendmodulatetexture" "nature/grass_blendmask"
"$bumpmap" "nature/rockwall009_height-ssbump"
"$ssbump" "1"
"$ssbump" "1"
"%keywords" "tf"
"$surfaceprop" "dirt"
}

View file

@ -1,8 +1,8 @@
"patch"
{
"include" "materials/glass/glasswindow001a.vmt"
"include" "tests/data/concretefloor003.vmt"
"replace"
{
"$envmap" "maps/koth_bagel_rc2a/c1920_704_41"
"$ssbump" "0"
}
}

View file

@ -1,7 +1,17 @@
use miette::{GraphicalReportHandler, GraphicalTheme};
use std::fs::read_to_string;
use test_case::test_case;
use thiserror::Error;
use vmt_parser::from_str;
use vmt_parser::material::Material;
#[derive(Debug, Error)]
enum LoaderError {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Vdf(#[from] vdf_reader::VdfError),
}
#[test_case("tests/data/concretefloor003.vmt")]
#[test_case("tests/data/mvm_backpack.vmt")]
@ -11,7 +21,15 @@ use vmt_parser::from_str;
fn test_serde(path: &str) {
let raw = read_to_string(path).unwrap();
match from_str(&raw) {
Ok(result) => insta::assert_ron_snapshot!(path, result),
Ok(result) => {
insta::assert_ron_snapshot!(path, result);
if let Material::Patch(patch) = result {
let patched = patch
.resolve(|path| read_to_string(path).map_err(LoaderError::from))
.unwrap();
insta::assert_ron_snapshot!(format!("{}_resolved", path), patched);
}
}
Err(e) => {
let handler = GraphicalReportHandler::new_themed(GraphicalTheme::unicode_nocolor());
let mut out = String::new();

View file

@ -3,8 +3,8 @@ source: tests/parse.rs
expression: result
---
patch(PatchMaterial(
include: "materials/glass/glasswindow001a.vmt",
include: "tests/data/concretefloor003.vmt",
replace: {
"$envmap": "maps/koth_bagel_rc2a/c1920_704_41",
"$ssbump": "0",
},
))

View file

@ -0,0 +1,32 @@
---
source: tests/parse.rs
expression: patched
---
lightmappedgeneric(LightMappedGenericMaterial(
r#$basetexture: "cp_mountainlab/concrete/concretefloor003",
r#$decal: false,
r#$detail: Some("overlays/detail001"),
r#$surfaceprop: None,
r#$basetexturetransform: "center 0.5 0.5 scale 1 1 rotate 0 translate 0 0",
r#$color: Vec3((1.0, 1.0, 1.0)),
r#$decalscale: 1.0,
r#$decalscale: Vec2((4.0, 4.0)),
r#$detailblendfactor: 1.0,
r#$detailblendmode: 0,
r#$modelmaterial: None,
r#$pointsamplemagfilter: false,
r#$seamless_scale: 1.0,
r#$alpha: 1.0,
r#$alphatest: false,
r#$distancealpha: false,
r#$nocull: false,
r#$translucent: false,
r#$bumpmap: Some("concrete/concretefloor007b_height-ssbump"),
r#$lightwarptexture: None,
r#$selfillum: false,
r#$ssbump: false,
r#$envmap: None,
r#$phong: false,
r#$nofog: false,
r#$ignorez: false,
))