mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-21 23:10:43 +01:00
Auto: Repair invalid decal symmetry axes on project load
Clamp saved axis values above 2 to Z, matching the renderer’s fallback. Extend the regression to check that a saved axis of 255 becomes 2 on load and stays 2 after a rotation edit.
This commit is contained in:
1 parent
0ff72b0d46
commit
f9635574ea
2 files changed
+11
-5
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
use super::DecalFlip;
|
||||
|
||||
@@ -6,6 +6,7 @@ use super::DecalFlip;
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DecalSymmetry {
|
||||
/// Axis the mirror plane is perpendicular to (0 = X, 1 = Y, 2 = Z)
|
||||
#[serde(deserialize_with = "deserialize_axis")]
|
||||
pub axis: u8,
|
||||
/// Extra flip of the image on the mirrored copy, on top of the reflection itself
|
||||
#[serde(default)]
|
||||
@@ -15,6 +16,11 @@ pub struct DecalSymmetry {
|
||||
pub offset: f32,
|
||||
}
|
||||
|
||||
fn deserialize_axis<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u8, D::Error> {
|
||||
// Recover malformed projects with the same Z plane used by the renderer
|
||||
Ok(u8::deserialize(deserializer)?.min(2))
|
||||
}
|
||||
|
||||
fn is_zero(value: &f32) -> bool {
|
||||
*value == 0.0
|
||||
}
|
||||
@@ -901,7 +901,7 @@ fn a_decal_dragged_over_the_sphere_never_flips_its_up_between_steps() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_a_saved_decal_with_an_out_of_range_axis_repairs_its_projection() {
|
||||
fn a_saved_decal_with_an_out_of_range_axis_is_repaired_on_load_and_can_be_edited() {
|
||||
let mut session = session();
|
||||
let image = session.import_resource_bytes("decal.png", png(4, 4, |_, _| [255; 4])).unwrap();
|
||||
let layer = id(execute(&mut session, "layer.add.decal", &json!({"image": image, "symmetry": "x"})).unwrap(), "layer");
|
||||
@@ -909,11 +909,11 @@ fn editing_a_saved_decal_with_an_out_of_range_axis_repairs_its_projection() {
|
||||
let Projection::Decal(decal) = &mut fill.projection else { panic!("expected decal") };
|
||||
decal.symmetry.as_mut().unwrap().axis = u8::MAX;
|
||||
let bytes = session.to_project_bytes().unwrap();
|
||||
|
||||
let mut loaded = Session::from_project_bytes(&bytes).unwrap();
|
||||
assert_eq!(decal_of(&loaded, layer).symmetry.unwrap().axis, 2);
|
||||
|
||||
execute(&mut loaded, "layer.decal.set", &json!({"layer": layer.0, "rotation": 12})).unwrap();
|
||||
|
||||
let LayerKind::Fill(fill) = &loaded.doc.project.layer(layer).unwrap().kind else { panic!("expected fill") };
|
||||
let Projection::Decal(decal) = &fill.projection else { panic!("expected decal") };
|
||||
assert_eq!(decal.symmetry.unwrap().axis, 2);
|
||||
assert_eq!(decal_of(&loaded, layer).symmetry.unwrap().axis, 2);
|
||||
}
|
||||
Reference in new issue
Block a user