rakata_formats/lyt/
mod.rs1mod reader;
25mod writer;
26
27pub use reader::{read_lyt, read_lyt_from_bytes};
28pub use writer::{write_lyt, write_lyt_to_vec};
29
30use thiserror::Error;
31
32use rakata_core::{DecodeTextError, EncodeTextError};
33
34use crate::binary::{DecodeBinary, EncodeBinary};
35
36#[derive(Debug, Clone, PartialEq, Default)]
38pub struct Lyt {
39 pub rooms: Vec<LytRoom>,
41 pub tracks: Vec<LytTrack>,
43 pub obstacles: Vec<LytObstacle>,
45 pub doorhooks: Vec<LytDoorHook>,
47}
48
49impl Lyt {
50 pub fn new() -> Self {
52 Self::default()
53 }
54}
55
56impl DecodeBinary for Lyt {
57 type Error = LytError;
58
59 fn decode_binary(bytes: &[u8]) -> Result<Self, Self::Error> {
60 read_lyt_from_bytes(bytes)
61 }
62}
63
64impl EncodeBinary for Lyt {
65 type Error = LytError;
66
67 fn encode_binary(&self) -> Result<Vec<u8>, Self::Error> {
68 write_lyt_to_vec(self)
69 }
70}
71
72#[derive(Debug, Clone, PartialEq)]
74pub struct LytRoom {
75 pub model: String,
77 pub position: Vec3,
79}
80
81#[derive(Debug, Clone, PartialEq)]
83pub struct LytTrack {
84 pub model: String,
86 pub position: Vec3,
88}
89
90#[derive(Debug, Clone, PartialEq)]
92pub struct LytObstacle {
93 pub model: String,
95 pub position: Vec3,
97}
98
99#[derive(Debug, Clone, PartialEq)]
101pub struct LytDoorHook {
102 pub room: String,
104 pub door: String,
106 pub position: Vec3,
108 pub orientation: Quaternion,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq)]
114pub struct Vec3 {
115 pub x: f32,
117 pub y: f32,
119 pub z: f32,
121}
122
123impl Vec3 {
124 pub const fn new(x: f32, y: f32, z: f32) -> Self {
126 Self { x, y, z }
127 }
128}
129
130#[derive(Debug, Clone, Copy, PartialEq)]
132pub struct Quaternion {
133 pub x: f32,
135 pub y: f32,
137 pub z: f32,
139 pub w: f32,
141}
142
143impl Quaternion {
144 pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
146 Self { x, y, z, w }
147 }
148}
149
150#[derive(Debug, Error)]
152pub enum LytError {
153 #[error(transparent)]
155 Io(#[from] std::io::Error),
156 #[error("invalid LYT data: {0}")]
158 InvalidData(String),
159 #[error("LYT text encoding failed for {context}: {source}")]
161 TextEncoding {
162 context: String,
164 #[source]
166 source: EncodeTextError,
167 },
168 #[error("LYT text decoding failed for {context}: {source}")]
170 TextDecoding {
171 context: String,
173 #[source]
175 source: DecodeTextError,
176 },
177 #[error("invalid LYT {field} token `{value}` (whitespace is not allowed)")]
179 InvalidName {
180 field: &'static str,
182 value: String,
184 },
185}