mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-19 22:10:42 +01:00
No new paths in fill layers or the quick mask; quick mask Edit needs the mask on
A path committed on a fill layer (its content, an effect in it or an instance of it) or while the quick mask is edited is refused; paths already saved in a fill layer stay editable through their sublayer. Edit and Invert quick mask are enabled only while the quick mask is on, and turning it off stops editing it.
This commit is contained in:
1 parent
77d5edbce6
commit
fc2f62656e
6 files changed
+303
-59
No files matched your search
@@ -12,7 +12,7 @@ use std::sync::Arc;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_compose::{PaintTarget, PixelStore};
|
||||
use texturecraft_core::{Channel, Effect, EffectKind, LayerId, Mask, MaskBackground, PathShape};
|
||||
use texturecraft_core::{Channel, Effect, EffectKind, LayerId, LayerKind, Mask, MaskBackground, PathShape};
|
||||
use texturecraft_geom::glam::{Mat3, Vec2, Vec3};
|
||||
use texturecraft_geom::{OrbitCamera, surface_at};
|
||||
use texturecraft_paint::{BrushSettings, Lasso, PickCtx, fill_coverage, pick, spline, spline_segments};
|
||||
@@ -706,33 +706,40 @@ impl Session {
|
||||
self.path_steps = Default::default();
|
||||
}
|
||||
|
||||
/// The selected path sublayer, or a new one on the selected layer's content or mask
|
||||
/// (whichever is selected).
|
||||
/// The selected path sublayer, or a new one on the selected paint layer's content or mask
|
||||
fn path_effect(&mut self) -> Result<LayerId> {
|
||||
let id = self.selected_layer().ok_or_else(|| EngineError::Other("select a layer to add the path to".into()))?;
|
||||
let p = &self.doc.project;
|
||||
if self.quick_mask.editing {
|
||||
return Err(EngineError::Other("paths can't edit the quick mask: stop editing it first".into()));
|
||||
}
|
||||
|
||||
let selected = self.selected_layer().ok_or_else(|| EngineError::Other("select a layer to add the path to".into()))?;
|
||||
let project = &self.doc.project;
|
||||
let mask = match self.target {
|
||||
StackTarget::Effect(e) => match p.effect(e) {
|
||||
Some((_, x)) if matches!(x.kind, EffectKind::Path(_)) => return Ok(e),
|
||||
Some((owner, _)) => !p.layer(owner)?.content_effects.iter().any(|x| x.id == e),
|
||||
StackTarget::Effect(effect) => match project.effect(effect) {
|
||||
// Paths saved in a fill layer before paths there were removed stay editable
|
||||
Some((_, found)) if matches!(found.kind, EffectKind::Path(_)) => return Ok(effect),
|
||||
Some((owner, _)) => !project.layer(owner)?.content_effects.iter().any(|candidate| candidate.id == effect),
|
||||
None => false,
|
||||
},
|
||||
StackTarget::Mask => true,
|
||||
StackTarget::Content => false,
|
||||
};
|
||||
// An instance's content and (unless it has its own) mask belong to its source.
|
||||
let owner = if mask { p.mask_owner(id) } else { p.content_layer(id).map_or(id, |l| l.id) };
|
||||
let eid = self.doc.project.alloc_id();
|
||||
let l = self.doc.project.layer_mut(owner)?;
|
||||
let e = Effect::new(eid, EffectKind::Path(Vec::new()));
|
||||
|
||||
// An instance's content and (unless it has its own) mask belong to its source
|
||||
let owner = if mask { project.mask_owner(selected) } else { project.content_layer(selected).map_or(selected, |layer| layer.id) };
|
||||
let path_id = self.doc.project.alloc_id();
|
||||
let layer = self.doc.project.layer_mut(owner)?;
|
||||
let path = Effect::new(path_id, EffectKind::Path(Vec::new()));
|
||||
if mask {
|
||||
l.mask.get_or_insert_with(|| Mask::new(MaskBackground::Black)).effects.push(e);
|
||||
} else if l.is_group() {
|
||||
return Err(EngineError::Other(format!("\"{}\" is a folder: add the path to a layer or a mask", l.name)));
|
||||
layer.mask.get_or_insert_with(|| Mask::new(MaskBackground::Black)).effects.push(path);
|
||||
} else if layer.is_group() {
|
||||
return Err(EngineError::Other(format!("\"{}\" is a folder: add the path to a layer or a mask", layer.name)));
|
||||
} else if matches!(layer.kind, LayerKind::Paint) {
|
||||
layer.content_effects.push(path);
|
||||
} else {
|
||||
l.content_effects.push(e);
|
||||
return Err(EngineError::Other(format!("\"{}\" is not a paint layer: add the path to a paint layer or a mask", layer.name)));
|
||||
}
|
||||
Ok(eid)
|
||||
Ok(path_id)
|
||||
}
|
||||
|
||||
/// [`Session::put_path`] recompositing only the tiles it changed, with no undo step: returns the paint report and the document before
|
||||
|
||||
@@ -35,14 +35,18 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Edit quick mask",
|
||||
["Viewport"],
|
||||
Some("U"),
|
||||
"{editing?: bool} — toggles when omitted; editing enables the mask",
|
||||
always,
|
||||
"{editing?: bool} — toggles when omitted; needs the quick mask enabled",
|
||||
mask_enabled,
|
||||
edit
|
||||
),
|
||||
cmd!("viewport.quickMask.invert", "Invert quick mask", ["Viewport"], Some("Ctrl+Shift+I"), "{}", always, invert),
|
||||
cmd!("viewport.quickMask.invert", "Invert quick mask", ["Viewport"], Some("Ctrl+Shift+I"), "{}", mask_enabled, invert),
|
||||
]
|
||||
}
|
||||
|
||||
fn mask_enabled(session: &Session) -> std::result::Result<(), String> {
|
||||
if session.quick_mask.enabled { Ok(()) } else { Err("enable the quick mask first".into()) }
|
||||
}
|
||||
|
||||
fn state(s: &Session) -> Value {
|
||||
let q = &s.quick_mask;
|
||||
json!({
|
||||
@@ -57,17 +61,22 @@ fn changed(s: &mut Session) -> Result<Value> {
|
||||
Ok(state(s))
|
||||
}
|
||||
|
||||
fn enable(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.quick_mask.enabled = boolp(p, "enabled").unwrap_or(!s.quick_mask.enabled);
|
||||
changed(s)
|
||||
fn enable(session: &mut Session, params: &Value) -> Result<Value> {
|
||||
let enabled = boolp(params, "enabled").unwrap_or(!session.quick_mask.enabled);
|
||||
if !enabled && session.quick_mask.editing {
|
||||
session.cancel_stroke();
|
||||
session.quick_mask.editing = false;
|
||||
}
|
||||
|
||||
session.quick_mask.enabled = enabled;
|
||||
changed(session)
|
||||
}
|
||||
|
||||
fn edit(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.cancel_stroke();
|
||||
let q = &mut s.quick_mask;
|
||||
q.editing = boolp(p, "editing").unwrap_or(!q.editing);
|
||||
q.enabled |= q.editing;
|
||||
changed(s)
|
||||
fn edit(session: &mut Session, params: &Value) -> Result<Value> {
|
||||
session.cancel_stroke();
|
||||
let quick_mask = &mut session.quick_mask;
|
||||
quick_mask.editing = boolp(params, "editing").unwrap_or(!quick_mask.editing);
|
||||
changed(session)
|
||||
}
|
||||
|
||||
fn invert(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Which tools can act on each selection
|
||||
//! Which tools can act on each selection, and that every usable tool acts there in both views
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::core::LayerId;
|
||||
use texturecraft_engine::core::{Effect, EffectKind, LayerId};
|
||||
use texturecraft_engine::geom::glam::{Vec2, Vec3};
|
||||
use texturecraft_engine::{Session, StackTarget, Tool, execute};
|
||||
|
||||
@@ -32,12 +32,13 @@ enum Selection {
|
||||
InstanceOfPaint,
|
||||
InstanceOfFill,
|
||||
Nothing,
|
||||
QuickMaskOverPaint,
|
||||
QuickMaskOverFill,
|
||||
QuickMaskOverNothing,
|
||||
}
|
||||
|
||||
impl Selection {
|
||||
const ALL: [Selection; 21] = [
|
||||
const ALL: [Selection; 22] = [
|
||||
Selection::PaintContent,
|
||||
Selection::FillContent,
|
||||
Selection::PaintMask,
|
||||
@@ -57,6 +58,7 @@ impl Selection {
|
||||
Selection::InstanceOfPaint,
|
||||
Selection::InstanceOfFill,
|
||||
Selection::Nothing,
|
||||
Selection::QuickMaskOverPaint,
|
||||
Selection::QuickMaskOverFill,
|
||||
Selection::QuickMaskOverNothing,
|
||||
];
|
||||
@@ -74,11 +76,19 @@ impl Selection {
|
||||
!reads_content
|
||||
}
|
||||
Selection::PathSublayer => tool == Tool::Path,
|
||||
Selection::QuickMaskOverFill | Selection::QuickMaskOverNothing => tool != Tool::Path,
|
||||
Selection::QuickMaskOverPaint | Selection::QuickMaskOverFill | Selection::QuickMaskOverNothing => tool != Tool::Path,
|
||||
_ => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Greyed in the shelf, but scripts still paint here: below the effect, or the instance's source
|
||||
fn scripts_still_paint(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Selection::FilterInPaint | Selection::FillEffectInPaint | Selection::FilterInMask | Selection::GeneratorInFillMask | Selection::InstanceOfPaint
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn stencil_png() -> Vec<u8> {
|
||||
@@ -218,8 +228,9 @@ fn session_with(selection: Selection) -> Session {
|
||||
select(&mut session, instance, json!("content"));
|
||||
}
|
||||
Selection::Nothing => select_nothing(&mut session),
|
||||
Selection::QuickMaskOverFill => {
|
||||
let layer = add_layer(&mut session, "layer.add.fill");
|
||||
Selection::QuickMaskOverPaint | Selection::QuickMaskOverFill => {
|
||||
let command = if selection == Selection::QuickMaskOverFill { "layer.add.fill" } else { "layer.add.paint" };
|
||||
let layer = add_layer(&mut session, command);
|
||||
select(&mut session, layer, json!("content"));
|
||||
execute(&mut session, "viewport.quickMask", &json!({"enabled": true})).unwrap();
|
||||
execute(&mut session, "viewport.quickMask.edit", &json!({"editing": true})).unwrap();
|
||||
@@ -233,6 +244,49 @@ fn session_with(selection: Selection) -> Session {
|
||||
session
|
||||
}
|
||||
|
||||
/// Uses `tool` once the way the viewport does: a stroke, a click or a committed path
|
||||
fn use_tool(session: &mut Session, tool: Tool, in_2d_view: bool) -> texturecraft_engine::Result<()> {
|
||||
session.tool.tool = tool;
|
||||
if tool == Tool::Clone {
|
||||
let source = screen(session, [1.2, 0.3, 0.0]);
|
||||
execute(session, "tool.cloneSource", &json!({"x": source.x, "y": source.y}))?;
|
||||
}
|
||||
|
||||
let points = [screen(session, [0.3, 0.3, 0.0]), screen(session, [0.6, 0.4, 0.0]), screen(session, [0.9, 0.5, 0.0])];
|
||||
let uv_points = [Vec2::new(0.05, 0.95), Vec2::new(0.1, 0.92), Vec2::new(0.15, 0.9)];
|
||||
if tool == Tool::Path {
|
||||
let params = if in_2d_view {
|
||||
json!({"uvPoints": uv_points.iter().map(|uv| [uv.x, uv.y]).collect::<Vec<_>>()})
|
||||
} else {
|
||||
json!({"points": points.iter().map(|point| [point.x, point.y]).collect::<Vec<_>>()})
|
||||
};
|
||||
execute(session, "tool.path", ¶ms)?;
|
||||
execute(session, "tool.path", &json!({"commit": true}))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let single_click = matches!(tool, Tool::PolygonFill | Tool::ColorPicker | Tool::GeometryMask);
|
||||
let viewport = session.viewport;
|
||||
if in_2d_view {
|
||||
session.begin_stroke_uv(uv_points[0], 1.0)?;
|
||||
} else {
|
||||
session.begin_stroke(points[0], viewport, 1.0)?;
|
||||
}
|
||||
|
||||
if single_click {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
for (point, uv) in points.iter().zip(&uv_points).skip(1) {
|
||||
if in_2d_view {
|
||||
session.continue_stroke_uv(*uv, 1.0);
|
||||
} else {
|
||||
session.continue_stroke(*point, 1.0);
|
||||
}
|
||||
}
|
||||
session.end_stroke()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_selection_offers_the_tools_that_can_act_on_it() {
|
||||
let mut wrong = Vec::new();
|
||||
@@ -248,3 +302,82 @@ fn every_selection_offers_the_tools_that_can_act_on_it() {
|
||||
|
||||
assert!(wrong.is_empty(), "{wrong:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_usable_tool_acts_in_both_views() {
|
||||
let mut wrong = Vec::new();
|
||||
for in_2d_view in [false, true] {
|
||||
for selection in Selection::ALL {
|
||||
for tool in Tool::ALL {
|
||||
// The picker and the geometry mask read the 3D view only, whatever is selected
|
||||
if in_2d_view && matches!(tool, Tool::ColorPicker | Tool::GeometryMask) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut session = session_with(selection);
|
||||
let usable = session.tool_usable(tool);
|
||||
|
||||
let result = use_tool(&mut session, tool, in_2d_view);
|
||||
|
||||
let view = if in_2d_view { "2D" } else { "3D" };
|
||||
match result {
|
||||
Err(error) if usable => wrong.push(format!("{view} {selection:?} {tool:?}: usable but {error}")),
|
||||
Ok(()) if !usable && !selection.scripts_still_paint() => wrong.push(format!("{view} {selection:?} {tool:?}: greyed but acts")),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert!(wrong.is_empty(), "{wrong:#?}");
|
||||
}
|
||||
|
||||
fn commit_path(session: &mut Session) -> texturecraft_engine::Result<Value> {
|
||||
execute(session, "tool.path", &json!({"uvPoints": [[0.05, 0.95], [0.15, 0.9]], "commit": true}))
|
||||
}
|
||||
|
||||
fn path_count(session: &Session, path_sublayer: LayerId) -> usize {
|
||||
match session.doc.project.effect(path_sublayer).map(|(_, effect)| &effect.kind) {
|
||||
Some(EffectKind::Path(paths)) => paths.len(),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paths_are_refused_on_fill_layers_and_the_quick_mask_but_saved_ones_stay_editable() {
|
||||
let mut session = session_with(Selection::FillContent);
|
||||
let fill = session.selected_layer().unwrap();
|
||||
|
||||
assert!(commit_path(&mut session).is_err(), "no new paths in a fill layer");
|
||||
assert!(session.doc.project.layer(fill).unwrap().content_effects.is_empty());
|
||||
|
||||
let mut session = session_with(Selection::QuickMaskOverPaint);
|
||||
assert!(commit_path(&mut session).is_err(), "paths can't edit the quick mask");
|
||||
|
||||
// A project saved while paths could go into fill layers
|
||||
let mut session = session_with(Selection::FillContent);
|
||||
let fill = session.selected_layer().unwrap();
|
||||
let saved_path = session.doc.project.alloc_id();
|
||||
session.doc.project.layer_mut(fill).unwrap().content_effects.push(Effect::new(saved_path, EffectKind::Path(Vec::new())));
|
||||
select(&mut session, fill.0, json!(saved_path.0));
|
||||
|
||||
assert!(session.tool_usable(Tool::Path));
|
||||
|
||||
commit_path(&mut session).unwrap();
|
||||
|
||||
assert_eq!(path_count(&session, saved_path), 1, "the saved path sublayer takes the new path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_mask_edit_and_invert_need_the_mask_on() {
|
||||
let mut session = base_session();
|
||||
|
||||
assert!(execute(&mut session, "viewport.quickMask.edit", &json!({"editing": true})).is_err());
|
||||
assert!(execute(&mut session, "viewport.quickMask.invert", &json!({})).is_err());
|
||||
|
||||
execute(&mut session, "viewport.quickMask", &json!({"enabled": true})).unwrap();
|
||||
execute(&mut session, "viewport.quickMask.edit", &json!({"editing": true})).unwrap();
|
||||
execute(&mut session, "viewport.quickMask", &json!({"enabled": false})).unwrap();
|
||||
|
||||
assert!(!session.quick_mask.editing, "turning the mask off stops editing it");
|
||||
}
|
||||
@@ -153,32 +153,39 @@ fn library_alphas_shape_the_stamp() {
|
||||
|
||||
#[test]
|
||||
fn quick_mask_limits_painting() {
|
||||
let mut s = session();
|
||||
paint_red(&mut s, 20.0);
|
||||
let r = execute(&mut s, "viewport.quickMask.edit", &Value::Null).unwrap();
|
||||
assert_eq!(r["editing"], json!(true));
|
||||
assert_eq!(r["enabled"], json!(true), "editing enables the mask");
|
||||
let undo = s.history_labels().len();
|
||||
dab(&mut s, 150.0, 200.0);
|
||||
assert!(!red(color_at(&s, 150.0, 200.0)), "mask strokes do not paint the layer");
|
||||
assert_eq!(s.history_labels().len(), undo, "mask strokes stay out of the history");
|
||||
assert!(s.quick_mask_rgba(0, 64).is_some_and(|v| v.len() == 64 * 64 * 4));
|
||||
execute(&mut s, "viewport.quickMask.edit", &Value::Null).unwrap();
|
||||
let mut session = session();
|
||||
paint_red(&mut session, 20.0);
|
||||
execute(&mut session, "viewport.quickMask", &json!({"enabled": true})).unwrap();
|
||||
|
||||
execute(&mut s, "tool.brush", &json!({"size": 6})).unwrap();
|
||||
dab(&mut s, 150.0, 200.0);
|
||||
dab(&mut s, 250.0, 200.0);
|
||||
assert!(red(color_at(&s, 150.0, 200.0)), "inside the mask");
|
||||
assert!(!red(color_at(&s, 250.0, 200.0)), "outside the mask");
|
||||
let state = execute(&mut session, "viewport.quickMask.edit", &Value::Null).unwrap();
|
||||
let undo = session.history_labels().len();
|
||||
dab(&mut session, 150.0, 200.0);
|
||||
|
||||
execute(&mut s, "viewport.quickMask.invert", &Value::Null).unwrap();
|
||||
dab(&mut s, 250.0, 200.0);
|
||||
assert!(red(color_at(&s, 250.0, 200.0)), "inverted: outside is open");
|
||||
assert_eq!(state["editing"], json!(true));
|
||||
assert!(!red(color_at(&session, 150.0, 200.0)), "mask strokes do not paint the layer");
|
||||
assert_eq!(session.history_labels().len(), undo, "mask strokes stay out of the history");
|
||||
let overlay_size: u32 = 64;
|
||||
let rgba_bytes = (overlay_size * overlay_size * 4) as usize;
|
||||
assert!(session.quick_mask_rgba(0, overlay_size).is_some_and(|pixels| pixels.len() == rgba_bytes), "an RGBA8 overlay of the requested size");
|
||||
|
||||
execute(&mut s, "viewport.quickMask", &json!({"enabled": false})).unwrap();
|
||||
execute(&mut s, "tool.material", &json!({"channel": "baseColor", "color": [0.0, 1.0, 0.0]})).unwrap();
|
||||
dab(&mut s, 150.0, 200.0);
|
||||
assert!(color_at(&s, 150.0, 200.0)[1] > 0.85, "disabled: everything is open");
|
||||
execute(&mut session, "viewport.quickMask.edit", &Value::Null).unwrap();
|
||||
execute(&mut session, "tool.brush", &json!({"size": 6})).unwrap();
|
||||
dab(&mut session, 150.0, 200.0);
|
||||
dab(&mut session, 250.0, 200.0);
|
||||
|
||||
assert!(red(color_at(&session, 150.0, 200.0)), "inside the mask");
|
||||
assert!(!red(color_at(&session, 250.0, 200.0)), "outside the mask");
|
||||
|
||||
execute(&mut session, "viewport.quickMask.invert", &Value::Null).unwrap();
|
||||
dab(&mut session, 250.0, 200.0);
|
||||
|
||||
assert!(red(color_at(&session, 250.0, 200.0)), "inverted: outside is open");
|
||||
|
||||
execute(&mut session, "viewport.quickMask", &json!({"enabled": false})).unwrap();
|
||||
execute(&mut session, "tool.material", &json!({"channel": "baseColor", "color": [0.0, 1.0, 0.0]})).unwrap();
|
||||
dab(&mut session, 150.0, 200.0);
|
||||
|
||||
assert!(color_at(&session, 150.0, 200.0)[1] > 0.85, "disabled: everything is open");
|
||||
}
|
||||
|
||||
/// How much redder than green a texel must be to count as painted (faded edges included)
|
||||
|
||||
@@ -272,8 +272,11 @@ fn color_selection_snapshots_and_quick_mask_pick() {
|
||||
let center = harness.state().viewport_rect.center();
|
||||
harness.hover_at(center + egui::vec2(80.0, 0.0));
|
||||
let expected = save(&mut harness, "color-selection-picking");
|
||||
|
||||
execute(&mut harness.state_mut().session, "viewport.quickMask", &json!({"enabled": true})).unwrap();
|
||||
execute(&mut harness.state_mut().session, "viewport.quickMask.edit", &json!({"editing": true})).unwrap();
|
||||
let with_quick_mask = save(&mut harness, "color-selection-picking-quick-mask");
|
||||
|
||||
assert_eq!(
|
||||
with_quick_mask.get_pixel(center.x as u32, center.y as u32),
|
||||
expected.get_pixel(center.x as u32, center.y as u32),
|
||||
@@ -281,14 +284,18 @@ fn color_selection_snapshots_and_quick_mask_pick() {
|
||||
);
|
||||
|
||||
click_at(&mut harness, center);
|
||||
|
||||
assert!(harness.state().session.quick_mask.editing, "picking preserves quick-mask editing");
|
||||
save(&mut harness, "color-selection-quick-mask-restored");
|
||||
|
||||
execute(&mut harness.state_mut().session, "viewport.quickMask.edit", &json!({"editing": false})).unwrap();
|
||||
harness.state_mut().ui.layout = texturecraft_ui_egui::state::ViewLayout::Only2D;
|
||||
harness.get_by_label(&pick_color_label()).click();
|
||||
save(&mut harness, "color-selection-picking-2d");
|
||||
click_at(&mut harness, center);
|
||||
|
||||
assert!(harness.state().picking_id_color.is_none());
|
||||
|
||||
execute(&mut harness.state_mut().session, "textureSet.meshMap.clear", &json!({"map": "id"})).unwrap();
|
||||
save(&mut harness, "color-selection-no-id-map");
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//! The shelf greys tools that can't act on the selection; the top bar and Properties follow it
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::{Value, json};
|
||||
use texturecraft_engine::{Session, StackTarget, Tool, execute};
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
use texturecraft_ui_egui::state::Mode;
|
||||
use texturecraft_ui_egui::theme::Brightness;
|
||||
|
||||
fn add_layer(session: &mut Session, command: &str) -> u64 {
|
||||
execute(session, command, &json!({})).unwrap()["layer"].as_u64().unwrap()
|
||||
}
|
||||
|
||||
fn select(session: &mut Session, layer: u64, target: Value) {
|
||||
execute(session, "layer.select", &json!({"layer": layer, "target": target})).unwrap();
|
||||
}
|
||||
|
||||
fn select_nothing(session: &mut Session) {
|
||||
let set = session.ts();
|
||||
session.selected.remove(&set);
|
||||
session.target = StackTarget::Content;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "offscreen GPU snapshots; set TC_UI_SNAPSHOTS to an output directory"]
|
||||
fn tool_availability_snapshots() {
|
||||
let Some(directory) = std::env::var_os("TC_UI_SNAPSHOTS").map(std::path::PathBuf::from) else {
|
||||
return;
|
||||
};
|
||||
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
let session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 960.0)).wgpu().build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
let save = |harness: &mut Harness<'_, TextureCraftApp>, name: &str| {
|
||||
for (brightness, suffix) in [(Brightness::MediumDark, "medium"), (Brightness::Dark, "dark"), (Brightness::Light, "light")] {
|
||||
harness.state_mut().ui.prefs.brightness = brightness;
|
||||
harness.run_steps(8);
|
||||
harness.render().unwrap().save(directory.join(format!("{name}-{suffix}.png"))).unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
let paint = add_layer(session, "layer.add.paint");
|
||||
select(session, paint, json!("content"));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "01-paint-layer");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
let fill = add_layer(session, "layer.add.fill");
|
||||
select(session, fill, json!("content"));
|
||||
session.tool.tool = Tool::PolygonFill;
|
||||
save(&mut harness, "04-fill-content-polygon-fill");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
execute(session, "effect.add.filter", &json!({"layer": paint, "target": "content", "filter": "blur"})).unwrap();
|
||||
let filter = session.doc.project.layer(texturecraft_engine::core::LayerId(paint)).unwrap().content_effects.last().unwrap().id.0;
|
||||
select(session, paint, json!(filter));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "07-filter");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
execute(session, "mask.add.black", &json!({"layer": paint})).unwrap();
|
||||
select(session, paint, json!("mask"));
|
||||
session.tool.tool = Tool::Smudge;
|
||||
save(&mut harness, "05-mask-smudge");
|
||||
|
||||
let session = &mut harness.state_mut().session;
|
||||
let folder = add_layer(session, "layer.add.group");
|
||||
select(session, folder, json!("content"));
|
||||
session.tool.tool = Tool::Paint;
|
||||
save(&mut harness, "09-folder");
|
||||
|
||||
select_nothing(&mut harness.state_mut().session);
|
||||
save(&mut harness, "12-nothing-selected");
|
||||
|
||||
harness.state_mut().ui.mode = Mode::Baking;
|
||||
save(&mut harness, "15-bake");
|
||||
|
||||
harness.state_mut().ui.mode = Mode::Rendering;
|
||||
save(&mut harness, "16-render");
|
||||
}
|
||||
Reference in new issue
Block a user