remove alpha channel

This commit is contained in:
Max Bradbury 2021-05-15 22:38:43 +01:00
parent 6a0251dc0c
commit ea136148f9
3 changed files with 15 additions and 11 deletions

View File

@ -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~

View File

@ -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<u8> {
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);
}
}

View File

@ -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 },
],
}
}