Skip to content

armgit / klad

Public Imported from GitHub
0

A drawing app built for agent/human collaboration

Rust

klad export -o takes a folder for every kind of export

Indicode BV459e21eb09aa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6380d89..b540549 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
The first builds, and klad's licences.
+- `klad export -o` takes a folder that exists for every kind of export and puts the export in it under its usual name; a sheet used to land next to the folder.
- A new icon, painted in klad: a K in two brush strokes.
- Two pixel art samples, `sprout` (a 32 px character with an idle and a walk) and `ground` (a tileset of 16 px tiles), in the start window and `klad samples`, and a guide, Drawing pixel art.
- A third agent skill, `klad skill pixel`: the craft of pixel art (size and palette, silhouette, clusters, clean lines, outlines, ramps with hue shift, shading without pillow shading or banding, anti-aliasing by hand, tiles, and a checklist at real size), and animating a sprite frame by frame: the four poses of a walk, heights and holds, what moves with the body and what trails it, the idle, and how to judge it. Under the MIT licence, like the other two.
diff --git a/crates/cli/src/aseprite.rs b/crates/cli/src/aseprite.rs
index ba63815..a50b78c 100644
--- a/crates/cli/src/aseprite.rs
+++ b/crates/cli/src/aseprite.rs
@@ -629,9 +629,12 @@ pub fn export(path: &Path, out: Option<PathBuf>, variant: Option<&str>) -> Resul
let bundle = Bundle::open(path)?;
let (sprite, notes) = sprite_of(&bundle, variant)?;
let bytes = klad_render::aseprite::write(&sprite)?;
- let file = out.unwrap_or_else(|| {
- bundle_dir(&bundle).join(format!("{}{}.aseprite", bundle_stem(&bundle), variant_tag(variant)))
- });
+ let usual = format!("{}{}.aseprite", bundle_stem(&bundle), variant_tag(variant));
+ let file = match out {
+ Some(folder) if folder.is_dir() => folder.join(usual),
+ Some(file) => file,
+ None => bundle_dir(&bundle).join(usual),
+ };
write_atomic(&file, &bytes)?;
println!("{}", file.display());
eprintln!(
diff --git a/crates/cli/src/export.rs b/crates/cli/src/export.rs
index 58db669..6443b62 100644
--- a/crates/cli/src/export.rs
+++ b/crates/cli/src/export.rs
@@ -89,9 +89,12 @@ pub fn run(path: &Path, opts: Export) -> Result<()> {
l.name.as_str()
}
});
- let out = opts
- .out
- .unwrap_or_else(|| default_path(&bundle, name, opts.frame, opts.scale, opts.variant.as_deref()));
+ let usual = default_path(&bundle, name, opts.frame, opts.scale, opts.variant.as_deref());
+ let out = match opts.out {
+ Some(folder) if folder.is_dir() => folder.join(usual.file_name().unwrap_or_default()),
+ Some(file) => file,
+ None => usual,
+ };
write_atomic(&out, &bytes)?;
println!("{}", out.display());
eprintln!(
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index 07ce1b9..2b80d08 100644
--- a/crates/cli/src/main.rs
+++ b/crates/cli/src/main.rs
@@ -2119,7 +2119,11 @@ enum Command {
padding: u32,
#[arg(long, default_value_t = 4096, help = "Sheets: largest page side in px")]
max: u32,
- #[arg(short, long)]
+ #[arg(
+ short,
+ long,
+ help = "Where the export goes: a file name, or a folder that exists, which takes the export under its usual name (frames and Godot exports always take a folder)"
+ )]
out: Option<PathBuf>,
},
#[command(
@@ -4367,7 +4371,7 @@ fn run() -> Result<()> {
names.into_iter().try_for_each(|variant| {
let tag = layers::variant_tag(variant.as_deref());
let out = match (&out, several && !tag.is_empty() && godot.is_none()) {
- (Some(given), true) => Some(sprites::tagged(given, &tag)),
+ (Some(given), true) if !given.is_dir() => Some(sprites::tagged(given, &tag)),
_ => out.clone(),
};
let look = sprites::Look {
diff --git a/crates/cli/src/sprites.rs b/crates/cli/src/sprites.rs
index 05b4cde..f6fe8ec 100644
--- a/crates/cli/src/sprites.rs
+++ b/crates/cli/src/sprites.rs
@@ -289,18 +289,23 @@ pub fn sheet(path: &Path, spec: &str, look: &Look, packing: &Packing, out: Optio
let bundle = Bundle::open(path)?;
let animations = sprites::animations(&bundle.doc, spec)?;
let stem = stem_for(&bundle, look);
+ let usual = format!(
+ "{stem}-{}{}",
+ if spec == "all" { "sheet".into() } else { file_safe(spec) },
+ scale_tag(look.scale)
+ );
let name = match out {
+ Some(folder) if folder.is_dir() => Name {
+ dir: folder,
+ stem: usual,
+ },
Some(out) => Name {
dir: out.parent().map_or(PathBuf::from("."), Path::to_path_buf),
stem: file_name(&out).trim_end_matches(".png").to_string(),
},
None => Name {
dir: bundle_dir(&bundle),
- stem: format!(
- "{stem}-{}{}",
- if spec == "all" { "sheet".into() } else { file_safe(spec) },
- scale_tag(look.scale)
- ),
+ stem: usual,
},
};
let pics = pictures(&bundle, animations, look)?;
@@ -453,6 +458,7 @@ pub fn gif(path: &Path, spec: &str, look: &Look, dither: bool, out: Option<PathB
};
let file = match (&out, folder) {
(_, Some(dir)) => dir.join(name),
+ (Some(given), None) if given.is_dir() => given.join(name),
(Some(given), None) => given.clone(),
(None, None) => bundle_dir(&bundle).join(name),
};
diff --git a/crates/cli/tests/binary.rs b/crates/cli/tests/binary.rs
index 9360c02..51cbabc 100644
--- a/crates/cli/tests/binary.rs
+++ b/crates/cli/tests/binary.rs
@@ -1312,6 +1312,34 @@ fn a_pixel_drawing_exports_sharp_at_whole_number_scales_as_png_gif_sheet_and_god
scene.contains("type=\"AnimatedSprite2D\"") && scene.contains("texture_filter = 1\n"),
"{scene}"
);
+
+ let folder = dir.join("into");
+ std::fs::create_dir_all(&folder).unwrap();
+ let into = folder.to_str().unwrap();
+ draw(&["export", path, "--sheet", "all", "-o", into]);
+ draw(&["export", path, "--gif", "hop", "--scale", "2", "-o", into]);
+ draw(&["export", path, "--frame", "2", "--scale", "2", "-o", into]);
+ draw(&["export", path, "--aseprite", "-o", into]);
+ let mut inside: Vec<String> = std::fs::read_dir(&folder)
+ .unwrap()
+ .map(|e| e.unwrap().file_name().to_string_lossy().to_string())
+ .collect();
+ inside.sort();
+ assert_eq!(
+ inside,
+ [
+ "hop-sheet.json",
+ "hop-sheet.png",
+ "hop.aseprite"
+ ],
+ "a folder that exists takes every kind of export under its usual name"
+ );
+ assert!(
+ !dir.join("into.png").exists() && !dir.join("into.json").exists(),
+ "nothing lands next to the folder"
+ );
std::fs::remove_dir_all(&dir).unwrap();
}
diff --git a/docs/cli.md b/docs/cli.md
index fa53f8e..b1b88a5 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -3627,7 +3627,7 @@ Options:
[default: 4096]
-o, --out <OUT>
-
+ Where the export goes: a file name, or a folder that exists, which takes the export under its usual name (frames and Godot exports always take a folder)
-h, --help
Print help (see a summary with '-h')