Skip to content

Commit

Permalink
Merge pull request #17 from CJLove/master
Browse files Browse the repository at this point in the history
Add 'list' subcommand for palette, imageset, sprite, tilemap and bitmap elements
  • Loading branch information
yeastplume committed May 25, 2020
2 parents f38cb3b + 6a1a52b commit f95adad
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/bin/aloevera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ subcommands:
- input_file:
help: Input PNG file name
index: 2
- list:
about: List palettes in a project file
- imageset:
about: Import and manipulate image sets
subcommands:
Expand Down Expand Up @@ -114,6 +116,8 @@ subcommands:
- pixel_depth:
help: Target Pixel Depth (8, 4, 2 or 1)
index: 3
- list:
about: List image sets in a project file
- tilemap:
about: Import and manipulate tilemaps
subcommands:
Expand Down Expand Up @@ -183,6 +187,8 @@ subcommands:
short: c
takes_value: true
default_value: "0"
- list:
about: List tilemaps in a project file
- sprite:
about: Interpret an existing Imageset as a Sprite
subcommands:
Expand All @@ -195,6 +201,8 @@ subcommands:
- imageset_id:
help: ID of the existing, formatted Imageset to use as a Sprite
index: 2
- list:
about: List sprites in a project file
- bitmap:
about: Interpret an existing Imageset as a Bitmap
subcommands:
Expand All @@ -207,3 +215,5 @@ subcommands:
- imageset_id:
help: ID of the existing, formatted Imageset to use as a Bitmap
index: 2
- list:
about: List bitmaps in a project file
14 changes: 14 additions & 0 deletions src/cmd/bitmap/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ pub fn bitmap_init(g_args: &GlobalArgs, args: &BitmapInitArgs) -> Result<(), Err

Ok(())
}

pub fn bitmap_list(g_args: &GlobalArgs) -> Result<(), Error> {
let proj = common::load_project(g_args.project_file.clone())?;
println!("Bitmaps:");
for (id, bitmap) in proj.bitmaps {
println!(
" {}: width {} depth {}",
id,
bitmap.width.val_as_u32(),
bitmap.depth
);
}
Ok(())
}
1 change: 1 addition & 0 deletions src/cmd/bitmap/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn execute_bitmap_command(g_args: &GlobalArgs, args: &ArgMatches) -> Result<
let a = arg_parse!(parse_bitmap_init_args(g_args, args));
command::bitmap_init(g_args, &a)
}
("list", Some(_)) => command::bitmap_list(g_args),
_ => {
let msg = format!("Unknown sub command, use 'aloevera bitmap --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
Expand Down
26 changes: 26 additions & 0 deletions src/cmd/imageset/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,29 @@ pub fn imageset_format(g_args: &GlobalArgs, args: &ImageSetFormatArgs) -> Result

Ok(())
}

/// Imageset list
pub fn imageset_list(g_args: &GlobalArgs) -> Result<(), Error> {
let proj = common::load_project(g_args.project_file.clone())?;
println!("Image sets:");
for (id, imageset) in proj.imagesets {
match imageset.depth {
None => println!(
" {}: {} {}x{} frames",
id,
imageset.frame_data.len(),
imageset.frame_width,
imageset.frame_height
),
pixel_depth => print!(
" {}: {} {}x{} frames depth {}",
id,
imageset.frame_data.len(),
imageset.frame_width,
imageset.frame_height,
pixel_depth.unwrap()
),
}
}
Ok(())
}
1 change: 1 addition & 0 deletions src/cmd/imageset/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn execute_imageset_command(g_args: &GlobalArgs, args: &ArgMatches) -> Resul
let a = arg_parse!(parse_imageset_format_args(g_args, args));
command::imageset_format(g_args, &a)
}
("list", Some(_)) => command::imageset_list(g_args),
_ => {
let msg = format!("Unknown sub command, use 'aloevera imageset --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/palette/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ pub fn palette_import(g_args: &GlobalArgs, args: &PaletteImportArgs) -> Result<(

Ok(())
}

/// Palette list command
pub fn palette_list(g_args: &GlobalArgs) -> Result<(), Error> {
// load up the project json
let project_file = match &g_args.project_file {
Some(f) => f,
None => {
return Err(ErrorKind::ArgumentError("Missing project file name".to_string()).into())
}
};
let proj_json: String = common::read_file_string(&project_file)?;
let proj = AloeVeraProject::new_from_json(&proj_json)?;
println!("Palettes:");
for (id, palette) in proj.palettes {
println!(" {}: {} colors", id, palette.len());
}

Ok(())
}
1 change: 1 addition & 0 deletions src/cmd/palette/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn execute_palette_command(g_args: &GlobalArgs, args: &ArgMatches) -> Result
let a = arg_parse!(parse_palette_import_args(g_args, args));
command::palette_import(g_args, &a)
}
("list", Some(_)) => command::palette_list(g_args),
_ => {
let msg = format!("Unknown sub command, use 'aloevera palette --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
Expand Down
16 changes: 16 additions & 0 deletions src/cmd/sprite/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,19 @@ pub fn sprite_init(g_args: &GlobalArgs, args: &SpriteInitArgs) -> Result<(), Err

Ok(())
}

/// Sprite list command
pub fn sprite_list(g_args: &GlobalArgs) -> Result<(), Error> {
let proj = common::load_project(g_args.project_file.clone())?;
println!("Sprites:");
for (id, sprite) in proj.sprites {
print!(
" {}: {}x{} depth {}",
id,
sprite.frame_width.val_as_u32(),
sprite.frame_height.val_as_u32(),
sprite.depth
);
}
Ok(())
}
1 change: 1 addition & 0 deletions src/cmd/sprite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn execute_sprite_command(g_args: &GlobalArgs, args: &ArgMatches) -> Result<
let a = arg_parse!(parse_sprite_init_args(g_args, args));
command::sprite_init(g_args, &a)
}
("list", Some(_)) => command::sprite_list(g_args),
_ => {
let msg = format!("Unknown sub command, use 'aloevera sprite --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/tilemap/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@ pub fn tilemap_load(g_args: &GlobalArgs, args: &LoadTileMapArgs) -> Result<(), E

Ok(())
}

/// Tilemap list command
pub fn tilemap_list(g_args: &GlobalArgs) -> Result<(), Error> {
let proj = common::load_project(g_args.project_file.clone())?;
println!("Tilemaps:");
for (id, tilemap) in proj.tilemaps {
println!(
" {}: map {}x{} tiles {}x{} mode {}",
id,
tilemap.map_width(),
tilemap.map_height(),
tilemap.tile_width(),
tilemap.tile_height(),
tilemap.mode
);
}
Ok(())
}
1 change: 1 addition & 0 deletions src/cmd/tilemap/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn execute_tilemap_command(g_args: &GlobalArgs, args: &ArgMatches) -> Result
let a = arg_parse!(parse_load_tilemap_args(g_args, args));
command::tilemap_load(g_args, &a)
}
("list", Some(_)) => command::tilemap_list(g_args),
_ => {
let msg = format!("Unknown sub command, use 'aloevera tilemap --help' for details");
return Err(ErrorKind::ArgumentError(msg).into());
Expand Down
2 changes: 1 addition & 1 deletion vera/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl fmt::Display for VeraBitmapDim {
}

impl VeraBitmapDim {
fn val_as_u32(&self) -> u32 {
pub fn val_as_u32(&self) -> u32 {
match self {
VeraBitmapDim::Dim320 => 320,
VeraBitmapDim::Dim640 => 640,
Expand Down
2 changes: 1 addition & 1 deletion vera/src/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl fmt::Display for VeraSpriteDim {
}

impl VeraSpriteDim {
fn _val_as_u32(&self) -> u32 {
pub fn val_as_u32(&self) -> u32 {
match self {
VeraSpriteDim::Dim8 => 8,
VeraSpriteDim::Dim16 => 16,
Expand Down
20 changes: 20 additions & 0 deletions vera/src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ impl VeraTileMap {
self.tiles.len() * 2
}

/// map width as u32
pub fn map_width(&self) -> u32 {
self.map_width.val_as_u32()
}

/// map height as u32
pub fn map_height(&self) -> u32 {
self.map_height.val_as_u32()
}

/// tile width as u32
pub fn tile_width(&self) -> u32 {
self.tile_height.val_as_u32()
}

/// tile height as u32
pub fn tile_height(&self) -> u32 {
self.tile_height.val_as_u32()
}

/// Return data formatted appropriately for the current map mode
fn entry_from_image(
&self,
Expand Down

0 comments on commit f95adad

Please sign in to comment.