mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 03:29:58 +00:00
Preserve loaded Artistic library name before built-in alias
This commit is contained in:
@@ -822,11 +822,15 @@ pub fn library(s: &Session, key: &str) -> Option<(LibraryInfo, Arc<BrushLibrary>
|
||||
if let Some(found) = concealed_library_id(s, key).and_then(|id| s.brush_libraries.get(&id)) {
|
||||
return Some(found);
|
||||
}
|
||||
if let Some(b) = BUILTIN.iter().find(|b| b.id == key || (b.id == "artistic" && key.eq_ignore_ascii_case("Artistic"))) {
|
||||
if let Some(b) = BUILTIN.iter().find(|b| b.id == key) {
|
||||
return Some((builtin_info(b), builtin_library(b.id)?));
|
||||
}
|
||||
let id = libraries(s).into_iter().find(|l| l.name.eq_ignore_ascii_case(key))?.id;
|
||||
library(s, &id)
|
||||
if let Some(id) = libraries(s).into_iter().find(|l| l.name.eq_ignore_ascii_case(key)).map(|l| l.id) {
|
||||
return library(s, &id);
|
||||
}
|
||||
// Keep the short built-in alias, but let a user or loaded library own its display name.
|
||||
let b = key.eq_ignore_ascii_case("Artistic").then(|| BUILTIN.iter().find(|b| b.id == "artistic")).flatten()?;
|
||||
Some((builtin_info(b), builtin_library(b.id)?))
|
||||
}
|
||||
|
||||
fn library_param(s: &Session, p: &Value, cmd: &str) -> Result<(LibraryInfo, Arc<BrushLibrary>)> {
|
||||
|
||||
@@ -220,6 +220,20 @@ fn artistic_library_strokes_are_editable_and_reopen_from_a_saved_library() {
|
||||
assert_eq!(vectorcraft_brush::library(&reopened), lib.brushes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_loaded_library_named_artistic_keeps_its_name_ahead_of_the_builtin_alias() {
|
||||
let mut file = vectorcraft_doc::Document::new(100.0, 100.0);
|
||||
vectorcraft_brush::store(&mut file, &[vectorcraft_brush::defaults()[0].clone()]);
|
||||
let b64 = vectorcraft_format::base64_encode(&vectorcraft_format::save_file(&file));
|
||||
let mut s = session();
|
||||
let loaded = run(&mut s, "brush.loadLibrary", json!({"dataBase64": b64, "name": "Artistic.vectorcraft"}));
|
||||
assert_eq!(loaded["name"], "Artistic");
|
||||
let id = loaded["library"].as_str().unwrap();
|
||||
assert_eq!(run(&mut s, "brush.library", json!({"library": "Artistic"}))["id"], id);
|
||||
assert_eq!(run(&mut s, "brush.library", json!({"library": "ARTISTIC"}))["id"], id);
|
||||
assert_eq!(run(&mut s, "brush.library", json!({"library": "artistic"}))["id"], "artistic", "exact built-in id still works");
|
||||
}
|
||||
|
||||
/// Every path of brush art `n`: (anchors, opacity).
|
||||
fn art_paths(n: &vectorcraft_doc::Node) -> Vec<(usize, f32)> {
|
||||
let mut out = vec![];
|
||||
|
||||
Reference in New Issue
Block a user