mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 00:59:29 +01:00
fix(engine): inspect direction on earlier-model generators (#873)
This commit is contained in:
1 parent
1f77416ace
commit
5ddec31f80
2 files changed
+27
-1
No files matched your search
@@ -2,7 +2,7 @@
|
||||
//! without a screenshot.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_core::{Effect, EffectKind, Fill, Filter, Generator, Layer, LayerKind, NormalFormat, Projection, Sampling, Source};
|
||||
use texturecraft_core::{Effect, EffectKind, Fill, Filter, Generator, GeneratorKind, Layer, LayerKind, NormalFormat, Projection, Sampling, Source};
|
||||
|
||||
use crate::Session;
|
||||
use crate::session::StackTarget;
|
||||
@@ -162,6 +162,9 @@ fn generator_json(generator: &Generator) -> Value {
|
||||
if let Some(light) = &generator.light {
|
||||
out["light"] = json!(light);
|
||||
}
|
||||
if generator.on_earlier_model() && matches!(generator.kind, GeneratorKind::Position | GeneratorKind::Direction) {
|
||||
out["direction"] = json!(generator.direction);
|
||||
}
|
||||
if let Some(texture) = &generator.texture {
|
||||
out["texture"] = json!(texture);
|
||||
}
|
||||
|
||||
@@ -167,3 +167,26 @@ fn inspect_reports_the_reference_controls_set() {
|
||||
assert!(inspected.contains(&format!("\"{key}\"")) && inspected.contains(value), "{key} with {value} in {inspected}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inspect_reports_direction_only_on_the_earlier_model() {
|
||||
let mut session = session();
|
||||
let earlier_dir = add(&mut session, json!({"generator": "direction", "direction": [1.0, 0.0, 0.0]}));
|
||||
let light_dir = add(&mut session, json!({"generator": "direction", "lightHorizontal": 90.0}));
|
||||
let earlier_pos = add(&mut session, json!({"generator": "position", "direction": [0.0, 0.0, 1.0]}));
|
||||
let section_pos = add(&mut session, json!({"generator": "position", "sectionContrast": 0.25}));
|
||||
|
||||
let inspected = execute(&mut session, "project.inspect", &Value::Null).unwrap();
|
||||
let effects = inspected["layers"][0]["mask"]["effects"].as_array().unwrap();
|
||||
let gen_of = |effect_id: u64| &effects.iter().find(|entry| entry["id"] == effect_id).unwrap()["generator"];
|
||||
|
||||
assert_eq!(gen_of(earlier_dir)["direction"], json!([1.0, 0.0, 0.0]));
|
||||
assert!(gen_of(earlier_dir).get("light").is_none());
|
||||
assert!(gen_of(light_dir).get("direction").is_none());
|
||||
assert!(gen_of(light_dir).get("light").is_some());
|
||||
|
||||
assert_eq!(gen_of(earlier_pos)["direction"], json!([0.0, 0.0, 1.0]));
|
||||
assert!(gen_of(earlier_pos).get("section").is_none());
|
||||
assert!(gen_of(section_pos).get("direction").is_none());
|
||||
assert!(gen_of(section_pos).get("section").is_some());
|
||||
}
|
||||
Reference in new issue
Block a user