From c6b1c4b8246395177c88076cd1583591c0a1d2c2 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 17:45:21 +0100 Subject: [PATCH] Refactor to use a builder pattern --- agb-image-converter/Cargo.lock | 47 ++++++++++++++++++++++++++++++++++ agb-image-converter/Cargo.toml | 3 ++- agb-image-converter/src/lib.rs | 14 ++++++---- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/agb-image-converter/Cargo.lock b/agb-image-converter/Cargo.lock index e81e9ed8..da9674ef 100644 --- a/agb-image-converter/Cargo.lock +++ b/agb-image-converter/Cargo.lock @@ -19,6 +19,7 @@ name = "agb_image_converter" version = "0.1.0" dependencies = [ "image", + "typed-builder", ] [[package]] @@ -277,6 +278,24 @@ dependencies = [ "miniz_oxide 0.3.7", ] +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rayon" version = "1.5.0" @@ -314,6 +333,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "syn" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "tiff" version = "0.6.1" @@ -325,6 +355,23 @@ dependencies = [ "weezl", ] +[[package]] +name = "typed-builder" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345426c7406aa355b60c5007c79a2d1f5b605540072795222f17f6443e6a9c6f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + [[package]] name = "weezl" version = "0.1.5" diff --git a/agb-image-converter/Cargo.toml b/agb-image-converter/Cargo.toml index 6adc08c5..192f0129 100644 --- a/agb-image-converter/Cargo.toml +++ b/agb-image-converter/Cargo.toml @@ -7,4 +7,5 @@ license = "MPL-2.0" description = "Library for converting graphics for use on the Game Boy Advance" [dependencies] -image = "0.23.14" \ No newline at end of file +image = "0.23.14" +typed-builder = "0.9.0" \ No newline at end of file diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 2d8b3450..3cc0d6c5 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -2,6 +2,8 @@ use std::fs::File; use std::io::BufWriter; use std::path::PathBuf; +use typed_builder::TypedBuilder; + mod colour; mod image_loader; mod palette16; @@ -26,14 +28,16 @@ impl TileSize { } } +#[derive(TypedBuilder)] pub struct ImageConverterConfig { - pub transparent_colour: Option, - pub tile_size: TileSize, - pub input_image: PathBuf, - pub output_file: PathBuf, + #[builder(default, setter(strip_option))] + transparent_colour: Option, + tile_size: TileSize, + input_image: PathBuf, + output_file: PathBuf, } -pub fn convert_image(settings: &ImageConverterConfig) { +pub fn convert_image(settings: ImageConverterConfig) { let image = Image::load_from_file(&settings.input_image); let tile_size = settings.tile_size.to_size();