mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-21 18:04:03 +01:00
Pathfinder: inserted effect steps take their options from the engine's helper
effect.apply and Insert Menu Item now read a new Pathfinder effect's options from one engine function, pathfinder_effect_options, so the step an inserted Effect › Pathfinder item holds and the params the click journals come from the same rule. A new test checks every Effect › Pathfinder item with options other than the defaults, removeUnpainted included.
This commit is contained in:
1 parent
17bbb52b5b
commit
295fc36d2b
4 files changed
+56
-17
No files matched your search
@@ -861,6 +861,9 @@ pub use compoundshape::selected_member_modes;
|
||||
/// Pathfinder Options (`Prefs::pathfinder`).
|
||||
pub use pathops::{PATHFINDER_PRECISION_RANGE, PathfinderOptions};
|
||||
|
||||
/// The Pathfinder Options a new Pathfinder effect takes (`effect.apply`).
|
||||
pub use effectcmd::pathfinder_effect_options;
|
||||
|
||||
/// The Attributes panel's state ([`Session::attributes_info`]).
|
||||
pub use overprint::AttributesInfo;
|
||||
|
||||
|
||||
@@ -444,6 +444,17 @@ fn check_revolve_count(n: &Node, cmd: &str) -> Result<()> {
|
||||
|
||||
pub(crate) const ONE_3D: &str = "An object takes one 3D effect. Edit the existing effect's options, or remove it first.";
|
||||
|
||||
/// The Pathfinder Options that `effect.apply` gives a Pathfinder effect for the keys its `params`
|
||||
/// leave out: the preferences' Pathfinder Options in force.
|
||||
pub fn pathfinder_effect_options(s: &Session) -> effects::PathfinderEffectOptions {
|
||||
let current = super::pathops::current_pf_options(s);
|
||||
effects::PathfinderEffectOptions {
|
||||
precision: current.precision,
|
||||
remove_redundant_points: current.remove_redundant_points,
|
||||
remove_unpainted: current.remove_unpainted,
|
||||
}
|
||||
}
|
||||
|
||||
/// `effect.apply`: adds effect `effect` (or `id`) with `params`, its defaults filled in, to the
|
||||
/// targets' active item as one undo step. A 3D effect must fit each target, which takes only one;
|
||||
/// a Pathfinder effect on loose objects groups them first. → `{ids, index, item}`.
|
||||
@@ -475,13 +486,7 @@ pub(crate) fn apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// A Pathfinder effect keeps the Pathfinder Options in force when it is applied, those `params`
|
||||
// give aside. They join the journal entry, so replaying it gives the same effect.
|
||||
if effects::takes_pathfinder_options(id) {
|
||||
let current = super::pathops::current_pf_options(s);
|
||||
let options = effects::PathfinderEffectOptions {
|
||||
precision: current.precision,
|
||||
remove_redundant_points: current.remove_redundant_points,
|
||||
remove_unpainted: current.remove_unpainted,
|
||||
};
|
||||
if let Value::Object(filled) = options.to_params() {
|
||||
if let Value::Object(filled) = pathfinder_effect_options(s).to_params() {
|
||||
for (key, v) in filled {
|
||||
if params.get(&key).is_none() {
|
||||
params[key.as_str()] = v;
|
||||
|
||||
@@ -21,14 +21,9 @@ pub fn open(app: &mut VectorcraftApp) {
|
||||
app.ui.dialog = Some(Dialog::new(KIND, json!(app.session.prefs.pathfinder)));
|
||||
}
|
||||
|
||||
/// The Pathfinder Options that `effect.apply` gives a new Pathfinder effect: the Pathfinder panel's,
|
||||
/// with the default precision in place of one out of range.
|
||||
/// The Pathfinder Options that `effect.apply` gives a new Pathfinder effect, as its params.
|
||||
pub fn options_in_force(app: &VectorcraftApp) -> Value {
|
||||
let mut current = app.session.prefs.pathfinder;
|
||||
if !vectorcraft_engine::cmd::PATHFINDER_PRECISION_RANGE.contains(¤t.precision) {
|
||||
current.precision = vectorcraft_engine::PathfinderOptions::default().precision;
|
||||
}
|
||||
json!(current)
|
||||
vectorcraft_engine::cmd::pathfinder_effect_options(&app.session).to_params()
|
||||
}
|
||||
|
||||
/// The params that an Effect › Pathfinder menu item with params `p` (`effect.apply`) runs with: its
|
||||
|
||||
@@ -1162,8 +1162,9 @@ pub const INSERT_MENU_ITEM: &str = "ui.action.insertMenuItem";
|
||||
/// step that aligns to the key object fails in playback when there is none then. An Effect ›
|
||||
/// Pathfinder item's step holds the Pathfinder Options in force now
|
||||
/// ([`crate::dialogs::pathfinder_options::menu_effect_params`]), as clicking the item applies the
|
||||
/// effect with them, so a later Pathfinder Options change does not change the step. A View menu item that the app runs itself
|
||||
/// ([`crate::menus::plays_in_app`]) plays on its own, with no undo step ([`play`]). The place is as
|
||||
/// effect with them, so a later Pathfinder Options change does not change the step. A View menu
|
||||
/// item that the app runs itself ([`crate::menus::plays_in_app`]) plays on its own, with no undo
|
||||
/// step ([`play`]). The place is as
|
||||
/// [`insert_stop`] takes it, and the step is selected as a stop is. A command and params that no such
|
||||
/// item has, a param of another type, params that are not an object, or a place [`insert_stop`]
|
||||
/// refuses is an error, and then nothing changes. Insert Menu Item's OK runs this. → {set, action,
|
||||
@@ -5621,7 +5622,8 @@ mod tests {
|
||||
|
||||
/// A listed menu item runs from the menu what its step runs in playback: the click opens no
|
||||
/// dialog, and it journals the item's own command with the params its step holds. An Object ›
|
||||
/// Align item's step holds the Align To choice that the click sends, and the app adds the active
|
||||
/// Align item's step holds the Align To choice that the click sends, an Effect › Pathfinder
|
||||
/// item's step holds the Pathfinder Options that the click applies, and the app adds the active
|
||||
/// artboard to both.
|
||||
#[test]
|
||||
fn every_listed_menu_item_runs_from_the_menu_what_its_step_holds() {
|
||||
@@ -5681,6 +5683,40 @@ mod tests {
|
||||
assert_eq!((effects.len(), effects[0].id.as_str(), &effects[0].params), (1, "pathfinder.add", &options));
|
||||
}
|
||||
|
||||
/// Every Effect › Pathfinder item's step holds the Pathfinder Options that clicking the item
|
||||
/// journals, with options other than the defaults in force.
|
||||
#[test]
|
||||
fn every_pathfinder_effect_item_step_holds_the_options_its_click_applies() {
|
||||
let options = json!({"precision": 0.25, "removeRedundantPoints": false, "removeUnpainted": true});
|
||||
let items: Vec<_> = crate::menus::insertable_items(false)
|
||||
.into_iter()
|
||||
.filter(|item| {
|
||||
item.command == "effect.apply"
|
||||
&& item.params.get("effect").and_then(Value::as_str).is_some_and(vectorcraft_effects::takes_pathfinder_options)
|
||||
})
|
||||
.collect();
|
||||
assert!(!items.is_empty());
|
||||
for item in items {
|
||||
let (mut app, _, ids) = app_with_two_rectangles();
|
||||
app.run("object.pathfinder.options", options.clone()).unwrap();
|
||||
app.ui.action_sets[0].actions[0].steps.clear();
|
||||
app.run(INSERT_MENU_ITEM, json!({"set": 0, "action": 0, "command": item.command, "params": item.params})).unwrap();
|
||||
let held = app.ui.action_sets[0].actions[0].steps[0].1.clone();
|
||||
assert_eq!(held["params"], options, "{item:?}");
|
||||
app.run("select.set", json!({ "ids": ids })).unwrap();
|
||||
let start = app.session.journal.len();
|
||||
crate::menus::invoke(&mut app, item.command, item.params.clone());
|
||||
let ran: Vec<_> = app.session.journal_for_action(start).into_iter().filter(|(c, _)| c == item.command).collect();
|
||||
assert!(!ran.is_empty(), "{item:?} did not run");
|
||||
for (_, mut p) in ran {
|
||||
if let Some(o) = p.as_object_mut() {
|
||||
o.remove("artboard");
|
||||
}
|
||||
assert_eq!(p, held, "{item:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// With anchor points selected, an Object › Align item sends its params unchanged, and the points
|
||||
/// align to their own bounds: its step holds the same params, without the Align To choice.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user