assembly_maps/lvl/
file.rs

1//! # General structs and data
2use assembly_core::{
3    ldf::{LDFError, LDF},
4    types::{ObjectID, ObjectTemplate, Quaternion, Vector3f},
5};
6
7#[cfg(feature = "serde-derives")]
8use serde::Serialize;
9
10#[derive(Debug)]
11#[cfg_attr(feature = "serde-derives", derive(Serialize))]
12pub struct Level {
13    pub env: Option<Environment>,
14    pub objects: Vec<Object<LDF>>,
15}
16
17#[derive(Debug)]
18#[cfg_attr(feature = "serde-derives", derive(Serialize))]
19pub struct Environment {
20    pub sec1: Section1,
21    pub sky: SkySection,
22}
23
24/// The version of a chunk
25#[derive(Debug, Copy, Clone)]
26pub struct ChunkVersion {
27    /// The version of the chunk header format
28    pub header: u16,
29    /// The version of the chunk data format
30    pub data: u16,
31}
32
33/// The header for a single chunk
34#[derive(Debug)]
35pub struct ChunkHeader {
36    /// The ID of this chunk
37    pub id: u32,
38    /// The version of this chunk
39    pub version: ChunkVersion,
40    /// The chunk size
41    pub size: u32,
42    /// The chunk data offset
43    pub offset: u32,
44}
45
46/// A chunk (header + data)
47#[derive(Debug)]
48pub struct Chunk<T> {
49    /// The chunk header
50    pub header: ChunkHeader,
51    /// The chunk data
52    pub data: T,
53}
54
55/// The chunk containing the offsets of the other chunks
56#[derive(Debug)]
57pub struct FileMetaChunkData {
58    /// The version of this file
59    pub version: u32,
60    /// The revision of this file
61    pub revision: u32,
62    /// The pointer to the chunk #2000
63    pub chunk_2000_offset: u32,
64    /// The pointer to the chunk #2001
65    pub chunk_2001_offset: u32,
66    /// The pointer to the chunk #2002
67    pub chunk_2002_offset: u32,
68}
69
70/// The file meta chunk
71pub type FileMetaChunk = Chunk<FileMetaChunkData>;
72
73#[derive(Debug)]
74pub struct Chunk2000Data {}
75
76#[derive(Debug)]
77#[cfg_attr(feature = "serde-derives", derive(Serialize))]
78pub struct ObjectExtra {
79    pub field_1a: [u8; 32],
80    pub field_1b: [u8; 32],
81    pub field_2: u32,
82    pub field_3: bool,
83    pub field_4: [u32; 16],
84    pub field_5: [u8; 3],
85}
86
87#[derive(Debug)]
88#[cfg_attr(feature = "serde-derives", derive(Serialize))]
89pub struct Object<S> {
90    pub obj_id: ObjectID,
91    pub lot: ObjectTemplate,
92    pub asset_type: Option<u32>,
93    pub value_1: Option<u32>,
94    pub position: Vector3f,
95    pub rotation: Quaternion,
96    pub scale: f32,
97    pub settings: S,
98    pub extra: Vec<ObjectExtra>,
99}
100
101impl Object<String> {
102    pub fn parse_settings(self) -> Result<Object<LDF>, LDFError> {
103        let settings = self.settings.parse()?;
104        Ok(Object {
105            obj_id: self.obj_id,
106            lot: self.lot,
107            asset_type: self.asset_type,
108            value_1: self.value_1,
109            position: self.position,
110            rotation: self.rotation,
111            scale: self.scale,
112            settings,
113            extra: self.extra,
114        })
115    }
116}
117
118#[derive(Debug)]
119pub struct ObjectsChunkData<S> {
120    pub objects: Vec<Object<S>>,
121}
122
123impl ObjectsChunkData<String> {
124    pub fn parse_settings(mut self) -> Result<ObjectsChunkData<LDF>, LDFError> {
125        let objects = self
126            .objects
127            .drain(..)
128            .map(Object::parse_settings)
129            .collect::<Result<Vec<_>, _>>()?;
130        Ok(ObjectsChunkData { objects })
131    }
132}
133
134#[derive(Debug)]
135pub struct EnvironmentChunkData {
136    pub section1_address: u32,
137    pub sky_address: u32,
138    pub section3_address: u32,
139}
140
141#[derive(Debug)]
142#[cfg_attr(feature = "serde-derives", derive(Serialize))]
143pub struct Color {
144    pub red: f32,
145    pub green: f32,
146    pub blue: f32,
147}
148
149#[derive(Debug)]
150#[cfg_attr(feature = "serde-derives", derive(Serialize))]
151pub struct Section1 {
152    pub value1: Option<f32>,
153    pub value2: Color,
154    pub value3: Color,
155    pub value4: Color,
156    pub value5: Vector3f,
157    pub value6: Option<Section1_31>,
158    pub value7: Option<Color>,
159    pub value8: Option<Section1_43>,
160}
161
162#[derive(Debug)]
163#[cfg_attr(feature = "serde-derives", derive(Serialize))]
164pub struct Section1_31 {
165    pub value1: Section1_39,
166    pub value2: Color,
167}
168
169#[derive(Debug)]
170#[cfg_attr(feature = "serde-derives", derive(Serialize))]
171pub enum Section1_39 {
172    Before {
173        value1: f32,
174        value2: f32,
175    },
176    After {
177        values: Box<[f32; 12]>,
178        array: Vec<Section1_40>,
179    },
180}
181
182#[derive(Debug)]
183#[cfg_attr(feature = "serde-derives", derive(Serialize))]
184pub struct Section1_40 {
185    pub id: u32,
186    pub float1: f32,
187    pub float2: f32,
188}
189
190#[derive(Debug)]
191#[cfg_attr(feature = "serde-derives", derive(Serialize))]
192pub struct Section1_43 {
193    pub pos: Vector3f,
194    pub rot: Option<Quaternion>,
195}
196
197#[derive(Debug)]
198#[cfg_attr(feature = "serde-derives", derive(Serialize))]
199#[cfg_attr(feature = "serde-derives", serde(transparent))]
200pub struct SkySection {
201    pub files: [String; 6],
202}