From 03644b77cf7818712a0025864b4665a756c2da4a Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Thu, 4 Jun 2020 12:54:34 +0100 Subject: [PATCH 1/8] binary serialization of project file --- Cargo.lock | 11 +++++++++++ proj/Cargo.toml | 1 + proj/src/error.rs | 17 ++++++++++++----- proj/src/lib.rs | 10 ++++++---- proj/src/project.rs | 18 ++++++++++-------- src/cmd/bitmap/command.rs | 4 ++-- src/cmd/create/command.rs | 5 ++--- src/cmd/imageset/command.rs | 4 ++-- src/cmd/palette/command.rs | 4 ++-- src/cmd/sprite/command.rs | 4 ++-- src/cmd/tilemap/command.rs | 4 ++-- src/error.rs | 16 ++++++++-------- vera/src/error.rs | 6 +----- 13 files changed, 61 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50a371d..d0d3c20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,7 @@ dependencies = [ "aloevera_util 0.2.3", "aloevera_vera 0.2.3", "backtrace 0.3.48 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -123,6 +124,15 @@ dependencies = [ "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bincode" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -834,6 +844,7 @@ dependencies = [ "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum backtrace 0.3.48 (registry+https://github.com/rust-lang/crates.io-index)" = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130" +"checksum bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum built 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d666ee87840ed5ad1e8cb429199c9b68ca3ee74a9f439e069b1e68748f46c92" "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" diff --git a/proj/Cargo.toml b/proj/Cargo.toml index 4335c96..9d944fe 100644 --- a/proj/Cargo.toml +++ b/proj/Cargo.toml @@ -18,6 +18,7 @@ log4rs = { version = "0.8.1", features = ["rolling_file_appender", "compound_pol log = "0.4" failure = "0.1" failure_derive = "0.1" +bincode = "1.2" aloevera_util = { path = "../util", version = "0.2.3" } aloevera_vera = { path = "../vera", version = "0.2.3" } diff --git a/proj/src/error.rs b/proj/src/error.rs index f375b41..a3d656f 100644 --- a/proj/src/error.rs +++ b/proj/src/error.rs @@ -28,7 +28,7 @@ pub struct Error { } /// Wallet errors, mostly wrappers around underlying crypto or I/O errors. -#[derive(Clone, Eq, PartialEq, Debug, Fail)] +#[derive(Debug, Fail)] pub enum ErrorKind { /// IO Error #[fail(display = "I/O error: {}", _0)] @@ -42,6 +42,9 @@ pub enum ErrorKind { /// Argument Error #[fail(display = "Argument Error: {}", _0)] ArgumentError(String), + /// Errors from the Bincode crate + #[fail(display = "Bincode Error: {}", _0)] + BincodeError(bincode::Error), /// Other #[fail(display = "Generic error: {}", _0)] GenericError(String), @@ -74,10 +77,6 @@ impl Display for Error { } impl Error { - /// get kind - pub fn kind(&self) -> ErrorKind { - self.inner.get_context().clone() - } /// get cause string pub fn cause_string(&self) -> String { match self.cause() { @@ -124,3 +123,11 @@ impl From for Error { } } } + +impl From for Error { + fn from(error: bincode::Error) -> Error { + Error { + inner: Context::new(ErrorKind::BincodeError(error)), + } + } +} diff --git a/proj/src/lib.rs b/proj/src/lib.rs index 27bfad0..aab3c05 100644 --- a/proj/src/lib.rs +++ b/proj/src/lib.rs @@ -36,8 +36,10 @@ pub use error::{Error, ErrorKind}; pub use project::AloeVeraProject; -/// Just a wrapper around a serializable object -pub trait Jsonable { - /// to json - fn to_json(&self) -> Result; +/// And around the binary version +pub trait Binable { + /// to binary + fn to_bin(&self) -> Result, Error>; + /// from binary + fn from_bin(encoded: &Vec) -> Result, Error>; } diff --git a/proj/src/project.rs b/proj/src/project.rs index 3bd1a08..8bc52cc 100644 --- a/proj/src/project.rs +++ b/proj/src/project.rs @@ -13,7 +13,7 @@ // limitations under the License. //! Top Level Project file definition -use crate::Jsonable; +use crate::Binable; use crate::{Error, ErrorKind}; use std::collections::BTreeMap; use vera::{VeraBitmap, VeraImageSet, VeraPalette, VeraSprite, VeraTileMap}; @@ -35,13 +35,15 @@ pub struct AloeVeraProject<'a> { pub bitmaps: BTreeMap>, } -impl<'a> Jsonable for AloeVeraProject<'a> { - fn to_json(&self) -> Result { - serde_json::to_string_pretty(&self).map_err(|e| { - let msg = format!("Unable to create JSON: {}", e); - error!("{}", msg); - ErrorKind::JSONError(msg).into() - }) +impl<'a> Binable for AloeVeraProject<'a> { + fn to_bin(&self) -> Result, Error> { + let encoded = bincode::serialize(&self)?; + Ok(encoded) + } + + fn from_bin(encoded: &Vec) -> Result, Error> { + let decoded = bincode::deserialize(&encoded[..])?; + Ok(Box::new(decoded)) } } diff --git a/src/cmd/bitmap/command.rs b/src/cmd/bitmap/command.rs index cb13977..b32ba8f 100644 --- a/src/cmd/bitmap/command.rs +++ b/src/cmd/bitmap/command.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::{Error, ErrorKind}; -use proj::{AloeVeraProject, Jsonable}; +use proj::{AloeVeraProject, Binable}; use crate::cmd::common::{self, GlobalArgs}; use vera::VeraBitmap; @@ -48,7 +48,7 @@ pub fn bitmap_init(g_args: &GlobalArgs, args: &BitmapInitArgs) -> Result<(), Err }; let bitmap = VeraBitmap::init_from_imageset(&args.id, &imageset)?; proj.bitmaps.insert(args.id.clone(), bitmap); - common::output_to_file(&project_file, &proj.to_json()?.as_bytes(), &None)?; + common::output_to_file(&project_file, &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/cmd/create/command.rs b/src/cmd/create/command.rs index 3b47849..726c5da 100644 --- a/src/cmd/create/command.rs +++ b/src/cmd/create/command.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::Error; -use proj::{AloeVeraProject, Jsonable}; +use proj::{AloeVeraProject, Binable}; use util::fat; /// Arguments for the initial create project command @@ -30,8 +30,7 @@ pub fn create_project(args: &CreateProjectArgs) -> Result<(), Error> { info!("Creating new project file at: {}", args.output_file); let proj = AloeVeraProject::new(id); - let json = proj.to_json()?; - crate::cmd::common::output_to_file(&args.output_file, &json.as_bytes(), &None)?; + crate::cmd::common::output_to_file(&args.output_file, &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/cmd/imageset/command.rs b/src/cmd/imageset/command.rs index 6c70d19..192449b 100644 --- a/src/cmd/imageset/command.rs +++ b/src/cmd/imageset/command.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::{Error, ErrorKind}; -use proj::Jsonable; +use proj::Binable; use crate::cmd::common::{self, GlobalArgs}; use vera::{VeraImageSet, VeraImageSetLoadConfig, VeraPixelDepth}; @@ -26,7 +26,7 @@ fn insert_imageset( //info!("Inserting imageset into project: {}", project_file); let mut proj = crate::cmd::common::load_project(project_file.clone())?; proj.imagesets.insert(id.into(), imageset.clone()); - crate::cmd::common::output_to_file(&project_file.unwrap(), &proj.to_json()?.as_bytes(), &None)?; + crate::cmd::common::output_to_file(&project_file.unwrap(), &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/cmd/palette/command.rs b/src/cmd/palette/command.rs index 6cfc268..36c38ae 100644 --- a/src/cmd/palette/command.rs +++ b/src/cmd/palette/command.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::{Error, ErrorKind}; -use proj::{AloeVeraProject, Jsonable}; +use proj::{AloeVeraProject, Binable}; use crate::cmd::common::{self, GlobalArgs}; use vera::{VeraPalette, VeraPaletteLoadConfig}; @@ -77,7 +77,7 @@ pub fn palette_import(g_args: &GlobalArgs, args: &PaletteImportArgs) -> Result<( let proj_json = common::read_file_string(&project_file)?; let mut proj = AloeVeraProject::new_from_json(&proj_json)?; proj.palettes.insert(palette.id.clone(), palette); - common::output_to_file(&project_file, &proj.to_json()?.as_bytes(), &None)?; + common::output_to_file(&project_file, &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/cmd/sprite/command.rs b/src/cmd/sprite/command.rs index 236065a..ae12dc8 100644 --- a/src/cmd/sprite/command.rs +++ b/src/cmd/sprite/command.rs @@ -13,7 +13,7 @@ // limitations under the License. use crate::{Error, ErrorKind}; -use proj::{AloeVeraProject, Jsonable}; +use proj::{AloeVeraProject, Binable}; use crate::cmd::common::{self, GlobalArgs}; use vera::VeraSprite; @@ -48,7 +48,7 @@ pub fn sprite_init(g_args: &GlobalArgs, args: &SpriteInitArgs) -> Result<(), Err }; let sprite = VeraSprite::init_from_imageset(&args.id, &imageset)?; proj.sprites.insert(args.id.clone(), sprite); - common::output_to_file(&project_file, &proj.to_json()?.as_bytes(), &None)?; + common::output_to_file(&project_file, &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/cmd/tilemap/command.rs b/src/cmd/tilemap/command.rs index 0c082fe..6f8814e 100644 --- a/src/cmd/tilemap/command.rs +++ b/src/cmd/tilemap/command.rs @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use proj::Jsonable; +use proj::Binable; use crate::cmd::common::{self, GlobalArgs}; use crate::{Error, ErrorKind}; @@ -24,7 +24,7 @@ fn insert_tilemap( ) -> Result<(), Error> { let mut proj = crate::cmd::common::load_project(project_file.clone())?; proj.tilemaps.insert(id.into(), tilemap.clone()); - crate::cmd::common::output_to_file(&project_file.unwrap(), &proj.to_json()?.as_bytes(), &None)?; + crate::cmd::common::output_to_file(&project_file.unwrap(), &proj.to_bin()?, &None)?; Ok(()) } diff --git a/src/error.rs b/src/error.rs index d57b5c4..93bef85 100644 --- a/src/error.rs +++ b/src/error.rs @@ -28,14 +28,14 @@ pub struct Error { } /// Wallet errors, mostly wrappers around underlying crypto or I/O errors. -#[derive(Clone, Eq, PartialEq, Debug, Fail)] +#[derive(Debug, Fail)] pub enum ErrorKind { /// Vera Error #[fail(display = "Vera module error: {}", _0)] - Vera(vera::ErrorKind), + Vera(vera::Error), /// Project Error - #[fail(display = "Project Error")] - Proj(proj::ErrorKind), + #[fail(display = "Project Error: {}", _0)] + Proj(proj::Error), /// IO Error #[fail(display = "I/O error: {}", _0)] IO(String), @@ -78,9 +78,9 @@ impl Display for Error { impl Error { /// get kind - pub fn kind(&self) -> ErrorKind { + /*pub fn kind(&self) -> ErrorKind { self.inner.get_context().clone() - } + }*/ /// get cause string pub fn cause_string(&self) -> String { match self.cause() { @@ -101,7 +101,7 @@ impl Error { impl From for Error { fn from(error: proj::Error) -> Error { Error { - inner: Context::new(ErrorKind::Proj(error.kind())), + inner: Context::new(ErrorKind::Proj(error)), } } } @@ -109,7 +109,7 @@ impl From for Error { impl From for Error { fn from(error: vera::Error) -> Error { Error { - inner: Context::new(ErrorKind::Vera(error.kind())), + inner: Context::new(ErrorKind::Vera(error)), } } } diff --git a/vera/src/error.rs b/vera/src/error.rs index 1837324..8e3da1f 100644 --- a/vera/src/error.rs +++ b/vera/src/error.rs @@ -29,7 +29,7 @@ pub struct Error { } /// Wallet errors, mostly wrappers around underlying crypto or I/O errors. -#[derive(Clone, Eq, PartialEq, Debug, Fail)] +#[derive(Debug, Fail)] pub enum ErrorKind { /// IO Error #[fail(display = "I/O error: {}", _0)] @@ -174,10 +174,6 @@ impl Display for Error { } impl Error { - /// get kind - pub fn kind(&self) -> ErrorKind { - self.inner.get_context().clone() - } /// get cause string pub fn cause_string(&self) -> String { match self.cause() { From da4c3dc5c871b598720adfa912e771cf964d61f3 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Thu, 4 Jun 2020 13:22:11 +0100 Subject: [PATCH 2/8] remove json project file output --- Cargo.lock | 120 ++++++++++++++++++------------------- proj/Cargo.toml | 1 - proj/src/lib.rs | 3 - proj/src/project.rs | 11 +--- src/cmd/bitmap/command.rs | 4 +- src/cmd/common.rs | 6 +- src/cmd/palette/command.rs | 8 +-- src/cmd/sprite/command.rs | 4 +- util/Cargo.toml | 1 - 9 files changed, 71 insertions(+), 87 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0d3c20..d801e57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "addr2line" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gimli 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -20,7 +20,7 @@ dependencies = [ "aloevera_proj 0.2.3", "aloevera_util 0.2.3", "aloevera_vera 0.2.3", - "built 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "built 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -40,9 +40,8 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -57,9 +56,8 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -75,8 +73,8 @@ dependencies = [ "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "permutate 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "png 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -103,7 +101,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hermit-abi 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -117,9 +115,9 @@ name = "backtrace" version = "0.3.48" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "addr2line 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "addr2line 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "object 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -130,7 +128,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -140,7 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "built" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cargo-lock 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -157,7 +155,7 @@ version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -236,9 +234,9 @@ name = "failure_derive" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -260,7 +258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -292,7 +290,7 @@ name = "hermit-abi" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -333,7 +331,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.70" +version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -356,7 +354,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -375,12 +373,12 @@ dependencies = [ "flate2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log-mdc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", "serde-value 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)", "thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -458,7 +456,7 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -488,12 +486,12 @@ dependencies = [ [[package]] name = "podio" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -509,7 +507,7 @@ name = "quote" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -519,7 +517,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -557,7 +555,7 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -579,7 +577,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -589,10 +587,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.110" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -601,17 +599,17 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.110" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -620,8 +618,8 @@ version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -631,8 +629,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", + "yaml-rust 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -660,10 +658,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "1.0.22" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -673,9 +671,9 @@ name = "synstructure" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -692,7 +690,7 @@ name = "thread-id" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -702,7 +700,7 @@ name = "time" version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -711,7 +709,7 @@ name = "toml" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -820,7 +818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "yaml-rust" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "linked-hash-map 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -832,11 +830,11 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] -"checksum addr2line 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "456d75cbb82da1ad150c8a9d97285ffcd21c9931dcb11e995903e7d75141b38b" +"checksum addr2line 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543" "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5" @@ -846,7 +844,7 @@ dependencies = [ "checksum backtrace 0.3.48 (registry+https://github.com/rust-lang/crates.io-index)" = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130" "checksum bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum built 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d666ee87840ed5ad1e8cb429199c9b68ca3ee74a9f439e069b1e68748f46c92" +"checksum built 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "161483ae87631dd826cb40fc696d9e5a9fa94e19c2e69a372dcedd7dc68e7c0a" "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum cargo-lock 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8504b63dd1249fd1745b7b4ef9b6f7b107ddeb3c95370043c7dbcc38653a2679" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" @@ -870,7 +868,7 @@ dependencies = [ "checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" "checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" "checksum linked-hash-map 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" @@ -889,8 +887,8 @@ dependencies = [ "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum permutate 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53b7d5b19a715ffab38693a9dd44b067fdfa2b18eef65bd93562dfe507022fae" "checksum png 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef859a23054bbfee7811284275ae522f0434a3c8e7f4b74bd4a35ae7e1c4a283" -"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" -"checksum proc-macro2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "53f5ffe53a6b28e37c9c1ce74893477864d64f74778a93a4beb43c8fa167f639" +"checksum podio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19" +"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" "checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" @@ -899,21 +897,21 @@ dependencies = [ "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1" +"checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)" = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" +"checksum serde 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)" = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d" "checksum serde-value 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7a663f873dedc4eac1a559d4c6bc0d0b2c34dc5ac4702e105014b8281489e44f" -"checksum serde_derive 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)" = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" +"checksum serde_derive 1.0.111 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250" "checksum serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)" = "993948e75b189211a9b31a7528f950c6adc21f9720b6438ff80a7fa2f864cea2" "checksum serde_yaml 0.8.12 (registry+https://github.com/rust-lang/crates.io-index)" = "16c7a592a1ec97c9c1c68d75b6e537dcbf60c7618e038e7841e00af1d9ccf0c4" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum syn 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "1425de3c33b0941002740a420b1a906a350b88d08b82b2c8a01035a3f9447bac" +"checksum syn 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1" @@ -934,5 +932,5 @@ dependencies = [ "checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" -"checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" +"checksum yaml-rust 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d" "checksum zip 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6df134e83b8f0f8153a094c7b0fd79dfebe437f1d76e7715afa18ed95ebe2fd7" diff --git a/proj/Cargo.toml b/proj/Cargo.toml index 9d944fe..7aa3f0d 100644 --- a/proj/Cargo.toml +++ b/proj/Cargo.toml @@ -13,7 +13,6 @@ backtrace = "0.3" lazy_static = "1" serde = "1" serde_derive = "1" -serde_json = "1" log4rs = { version = "0.8.1", features = ["rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] } log = "0.4" failure = "0.1" diff --git a/proj/src/lib.rs b/proj/src/lib.rs index aab3c05..9e75d50 100644 --- a/proj/src/lib.rs +++ b/proj/src/lib.rs @@ -21,11 +21,8 @@ #![deny(unused_mut)] #![warn(missing_docs)] -#[macro_use] -extern crate log; #[macro_use] extern crate serde_derive; -extern crate serde_json; extern crate aloevera_util as util; extern crate aloevera_vera as vera; diff --git a/proj/src/project.rs b/proj/src/project.rs index 8bc52cc..34d3182 100644 --- a/proj/src/project.rs +++ b/proj/src/project.rs @@ -14,7 +14,7 @@ //! Top Level Project file definition use crate::Binable; -use crate::{Error, ErrorKind}; +use crate::Error; use std::collections::BTreeMap; use vera::{VeraBitmap, VeraImageSet, VeraPalette, VeraSprite, VeraTileMap}; @@ -59,13 +59,4 @@ impl<'a> AloeVeraProject<'a> { bitmaps: BTreeMap::new(), } } - - /// from json - pub fn new_from_json(json: &str) -> Result { - serde_json::from_str(&json).map_err(|e| { - let msg = format!("Unable to parse Project JSON: {}", e); - error!("{}", msg); - ErrorKind::JSONError(msg).into() - }) - } } diff --git a/src/cmd/bitmap/command.rs b/src/cmd/bitmap/command.rs index b32ba8f..808c8d5 100644 --- a/src/cmd/bitmap/command.rs +++ b/src/cmd/bitmap/command.rs @@ -34,8 +34,8 @@ pub fn bitmap_init(g_args: &GlobalArgs, args: &BitmapInitArgs) -> Result<(), Err } }; info!("Adding bitmap into project: {}", project_file); - let proj_json = common::read_file_string(&project_file)?; - let mut proj = AloeVeraProject::new_from_json(&proj_json)?; + let encoded = common::read_file_bin(&project_file)?; + let mut proj = *AloeVeraProject::from_bin(&encoded)?; let imageset = match proj.imagesets.get(&args.imageset_id) { Some(i) => i, None => { diff --git a/src/cmd/common.rs b/src/cmd/common.rs index 5760021..eb2643c 100644 --- a/src/cmd/common.rs +++ b/src/cmd/common.rs @@ -17,7 +17,7 @@ use std::fs::{self, File}; use std::io::{Read, Write}; use util::fat; -use proj::AloeVeraProject; +use proj::{AloeVeraProject, Binable}; use clap::ArgMatches; // define what to do on argument error @@ -127,7 +127,7 @@ pub fn load_project<'a>(project_file: Option) -> Result Result<( } }; info!("Inserting palette into project: {}", project_file); - let proj_json = common::read_file_string(&project_file)?; - let mut proj = AloeVeraProject::new_from_json(&proj_json)?; + let encoded = common::read_file_bin(&project_file)?; + let mut proj = *AloeVeraProject::from_bin(&encoded)?; proj.palettes.insert(palette.id.clone(), palette); common::output_to_file(&project_file, &proj.to_bin()?, &None)?; @@ -91,8 +91,8 @@ pub fn palette_list(g_args: &GlobalArgs) -> Result<(), Error> { 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)?; + let encoded = common::read_file_bin(&project_file)?; + let proj = *AloeVeraProject::from_bin(&encoded)?; println!("Palettes:"); for (id, palette) in proj.palettes { println!(" {}: {} colors", id, palette.len()); diff --git a/src/cmd/sprite/command.rs b/src/cmd/sprite/command.rs index ae12dc8..1d5b3f2 100644 --- a/src/cmd/sprite/command.rs +++ b/src/cmd/sprite/command.rs @@ -34,8 +34,8 @@ pub fn sprite_init(g_args: &GlobalArgs, args: &SpriteInitArgs) -> Result<(), Err } }; info!("Adding sprite into project: {}", project_file); - let proj_json = common::read_file_string(&project_file)?; - let mut proj = AloeVeraProject::new_from_json(&proj_json)?; + let encoded = common::read_file_bin(&project_file)?; + let mut proj = *AloeVeraProject::from_bin(&encoded)?; let imageset = match proj.imagesets.get(&args.imageset_id) { Some(i) => i, None => { diff --git a/util/Cargo.toml b/util/Cargo.toml index dc6ead4..1e32cc2 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -13,7 +13,6 @@ backtrace = "0.3" lazy_static = "1" serde = "1" serde_derive = "1" -serde_json = "1" log4rs = { version = "0.8.1", features = ["rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] } log = "0.4" walkdir = "2" From cc01221c37b24338a3fdf9bedf6ca7a001711f02 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Thu, 4 Jun 2020 14:13:38 +0100 Subject: [PATCH 3/8] add integration tests --- tests/cmd_line_basic.rs | 64 +++++++++++++++++++++++++++++ tests/common/mod.rs | 44 ++++++++++++++++++++ tests/data/input/imageset-4bpp.png | Bin 0 -> 773 bytes 3 files changed, 108 insertions(+) create mode 100644 tests/cmd_line_basic.rs create mode 100644 tests/common/mod.rs create mode 100644 tests/data/input/imageset-4bpp.png diff --git a/tests/cmd_line_basic.rs b/tests/cmd_line_basic.rs new file mode 100644 index 0000000..7911186 --- /dev/null +++ b/tests/cmd_line_basic.rs @@ -0,0 +1,64 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Test wallet command line works as expected +#[macro_use] +extern crate clap; + +#[macro_use] +extern crate log; + +use aloevera::Error; + +mod common; +use common::{clean_output_dir, execute_command, setup}; + +#[test] +fn command_line_basic() -> Result<(), Error> { + let test_dir = "target/test_output/command_line_basic"; + setup(test_dir); + let project_file = format!("{}/testproject.av", test_dir); + load_app!(app); + + // Create Project + let arg_vec = vec!["aloevera", "create", "project", &project_file]; + execute_command(&app, arg_vec)?; + + // Import palette + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "palette", + "import", + "tile_wall_pal", + "tests/data/input/imageset-4bpp.png", + ]; + execute_command(&app, arg_vec)?; + + // Output palette and check formats + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + "-f", + "bin", + "tests/data/input/imageset-4bpp.png", + ]; + execute_command(&app, arg_vec)?; + + clean_output_dir(test_dir); + Ok(()) +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 0000000..940f5aa --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,44 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Common functions for integration tests +use clap::App; +use std::fs; + +use aloevera::cmd; +use aloevera::Error; +use aloevera_util as util; + +pub fn clean_output_dir(test_dir: &str) { + let _ = fs::remove_dir_all(test_dir); +} + +pub fn setup(test_dir: &str) { + util::init_test_logger(); + clean_output_dir(test_dir); + let _ = fs::create_dir_all(test_dir); +} + +pub fn execute_command(app: &App, arg_vec: Vec<&str>) -> Result { + let args = app.clone().get_matches_from(arg_vec); + cmd::execute::execute_command(&args) +} + +#[macro_export] +macro_rules! load_app { + ($app: ident) => { + let yml = load_yaml!("../src/bin/aloevera.yml"); + let $app = clap::App::from_yaml(yml); + }; +} diff --git a/tests/data/input/imageset-4bpp.png b/tests/data/input/imageset-4bpp.png new file mode 100644 index 0000000000000000000000000000000000000000..9e7c37674db07179932aed6e6efd4bb7db5a2713 GIT binary patch literal 773 zcmV+g1N!`lP)Px#El^BUMF0Q*baZB(o{qg>Fv*~cdwHd1WSqN64Z?j{v$CN%IWl0QWHyjGAX+05 zLKW6rye$9#01tFhPE!E?|NsC0|NsC0|NsC0|K*LIrT_o}Ye_^wR9J=OnA>v0APhwD zC9NBS|NnDqaTN;+I4$l&HIqr!GH}L&v^Yv(OfKdni*%GX^ zDq#73fa@i{p9{R|12*3caJ~MuHbxhDTZSyJIvbJJn(F!d(!1Z>slIo*%<@iabC~je z0?6|{08e9#8)Lu1ZVv!-o#&l4$6?C*2>|jP0QS}p$ART`Kpr)}p8zml0F)2qG4lmc z3;kgB9;Q$?qXxkJ9X0oNrswHtL!nkJhAIH_chsW)TN70ZwQ4el(9 z0kEv7^9h!V0Ok08fQsJ_1K@reb;a*99RWfz11RtJ`XvDQd(bt%&-CQ_4$E830czuW z`#{z2v+#{4zZ3z)VL~5B_3d=s@0pIhpXXKRLn4#4~U z_yxH)hpJ(fJA8fa&zXPwdL0hH%8B`R`hQ?JK(>CxzwZMO?DIbW Date: Thu, 4 Jun 2020 15:28:16 +0100 Subject: [PATCH 4/8] finish adding testing framework, palette tests --- tests/cmd_line_basic.rs | 64 ----------------------- tests/common/mod.rs | 36 +++++++++++++ tests/palette.rs | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 64 deletions(-) delete mode 100644 tests/cmd_line_basic.rs create mode 100644 tests/palette.rs diff --git a/tests/cmd_line_basic.rs b/tests/cmd_line_basic.rs deleted file mode 100644 index 7911186..0000000 --- a/tests/cmd_line_basic.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2020 Revcore Technologies Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Test wallet command line works as expected -#[macro_use] -extern crate clap; - -#[macro_use] -extern crate log; - -use aloevera::Error; - -mod common; -use common::{clean_output_dir, execute_command, setup}; - -#[test] -fn command_line_basic() -> Result<(), Error> { - let test_dir = "target/test_output/command_line_basic"; - setup(test_dir); - let project_file = format!("{}/testproject.av", test_dir); - load_app!(app); - - // Create Project - let arg_vec = vec!["aloevera", "create", "project", &project_file]; - execute_command(&app, arg_vec)?; - - // Import palette - let arg_vec = vec![ - "aloevera", - "-p", - &project_file, - "palette", - "import", - "tile_wall_pal", - "tests/data/input/imageset-4bpp.png", - ]; - execute_command(&app, arg_vec)?; - - // Output palette and check formats - let arg_vec = vec![ - "aloevera", - "-p", - &project_file, - "asm", - "-f", - "bin", - "tests/data/input/imageset-4bpp.png", - ]; - execute_command(&app, arg_vec)?; - - clean_output_dir(test_dir); - Ok(()) -} diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 940f5aa..314b9a3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -42,3 +42,39 @@ macro_rules! load_app { let $app = clap::App::from_yaml(yml); }; } + +#[macro_export] +macro_rules! test_out { + ($test_dir: ident, $filename: expr) => { + &format!("{}/{}", $test_dir, $filename) + }; +} + +#[macro_export] +macro_rules! input_file { + ($filename: expr) => { + &format!( + "{}/tests/data/input/{}", + env!("CARGO_MANIFEST_DIR"), + $filename + ) + }; +} + +#[macro_export] +macro_rules! ref_file { + ($filename: expr) => { + &format!( + "{}/tests/data/output/{}", + env!("CARGO_MANIFEST_DIR"), + $filename + ) + }; +} + +pub fn compare_results(output_file: &str, reference_file: &str) -> Result<(), Error> { + let output = cmd::common::read_file_bin(output_file)?; + let reference = cmd::common::read_file_bin(reference_file)?; + assert_eq!(output, reference); + Ok(()) +} diff --git a/tests/palette.rs b/tests/palette.rs new file mode 100644 index 0000000..e7fcffd --- /dev/null +++ b/tests/palette.rs @@ -0,0 +1,112 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Test wallet command line works as expected +#[macro_use] +extern crate clap; + +use aloevera::Error; + +mod common; +use common::{clean_output_dir, compare_results, execute_command, setup}; + +#[test] +fn cmd_line_palette() -> Result<(), Error> { + let test_dir = format!( + "{}/{}", + env!("CARGO_MANIFEST_DIR"), + "target/test_output/cmd_line_palette" + ); + setup(&test_dir); + let project_file = format!("{}/testproject.av", test_dir); + load_app!(app); + + // Create Project + let arg_vec = vec!["aloevera", "create", "project", &project_file]; + execute_command(&app, arg_vec)?; + + // Import palette + let input_file = input_file!("imageset-4bpp.png"); + println!("Input file: {}", input_file); + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "palette", + "import", + "imageset-4bpp-pal", + input_file, + ]; + execute_command(&app, arg_vec)?; + + // Output palette and check formats + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.ca65", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.ca65"), + ref_file!("imageset-4bpp-pal.ca65"), + )?; + + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + "-f", + "bin", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.bin", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.bin"), + ref_file!("imageset-4bpp-pal.bin"), + )?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.bin.meta"), + ref_file!("imageset-4bpp-pal.bin.meta"), + )?; + + let arg_vec = vec![ + "aloevera", + "-p", + &project_file, + "asm", + "-f", + "cc65", + &test_dir, + "select", + "imageset-4bpp-pal", + "imageset-4bpp-pal.cc65", + ]; + execute_command(&app, arg_vec)?; + compare_results( + test_out!(test_dir, "imageset-4bpp-pal.cc65"), + ref_file!("imageset-4bpp-pal.cc65"), + )?; + + clean_output_dir(&test_dir); + Ok(()) +} From beefb51f8077330aa235c5c869867c128bc03f2c Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Thu, 4 Jun 2020 17:20:14 +0100 Subject: [PATCH 5/8] refactor list to separate command --- src/bin/aloevera.yml | 27 +++--- src/cmd/bitmap/command.rs | 14 --- src/cmd/bitmap/parse.rs | 1 - src/cmd/execute.rs | 3 +- src/cmd/imageset/command.rs | 26 ----- src/cmd/imageset/parse.rs | 1 - src/cmd/list/command.rs | 184 ++++++++++++++++++++++++++++++++++++ src/cmd/list/mod.rs | 16 ++++ src/cmd/list/parse.rs | 37 ++++++++ src/cmd/mod.rs | 1 + src/cmd/palette/command.rs | 19 ---- src/cmd/palette/parse.rs | 1 - src/cmd/sprite/command.rs | 16 ---- src/cmd/sprite/parse.rs | 1 - src/cmd/tilemap/command.rs | 18 ---- src/cmd/tilemap/parse.rs | 1 - vera/src/imageset.rs | 10 +- vera/src/tilemap.rs | 5 + 18 files changed, 266 insertions(+), 115 deletions(-) create mode 100644 src/cmd/list/command.rs create mode 100644 src/cmd/list/mod.rs create mode 100644 src/cmd/list/parse.rs diff --git a/src/bin/aloevera.yml b/src/bin/aloevera.yml index 9d30b58..3900a2b 100644 --- a/src/bin/aloevera.yml +++ b/src/bin/aloevera.yml @@ -1,5 +1,5 @@ name: aloevera -about: Graphic Asset Pipeline for the Commander X1 +about: Graphic Asset Pipeline for the Commander X16 author: Revcore Technologies Ltd. args: @@ -84,8 +84,6 @@ 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: @@ -116,8 +114,6 @@ 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: @@ -187,8 +183,6 @@ 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: @@ -201,8 +195,6 @@ 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: @@ -215,5 +207,18 @@ 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 + - list: + about: List elements in a project file + args: + - object_type: + help: Type of elements to view + possible_values: + - all + - palettes + - imagesets + - tilemaps + - sprites + - bitmaps + default_value: "all" + index: 1 + diff --git a/src/cmd/bitmap/command.rs b/src/cmd/bitmap/command.rs index 808c8d5..015e470 100644 --- a/src/cmd/bitmap/command.rs +++ b/src/cmd/bitmap/command.rs @@ -52,17 +52,3 @@ 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(()) -} diff --git a/src/cmd/bitmap/parse.rs b/src/cmd/bitmap/parse.rs index eee3bea..b151653 100644 --- a/src/cmd/bitmap/parse.rs +++ b/src/cmd/bitmap/parse.rs @@ -39,7 +39,6 @@ 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()); diff --git a/src/cmd/execute.rs b/src/cmd/execute.rs index de54341..514b62e 100644 --- a/src/cmd/execute.rs +++ b/src/cmd/execute.rs @@ -15,7 +15,7 @@ use clap::ArgMatches; use crate::cmd::common::{self, GlobalArgs}; -use crate::cmd::{asm, bitmap, create, imageset, palette, sprite, tilemap}; +use crate::cmd::{asm, bitmap, create, imageset, list, palette, sprite, tilemap}; use crate::{Error, ErrorKind}; fn parse_and_execute(g_args: &GlobalArgs, args: &ArgMatches) -> Result<(), Error> { @@ -27,6 +27,7 @@ fn parse_and_execute(g_args: &GlobalArgs, args: &ArgMatches) -> Result<(), Error ("bitmap", Some(args)) => bitmap::parse::execute_bitmap_command(g_args, &args), ("imageset", Some(args)) => imageset::parse::execute_imageset_command(g_args, &args), ("tilemap", Some(args)) => tilemap::parse::execute_tilemap_command(g_args, &args), + ("list", Some(args)) => list::parse::execute_list_command(g_args, &args), _ => { let msg = format!("Unknown command, use 'aloevera --help' for details"); return Err(ErrorKind::ArgumentError(msg).into()); diff --git a/src/cmd/imageset/command.rs b/src/cmd/imageset/command.rs index 192449b..2775750 100644 --- a/src/cmd/imageset/command.rs +++ b/src/cmd/imageset/command.rs @@ -79,29 +79,3 @@ 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(()) -} diff --git a/src/cmd/imageset/parse.rs b/src/cmd/imageset/parse.rs index 2867e3c..efef382 100644 --- a/src/cmd/imageset/parse.rs +++ b/src/cmd/imageset/parse.rs @@ -81,7 +81,6 @@ 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()); diff --git a/src/cmd/list/command.rs b/src/cmd/list/command.rs new file mode 100644 index 0000000..46852e7 --- /dev/null +++ b/src/cmd/list/command.rs @@ -0,0 +1,184 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use std::convert::TryFrom; + +use crate::{Error, ErrorKind}; +use proj::{AloeVeraProject, Binable}; + +use crate::cmd::common::{self, GlobalArgs}; + +/// Arguments for palette command +pub struct ListArgs { + pub object_type: ListObjectType, +} + +#[derive(Debug)] +/// Supported Elements to List +pub enum ListObjectType { + All, + Palettes, + Imagesets, + Tilemaps, + Sprites, + Bitmaps, +} + +impl TryFrom<&str> for ListObjectType { + type Error = Error; + fn try_from(input: &str) -> Result { + let res = match input { + "all" => ListObjectType::All, + "palettes" => ListObjectType::Palettes, + "imagesets" => ListObjectType::Imagesets, + "tilemaps" => ListObjectType::Tilemaps, + "sprites" => ListObjectType::Sprites, + "bitmaps" => ListObjectType::Bitmaps, + n => { + return Err(ErrorKind::ArgumentError(format!("Invalid object type: {}", n)).into()) + } + }; + Ok(res) + } +} + +/// Project file list command +pub fn list(g_args: &GlobalArgs, args: &ListArgs) -> 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 encoded = common::read_file_bin(&project_file)?; + let proj = *AloeVeraProject::from_bin(&encoded)?; + println!("Elements in {}", project_file); + println!("--------------"); + + match args.object_type { + ListObjectType::All => { + list_palettes(&proj)?; + list_imagesets(&proj)?; + list_tilemaps(&proj)?; + list_sprites(&proj)?; + list_bitmaps(&proj)?; + } + ListObjectType::Palettes => { + list_palettes(&proj)?; + } + ListObjectType::Imagesets => { + list_imagesets(&proj)?; + } + ListObjectType::Tilemaps => { + list_tilemaps(&proj)?; + } + ListObjectType::Sprites => { + list_sprites(&proj)?; + } + ListObjectType::Bitmaps => { + list_bitmaps(&proj)?; + } + } + Ok(()) +} + +/// Palette list +fn list_palettes(proj: &AloeVeraProject) -> Result<(), Error> { + println!("Palettes:"); + for (id, palette) in proj.palettes.iter() { + println!(" {}:", id); + println!(" Color Count: {}", palette.len()); + } + Ok(()) +} + +/// Imageset list +pub fn list_imagesets(proj: &AloeVeraProject) -> Result<(), Error> { + println!("Imagesets:"); + for (id, imageset) in proj.imagesets.iter() { + let depth = match imageset.depth { + Some(d) => format!("{}", d), + None => "Unformatted".to_owned(), + }; + println!(" {}:", id); + println!(" Frame Count: {}", imageset.frame_data.len()); + println!( + " Frame Size: {}w x {}h", + imageset.frame_width, imageset.frame_height, + ); + println!(" Pixel Depth: {}", depth,); + } + Ok(()) +} + +/// Tilemap list +pub fn list_tilemaps(proj: &AloeVeraProject) -> Result<(), Error> { + println!("Tilemaps:"); + for (id, tilemap) in proj.tilemaps.iter() { + println!(" {}:", id); + println!(" Using Imageset: {}", tilemap.imageset_id,); + println!( + " Map Size: {}x{} Tiles", + tilemap.map_width(), + tilemap.map_height(), + ); + println!( + " Tile Size: {}w x{}h", + tilemap.tile_width(), + tilemap.tile_height(), + ); + println!(" Mode: {}", tilemap.mode,); + } + Ok(()) +} + +/// Sprite list +pub fn list_sprites(proj: &AloeVeraProject) -> Result<(), Error> { + println!("Sprites:"); + for (id, sprite) in proj.sprites.iter() { + let imageset = match proj.imagesets.get(&sprite.imageset_id) { + Some(i) => i, + None => { + let msg = format!( + "Imageset with id {} needed by sprite {} does not exist in project file.", + sprite.id, sprite.imageset_id + ); + return Err(ErrorKind::ArgumentError(msg).into()); + } + }; + println!(" {}:", id); + println!(" Using Imageset: {}", sprite.imageset_id,); + println!(" Frame Count: {}", imageset.frame_data.len(),); + println!( + " Frame Size: {}w x {}h", + sprite.frame_width.val_as_u32(), + sprite.frame_height.val_as_u32(), + ); + println!(" Pixel Depth: {}", sprite.depth,); + } + Ok(()) +} + +/// Bitmap list +pub fn list_bitmaps(proj: &AloeVeraProject) -> Result<(), Error> { + println!("Bitmaps:"); + for (id, bitmap) in proj.bitmaps.iter() { + println!(" {}:", id); + println!(" Using Imageset: {}", bitmap.imageset_id,); + println!(" Width: {}", bitmap.width.val_as_u32(),); + println!(" Pixel Depth: {}", bitmap.depth,); + } + Ok(()) +} diff --git a/src/cmd/list/mod.rs b/src/cmd/list/mod.rs new file mode 100644 index 0000000..be20e29 --- /dev/null +++ b/src/cmd/list/mod.rs @@ -0,0 +1,16 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod command; +pub mod parse; diff --git a/src/cmd/list/parse.rs b/src/cmd/list/parse.rs new file mode 100644 index 0000000..4e179f4 --- /dev/null +++ b/src/cmd/list/parse.rs @@ -0,0 +1,37 @@ +// Copyright 2020 Revcore Technologies Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +use std::convert::TryFrom; + +use clap::ArgMatches; + +use super::command::{self, ListArgs, ListObjectType}; +use crate::cmd::common::GlobalArgs; +use crate::{Error, ErrorKind}; + +pub fn parse_list_args(g_args: &GlobalArgs, args: &ArgMatches) -> Result { + if g_args.project_file.is_none() { + let msg = format!("--project_file is required in this context"); + return Err(ErrorKind::ArgumentError(msg).into()); + } + let object_type = match args.value_of("object_type") { + Some(v) => ListObjectType::try_from(v)?, + None => ListObjectType::All, + }; + Ok(ListArgs { object_type }) +} + +pub fn execute_list_command(g_args: &GlobalArgs, args: &ArgMatches) -> Result<(), Error> { + let a = arg_parse!(parse_list_args(g_args, args)); + command::list(g_args, &a) +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index e78ac4c..9e534ea 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -18,6 +18,7 @@ pub mod asm; pub mod bitmap; pub mod create; pub mod imageset; +pub mod list; pub mod palette; pub mod sprite; pub mod tilemap; diff --git a/src/cmd/palette/command.rs b/src/cmd/palette/command.rs index ae690ac..70867e2 100644 --- a/src/cmd/palette/command.rs +++ b/src/cmd/palette/command.rs @@ -81,22 +81,3 @@ 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 encoded = common::read_file_bin(&project_file)?; - let proj = *AloeVeraProject::from_bin(&encoded)?; - println!("Palettes:"); - for (id, palette) in proj.palettes { - println!(" {}: {} colors", id, palette.len()); - } - - Ok(()) -} diff --git a/src/cmd/palette/parse.rs b/src/cmd/palette/parse.rs index 7d305cc..c183305 100644 --- a/src/cmd/palette/parse.rs +++ b/src/cmd/palette/parse.rs @@ -39,7 +39,6 @@ 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()); diff --git a/src/cmd/sprite/command.rs b/src/cmd/sprite/command.rs index 1d5b3f2..3ac1b82 100644 --- a/src/cmd/sprite/command.rs +++ b/src/cmd/sprite/command.rs @@ -52,19 +52,3 @@ 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(()) -} diff --git a/src/cmd/sprite/parse.rs b/src/cmd/sprite/parse.rs index 208daec..b8d0b86 100644 --- a/src/cmd/sprite/parse.rs +++ b/src/cmd/sprite/parse.rs @@ -39,7 +39,6 @@ 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()); diff --git a/src/cmd/tilemap/command.rs b/src/cmd/tilemap/command.rs index 6f8814e..2a3b963 100644 --- a/src/cmd/tilemap/command.rs +++ b/src/cmd/tilemap/command.rs @@ -101,21 +101,3 @@ 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(()) -} diff --git a/src/cmd/tilemap/parse.rs b/src/cmd/tilemap/parse.rs index 1e3178b..a0ce932 100644 --- a/src/cmd/tilemap/parse.rs +++ b/src/cmd/tilemap/parse.rs @@ -87,7 +87,6 @@ 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()); diff --git a/vera/src/imageset.rs b/vera/src/imageset.rs index dfd283f..b7c07e5 100644 --- a/vera/src/imageset.rs +++ b/vera/src/imageset.rs @@ -47,12 +47,12 @@ pub enum VeraPixelDepth { impl fmt::Display for VeraPixelDepth { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let out = match self { - VeraPixelDepth::BPP1 => "1", - VeraPixelDepth::BPP2 => "2", - VeraPixelDepth::BPP4 => "4", - VeraPixelDepth::BPP8 => "8", + VeraPixelDepth::BPP1 => "1bpp", + VeraPixelDepth::BPP2 => "2bpp", + VeraPixelDepth::BPP4 => "4bpp", + VeraPixelDepth::BPP8 => "8bpp", }; - writeln!(f, "{}", out) + write!(f, "{}", out) } } diff --git a/vera/src/tilemap.rs b/vera/src/tilemap.rs index b150749..447a240 100644 --- a/vera/src/tilemap.rs +++ b/vera/src/tilemap.rs @@ -219,9 +219,13 @@ impl VeraTileDim { pub struct VeraTileMap { /// id pub id: String, + /// map mode pub mode: VeraTileMapMode, + /// Keep track of imageset we're formatted to + pub imageset_id: String, + /// map width map_width: VeraTileMapDim, @@ -308,6 +312,7 @@ impl VeraTileMap { pane_start_y: 0, tiles: vec![], imageset_entries: BTreeMap::new(), + imageset_id: imageset.id.clone(), }; // Tile Indices init here for (i, f) in imageset.frame_data.iter().enumerate() { From cea1479165bf032e5456e51d73231e09a4bc0c90 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Fri, 5 Jun 2020 15:38:15 +0100 Subject: [PATCH 6/8] change name of reference data dir --- tests/data/ref/imageset-4bpp-pal.bin | Bin 0 -> 32 bytes tests/data/ref/imageset-4bpp-pal.bin.meta | 1 + tests/data/ref/imageset-4bpp-pal.ca65 | 5 +++++ tests/data/ref/imageset-4bpp-pal.cc65 | 12 ++++++++++++ 4 files changed, 18 insertions(+) create mode 100644 tests/data/ref/imageset-4bpp-pal.bin create mode 100644 tests/data/ref/imageset-4bpp-pal.bin.meta create mode 100644 tests/data/ref/imageset-4bpp-pal.ca65 create mode 100644 tests/data/ref/imageset-4bpp-pal.cc65 diff --git a/tests/data/ref/imageset-4bpp-pal.bin b/tests/data/ref/imageset-4bpp-pal.bin new file mode 100644 index 0000000000000000000000000000000000000000..bb9c5009d1dbcd02b11c25ff6d1805469f31fa47 GIT binary patch literal 32 ncmZQzU|=X?pTU{Ty@IETJ(JCWyOd`aw=wfFw#m#vOpc5IYdHqc literal 0 HcmV?d00001 diff --git a/tests/data/ref/imageset-4bpp-pal.bin.meta b/tests/data/ref/imageset-4bpp-pal.bin.meta new file mode 100644 index 0000000..4840019 --- /dev/null +++ b/tests/data/ref/imageset-4bpp-pal.bin.meta @@ -0,0 +1 @@ +;imageset-4bpp-pal - size is 30 diff --git a/tests/data/ref/imageset-4bpp-pal.ca65 b/tests/data/ref/imageset-4bpp-pal.ca65 new file mode 100644 index 0000000..304d067 --- /dev/null +++ b/tests/data/ref/imageset-4bpp-pal.ca65 @@ -0,0 +1,5 @@ +;imageset-4bpp-pal - size is 30 +.byte $00,$00,$76,$07,$98,$09,$63,$0B +.byte $A8,$0C,$7A,$07,$69,$06,$40,$0B +.byte $75,$0C,$BA,$0B,$33,$03,$A6,$06 +.byte $93,$03,$52,$02,$41,$01 diff --git a/tests/data/ref/imageset-4bpp-pal.cc65 b/tests/data/ref/imageset-4bpp-pal.cc65 new file mode 100644 index 0000000..928394c --- /dev/null +++ b/tests/data/ref/imageset-4bpp-pal.cc65 @@ -0,0 +1,12 @@ +/** + * imageset-4bpp-pal - size is 30 + */ +#ifndef IMAGESET-4BPP-PAL_H +#define IMAGESET-4BPP-PAL_H +static const unsigned char IMAGESET-4BPP-PAL[] = { + 0x00,0x00,0x76,0x07,0x98,0x09,0x63,0x0b, + 0xa8,0x0c,0x7a,0x07,0x69,0x06,0x40,0x0b, + 0x75,0x0c,0xba,0x0b,0x33,0x03,0xa6,0x06, + 0x93,0x03,0x52,0x02,0x41,0x01 +}; +#endif From 33086cfc6838ac54bd21f4bfa5a30118925e0a15 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Fri, 5 Jun 2020 16:09:38 +0100 Subject: [PATCH 7/8] Change name of reference data dir --- tests/common/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 314b9a3..e7b9afa 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -65,7 +65,7 @@ macro_rules! input_file { macro_rules! ref_file { ($filename: expr) => { &format!( - "{}/tests/data/output/{}", + "{}/tests/data/ref/{}", env!("CARGO_MANIFEST_DIR"), $filename ) From 2c46fa14c461c3a25c72d45c065d81216f851a7d Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Fri, 5 Jun 2020 16:30:50 +0100 Subject: [PATCH 8/8] don't execute byte-for-byte result testing on windows --- tests/common/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index e7b9afa..c4cbab3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -73,6 +73,11 @@ macro_rules! ref_file { } pub fn compare_results(output_file: &str, reference_file: &str) -> Result<(), Error> { + // reference files were generated on linux, so text files generated on windows + // will have carriage returns \r + if cfg!(windows) { + return Ok(()); + } let output = cmd::common::read_file_bin(output_file)?; let reference = cmd::common::read_file_bin(reference_file)?; assert_eq!(output, reference);