Maraiah/maraiah/shp/coll.rs

69 lines
1.7 KiB
Rust
Raw Normal View History

2019-04-11 21:04:39 -07:00
//! Shapes file collection type.
use crate::{bin::rd_ofstable, err::*};
2019-04-11 21:04:39 -07:00
use super::{bmap, clut, fram, sequ};
/// Reads a `Collection`.
pub fn read(b: &[u8]) -> ResultS<Collection>
{
2019-07-05 20:21:11 -07:00
read_data! {
endian: BIG, buf: b, size: 544, start: 0, data {
let version = u16[0];
let cl_type = u16[2] enum CollectionType;
let clr_num = u16[6] usize;
let tab_num = u16[8] usize;
let tab_ofs = u32[10] usize;
let seq_num = u16[14] usize;
let seq_ofs = u32[16] usize;
let frm_num = u16[20] usize;
let frm_ofs = u32[22] usize;
let bmp_num = u16[26] usize;
let bmp_ofs = u32[28] usize;
}
}
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
if version != 3 {
bail!("invalid collection definition");
}
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
let tabs = clut::read(b, tab_ofs, tab_num, clr_num)?;
let bmps = rd_ofstable(b, bmp_ofs, bmp_num, bmap::read)?;
let frms = rd_ofstable(b, frm_ofs, frm_num, fram::read)?;
let seqs = rd_ofstable(b, seq_ofs, seq_num, sequ::read)?;
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
Ok(Collection{ctyp: cl_type, tabs, bmps, frms, seqs})
2019-04-11 21:04:39 -07:00
}
/// A collection of color tables, bitmaps, frames and sequences.
#[derive(Clone, Debug, Eq, PartialEq)]
2019-06-25 03:52:21 -07:00
pub struct Collection {
2019-07-05 20:21:11 -07:00
/// The type of collection this is.
pub ctyp: CollectionType,
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
/// All of the color tables in this collection.
pub tabs: Vec<clut::Clut>,
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
/// All of the bitmaps in this collection.
pub bmps: Vec<bmap::Bitmap>,
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
/// All of the frames in this collection.
pub frms: Vec<fram::Frame>,
2019-04-11 21:04:39 -07:00
2019-07-05 20:21:11 -07:00
/// All of the sequences in this collection.
pub seqs: Vec<sequ::Sequence>,
2019-04-11 21:04:39 -07:00
}
c_enum! {
2019-07-05 20:21:11 -07:00
/// The type of a collection.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
pub enum CollectionType: u16 {
Unused = 0,
Wall = 1,
Object = 2,
Interface = 3,
Scenery = 4,
}
2019-04-11 21:04:39 -07:00
}
// EOF