diff --git a/src/vpx/color.rs b/src/vpx/color.rs index a4550fe..23972f0 100644 --- a/src/vpx/color.rs +++ b/src/vpx/color.rs @@ -11,6 +11,11 @@ pub struct ColorNoAlpha { b: u8, } +impl ColorNoAlpha { + pub const RED: ColorNoAlpha = ColorNoAlpha { r: 255, g: 0, b: 0 }; + pub const BLACK: ColorNoAlpha = ColorNoAlpha { r: 0, g: 0, b: 0 }; +} + /// Serialize as a string in the format "#RRGGBB". impl Serialize for ColorNoAlpha { fn serialize(&self, serializer: S) -> Result diff --git a/src/vpx/gamedata.rs b/src/vpx/gamedata.rs index 6801854..35a7ee8 100644 --- a/src/vpx/gamedata.rs +++ b/src/vpx/gamedata.rs @@ -6,7 +6,7 @@ use super::{ version::Version, }; use crate::vpx::biff::{BiffRead, BiffWrite}; -use crate::vpx::color::{Color, ColorJson, ColorNoAlpha}; +use crate::vpx::color::ColorNoAlpha; use crate::vpx::json::F32WithNanInf; use crate::vpx::material::{Material, SaveMaterial, SavePhysicsMaterial}; use crate::vpx::math::{dequantize_u8, quantize_u8}; @@ -221,7 +221,7 @@ pub struct GameData { pub fonts_size: u32, // SFNT 110 pub collections_size: u32, // SCOL 111 pub name: String, // NAME 112 - pub custom_colors: [Color; 16], //[Color; 16], // CCUS 113 + pub custom_colors: [ColorNoAlpha; 16], //[Color; 16], // CCUS 113 pub protection_data: Option>, // SECB (removed in ?) pub code: StringWithEncoding, // CODE 114 /// TLCK (added in 10.8 for tournament mode?) @@ -375,7 +375,7 @@ pub(crate) struct GameDataJson { pub tone_mapper: Option, pub bloom_strength: f32, pub name: String, - pub custom_colors: [ColorJson; 16], + pub custom_colors: [ColorNoAlpha; 16], pub protection_data: Option>, //pub code: StringWithEncoding, pub locked: Option, @@ -385,14 +385,6 @@ pub(crate) struct GameDataJson { impl GameDataJson { pub fn to_game_data(&self) -> GameData { - let custom_colors: [Color; 16] = self - .custom_colors - .iter() - .map(|c| c.to_color()) - .collect::>() - .try_into() - .unwrap(); - GameData { left: self.left, top: self.top, @@ -559,7 +551,7 @@ impl GameDataJson { // this data is loaded from a separate file collections_size: 0, name: self.name.clone(), - custom_colors, + custom_colors: self.custom_colors.clone(), protection_data: self.protection_data.clone(), code: StringWithEncoding::empty(), locked: self.locked, @@ -568,8 +560,6 @@ impl GameDataJson { } pub fn from_game_data(game_data: &GameData) -> GameDataJson { - let custom_colors: [ColorJson; 16] = - game_data.custom_colors.map(|c| ColorJson::from_color(&c)); GameDataJson { left: game_data.left, top: game_data.top, @@ -722,7 +712,7 @@ impl GameDataJson { tone_mapper: game_data.tone_mapper, bloom_strength: game_data.bloom_strength, name: game_data.name.clone(), - custom_colors, + custom_colors: game_data.custom_colors.clone(), protection_data: game_data.protection_data.clone(), // code: game_data.code.clone(), locked: game_data.locked, @@ -871,7 +861,7 @@ impl Default for GameData { fonts_size: 0, collections_size: 0, name: "Table1".to_string(), // seems to be the default name - custom_colors: [Color::BLACK; 16], + custom_colors: [ColorNoAlpha::BLACK; 16], protection_data: None, code: StringWithEncoding::empty(), bg_view_horizontal_offset_desktop: None, @@ -1477,19 +1467,19 @@ pub fn read_all_gamedata_records(input: &[u8], version: &Version) -> GameData { gamedata } -fn read_colors(data: Vec) -> [Color; 16] { +fn read_colors(data: Vec) -> [ColorNoAlpha; 16] { // COLORREF: 0x00BBGGRR // sizeof(COLORREF) * 16 let mut colors = Vec::new(); let mut buff = BytesMut::from(data.as_slice()); for _ in 0..16 { - let color = Color::new_bgr(buff.get_u32_le()); + let color = ColorNoAlpha::new_bgr(buff.get_u32_le()); colors.push(color); } - <[Color; 16]>::try_from(colors).unwrap() + <[ColorNoAlpha; 16]>::try_from(colors).unwrap() } -fn write_colors(colors: &[Color; 16]) -> Vec { +fn write_colors(colors: &[ColorNoAlpha; 16]) -> Vec { let mut bytes = BytesMut::new(); for color in colors { bytes.put_u32_le(color.bgr()); @@ -1637,7 +1627,7 @@ mod tests { materials: None, render_probes: Some(vec![Faker.fake(), Faker.fake()]), name: String::from("test name"), - custom_colors: [Color::RED; 16], + custom_colors: [ColorNoAlpha::RED; 16], protection_data: None, code: StringWithEncoding::from("test code wit some unicode: Ǣ"), bg_view_horizontal_offset_desktop: None,