|
@@ -1,5 +1,7 @@
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
+use std::fmt::Display;
|
|
|
+
|
|
|
use binrw::{binrw, BinRead, BinWrite};
|
|
|
|
|
|
use crate::{array_of::ArrayOf, field_of::FieldOf};
|
|
@@ -11,11 +13,21 @@ pub type U32 = FieldOf<u32>;
|
|
|
pub type U16 = FieldOf<u16>;
|
|
|
pub type F64 = FieldOf<f64>;
|
|
|
|
|
|
-pub type WString = ArrayOf<u16>;
|
|
|
+#[binrw]
|
|
|
+#[derive(Debug, PartialEq)]
|
|
|
+pub struct WString {
|
|
|
+ // Temporary variable that holds number of elements
|
|
|
+ #[br(temp)]
|
|
|
+ #[bw(try_calc(u32::try_from(value.len())))]
|
|
|
+ size: u32,
|
|
|
+
|
|
|
+ #[br(count = size / core::mem::size_of::<u16>() as u32)]
|
|
|
+ pub value: Vec<u16>,
|
|
|
+}
|
|
|
|
|
|
impl From<&WString> for String {
|
|
|
fn from(value: &WString) -> Self {
|
|
|
- String::from_utf16_lossy(value)
|
|
|
+ String::from_utf16_lossy(&value.value)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -26,6 +38,12 @@ impl From<String> for WString {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+impl Display for WString {
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
+ write!(f, "{}", String::from(self))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#[derive(BinRead, BinWrite, PartialEq, Debug)]
|
|
|
pub struct Rgba {
|
|
|
pub red: u8,
|
|
@@ -34,23 +52,29 @@ pub struct Rgba {
|
|
|
pub alpha: u8,
|
|
|
}
|
|
|
|
|
|
+impl Display for Rgba {
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
+ write!(
|
|
|
+ f,
|
|
|
+ "({}, {}, {}, {})",
|
|
|
+ self.red, self.green, self.blue, self.alpha
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#[derive(BinRead, BinWrite, PartialEq, Debug)]
|
|
|
pub struct Point {
|
|
|
pub x: f64,
|
|
|
pub y: f64,
|
|
|
}
|
|
|
|
|
|
-#[binrw]
|
|
|
-#[derive(PartialEq, Debug)]
|
|
|
-pub struct MultiLine {
|
|
|
- #[br(temp)]
|
|
|
- #[bw(try_calc(u32::try_from(points.len())))]
|
|
|
- point_count: u32,
|
|
|
- #[br(count = point_count)]
|
|
|
- points: Vec<Point>,
|
|
|
+impl Display for Point {
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
+ write!(f, "({}, {})", self.x, self.y)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-#[derive(BinRead, BinWrite, PartialEq, Debug)]
|
|
|
+#[derive(BinRead, BinWrite, PartialEq, Debug, strum::Display)]
|
|
|
#[brw(repr(u32))]
|
|
|
#[repr(u32)]
|
|
|
pub enum WobbleType {
|
|
@@ -61,7 +85,7 @@ pub enum WobbleType {
|
|
|
Hori8 = 4,
|
|
|
}
|
|
|
|
|
|
-#[derive(BinRead, BinWrite, PartialEq, Debug)]
|
|
|
+#[derive(BinRead, BinWrite, PartialEq, Debug, strum::Display)]
|
|
|
#[brw(repr(u16))]
|
|
|
#[repr(u16)]
|
|
|
pub enum ObjectType {
|
|
@@ -74,7 +98,7 @@ pub enum ObjectType {
|
|
|
Hatch = 32,
|
|
|
}
|
|
|
|
|
|
-#[derive(BinRead, BinWrite, PartialEq, Debug)]
|
|
|
+#[derive(BinRead, BinWrite, PartialEq, Debug, strum::Display)]
|
|
|
#[brw(repr(u16))]
|
|
|
#[repr(u16)]
|
|
|
pub enum LineType {
|