A drawing app built for agent/human collaboration
Rust
Exports of a keyed clip give a picture per pose
Indicode BVa920fd5b7581
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6070934..b552735 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,7 @@The first builds, and klad's licences.- A new icon, painted in klad: a K in two brush strokes.+- Fixed exports of a clip moved by keys (a layer, group or shape keyed between frames, with no drawing per frame): `klad export --sheet`, `--frames` and `--godot` wrote the first pose for every frame, and `klad render --sheet` showed them as held. Each pose is now its own picture.- A second agent skill, `klad skill drawing`: the craft of drawing and painting (planning a picture, light on form, values, edges, colour, materials, line, a painting method and a critique checklist), under the MIT licence like the first.- Drawings are `.klad` folders in a fresh format, `klad/6` (drawings from the first builds open as they are, except their bones, which are dropped). Drawings from before (`.draw` folders) do not open and are not converted.- Drawings live well in git: an edit changes only the files of what it edits (`doc.json` keeps no revision or id counter), and copies of a drawing edited apart, in a clone or a worktree, never make the same id, so edits to different layers merge. New ids end in the copy's two-letter tag (`l48qa`, `c12:s349qa`); `klad info` shows it. The editor follows a `git checkout` of an open drawing, and klad never renders an old picture from its cache after one. Recolouring several strokes or fills at once (the selection bar in the editor, or `klad recolour`) moves them to the new colour together and keeps each one's own shade, so a painted-over area stays painted. If a merge still leaves an id used twice, `klad repair` (or **Repair and open** when the drawing won't open) gives every later one a new id and moves its stroke files along.diff --git a/crates/cli/src/sheet.rs b/crates/cli/src/sheet.rsindex 8e4e526..bb2726d 100644--- a/crates/cli/src/sheet.rs+++ b/crates/cli/src/sheet.rs@@ -24,9 +24,15 @@ pub struct Sheet {pub(crate) type Cels = BTreeSet<(String, String, Kind)>;pub(crate) fn shown(doc: &Document, frame: u32) -> Vec<String> {+ let keyed = doc.keyed_state(frame).into_iter().flat_map(|(id, values)| {+ values+ .into_iter()+ .map(move |(prop, bits)| format!("{id} {prop} {bits:08x}"))+ });doc.all_layers().iter().map(|l| l.content_at(frame).map_or(String::new(), |c| c.id.clone()))+ .chain(keyed).collect()}diff --git a/crates/cli/src/sprites.rs b/crates/cli/src/sprites.rsindex f20be0a..e9dc824 100644--- a/crates/cli/src/sprites.rs+++ b/crates/cli/src/sprites.rs@@ -776,6 +776,42 @@ func _init():fs::remove_dir_all(&dir).unwrap();}+ #[test]+ fn a_clip_moved_by_keys_exports_a_picture_per_pose() {+ let dir = std::env::temp_dir().join(format!("draw-sprites-keys-{}", std::process::id()));+ let _ = fs::remove_dir_all(&dir);+ fs::create_dir_all(&dir).unwrap();+ let path = hop(&dir);+ let mut bundle = Bundle::open(&path).unwrap();+ let key = |frame: u32, value: f32| klad_core::keys::Key {+ frame,+ value,+ ease: klad_core::keys::Ease::Linear,+ };+ [key(0, 0.0), key(2, 12.0), key(3, 12.0)]+ .into_iter()+ .for_each(|k| klad_core::keys::set(&mut bundle.doc.layers[0].keys, "x", k).unwrap());+ bundle.save().unwrap();+ frames(&path, "idle", &look(1.0), None).unwrap();+ let read = |n: usize| fs::read(dir.join("hop-idle").join(format!("idle-{n:04}.png"))).unwrap();+ assert_ne!(read(0), read(1), "one drawing held, moved by a key");+ assert_ne!(read(1), read(2));+ sheet(&path, "idle", &look(1.0), &PACKING, None).unwrap();+ let json: Value = serde_json::from_str(&fs::read_to_string(dir.join("hop-idle.json")).unwrap()).unwrap();+ let rects: BTreeSet<String> = json["frames"]+ .as_array()+ .unwrap()+ .iter()+ .map(|f| f["frame"].to_string() + &f["spriteSourceSize"].to_string())+ .collect();+ assert_eq!(+ rects.len(),+ 4,+ "four poses: three of the held drawing and the next drawing"+ );+ fs::remove_dir_all(&dir).unwrap();+ }+fn frames_out(path: &Path, dir: &Path) {frames(path, "hop", &look(1.0), None).unwrap();let out = dir.join("hop-hop");diff --git a/crates/core/src/doc.rs b/crates/core/src/doc.rsindex b5f1b9c..e66f34e 100644--- a/crates/core/src/doc.rs+++ b/crates/core/src/doc.rs@@ -1034,6 +1034,19 @@ impl Document {out}+ pub fn keyed_state(&self, frame: u32) -> Vec<(String, Vec<(String, u32)>)> {+ self.all_layers()+ .into_iter()+ .flat_map(|layer| {+ let mut nodes = Vec::new();+ walk_nodes(layer.content_at(frame).map_or(&[][..], |c| &c.nodes), &mut nodes);+ std::iter::once((&layer.id, &layer.keys)).chain(nodes.into_iter().map(|n| (&n.id, &n.keys)))+ })+ .filter(|(_, keys)| !keys.is_empty())+ .map(|(id, keys)| (id.clone(), crate::keys::state(keys, frame)))+ .collect()+ }+pub fn ids(&self) -> BTreeSet<String> {self.all_layers().iter()diff --git a/crates/core/src/keys.rs b/crates/core/src/keys.rsindex 8e54f1b..b8ca2ce 100644--- a/crates/core/src/keys.rs+++ b/crates/core/src/keys.rs@@ -114,6 +114,12 @@ pub fn remove(keys: &mut Keys, prop: Option<&str>, frame: u32) {keys.retain(|_, list| !list.is_empty());}+pub fn state(keys: &Keys, frame: u32) -> Vec<(String, u32)> {+ keys.keys()+ .filter_map(|p| value(keys, p, frame).map(|v| (p.clone(), v.to_bits())))+ .collect()+}+pub fn frames(keys: &Keys) -> Vec<u32> {let mut all: Vec<u32> = keys.values().flatten().map(|k| k.frame).collect();all.sort_unstable();diff --git a/crates/render/src/sheet.rs b/crates/render/src/sheet.rsindex 13ccd2c..79d3a5c 100644--- a/crates/render/src/sheet.rs+++ b/crates/render/src/sheet.rs@@ -91,7 +91,8 @@ fn shown(layers: &[&Layer], frame: u32) -> Vec<Option<String>> {pub fn plan(doc: &Document, from: u32, to: u32, drawings: bool) -> Plan {let layers: Vec<&Layer> = sheet_layers(doc).into_iter().filter(|l| !l.cels().is_empty()).collect();let grid: Vec<Vec<Cell>> = layers.iter().map(|l| cells(l, to + 1)).collect();- let holds = |f: u32| f > 0 && shown(&layers, f) == shown(&layers, f - 1);+ let holds =+ |f: u32| f > 0 && shown(&layers, f) == shown(&layers, f - 1) && doc.keyed_state(f) == doc.keyed_state(f - 1);let tokens = |f: u32| grid.iter().map(|c| token(&c[f as usize])).collect::<Vec<_>>();let spots = match drawings {false => (from..=to)