From ea136148f9a8588624341e9a2c30ef7e6c46ee45 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 15 May 2021 22:38:43 +0100 Subject: [PATCH] remove alpha channel --- TODO.md | 6 ++++++ src/colour.rs | 12 +++++------- src/mock.rs | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 77f1d56..b35ce0d 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,12 @@ ## game data structure +### colours + +convert colours to hex +* accept abcdef, #abcdef, 0xabcdef (inc. uppercase) +* export as #abcdef + ### parser * ~move tests into their respective modules where appropriate~ diff --git a/src/colour.rs b/src/colour.rs index 0e9f258..4d6d1a0 100644 --- a/src/colour.rs +++ b/src/colour.rs @@ -5,7 +5,6 @@ pub struct Colour { pub red: u8, pub green: u8, pub blue: u8, - pub alpha: u8, } impl Colour { @@ -15,12 +14,11 @@ impl Colour { red: *colours.get(0).unwrap_or(&ZERO), green: *colours.get(1).unwrap_or(&ZERO), blue: *colours.get(2).unwrap_or(&ZERO), - alpha: *colours.get(3).unwrap_or(&255), } } pub fn to_vec(&self) -> Vec { - vec![self.red, self.green, self.blue, self.alpha] + vec![self.red, self.green, self.blue] } } @@ -30,15 +28,15 @@ mod test { #[test] fn test_colour_from_intermediate() { - let output = Colour::from(vec![64, 128, 192, 255]); - let expected = Colour { red: 64, green: 128, blue: 192, alpha: 255 }; + let output = Colour::from(vec![64, 128, 192]); + let expected = Colour { red: 64, green: 128, blue: 192 }; assert_eq!(output, expected); } #[test] fn test_colour_to_intermediate() { - let output = Colour { red: 64, green: 128, blue: 192, alpha: 255 }.to_vec(); - let expected = vec![64, 128, 192, 255]; + let output = Colour { red: 64, green: 128, blue: 192 }.to_vec(); + let expected = vec![64, 128, 192]; assert_eq!(output, expected); } } diff --git a/src/mock.rs b/src/mock.rs index d5ad745..368e928 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -84,10 +84,10 @@ pub(crate) mod palette { Palette { name: "blueprint".to_string(), colours: vec![ - Colour { red: 0, green: 0, blue: 0, alpha: 0 }, - Colour { red: 0, green: 81, blue: 104, alpha: 255 }, - Colour { red: 118, green: 159, blue: 155, alpha: 255 }, - Colour { red: 155, green: 155, blue: 155, alpha: 255 }, + Colour { red: 0, green: 0, blue: 0 }, + Colour { red: 0, green: 81, blue: 104 }, + Colour { red: 118, green: 159, blue: 155 }, + Colour { red: 155, green: 155, blue: 155 }, ], } }