G5: built-in Skill Icons symbol library

Five symbol libraries; MCP docs list Skill Icons with the other generated symbol libraries.
This commit is contained in:
Fabio William Conceição
2026-11-11 17:08:39 +00:00
parent 3deafc24eb
commit f07c2f7e9c
35 changed files with 261 additions and 19 deletions
+46
View File
@@ -159,6 +159,7 @@ pub const BUILTIN: &[BuiltinSymbolLibrary] = &[
BuiltinSymbolLibrary { id: "ui-frames", name: "UI Frames", make: ui_frames },
BuiltinSymbolLibrary { id: "map-markers", name: "Map Markers", make: map_markers },
BuiltinSymbolLibrary { id: "inventory-icons", name: "Inventory Icons", make: inventory_icons },
BuiltinSymbolLibrary { id: "skill-icons", name: "Skill Icons", make: skill_icons },
];
/// Built-in library `id`, made once.
@@ -312,6 +313,51 @@ fn inventory_icons() -> SymbolLibrary {
SymbolLibrary { name: "Inventory Icons".into(), doc }
}
/// Skill Icons: attack, defend, heal, buff and ult marks for RPG/UI art (original, no 9-slice).
fn skill_icons() -> SymbolLibrary {
let c = Point::ZERO;
let attack = [(-18.0, 14.0), (-6.0, 2.0), (-2.0, 6.0), (18.0, -14.0), (14.0, -18.0), (-6.0, -2.0), (-10.0, 2.0), (-18.0, 6.0)];
let defend = [(0.0, -18.0), (14.0, -10.0), (12.0, 6.0), (0.0, 18.0), (-12.0, 6.0), (-14.0, -10.0)];
let heal = [
(-4.0, -18.0),
(4.0, -18.0),
(4.0, -4.0),
(18.0, -4.0),
(18.0, 4.0),
(4.0, 4.0),
(4.0, 18.0),
(-4.0, 18.0),
(-4.0, 4.0),
(-18.0, 4.0),
(-18.0, -4.0),
(-4.0, -4.0),
];
let buff = [(0.0, -18.0), (10.0, -2.0), (4.0, -2.0), (4.0, 18.0), (-4.0, 18.0), (-4.0, -2.0), (-10.0, -2.0)];
let attack: Vec<Point> = attack.iter().map(|&(x, y)| Point::new(x, y)).collect();
let defend: Vec<Point> = defend.iter().map(|&(x, y)| Point::new(x, y)).collect();
let heal: Vec<Point> = heal.iter().map(|&(x, y)| Point::new(x, y)).collect();
let buff: Vec<Point> = buff.iter().map(|&(x, y)| Point::new(x, y)).collect();
let icons = [
("Attack", vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&attack, true)), "#e74c3c"),
("Defend", vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&defend, true)), "#3498db"),
("Heal", vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&heal, true)), "#2ecc71"),
("Buff", vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&buff, true)), "#f1c40f"),
("Ult", shapes::star(c, 18.0, 7.0, 8, 0.0), "#9b59b6"),
];
let mut doc = Document::new(100.0, 100.0);
for (name, path, hex) in icons {
let fill = Color::from_hex(hex).unwrap_or(Color::BLACK);
let edge = fill.lerp(&Color::BLACK, 0.35);
let id = doc.alloc_id();
let art = Node::path(id, path, Appearance::basic(Paint::solid(fill), Paint::solid(edge), 1.25));
let Ok((art, size, _)) = normalize(art) else { continue };
doc.symbols.push(Symbol { dynamic: false, name: name.into(), art: Arc::new(art) });
set_natural_size(&mut doc, name, Some(size));
}
doc.title = "Skill Icons".into();
SymbolLibrary { name: "Skill Icons".into(), doc }
}
/// An instance of symbol `name` (what the resource gathering follows).
fn instance(name: &str) -> Node {
Node::new(NodeId(0), NodeKind::SymbolInstance { symbol: name.into(), xf: Affine::IDENTITY })
+31 -1
View File
@@ -84,7 +84,7 @@ fn the_builtin_library_is_original_art_generated_in_code() {
let mut s = Session::new();
let list = run(&mut s, "symbol.libraries", json!({}));
let libs = list["libraries"].as_array().unwrap();
assert_eq!(libs.len(), 4, "{libs:?}");
assert_eq!(libs.len(), 5, "{libs:?}");
assert_eq!((libs[0]["id"].as_str(), libs[0]["category"].as_str()), (Some("basic-shapes"), Some("builtIn")));
assert_eq!(
(libs[1]["id"].as_str(), libs[1]["name"].as_str(), libs[1]["category"].as_str()),
@@ -98,6 +98,10 @@ fn the_builtin_library_is_original_art_generated_in_code() {
(libs[3]["id"].as_str(), libs[3]["name"].as_str(), libs[3]["category"].as_str()),
(Some("inventory-icons"), Some("Inventory Icons"), Some("builtIn"))
);
assert_eq!(
(libs[4]["id"].as_str(), libs[4]["name"].as_str(), libs[4]["category"].as_str()),
(Some("skill-icons"), Some("Skill Icons"), Some("builtIn"))
);
let lib = run(&mut s, "symbol.library", json!({"library": "basic shapes"}));
let names: Vec<&str> = lib["symbols"].as_array().unwrap().iter().map(|x| x["name"].as_str().unwrap()).collect();
assert_eq!(names, ["Circle", "Square", "Rounded Square", "Triangle", "Diamond", "Hexagon", "Star", "Burst", "Arrow"]);
@@ -159,6 +163,32 @@ fn inventory_icons_symbols_add_without_nine_slice() {
));
}
#[test]
fn skill_icons_symbols_add_without_nine_slice() {
let mut s = session();
let lib = run(&mut s, "symbol.library", json!({"library": "skill-icons"}));
let names: Vec<&str> = lib["symbols"].as_array().unwrap().iter().map(|x| x["name"].as_str().unwrap()).collect();
assert_eq!(names, ["Attack", "Defend", "Heal", "Buff", "Ult"]);
let mut placed = Vec::new();
for (i, name) in names.iter().enumerate() {
let r = run(
&mut s,
"symbol.addFromLibrary",
json!({"library": "skill-icons", "name": name, "place": true, "x": 100.0 + 80.0 * i as f64, "y": 100.0}),
);
assert_eq!(r["added"], json!([name]));
placed.push(r["placed"].as_u64().unwrap());
}
let d = doc(&s);
for name in &names {
assert_eq!(d.symbol_nine_slice(name), None, "{name} should not carry 9-slice guides");
}
assert!(matches!(
d.node(NodeId(placed[0])).map(|n| &n.kind),
Some(NodeKind::SymbolInstance { symbol, .. }) if symbol == "Attack"
));
}
#[test]
fn map_markers_symbols_add_without_nine_slice() {
let mut s = session();