diff --git a/README.md b/README.md index 4e28da8..18a3209 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,15 @@ is derived from the Japanese transliteration of "Mariah," and is pronounced ## `maraiah` The basis of this project is the Rust project `maraiah` which provides functions -and structures to build applications which work with Marathon's data. It is -subdivided into two libraries: `maraiah-durandal` and `maraiah-marathon`. -Ideally these would be separate libraries but Cargo is woefully unable to do so -for varying reasons. They will be treated as separate in this document. +and structures to build applications which work with Marathon's data. -## `maraiah-durandal` - -The `durandal` library is a set of almost fully portable tools written in Rust, +Maraiah comes with a set of almost fully portable tools written in Rust, including binary file reading, safe C-like `enum` reading, improved error handling, FFI tools, fixed point numbers, and image and sound structures. -## `maraiah-marathon` - -`marathon` is a library for working with various data formats, primarily +Maraiah also comes with APIs for working with various data formats, primarily Marathon's. It also handles Macintosh PICT files, Portable PixMap, TARGA, RIFF -WAVE and other formats. +WAVE, and more. ## `maraiah-leela` @@ -31,4 +24,4 @@ the underlying Maraiah library. ## `maraiah-tycho` -`tycho` is a map editor written in C++ and Rust using Qt for GUI. +`tycho` is a map editor written in C++ and Rust using Qt. diff --git a/source/durandal/bin.rs b/source/bin.rs similarity index 96% rename from source/durandal/bin.rs rename to source/bin.rs index 0d0827c..3c88b9a 100644 --- a/source/durandal/bin.rs +++ b/source/bin.rs @@ -1,6 +1,6 @@ //! Binary data conversion utilities. -use crate::durandal::err::*; +use crate::err::*; use std::{convert::{TryFrom, TryInto}, fmt, num::NonZeroU16}; #[doc(hidden)] @@ -159,7 +159,7 @@ macro_rules! rd_impl { /// /// ``` /// # #[macro_use] extern crate maraiah; -/// # use maraiah::durandal::err::*; +/// # use maraiah::err::*; /// let buffer = &[4, 0, 2, 0, 0, 0, 6]; /// /// read_data! { @@ -211,7 +211,7 @@ macro_rules! check_data { /// # Examples /// /// ``` -/// use maraiah::durandal::bin::usize_from_u32; +/// use maraiah::bin::usize_from_u32; /// /// assert_eq!(usize_from_u32(777u32), 777usize); /// ``` @@ -230,7 +230,7 @@ pub fn usize_from_u32(n: u32) -> usize /// # Examples /// /// ``` -/// use maraiah::durandal::bin::{ident, Ident}; +/// use maraiah::bin::{ident, Ident}; /// /// assert_eq!(ident(b"POLY"), Ident([b'P', b'O', b'L', b'Y'])); /// ``` @@ -249,7 +249,7 @@ pub fn ident(b: &[u8]) -> Ident /// # Examples /// /// ``` -/// use maraiah::durandal::bin::u32b; +/// use maraiah::bin::u32b; /// /// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32); /// ``` @@ -268,7 +268,7 @@ pub fn u32b(b: &[u8]) -> u32 /// # Examples /// /// ``` -/// use maraiah::durandal::bin::u16b; +/// use maraiah::bin::u16b; /// /// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16); /// ``` @@ -287,7 +287,7 @@ pub fn u16b(b: &[u8]) -> u16 /// # Examples /// /// ``` -/// use maraiah::durandal::bin::i32b; +/// use maraiah::bin::i32b; /// /// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32); /// ``` @@ -306,7 +306,7 @@ pub fn i32b(b: &[u8]) -> i32 /// # Examples /// /// ``` -/// use maraiah::durandal::bin::i16b; +/// use maraiah::bin::i16b; /// /// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16); /// ``` @@ -335,8 +335,7 @@ pub fn i16b(b: &[u8]) -> i16 /// # Examples /// /// ``` -/// use maraiah::durandal::{bin::{rd_array, u16b}, -/// err::*}; +/// use maraiah::{bin::{rd_array, u16b}, err::*}; /// /// fn read_a_u16(b: &[u8]) -> ResultS<(u16, usize)> {Ok((u16b(b), 2))} /// @@ -446,7 +445,7 @@ impl Into for OptU16 /// # Examples /// /// ``` - /// use maraiah::durandal::bin::OptU16; + /// use maraiah::bin::OptU16; /// /// let u16_max = u16::max_value(); /// @@ -473,7 +472,7 @@ impl OptU16 /// # Examples /// /// ``` - /// use maraiah::durandal::bin::OptU16; + /// use maraiah::bin::OptU16; /// /// assert_eq!(OptU16::none(), OptU16::from(u16::max_value())); /// ``` @@ -485,7 +484,7 @@ impl OptU16 /// # Examples /// /// ``` - /// use maraiah::durandal::bin::OptU16; + /// use maraiah::bin::OptU16; /// /// assert_eq!(OptU16::from(500u16).get(), Some(500u16)); /// assert_eq!(OptU16::from(u16::max_value()).get(), None); @@ -551,7 +550,7 @@ impl<'a> PartialEq<&'a [u8; 4]> for Ident /// # Examples /// /// ``` -/// use maraiah::durandal::bin::Ident; +/// use maraiah::bin::Ident; /// /// assert_eq!(Ident(*b"POLY").0, *b"POLY"); /// assert_eq!(Ident(*b"POLY"), *b"POLY"); diff --git a/source/durandal/bit.rs b/source/bit.rs similarity index 99% rename from source/durandal/bit.rs rename to source/bit.rs index a21afe9..534a566 100644 --- a/source/durandal/bit.rs +++ b/source/bit.rs @@ -1,6 +1,6 @@ //! Bit streams. -use crate::durandal::err::*; +use crate::err::*; /// Reads `width` bits from `b` starting at bit `cr_bit` into an integer, most /// significant bit first. diff --git a/source/durandal/cenum.rs b/source/cenum.rs similarity index 94% rename from source/durandal/cenum.rs rename to source/cenum.rs index ddbe60f..dc728e1 100644 --- a/source/durandal/cenum.rs +++ b/source/cenum.rs @@ -12,7 +12,7 @@ /// # Examples /// /// ``` -/// use maraiah::{c_enum, durandal::err::ReprError}; +/// use maraiah::{c_enum, err::ReprError}; /// use std::convert::TryFrom; /// /// c_enum! { @@ -53,7 +53,7 @@ macro_rules! c_enum #[allow(unused_qualifications)] impl std::convert::TryFrom<$ti> for $t { - type Error = $crate::durandal::err::ReprError; + type Error = $crate::err::ReprError; /// Returns, if representable, the variant of `Self` from `n`. fn try_from(n: $ti) -> Result @@ -70,7 +70,7 @@ macro_rules! c_enum #[cfg(test)] mod test { - use crate::durandal::err::ReprError; + use crate::err::ReprError; use std::convert::TryFrom; c_enum! { diff --git a/source/durandal/cksum.rs b/source/cksum.rs similarity index 93% rename from source/durandal/cksum.rs rename to source/cksum.rs index 9d496df..f37816a 100644 --- a/source/durandal/cksum.rs +++ b/source/cksum.rs @@ -26,7 +26,7 @@ fn crc_init() -> [u32; 256] /// # Examples /// /// ``` -/// use maraiah::durandal::cksum::adler32; +/// use maraiah::cksum::adler32; /// /// assert_eq!(adler32(b"Lorem ipsum dolor sit amet"), 0x83D5_09C5); /// ``` @@ -50,7 +50,7 @@ pub fn adler32(b: &[u8]) -> u32 /// # Examples /// /// ``` -/// use maraiah::durandal::cksum::crc32; +/// use maraiah::cksum::crc32; /// /// assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29_D461); /// ``` diff --git a/source/marathon/defl.rs b/source/defl.rs similarity index 99% rename from source/marathon/defl.rs rename to source/defl.rs index db5f220..59a2af0 100644 --- a/source/marathon/defl.rs +++ b/source/defl.rs @@ -1,6 +1,6 @@ //! DEFLATE loader. -use crate::durandal::{bit::*, err::*}; +use crate::{bit::*, err::*}; use std::cmp::Ordering; /// Loads a ZLIB file header. diff --git a/source/durandal.rs b/source/durandal.rs deleted file mode 100644 index c7fc605..0000000 --- a/source/durandal.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! Library for utilities. - -#[macro_use] -pub mod ffi; -#[macro_use] -pub mod err; -#[macro_use] -pub mod cenum; -#[macro_use] -pub mod bin; - -pub mod bit; -pub mod cksum; -pub mod file; -pub mod fixed; -pub mod image; -pub mod sound; - -// EOF diff --git a/source/durandal/err.rs b/source/err.rs similarity index 93% rename from source/durandal/err.rs rename to source/err.rs index 1781b3b..c3a68d9 100644 --- a/source/durandal/err.rs +++ b/source/err.rs @@ -33,7 +33,7 @@ macro_rules! bail { /// # Examples /// /// ``` -/// use maraiah::durandal::err::err_msg; +/// use maraiah::err::err_msg; /// /// assert_eq!(format!("{}", err_msg("oh no not things")), /// "oh no not things"); @@ -45,7 +45,7 @@ pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()} /// # Examples /// /// ``` -/// use maraiah::durandal::err::repr_error; +/// use maraiah::err::repr_error; /// /// assert_eq!(format!("{}", repr_error(77)), /// "representation error (got 77)"); @@ -59,7 +59,7 @@ impl ReprError /// # Examples /// /// ``` - /// use maraiah::durandal::err::ReprError; + /// use maraiah::err::ReprError; /// /// let err = ReprError::new(7); /// diff --git a/source/durandal/ffi.rs b/source/ffi.rs similarity index 93% rename from source/durandal/ffi.rs rename to source/ffi.rs index 194d222..97e2edc 100644 --- a/source/durandal/ffi.rs +++ b/source/ffi.rs @@ -1,6 +1,6 @@ //! Foreign function interface utilities. -use crate::durandal::err::*; +use crate::err::*; pub use std::{ffi::*, os::raw::*, ptr::{null, null_mut}}; @@ -9,7 +9,7 @@ pub use std::{ffi::*, #[macro_export] macro_rules! c_str { ($s:expr) => { - concat!($s, "\0").as_ptr() as $crate::durandal::ffi::NT + concat!($s, "\0").as_ptr() as $crate::ffi::NT }; } diff --git a/source/durandal/file.rs b/source/file.rs similarity index 90% rename from source/durandal/file.rs rename to source/file.rs index 1c3abe3..0f86c2b 100644 --- a/source/durandal/file.rs +++ b/source/file.rs @@ -1,6 +1,6 @@ //! File utilities. -use crate::durandal::err::*; +use crate::err::*; use std::fs; /// Confirms that the path `p` is a folder. diff --git a/source/durandal/fixed.rs b/source/fixed.rs similarity index 99% rename from source/durandal/fixed.rs rename to source/fixed.rs index e7d7b53..5692f7a 100644 --- a/source/durandal/fixed.rs +++ b/source/fixed.rs @@ -2,8 +2,7 @@ #![allow(clippy::use_self)] #![allow(clippy::cast_lossless)] -use std::{fmt::{self, Write}, - ops::*}; +use std::{fmt::{self, Write}, ops::*}; macro_rules! fixed_ref_unop { (impl $imp:ident, $method:ident for $t:ty) => { diff --git a/source/durandal/image.rs b/source/image.rs similarity index 97% rename from source/durandal/image.rs rename to source/image.rs index dc29b6f..e77d72d 100644 --- a/source/durandal/image.rs +++ b/source/image.rs @@ -1,11 +1,15 @@ //! Image and color representations. +pub mod pict; +pub mod ppm; +pub mod tga; + /// Creates a RGB8 color from a R5G5B5 format color. /// /// # Examples /// /// ``` -/// use maraiah::durandal::image::{r5g5b5_to_rgb8, Color8}; +/// use maraiah::image::{r5g5b5_to_rgb8, Color8}; /// /// assert_eq!(r5g5b5_to_rgb8(0x2345), Color8::new(64, 208, 40)); /// ``` @@ -22,7 +26,7 @@ pub fn r5g5b5_to_rgb8(rgb: u16) -> Color8 /// # Examples /// /// ``` -/// use maraiah::durandal::image::{r5g5b5_to_rgb16, Color16}; +/// use maraiah::image::{r5g5b5_to_rgb16, Color16}; /// /// assert_eq!(r5g5b5_to_rgb16(0x2345), /// Color16::new(0x4000, 0xD000, 0x2800)); @@ -40,7 +44,7 @@ pub fn r5g5b5_to_rgb16(rgb: u16) -> Color16 /// # Examples /// /// ``` -/// use maraiah::durandal::image; +/// use maraiah::image; /// /// let inpl = image::r5g5b5_to_rgb8(0x2345); /// let inph = image::r5g5b5_to_rgb16(0x2345); diff --git a/source/marathon/pict.rs b/source/image/pict.rs similarity index 98% rename from source/marathon/pict.rs rename to source/image/pict.rs index 523110a..bea0793 100644 --- a/source/marathon/pict.rs +++ b/source/image/pict.rs @@ -4,7 +4,7 @@ pub mod clut; pub mod pm; pub mod rle; -use crate::durandal::{bin::*, err::*, image::*}; +use crate::{bin::*, err::*, image::*}; /// Load a `PICT` image. pub fn read(b: &[u8]) -> ResultS diff --git a/source/marathon/pict/clut.rs b/source/image/pict/clut.rs similarity index 95% rename from source/marathon/pict/clut.rs rename to source/image/pict/clut.rs index 23d4dc1..2411fc7 100644 --- a/source/marathon/pict/clut.rs +++ b/source/image/pict/clut.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT color lookup tables. -use crate::durandal::{err::*, image::*}; +use crate::{err::*, image::*}; /// Read a `ColorTable` structure. pub fn read(b: &[u8]) -> ResultS<(Vec, usize)> diff --git a/source/marathon/pict/pm.rs b/source/image/pict/pm.rs similarity index 100% rename from source/marathon/pict/pm.rs rename to source/image/pict/pm.rs diff --git a/source/marathon/pict/pm/area.rs b/source/image/pict/pm/area.rs similarity index 89% rename from source/marathon/pict/pm/area.rs rename to source/image/pict/pm/area.rs index 3649850..5c68925 100644 --- a/source/marathon/pict/pm/area.rs +++ b/source/image/pict/pm/area.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT `PixMap` areas. -use crate::{durandal::{err::*, image::*}, marathon::pict::pm}; +use crate::{err::*, image::{*, pict::pm}}; /// Process a `CopyBits` operation. pub fn read(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS diff --git a/source/marathon/pict/pm/head.rs b/source/image/pict/pm/head.rs similarity index 96% rename from source/marathon/pict/pm/head.rs rename to source/image/pict/pm/head.rs index 3454ee1..ad8fded 100644 --- a/source/marathon/pict/pm/head.rs +++ b/source/image/pict/pm/head.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT `PixMap` headers. -use crate::{durandal::{bin::*, err::*, image::*}, marathon::pict}; +use crate::{bin::*, err::*, image::*}; use std::convert::TryFrom; /// Reads a `PixMap` header. diff --git a/source/marathon/pict/pm/ind.rs b/source/image/pict/pm/ind.rs similarity index 96% rename from source/marathon/pict/pm/ind.rs rename to source/image/pict/pm/ind.rs index 82d7493..d1ca7cf 100644 --- a/source/marathon/pict/pm/ind.rs +++ b/source/image/pict/pm/ind.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT indexed `PixMap`s. -use crate::{durandal::{err::*, image::*}, marathon::pict::{pm, rle}}; +use crate::{err::*, image::{*, pict::{pm, rle}}}; /// Reads an indexed `PixMap`. pub fn read(mut im: Image8, diff --git a/source/marathon/pict/pm/r5g5b5.rs b/source/image/pict/pm/r5g5b5.rs similarity index 90% rename from source/marathon/pict/pm/r5g5b5.rs rename to source/image/pict/pm/r5g5b5.rs index 6059420..565efd8 100644 --- a/source/marathon/pict/pm/r5g5b5.rs +++ b/source/image/pict/pm/r5g5b5.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT R5G5B5 `PixMap`s. -use crate::{durandal::{bin::u16b, err::*, image::*}, marathon::pict::{pm, rle}}; +use crate::{bin::u16b, err::*, image::{*, pict::{pm, rle}}}; /// Reads a R5G5B5 `PixMap`. pub fn read(mut im: Image8, diff --git a/source/marathon/pict/pm/rgb8.rs b/source/image/pict/pm/rgb8.rs similarity index 95% rename from source/marathon/pict/pm/rgb8.rs rename to source/image/pict/pm/rgb8.rs index 699bbd8..149fe77 100644 --- a/source/marathon/pict/pm/rgb8.rs +++ b/source/image/pict/pm/rgb8.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT RGB8 `PixMap`s. -use crate::{durandal::{err::*, image::*}, marathon::pict::{pm, rle}}; +use crate::{err::*, image::{*, pict::{pm, rle}}}; /// Reads a RGB8 `PixMap`. pub fn read(mut im: Image8, diff --git a/source/marathon/pict/rle.rs b/source/image/pict/rle.rs similarity index 98% rename from source/marathon/pict/rle.rs rename to source/image/pict/rle.rs index fbba299..8932331 100644 --- a/source/marathon/pict/rle.rs +++ b/source/image/pict/rle.rs @@ -1,6 +1,6 @@ //! QuickDraw PICT format run length encoded data. -use crate::durandal::{bin::*, err::*}; +use crate::{bin::*, err::*}; /// Read run-length encoded data. pub fn read(b: &[u8], pitch: usize) -> ResultS<(Vec, usize)> diff --git a/source/marathon/ppm.rs b/source/image/ppm.rs similarity index 96% rename from source/marathon/ppm.rs rename to source/image/ppm.rs index ca7458a..67162a1 100644 --- a/source/marathon/ppm.rs +++ b/source/image/ppm.rs @@ -1,6 +1,6 @@ //! Portable Pixel Map format images. -use crate::durandal::{err::*, fixed::FixedLong, image::*}; +use crate::{err::*, fixed::FixedLong, image::*}; use std::io; /// Writes a PPM file from an image. diff --git a/source/marathon/tga.rs b/source/image/tga.rs similarity index 95% rename from source/marathon/tga.rs rename to source/image/tga.rs index 29ed240..4099a0f 100644 --- a/source/marathon/tga.rs +++ b/source/image/tga.rs @@ -1,6 +1,6 @@ //! TARGA format images. -use crate::durandal::{err::*, image::*}; +use crate::{err::*, image::*}; use std::io; /// Writes a TGA file from an image. diff --git a/source/leela/main.rs b/source/leela/main.rs index 86b446d..9222c7f 100644 --- a/source/leela/main.rs +++ b/source/leela/main.rs @@ -1,8 +1,8 @@ #![allow(clippy::unit_arg)] -use maraiah::{durandal::{err::*, file::*, image::*, sound::*}, - marathon::{machdr, map, ppm, shp, snd, tga, wav}}; -use std::{fs, io, slice::from_ref}; +use maraiah::{err::*, file::*, image::*, sound::*, + machdr, map, ppm, shp, snd, tga, wav}; +use std::{collections::HashSet, fs, io, slice::from_ref}; fn open(path: &str) -> ResultS { @@ -27,9 +27,10 @@ fn exists(path: String) -> Result<(), String> } } -fn each_value<'a, F>(opt: &'a clap::ArgMatches<'a>, name: &str, mut f: F) - -> ResultS<()> - where F: FnMut(&'a str) -> ResultS<()> +fn each_value(opt: &clap::ArgMatches<'_>, + name: &str, + mut f: F) -> ResultS<()> + where F: FnMut(&str) -> ResultS<()> { if let Some(values) = opt.values_of(name) { for value in values { @@ -40,26 +41,53 @@ fn each_value<'a, F>(opt: &'a clap::ArgMatches<'a>, name: &str, mut f: F) Ok(()) } -fn dump_info(data: impl std::fmt::Debug) +fn dbg_info(data: impl std::fmt::Debug) { println!("{:#?}", data); } -fn sub_data_c<'a>(_opt: &clap::ArgMatches<'a>) -> ResultS<()> +fn dump_map(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()> +{ + let mut cnks = HashSet::new(); + + if let Some(opt_cnks) = opt.values_of("chunks") { + for typ in opt_cnks { + cnks.insert(typ); + } + } + + Ok(()) +} + +fn dump_shp(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()> { unimplemented!(); } -fn sub_dump_c<'a>(_opt: &clap::ArgMatches<'a>) -> ResultS<()> +fn dump_snd(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()> { unimplemented!(); } -fn sub_info_c<'a>(opt: &clap::ArgMatches<'a>) -> ResultS<()> +fn sub_data_c(_opt: &clap::ArgMatches<'_>) -> ResultS<()> { - each_value(opt, "map", |f| Ok(dump_info(file_read(f, map::read)?)))?; - each_value(opt, "shp", |f| Ok(dump_info(file_read(f, shp::read)?)))?; - each_value(opt, "snd", |f| Ok(dump_info(file_read(f, snd::read)?)))?; + unimplemented!(); +} + +fn sub_dump_c(opt: &clap::ArgMatches<'_>) -> ResultS<()> +{ + each_value(opt, "map", |f| dump_map(opt, f))?; + each_value(opt, "shp", |f| dump_shp(opt, f))?; + each_value(opt, "snd", |f| dump_snd(opt, f))?; + + Ok(()) +} + +fn sub_info_c(opt: &clap::ArgMatches<'_>) -> ResultS<()> +{ + each_value(opt, "map", |f| Ok(dbg_info(file_read(f, map::read)?)))?; + each_value(opt, "shp", |f| Ok(dbg_info(file_read(f, shp::read)?)))?; + each_value(opt, "snd", |f| Ok(dbg_info(file_read(f, snd::read)?)))?; Ok(()) } @@ -74,16 +102,22 @@ fn main() -> ResultS<()> let sub_dump = clap_app!(@subcommand dump => - (about: "Dumps particular parts of data")); + (about: "Dumps particular parts of data") + (@arg chunks: -c --chunks [name]... "Dumps named chunks from an entry") + (@group files => + (@attributes +required +multiple) + (@arg map: -m --map [file]... {exists} "Loads Map files") + (@arg shp: -s --shp [file]... {exists} "Loads Shapes files") + (@arg snd: -n --snd [file]... {exists} "Loads Sounds files"))); let sub_info = clap_app!(@subcommand info => (about: "Outputs debug info") (@group files => (@attributes +required +multiple) - (@arg map: -m --map [file]... {exists} "Loads a Map file") - (@arg shp: -s --shp [file]... {exists} "Loads a Shapes file") - (@arg snd: -n --snd [file]... {exists} "Loads a Sounds file"))); + (@arg map: -m --map [file]... {exists} "Loads Map files") + (@arg shp: -s --shp [file]... {exists} "Loads Shapes files") + (@arg snd: -n --snd [file]... {exists} "Loads Sounds files"))); let opt = clap_app!((env!("CARGO_PKG_NAME")) => diff --git a/source/lib.rs b/source/lib.rs index 842c7d2..afda207 100644 --- a/source/lib.rs +++ b/source/lib.rs @@ -48,7 +48,26 @@ #![deny(clippy::used_underscore_binding)] #[macro_use] -pub mod durandal; -pub mod marathon; +pub mod ffi; +#[macro_use] +pub mod err; +#[macro_use] +pub mod cenum; +#[macro_use] +pub mod bin; + +pub mod bit; +pub mod cksum; +pub mod defl; +pub mod file; +pub mod fixed; +pub mod image; +pub mod machdr; +pub mod map; +pub mod shp; +pub mod snd; +pub mod sound; +pub mod text; +pub mod xfer; // EOF diff --git a/source/marathon/machdr.rs b/source/machdr.rs similarity index 98% rename from source/marathon/machdr.rs rename to source/machdr.rs index c1b6e05..91b11a3 100644 --- a/source/marathon/machdr.rs +++ b/source/machdr.rs @@ -1,6 +1,6 @@ //! Macintosh archived format header utilities. -use crate::durandal::bin::*; +use crate::bin::*; /// Checks for an `AppleSingle` header. Returns offset to the resource fork. pub fn check_apple_single(b: &[u8]) -> Option diff --git a/source/marathon/map.rs b/source/map.rs similarity index 89% rename from source/marathon/map.rs rename to source/map.rs index fc629dc..978199f 100644 --- a/source/marathon/map.rs +++ b/source/map.rs @@ -32,7 +32,7 @@ pub mod trmf; pub mod trmg; pub mod wppx; -use crate::{durandal::err::*, marathon::text::mac_roman_cstr}; +use crate::{err::*, text::mac_roman_cstr}; use std::convert::TryFrom; /// Reads a Map file. @@ -66,9 +66,9 @@ pub fn read(b: &[u8]) -> ResultS bail!("invalid chunk size"); } - let entries = entr::read(b, old_wad, old_dat, siz_app, siz_ent, siz_cnk)?; + let entries = entr::read(b, old_wad, siz_app, siz_ent, siz_cnk)?; - Ok(Wad{name, siz_app, entries}) + Ok(Wad{name, siz_app, old_dat, entries}) } /// A Map file containing entries. @@ -82,6 +82,9 @@ pub struct Wad /// The size of each `Entry`'s `appdata` field. pub siz_app: usize, + /// If the data is in Marathon 1 format. + pub old_dat: bool, + /// All of the entries in this `Wad`. pub entries: entr::EntryMap, } diff --git a/source/marathon/map/ambi.rs b/source/map/ambi.rs similarity index 94% rename from source/marathon/map/ambi.rs rename to source/map/ambi.rs index 88328ba..0d24cd0 100644 --- a/source/marathon/map/ambi.rs +++ b/source/map/ambi.rs @@ -1,6 +1,6 @@ //! `SoundAmbi` type. -use crate::durandal::err::*; +use crate::err::*; /// Reads an `ambi` chunk. pub fn read(b: &[u8]) -> ResultS<(SoundAmbi, usize)> diff --git a/source/marathon/map/attk.rs b/source/map/attk.rs similarity index 88% rename from source/marathon/map/attk.rs rename to source/map/attk.rs index 6a707dc..bfb03bb 100644 --- a/source/marathon/map/attk.rs +++ b/source/map/attk.rs @@ -1,8 +1,6 @@ //! `Attack` type. -use crate::durandal::{bin::OptU16, - err::*, - fixed::{Angle, Unit}}; +use crate::{bin::OptU16, err::*, fixed::{Angle, Unit}}; /// Reads an `Attack` object. pub fn read(b: &[u8]) -> ResultS diff --git a/source/marathon/map/bonk.rs b/source/map/bonk.rs similarity index 94% rename from source/marathon/map/bonk.rs rename to source/map/bonk.rs index 89a73c1..13bba07 100644 --- a/source/marathon/map/bonk.rs +++ b/source/map/bonk.rs @@ -1,7 +1,6 @@ //! `SoundRand` type. -use crate::durandal::{err::*, - fixed::{Angle, Fixed}}; +use crate::{err::*, fixed::{Angle, Fixed}}; use bitflags::bitflags; /// Reads a `bonk` chunk. diff --git a/source/marathon/map/chnk.rs b/source/map/chnk.rs similarity index 51% rename from source/marathon/map/chnk.rs rename to source/map/chnk.rs index e92af17..9f71407 100644 --- a/source/marathon/map/chnk.rs +++ b/source/map/chnk.rs @@ -1,18 +1,13 @@ //! Wad file chunk type. -use crate::{durandal::{bin::*, err::*, image}, marathon::{map, pict}}; +use crate::{bin::*, err::*, image::{self, pict}, map}; /// Reads all chunks in an entry. -pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS> +pub fn read(b: &[u8], siz_cnk: usize) -> ResultS> { let mut chunks = Vec::new(); let mut p = 0; - let read_chunk_minf = if old {map::minf::read_old} else {map::minf::read}; - let read_chunk_sids = if old {map::sids::read_old} else {map::sids::read}; - let read_chunk_poly = if old {map::poly::read_old} else {map::poly::read}; - let read_chunk_lite = if old {map::lite::read_old} else {map::lite::read}; - while p < b.len() { read_data! { endian: BIG, buf: b, size: siz_cnk, start: p, data { @@ -23,34 +18,9 @@ pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS> let beg = p + siz_cnk; let end = beg + size; - let data = ok!(b.get(beg..end), "not enough data")?; + let data = ok!(b.get(beg..end), "not enough data")?.to_vec(); - chunks.push(match &iden.0 { - b"PICT" => Chunk::Pict(pict::load_pict(data)?), - b"Minf" => Chunk::Minf(read_chunk_minf(data)?), - b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?), - b"EPNT" => Chunk::Epnt(rd_array(data, map::epnt::read)?), - b"PNTS" => Chunk::Pnts(rd_array(data, map::pnts::read)?), - b"LINS" => Chunk::Lins(rd_array(data, map::lins::read)?), - b"SIDS" => Chunk::Sids(rd_array(data, read_chunk_sids)?), - b"POLY" => Chunk::Poly(rd_array(data, read_chunk_poly)?), - b"OBJS" => Chunk::Objs(rd_array(data, map::objs::read)?), - b"LITE" => Chunk::Lite(rd_array(data, read_chunk_lite)?), - b"plac" => Chunk::Plac(rd_array(data, map::plac::read)?), - b"ambi" => Chunk::Ambi(rd_array(data, map::ambi::read)?), - b"bonk" => Chunk::Bonk(rd_array(data, map::bonk::read)?), - b"medi" => Chunk::Medi(rd_array(data, map::medi::read)?), - b"plat" => Chunk::Plat(rd_array(data, map::plat::read)?), - b"NAME" => Chunk::Name(rd_array(data, map::name::read)?), - b"NOTE" => Chunk::Note(rd_array(data, map::note::read)?), - b"term" => Chunk::Term(rd_array(data, map::term::read)?), - b"FXpx" => Chunk::Fxpx(rd_array(data, map::fxpx::read)?), - b"MNpx" => Chunk::Mnpx(rd_array(data, map::mnpx::read)?), - b"PRpx" => Chunk::Prpx(rd_array(data, map::prpx::read)?), - b"PXpx" => Chunk::Pxpx(rd_array(data, map::pxpx::read)?), - b"WPpx" => Chunk::Wppx(rd_array(data, map::wppx::read)?), - _ => Chunk::Data{iden, data: data.to_vec()}, - }); + chunks.push(ChunkData{iden, data}); p = end; } @@ -58,38 +28,93 @@ pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS> Ok(chunks) } +/// Loads structured data from chunk data. +pub fn load(chunk_data: &[ChunkData], old: bool) -> ResultS> +{ + let mut chunks = Vec::new(); + + let read_chunk_minf = if old {map::minf::read_old} else {map::minf::read}; + let read_chunk_sids = if old {map::sids::read_old} else {map::sids::read}; + let read_chunk_poly = if old {map::poly::read_old} else {map::poly::read}; + let read_chunk_lite = if old {map::lite::read_old} else {map::lite::read}; + + for chunk in chunk_data.iter() { + let data = &chunk.data; + + let chunk = match &chunk.iden.0 { + b"EPNT" => Chunk::Epnt(rd_array(data, map::epnt::read)?), + b"FXpx" => Chunk::Fxpx(rd_array(data, map::fxpx::read)?), + b"LINS" => Chunk::Lins(rd_array(data, map::lins::read)?), + b"LITE" => Chunk::Lite(rd_array(data, read_chunk_lite)?), + b"MNpx" => Chunk::Mnpx(rd_array(data, map::mnpx::read)?), + b"Minf" => Chunk::Minf(read_chunk_minf(data)?), + b"NAME" => Chunk::Name(rd_array(data, map::name::read)?), + b"NOTE" => Chunk::Note(rd_array(data, map::note::read)?), + b"OBJS" => Chunk::Objs(rd_array(data, map::objs::read)?), + b"PICT" => Chunk::Pict(pict::read(data)?), + b"PNTS" => Chunk::Pnts(rd_array(data, map::pnts::read)?), + b"POLY" => Chunk::Poly(rd_array(data, read_chunk_poly)?), + b"PRpx" => Chunk::Prpx(rd_array(data, map::prpx::read)?), + b"PXpx" => Chunk::Pxpx(rd_array(data, map::pxpx::read)?), + b"SIDS" => Chunk::Sids(rd_array(data, read_chunk_sids)?), + b"WPpx" => Chunk::Wppx(rd_array(data, map::wppx::read)?), + b"ambi" => Chunk::Ambi(rd_array(data, map::ambi::read)?), + b"bonk" => Chunk::Bonk(rd_array(data, map::bonk::read)?), + b"iidx" => Chunk::Iidx(rd_array(data, map::iidx::read)?), + b"medi" => Chunk::Medi(rd_array(data, map::medi::read)?), + b"plac" => Chunk::Plac(rd_array(data, map::plac::read)?), + b"plat" => Chunk::Plat(rd_array(data, map::plat::read)?), + b"term" => Chunk::Term(rd_array(data, map::term::read)?), + _ => Chunk::Data(chunk.clone()), + }; + + chunks.push(chunk); + } + + Ok(chunks) +} + +/// The data of a Chunk read from a file. +#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct ChunkData +{ + /// The name of the chunk. + pub iden: Ident, + + /// The data. + pub data: Vec, +} + /// Any kind of chunk in an `Entry`. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] #[derive(Debug, Eq, PartialEq)] pub enum Chunk { - /** A `PICT` chunk. */ Pict(image::Image8), - /** A `Minf` chunk. */ Minf(map::minf::Minf), - /** An `iidx` chunk. */ Iidx(Vec), - /** An `EPNT` chunk. */ Epnt(Vec), - /** A `PNTS` chunk. */ Pnts(Vec), - /** A `LINS` chunk. */ Lins(Vec), - /** A `SIDS` chunk. */ Sids(Vec), - /** A `POLY` chunk. */ Poly(Vec), - /** A `LITE` chunk. */ Lite(Vec), - /** An `OBJS` chunk. */ Objs(Vec), - /** A `plac` chunk. */ Plac(Vec), - /** An `ambi` chunk. */ Ambi(Vec), - /** A `bonk` chunk. */ Bonk(Vec), - /** A `medi` chunk. */ Medi(Vec), - /** A `plat` chunk. */ Plat(Vec), - /** A `NAME` chunk. */ Name(Vec), - /** A `NOTE` chunk. */ Note(Vec), - /** A `term` chunk. */ Term(Vec), - /** A `FXpx` chunk. */ Fxpx(Vec), - /** A `MNpx` chunk. */ Mnpx(Vec), - /** A `PRpx` chunk. */ Prpx(Vec), - /** A `PXpx` chunk. */ Pxpx(Vec), - /** A `WPpx` chunk. */ Wppx(Vec), - - /// Any other type of chunk, which may have arbitrary data in it. - Data{/** The name of the chunk. */ iden: Ident, - /** The data. */ data: Vec}, + /** `EPNT` chunks. */ Epnt(Vec), + /** `FXpx` chunks. */ Fxpx(Vec), + /** `LINS` chunks. */ Lins(Vec), + /** `LITE` chunks. */ Lite(Vec), + /** `MNpx` chunks. */ Mnpx(Vec), + /** `Minf` chunks. */ Minf(map::minf::Minf), + /** `NAME` chunks. */ Name(Vec), + /** `NOTE` chunks. */ Note(Vec), + /** `OBJS` chunks. */ Objs(Vec), + /** `PICT` chunks. */ Pict(image::Image8), + /** `PNTS` chunks. */ Pnts(Vec), + /** `POLY` chunks. */ Poly(Vec), + /** `PRpx` chunks. */ Prpx(Vec), + /** `PXpx` chunks. */ Pxpx(Vec), + /** `SIDS` chunks. */ Sids(Vec), + /** `WPpx` chunks. */ Wppx(Vec), + /** `ambi` chunks. */ Ambi(Vec), + /** `bonk` chunks. */ Bonk(Vec), + /** `iidx` chunks. */ Iidx(Vec), + /** `medi` chunks. */ Medi(Vec), + /** `plac` chunks. */ Plac(Vec), + /** `plat` chunks. */ Plat(Vec), + /** `term` chunks. */ Term(Vec), + /** Unknown chunk. */ Data(ChunkData), } // EOF diff --git a/source/marathon/map/damg.rs b/source/map/damg.rs similarity index 98% rename from source/marathon/map/damg.rs rename to source/map/damg.rs index 7dd1c9f..af66a38 100644 --- a/source/marathon/map/damg.rs +++ b/source/map/damg.rs @@ -1,6 +1,6 @@ //! `Damage` type. -use crate::durandal::{err::*, fixed::Fixed}; +use crate::{err::*, fixed::Fixed}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon/map/entr.rs b/source/map/entr.rs similarity index 87% rename from source/marathon/map/entr.rs rename to source/map/entr.rs index 58a372c..4fa9829 100644 --- a/source/marathon/map/entr.rs +++ b/source/map/entr.rs @@ -1,13 +1,12 @@ //! Wad file entry type. -use crate::durandal::{bin::usize_from_u32, err::*}; +use crate::{bin::usize_from_u32, err::*}; use super::chnk; use std::collections::BTreeMap; /// Reads all entries in a `Wad`. pub fn read(b: &[u8], old_wad: bool, - old_dat: bool, siz_app: usize, siz_ent: usize, siz_cnk: usize) -> ResultS @@ -33,7 +32,7 @@ pub fn read(b: &[u8], let index = if old_wad {i as u16} else {index}; - let chunks = chnk::read(&b[offset..offset + size], old_dat, siz_cnk)?; + let chunks = chnk::read(&b[offset..offset + size], siz_cnk)?; let appdata = b[p..p + siz_app].to_vec(); entries.insert(index, Entry{chunks, appdata}); @@ -50,7 +49,7 @@ pub fn read(b: &[u8], pub struct Entry { /// All of the chunks in this `Entry`. - pub chunks: Vec, + pub chunks: Vec, /// The application specific data for this Entry. pub appdata: Vec, diff --git a/source/marathon/map/epnt.rs b/source/map/epnt.rs similarity index 96% rename from source/marathon/map/epnt.rs rename to source/map/epnt.rs index e2cdecb..64ad331 100644 --- a/source/marathon/map/epnt.rs +++ b/source/map/epnt.rs @@ -1,7 +1,7 @@ //! `Endpoint` type. use super::pnts; -use crate::durandal::{err::*, fixed::Unit}; +use crate::{err::*, fixed::Unit}; use bitflags::bitflags; /// Reads an `EPNT` chunk. diff --git a/source/marathon/map/fxpx.rs b/source/map/fxpx.rs similarity index 95% rename from source/marathon/map/fxpx.rs rename to source/map/fxpx.rs index a8793d0..384005e 100644 --- a/source/marathon/map/fxpx.rs +++ b/source/map/fxpx.rs @@ -1,6 +1,6 @@ //! `Effect` type. -use crate::durandal::{bin::OptU16, err::*, fixed::Fixed}; +use crate::{bin::OptU16, err::*, fixed::Fixed}; use bitflags::bitflags; /// Reads a `FXpx` chunk. diff --git a/source/marathon/map/iidx.rs b/source/map/iidx.rs similarity index 78% rename from source/marathon/map/iidx.rs rename to source/map/iidx.rs index 0559754..adc40c0 100644 --- a/source/marathon/map/iidx.rs +++ b/source/map/iidx.rs @@ -1,6 +1,6 @@ //! `iidx` chunk. -use crate::durandal::{bin::u16b, err::*}; +use crate::{bin::u16b, err::*}; /// Reads an `iidx` chunk. pub fn read(b: &[u8]) -> ResultS<(u16, usize)> diff --git a/source/marathon/map/lins.rs b/source/map/lins.rs similarity index 96% rename from source/marathon/map/lins.rs rename to source/map/lins.rs index bf3ef57..44e9cdb 100644 --- a/source/marathon/map/lins.rs +++ b/source/map/lins.rs @@ -1,6 +1,6 @@ //! `Line` type. -use crate::durandal::{bin::OptU16, err::*}; +use crate::{bin::OptU16, err::*}; use bitflags::bitflags; /// Reads a `LINS` chunk. diff --git a/source/marathon/map/lite.rs b/source/map/lite.rs similarity index 99% rename from source/marathon/map/lite.rs rename to source/map/lite.rs index b8aef8f..1952e14 100644 --- a/source/marathon/map/lite.rs +++ b/source/map/lite.rs @@ -1,7 +1,7 @@ //! `Light` type. use super::{ltfn, TICKS_PER_SECOND}; -use crate::durandal::{err::*, fixed::Fixed}; +use crate::{err::*, fixed::Fixed}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon/map/ltfn.rs b/source/map/ltfn.rs similarity index 96% rename from source/marathon/map/ltfn.rs rename to source/map/ltfn.rs index 88e71db..fc783ef 100644 --- a/source/marathon/map/ltfn.rs +++ b/source/map/ltfn.rs @@ -1,6 +1,6 @@ //! `LightFunc` type. -use crate::durandal::{err::*, fixed::Fixed}; +use crate::{err::*, fixed::Fixed}; use std::convert::TryFrom; /// Reads a `LightFunc` object. diff --git a/source/marathon/map/medi.rs b/source/map/medi.rs similarity index 91% rename from source/marathon/map/medi.rs rename to source/map/medi.rs index a32aa6f..0396c50 100644 --- a/source/marathon/map/medi.rs +++ b/source/map/medi.rs @@ -1,10 +1,10 @@ //! `Light` type. use super::pnts; -use crate::{durandal::{bin::OptU16, - err::*, - fixed::{Angle, Fixed, Unit}}, - marathon::xfer::TransferMode}; +use crate::{bin::OptU16, + err::*, + fixed::{Angle, Fixed, Unit}, + xfer::TransferMode}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon/map/minf.rs b/source/map/minf.rs similarity index 98% rename from source/marathon/map/minf.rs rename to source/map/minf.rs index 21a03d7..602c33f 100644 --- a/source/marathon/map/minf.rs +++ b/source/map/minf.rs @@ -1,6 +1,6 @@ //! `Minf` type. -use crate::{durandal::err::*, marathon::text::*}; +use crate::{err::*, text::*}; use bitflags::bitflags; /// Reads a `Minf` chunk. diff --git a/source/marathon/map/mnpx.rs b/source/map/mnpx.rs similarity index 98% rename from source/marathon/map/mnpx.rs rename to source/map/mnpx.rs index ca6aa94..877cccc 100644 --- a/source/marathon/map/mnpx.rs +++ b/source/map/mnpx.rs @@ -1,8 +1,6 @@ //! `Monster` type. -use crate::durandal::{bin::OptU16, - err::*, - fixed::{Fixed, Unit}}; +use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}}; use bitflags::bitflags; use super::{attk, damg}; diff --git a/source/marathon/map/name.rs b/source/map/name.rs similarity index 69% rename from source/marathon/map/name.rs rename to source/map/name.rs index d7f51cc..8248964 100644 --- a/source/marathon/map/name.rs +++ b/source/map/name.rs @@ -1,6 +1,6 @@ //! `NAME` chunk. -use crate::{durandal::err::*, marathon::text::mac_roman_cstr}; +use crate::{err::*, text::mac_roman_cstr}; /// Reads a `NAME` chunk. pub fn read(b: &[u8]) -> ResultS<(String, usize)> diff --git a/source/marathon/map/note.rs b/source/map/note.rs similarity index 91% rename from source/marathon/map/note.rs rename to source/map/note.rs index 171cc5e..66530d9 100644 --- a/source/marathon/map/note.rs +++ b/source/map/note.rs @@ -1,7 +1,7 @@ //! `Note` type. use super::pnts; -use crate::{durandal::err::*, marathon::text::*}; +use crate::{err::*, text::*}; /// Reads a `NOTE` chunk. pub fn read(b: &[u8]) -> ResultS<(Note, usize)> diff --git a/source/marathon/map/objs.rs b/source/map/objs.rs similarity index 94% rename from source/marathon/map/objs.rs rename to source/map/objs.rs index 618f1dd..8823846 100644 --- a/source/marathon/map/objs.rs +++ b/source/map/objs.rs @@ -1,7 +1,6 @@ //! `Object` type. -use crate::durandal::{err::*, - fixed::{Angle, Unit}}; +use crate::{err::*, fixed::{Angle, Unit}}; use bitflags::bitflags; /// Reads an `OBJS` chunk. diff --git a/source/marathon/map/plac.rs b/source/map/plac.rs similarity index 97% rename from source/marathon/map/plac.rs rename to source/map/plac.rs index 20b3cdf..ccae4dd 100644 --- a/source/marathon/map/plac.rs +++ b/source/map/plac.rs @@ -1,6 +1,6 @@ //! `ObjectFreq` type. -use crate::durandal::err::*; +use crate::err::*; use bitflags::bitflags; /// Reads a `plac` chunk. diff --git a/source/marathon/map/plat.rs b/source/map/plat.rs similarity index 98% rename from source/marathon/map/plat.rs rename to source/map/plat.rs index a5fc021..1e54de1 100644 --- a/source/marathon/map/plat.rs +++ b/source/map/plat.rs @@ -1,6 +1,6 @@ //! `Platform` type. -use crate::durandal::{err::*, fixed::Unit}; +use crate::{err::*, fixed::Unit}; use bitflags::bitflags; /// Reads a `plat` chunk. diff --git a/source/marathon/map/pnts.rs b/source/map/pnts.rs similarity index 94% rename from source/marathon/map/pnts.rs rename to source/map/pnts.rs index 812f472..af551ee 100644 --- a/source/marathon/map/pnts.rs +++ b/source/map/pnts.rs @@ -1,6 +1,6 @@ //! `Point` type. -use crate::durandal::{err::*, fixed::Unit}; +use crate::{err::*, fixed::Unit}; /// Reads a `Point` object. pub fn read_o(b: &[u8]) -> ResultS diff --git a/source/marathon/map/poly.rs b/source/map/poly.rs similarity index 98% rename from source/marathon/map/poly.rs rename to source/map/poly.rs index f13b083..008c045 100644 --- a/source/marathon/map/poly.rs +++ b/source/map/poly.rs @@ -1,8 +1,7 @@ //! `Polygon` type. use super::pnts; -use crate::{durandal::{bin::OptU16, err::*, fixed::Unit}, - marathon::xfer::TransferMode}; +use crate::{bin::OptU16, err::*, fixed::Unit, xfer::TransferMode}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon/map/prpx.rs b/source/map/prpx.rs similarity index 96% rename from source/marathon/map/prpx.rs rename to source/map/prpx.rs index 98c25f5..c179d75 100644 --- a/source/marathon/map/prpx.rs +++ b/source/map/prpx.rs @@ -1,8 +1,6 @@ //! `Projectile` type. -use crate::durandal::{bin::OptU16, - err::*, - fixed::{Fixed, Unit}}; +use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}}; use bitflags::bitflags; use super::damg; diff --git a/source/marathon/map/pxpx.rs b/source/map/pxpx.rs similarity index 97% rename from source/marathon/map/pxpx.rs rename to source/map/pxpx.rs index 8e2d779..7fb63bd 100644 --- a/source/marathon/map/pxpx.rs +++ b/source/map/pxpx.rs @@ -1,6 +1,6 @@ //! `Physics` type. -use crate::durandal::{err::*, fixed::Fixed}; +use crate::{err::*, fixed::Fixed}; /// Reads a `PXpx` chunk. pub fn read(b: &[u8]) -> ResultS<(Physics, usize)> diff --git a/source/marathon/map/sids.rs b/source/map/sids.rs similarity index 95% rename from source/marathon/map/sids.rs rename to source/map/sids.rs index cced9a7..d66c2e8 100644 --- a/source/marathon/map/sids.rs +++ b/source/map/sids.rs @@ -1,8 +1,7 @@ //! `Side` type. use super::stex; -use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed}, - marathon::xfer::TransferMode}; +use crate::{bin::OptU16, err::*, fixed::Fixed, xfer::TransferMode}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon/map/stex.rs b/source/map/stex.rs similarity index 94% rename from source/marathon/map/stex.rs rename to source/map/stex.rs index 8d4abdb..0ad6288 100644 --- a/source/marathon/map/stex.rs +++ b/source/map/stex.rs @@ -1,6 +1,6 @@ //! `SideTex` type. -use crate::durandal::{bin::OptU16, err::*}; +use crate::{bin::OptU16, err::*}; use super::pnts; /// Reads a `SideTex` object. diff --git a/source/marathon/map/term.rs b/source/map/term.rs similarity index 95% rename from source/marathon/map/term.rs rename to source/map/term.rs index a93ba94..3aaffd9 100644 --- a/source/marathon/map/term.rs +++ b/source/map/term.rs @@ -1,8 +1,7 @@ //! `Terminal` type. use super::{trmf, trmg}; -use crate::{durandal::{bin, err::*}, - marathon::text}; +use crate::{bin, err::*, text}; /// Reads a `term` chunk. pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)> diff --git a/source/marathon/map/trig.rs b/source/map/trig.rs similarity index 97% rename from source/marathon/map/trig.rs rename to source/map/trig.rs index 15a7546..ceb465b 100644 --- a/source/marathon/map/trig.rs +++ b/source/map/trig.rs @@ -1,6 +1,6 @@ //! `Monster` type. -use crate::durandal::{bin::OptU16, err::*, fixed::Unit}; +use crate::{bin::OptU16, err::*, fixed::Unit}; use std::convert::TryFrom; /// Reads a `Trigger` object. diff --git a/source/marathon/map/trmf.rs b/source/map/trmf.rs similarity index 94% rename from source/marathon/map/trmf.rs rename to source/map/trmf.rs index a8e1031..4fe4ab7 100644 --- a/source/marathon/map/trmf.rs +++ b/source/map/trmf.rs @@ -1,6 +1,6 @@ //! `Face` type. -use crate::durandal::err::*; +use crate::err::*; /// Reads a `Face`. pub fn read(b: &[u8]) -> ResultS<(Face, usize)> diff --git a/source/marathon/map/trmg.rs b/source/map/trmg.rs similarity index 98% rename from source/marathon/map/trmg.rs rename to source/map/trmg.rs index 2001114..8c39f8e 100644 --- a/source/marathon/map/trmg.rs +++ b/source/map/trmg.rs @@ -1,6 +1,6 @@ //! `Group` type. -use crate::durandal::err::*; +use crate::err::*; use bitflags::bitflags; /// Reads an `InterGroup`. diff --git a/source/marathon/map/wppx.rs b/source/map/wppx.rs similarity index 98% rename from source/marathon/map/wppx.rs rename to source/map/wppx.rs index 5e7a06d..f251c0f 100644 --- a/source/marathon/map/wppx.rs +++ b/source/map/wppx.rs @@ -1,6 +1,6 @@ //! `Weapon` type. -use crate::durandal::{bin::OptU16, err::*, fixed::Fixed}; +use crate::{bin::OptU16, err::*, fixed::Fixed}; use bitflags::bitflags; use std::convert::TryFrom; diff --git a/source/marathon.rs b/source/marathon.rs deleted file mode 100644 index 58ad930..0000000 --- a/source/marathon.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Library for file format data readers. - -pub mod defl; -pub mod machdr; -pub mod map; -pub mod pict; -pub mod ppm; -pub mod shp; -pub mod snd; -pub mod text; -pub mod tga; -pub mod wav; -pub mod xfer; - -// EOF diff --git a/source/marathon/shp.rs b/source/shp.rs similarity index 96% rename from source/marathon/shp.rs rename to source/shp.rs index e46e4a3..5c7df2d 100644 --- a/source/marathon/shp.rs +++ b/source/shp.rs @@ -6,7 +6,7 @@ pub mod coll; pub mod fram; pub mod sequ; -use crate::durandal::{bin::usize_from_u32, err::*}; +use crate::{bin::usize_from_u32, err::*}; /// Reads a collection at an offset provided by the Shapes header. pub fn read_coll_at_offset(b: &[u8], diff --git a/source/marathon/shp/bmap.rs b/source/shp/bmap.rs similarity index 98% rename from source/marathon/shp/bmap.rs rename to source/shp/bmap.rs index f4bff3a..653f561 100644 --- a/source/marathon/shp/bmap.rs +++ b/source/shp/bmap.rs @@ -1,6 +1,6 @@ //! Shapes file bitmap type. -use crate::durandal::{err::*, image::Image}; +use crate::{err::*, image::Image}; use super::clut; use bitflags::bitflags; diff --git a/source/marathon/shp/clut.rs b/source/shp/clut.rs similarity index 98% rename from source/marathon/shp/clut.rs rename to source/shp/clut.rs index 1654c7c..bc6a32f 100644 --- a/source/marathon/shp/clut.rs +++ b/source/shp/clut.rs @@ -1,6 +1,6 @@ //! Shapes file color lookup tables. -use crate::durandal::{err::*, image::Color}; +use crate::{err::*, image::Color}; /// Reads a color from a color table into `clut`. pub fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()> diff --git a/source/marathon/shp/coll.rs b/source/shp/coll.rs similarity index 96% rename from source/marathon/shp/coll.rs rename to source/shp/coll.rs index 79314ad..a180773 100644 --- a/source/marathon/shp/coll.rs +++ b/source/shp/coll.rs @@ -1,6 +1,6 @@ //! Shapes file collection type. -use crate::durandal::{bin::{rd_ofstable, usize_from_u32}, err::*}; +use crate::{bin::{rd_ofstable, usize_from_u32}, err::*}; use super::{bmap, clut, fram, sequ}; use std::convert::TryFrom; diff --git a/source/marathon/shp/fram.rs b/source/shp/fram.rs similarity index 97% rename from source/marathon/shp/fram.rs rename to source/shp/fram.rs index 2a158ec..f6e6e86 100644 --- a/source/marathon/shp/fram.rs +++ b/source/shp/fram.rs @@ -1,6 +1,6 @@ //! Shapes file frame type. -use crate::durandal::{err::*, fixed::*}; +use crate::{err::*, fixed::*}; use bitflags::bitflags; /// Reads a `Frame`. diff --git a/source/marathon/shp/sequ.rs b/source/shp/sequ.rs similarity index 93% rename from source/marathon/shp/sequ.rs rename to source/shp/sequ.rs index 1147433..400bc71 100644 --- a/source/marathon/shp/sequ.rs +++ b/source/shp/sequ.rs @@ -1,8 +1,8 @@ //! Shapes file sequence type. -use crate::{durandal::{bin::OptU16, err::*}, - marathon::{text::{mac_roman_conv, pascal_str}, - xfer::TransferMode}}; +use crate::{bin::OptU16, err::*, + text::{mac_roman_conv, pascal_str}, + xfer::TransferMode}; use std::convert::TryFrom; /// Reads a `Sequence`. diff --git a/source/marathon/snd.rs b/source/snd.rs similarity index 96% rename from source/marathon/snd.rs rename to source/snd.rs index 7a816bd..222d372 100644 --- a/source/marathon/snd.rs +++ b/source/snd.rs @@ -3,7 +3,7 @@ pub mod defs; pub mod snds; -use crate::durandal::{bin::Ident, err::*}; +use crate::{bin::Ident, err::*}; use std::collections::BTreeMap; /// Reads all sounds from a Sound file. diff --git a/source/marathon/snd/defs.rs b/source/snd/defs.rs similarity index 94% rename from source/marathon/snd/defs.rs rename to source/snd/defs.rs index bb6f8ce..5445744 100644 --- a/source/marathon/snd/defs.rs +++ b/source/snd/defs.rs @@ -1,9 +1,6 @@ //! Sounds format definition type. -use crate::durandal::{bin::{u32b, usize_from_u32}, - err::*, - fixed::*, - sound::Sound16}; +use crate::{bin::{u32b, usize_from_u32}, err::*, fixed::*, sound::Sound16}; use std::convert::TryFrom; use bitflags::bitflags; diff --git a/source/marathon/snd/snds.rs b/source/snd/snds.rs similarity index 94% rename from source/marathon/snd/snds.rs rename to source/snd/snds.rs index 7ed0511..ff29af0 100644 --- a/source/marathon/snd/snds.rs +++ b/source/snd/snds.rs @@ -1,6 +1,6 @@ //! Sounds file audio type. -use crate::durandal::{bin::usize_from_u32, err::*, sound::Sound16}; +use crate::{bin::usize_from_u32, err::*, sound::Sound16}; /// Reads a sound. pub fn read(b: &[u8]) -> ResultS diff --git a/source/durandal/sound.rs b/source/sound.rs similarity index 99% rename from source/durandal/sound.rs rename to source/sound.rs index acf46c7..a0fd00c 100644 --- a/source/durandal/sound.rs +++ b/source/sound.rs @@ -1,5 +1,7 @@ //! Sound representation. +pub mod wav; + /// Any PCM stream which may be represented as a 16-bit PCM stream. pub trait Sound { diff --git a/source/marathon/wav.rs b/source/sound/wav.rs similarity index 96% rename from source/marathon/wav.rs rename to source/sound/wav.rs index 1265185..3ae12a1 100644 --- a/source/marathon/wav.rs +++ b/source/sound/wav.rs @@ -1,6 +1,6 @@ //! RIFF WAVE format sounds. -use crate::durandal::{err::*, sound::*}; +use crate::{err::*, sound::*}; use std::io; /// Writes a WAVE file from a sound. diff --git a/source/marathon/text.rs b/source/text.rs similarity index 95% rename from source/marathon/text.rs rename to source/text.rs index 75ce830..6b63a04 100644 --- a/source/marathon/text.rs +++ b/source/text.rs @@ -5,7 +5,7 @@ /// # Examples /// /// ``` -/// use maraiah::marathon::text::to_binsize; +/// use maraiah::text::to_binsize; /// /// assert_eq!(to_binsize(5000), "5kB".to_string()); /// ``` @@ -57,7 +57,7 @@ pub fn fuck_string(s: &[u8]) -> Vec /// # Examples /// /// ``` -/// use maraiah::marathon::text::pascal_str; +/// use maraiah::text::pascal_str; /// /// assert_eq!(pascal_str(b"\x0bhello world"), b"hello world"[..].into()); /// assert_eq!(pascal_str(b"\x0chello world"), None); @@ -74,7 +74,7 @@ pub fn pascal_str(b: &[u8]) -> Option<&[u8]> /// # Examples /// /// ``` -/// use maraiah::marathon::text::mac_roman_conv; +/// use maraiah::text::mac_roman_conv; /// /// assert_eq!(mac_roman_conv(b"p\x8cth"), "påth"); /// assert_eq!(mac_roman_conv(b"I\xd5ve"), "I’ve"); @@ -101,7 +101,7 @@ pub fn mac_roman_conv(s: &[u8]) -> String /// # Examples /// /// ``` -/// use maraiah::marathon::text::mac_roman_cstr; +/// use maraiah::text::mac_roman_cstr; /// /// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed"), "I’ve awaken"); /// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "I’ve awaken"); @@ -122,7 +122,7 @@ pub fn mac_roman_cstr(s: &[u8]) -> String /// # Examples /// /// ``` -/// use maraiah::marathon::text::to_mac_roman; +/// use maraiah::text::to_mac_roman; /// /// assert_eq!(to_mac_roman("påth"), b"p\x8cth".to_vec()); /// assert_eq!(to_mac_roman("I’ve\n"), b"I\xd5ve\r".to_vec()); @@ -155,7 +155,7 @@ pub fn to_mac_roman(s: &str) -> Vec /// # Examples /// /// ``` -/// use maraiah::marathon::text::{pad_zero, to_mac_roman}; +/// use maraiah::text::{pad_zero, to_mac_roman}; /// /// let s = to_mac_roman("påth"); /// diff --git a/source/marathon/xfer.rs b/source/xfer.rs similarity index 100% rename from source/marathon/xfer.rs rename to source/xfer.rs diff --git a/tests/defl.rs b/tests/defl.rs index 40ae8ca..007b491 100644 --- a/tests/defl.rs +++ b/tests/defl.rs @@ -1,4 +1,4 @@ -use maraiah::marathon::defl; +use maraiah::defl; include!("data/rand.rs"); diff --git a/tests/map.rs b/tests/map.rs index a2da088..b9ee488 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -1,5 +1,4 @@ -use maraiah::{durandal::{bin, fixed::*}, - marathon::map}; +use maraiah::{bin, fixed::*, map}; include!("data/rand.rs"); diff --git a/tests/misc.rs b/tests/misc.rs index fa63293..fe9a2ce 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -1,4 +1,4 @@ -use maraiah::marathon::machdr; +use maraiah::machdr; include!("data/rand.rs"); diff --git a/tests/pict.rs b/tests/pict.rs index cd7076b..335d32d 100644 --- a/tests/pict.rs +++ b/tests/pict.rs @@ -1,4 +1,4 @@ -use maraiah::{durandal::image::Color8, marathon::pict}; +use maraiah::{image::{Color8, pict}}; include!("data/rand.rs"); diff --git a/tests/shp.rs b/tests/shp.rs index 10faea2..1e82ff2 100644 --- a/tests/shp.rs +++ b/tests/shp.rs @@ -1,4 +1,4 @@ -use maraiah::marathon::shp; +use maraiah::shp; include!("data/rand.rs"); diff --git a/tests/snd.rs b/tests/snd.rs index 8b7897d..564b451 100644 --- a/tests/snd.rs +++ b/tests/snd.rs @@ -1,4 +1,4 @@ -use maraiah::marathon::snd; +use maraiah::snd; include!("data/rand.rs");