maraiah: reorganize project

master
an 2019-06-13 21:09:07 -04:00
parent 25d5ac1314
commit dafa691002
78 changed files with 275 additions and 247 deletions

View File

@ -7,22 +7,15 @@ is derived from the Japanese transliteration of "Mariah," and is pronounced
## `maraiah` ## `maraiah`
The basis of this project is the Rust project `maraiah` which provides functions 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 and structures to build applications which work with Marathon's data.
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.
## `maraiah-durandal` Maraiah comes with a set of almost fully portable tools written in Rust,
The `durandal` library is a set of almost fully portable tools written in Rust,
including binary file reading, safe C-like `enum` reading, improved error including binary file reading, safe C-like `enum` reading, improved error
handling, FFI tools, fixed point numbers, and image and sound structures. handling, FFI tools, fixed point numbers, and image and sound structures.
## `maraiah-marathon` Maraiah also comes with APIs for working with various data formats, primarily
`marathon` is a library for working with various data formats, primarily
Marathon's. It also handles Macintosh PICT files, Portable PixMap, TARGA, RIFF Marathon's. It also handles Macintosh PICT files, Portable PixMap, TARGA, RIFF
WAVE and other formats. WAVE, and more.
## `maraiah-leela` ## `maraiah-leela`
@ -31,4 +24,4 @@ the underlying Maraiah library.
## `maraiah-tycho` ## `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.

View File

@ -1,6 +1,6 @@
//! Binary data conversion utilities. //! Binary data conversion utilities.
use crate::durandal::err::*; use crate::err::*;
use std::{convert::{TryFrom, TryInto}, fmt, num::NonZeroU16}; use std::{convert::{TryFrom, TryInto}, fmt, num::NonZeroU16};
#[doc(hidden)] #[doc(hidden)]
@ -159,7 +159,7 @@ macro_rules! rd_impl {
/// ///
/// ``` /// ```
/// # #[macro_use] extern crate maraiah; /// # #[macro_use] extern crate maraiah;
/// # use maraiah::durandal::err::*; /// # use maraiah::err::*;
/// let buffer = &[4, 0, 2, 0, 0, 0, 6]; /// let buffer = &[4, 0, 2, 0, 0, 0, 6];
/// ///
/// read_data! { /// read_data! {
@ -211,7 +211,7 @@ macro_rules! check_data {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::usize_from_u32; /// use maraiah::bin::usize_from_u32;
/// ///
/// assert_eq!(usize_from_u32(777u32), 777usize); /// assert_eq!(usize_from_u32(777u32), 777usize);
/// ``` /// ```
@ -230,7 +230,7 @@ pub fn usize_from_u32(n: u32) -> usize
/// # Examples /// # 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'])); /// 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 /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::u32b; /// use maraiah::bin::u32b;
/// ///
/// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32); /// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32);
/// ``` /// ```
@ -268,7 +268,7 @@ pub fn u32b(b: &[u8]) -> u32
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::u16b; /// use maraiah::bin::u16b;
/// ///
/// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16); /// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16);
/// ``` /// ```
@ -287,7 +287,7 @@ pub fn u16b(b: &[u8]) -> u16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::i32b; /// use maraiah::bin::i32b;
/// ///
/// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32); /// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32);
/// ``` /// ```
@ -306,7 +306,7 @@ pub fn i32b(b: &[u8]) -> i32
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::i16b; /// use maraiah::bin::i16b;
/// ///
/// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16); /// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16);
/// ``` /// ```
@ -335,8 +335,7 @@ pub fn i16b(b: &[u8]) -> i16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::{bin::{rd_array, u16b}, /// use maraiah::{bin::{rd_array, u16b}, err::*};
/// err::*};
/// ///
/// fn read_a_u16(b: &[u8]) -> ResultS<(u16, usize)> {Ok((u16b(b), 2))} /// fn read_a_u16(b: &[u8]) -> ResultS<(u16, usize)> {Ok((u16b(b), 2))}
/// ///
@ -446,7 +445,7 @@ impl Into<u16> for OptU16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::OptU16; /// use maraiah::bin::OptU16;
/// ///
/// let u16_max = u16::max_value(); /// let u16_max = u16::max_value();
/// ///
@ -473,7 +472,7 @@ impl OptU16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::OptU16; /// use maraiah::bin::OptU16;
/// ///
/// assert_eq!(OptU16::none(), OptU16::from(u16::max_value())); /// assert_eq!(OptU16::none(), OptU16::from(u16::max_value()));
/// ``` /// ```
@ -485,7 +484,7 @@ impl OptU16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::OptU16; /// use maraiah::bin::OptU16;
/// ///
/// assert_eq!(OptU16::from(500u16).get(), Some(500u16)); /// assert_eq!(OptU16::from(500u16).get(), Some(500u16));
/// assert_eq!(OptU16::from(u16::max_value()).get(), None); /// assert_eq!(OptU16::from(u16::max_value()).get(), None);
@ -551,7 +550,7 @@ impl<'a> PartialEq<&'a [u8; 4]> for Ident
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::bin::Ident; /// use maraiah::bin::Ident;
/// ///
/// assert_eq!(Ident(*b"POLY").0, *b"POLY"); /// assert_eq!(Ident(*b"POLY").0, *b"POLY");
/// assert_eq!(Ident(*b"POLY"), *b"POLY"); /// assert_eq!(Ident(*b"POLY"), *b"POLY");

View File

@ -1,6 +1,6 @@
//! Bit streams. //! Bit streams.
use crate::durandal::err::*; use crate::err::*;
/// Reads `width` bits from `b` starting at bit `cr_bit` into an integer, most /// Reads `width` bits from `b` starting at bit `cr_bit` into an integer, most
/// significant bit first. /// significant bit first.

View File

@ -12,7 +12,7 @@
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::{c_enum, durandal::err::ReprError}; /// use maraiah::{c_enum, err::ReprError};
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// ///
/// c_enum! { /// c_enum! {
@ -53,7 +53,7 @@ macro_rules! c_enum
#[allow(unused_qualifications)] #[allow(unused_qualifications)]
impl std::convert::TryFrom<$ti> for $t 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`. /// Returns, if representable, the variant of `Self` from `n`.
fn try_from(n: $ti) -> Result<Self, Self::Error> fn try_from(n: $ti) -> Result<Self, Self::Error>
@ -70,7 +70,7 @@ macro_rules! c_enum
#[cfg(test)] #[cfg(test)]
mod test mod test
{ {
use crate::durandal::err::ReprError; use crate::err::ReprError;
use std::convert::TryFrom; use std::convert::TryFrom;
c_enum! { c_enum! {

View File

@ -26,7 +26,7 @@ fn crc_init() -> [u32; 256]
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::cksum::adler32; /// use maraiah::cksum::adler32;
/// ///
/// assert_eq!(adler32(b"Lorem ipsum dolor sit amet"), 0x83D5_09C5); /// assert_eq!(adler32(b"Lorem ipsum dolor sit amet"), 0x83D5_09C5);
/// ``` /// ```
@ -50,7 +50,7 @@ pub fn adler32(b: &[u8]) -> u32
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::cksum::crc32; /// use maraiah::cksum::crc32;
/// ///
/// assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29_D461); /// assert_eq!(crc32(b"Lorem ipsum dolor sit amet", !0), 0x5F29_D461);
/// ``` /// ```

View File

@ -1,6 +1,6 @@
//! DEFLATE loader. //! DEFLATE loader.
use crate::durandal::{bit::*, err::*}; use crate::{bit::*, err::*};
use std::cmp::Ordering; use std::cmp::Ordering;
/// Loads a ZLIB file header. /// Loads a ZLIB file header.

View File

@ -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

View File

@ -33,7 +33,7 @@ macro_rules! bail {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::err::err_msg; /// use maraiah::err::err_msg;
/// ///
/// assert_eq!(format!("{}", err_msg("oh no not things")), /// assert_eq!(format!("{}", err_msg("oh no not things")),
/// "oh no not things"); /// "oh no not things");
@ -45,7 +45,7 @@ pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()}
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::err::repr_error; /// use maraiah::err::repr_error;
/// ///
/// assert_eq!(format!("{}", repr_error(77)), /// assert_eq!(format!("{}", repr_error(77)),
/// "representation error (got 77)"); /// "representation error (got 77)");
@ -59,7 +59,7 @@ impl ReprError
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::err::ReprError; /// use maraiah::err::ReprError;
/// ///
/// let err = ReprError::new(7); /// let err = ReprError::new(7);
/// ///

View File

@ -1,6 +1,6 @@
//! Foreign function interface utilities. //! Foreign function interface utilities.
use crate::durandal::err::*; use crate::err::*;
pub use std::{ffi::*, pub use std::{ffi::*,
os::raw::*, os::raw::*,
ptr::{null, null_mut}}; ptr::{null, null_mut}};
@ -9,7 +9,7 @@ pub use std::{ffi::*,
#[macro_export] #[macro_export]
macro_rules! c_str { macro_rules! c_str {
($s:expr) => { ($s:expr) => {
concat!($s, "\0").as_ptr() as $crate::durandal::ffi::NT concat!($s, "\0").as_ptr() as $crate::ffi::NT
}; };
} }

View File

@ -1,6 +1,6 @@
//! File utilities. //! File utilities.
use crate::durandal::err::*; use crate::err::*;
use std::fs; use std::fs;
/// Confirms that the path `p` is a folder. /// Confirms that the path `p` is a folder.

View File

@ -2,8 +2,7 @@
#![allow(clippy::use_self)] #![allow(clippy::use_self)]
#![allow(clippy::cast_lossless)] #![allow(clippy::cast_lossless)]
use std::{fmt::{self, Write}, use std::{fmt::{self, Write}, ops::*};
ops::*};
macro_rules! fixed_ref_unop { macro_rules! fixed_ref_unop {
(impl $imp:ident, $method:ident for $t:ty) => { (impl $imp:ident, $method:ident for $t:ty) => {

View File

@ -1,11 +1,15 @@
//! Image and color representations. //! Image and color representations.
pub mod pict;
pub mod ppm;
pub mod tga;
/// Creates a RGB8 color from a R5G5B5 format color. /// Creates a RGB8 color from a R5G5B5 format color.
/// ///
/// # Examples /// # 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)); /// assert_eq!(r5g5b5_to_rgb8(0x2345), Color8::new(64, 208, 40));
/// ``` /// ```
@ -22,7 +26,7 @@ pub fn r5g5b5_to_rgb8(rgb: u16) -> Color8
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::image::{r5g5b5_to_rgb16, Color16}; /// use maraiah::image::{r5g5b5_to_rgb16, Color16};
/// ///
/// assert_eq!(r5g5b5_to_rgb16(0x2345), /// assert_eq!(r5g5b5_to_rgb16(0x2345),
/// Color16::new(0x4000, 0xD000, 0x2800)); /// Color16::new(0x4000, 0xD000, 0x2800));
@ -40,7 +44,7 @@ pub fn r5g5b5_to_rgb16(rgb: u16) -> Color16
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::durandal::image; /// use maraiah::image;
/// ///
/// let inpl = image::r5g5b5_to_rgb8(0x2345); /// let inpl = image::r5g5b5_to_rgb8(0x2345);
/// let inph = image::r5g5b5_to_rgb16(0x2345); /// let inph = image::r5g5b5_to_rgb16(0x2345);

View File

@ -4,7 +4,7 @@ pub mod clut;
pub mod pm; pub mod pm;
pub mod rle; pub mod rle;
use crate::durandal::{bin::*, err::*, image::*}; use crate::{bin::*, err::*, image::*};
/// Load a `PICT` image. /// Load a `PICT` image.
pub fn read(b: &[u8]) -> ResultS<Image8> pub fn read(b: &[u8]) -> ResultS<Image8>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT color lookup tables. //! QuickDraw PICT color lookup tables.
use crate::durandal::{err::*, image::*}; use crate::{err::*, image::*};
/// Read a `ColorTable` structure. /// Read a `ColorTable` structure.
pub fn read(b: &[u8]) -> ResultS<(Vec<Color8>, usize)> pub fn read(b: &[u8]) -> ResultS<(Vec<Color8>, usize)>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT `PixMap` areas. //! QuickDraw PICT `PixMap` areas.
use crate::{durandal::{err::*, image::*}, marathon::pict::pm}; use crate::{err::*, image::{*, pict::pm}};
/// Process a `CopyBits` operation. /// Process a `CopyBits` operation.
pub fn read(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS<Image8> pub fn read(im: Image8, b: &[u8], pack: bool, clip: bool) -> ResultS<Image8>

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT `PixMap` headers. //! QuickDraw PICT `PixMap` headers.
use crate::{durandal::{bin::*, err::*, image::*}, marathon::pict}; use crate::{bin::*, err::*, image::*};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Reads a `PixMap` header. /// Reads a `PixMap` header.

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT indexed `PixMap`s. //! 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`. /// Reads an indexed `PixMap`.
pub fn read(mut im: Image8, pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT R5G5B5 `PixMap`s. //! 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`. /// Reads a R5G5B5 `PixMap`.
pub fn read(mut im: Image8, pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT RGB8 `PixMap`s. //! 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`. /// Reads a RGB8 `PixMap`.
pub fn read(mut im: Image8, pub fn read(mut im: Image8,

View File

@ -1,6 +1,6 @@
//! QuickDraw PICT format run length encoded data. //! QuickDraw PICT format run length encoded data.
use crate::durandal::{bin::*, err::*}; use crate::{bin::*, err::*};
/// Read run-length encoded data. /// Read run-length encoded data.
pub fn read<T>(b: &[u8], pitch: usize) -> ResultS<(Vec<T>, usize)> pub fn read<T>(b: &[u8], pitch: usize) -> ResultS<(Vec<T>, usize)>

View File

@ -1,6 +1,6 @@
//! Portable Pixel Map format images. //! Portable Pixel Map format images.
use crate::durandal::{err::*, fixed::FixedLong, image::*}; use crate::{err::*, fixed::FixedLong, image::*};
use std::io; use std::io;
/// Writes a PPM file from an image. /// Writes a PPM file from an image.

View File

@ -1,6 +1,6 @@
//! TARGA format images. //! TARGA format images.
use crate::durandal::{err::*, image::*}; use crate::{err::*, image::*};
use std::io; use std::io;
/// Writes a TGA file from an image. /// Writes a TGA file from an image.

View File

@ -1,8 +1,8 @@
#![allow(clippy::unit_arg)] #![allow(clippy::unit_arg)]
use maraiah::{durandal::{err::*, file::*, image::*, sound::*}, use maraiah::{err::*, file::*, image::*, sound::*,
marathon::{machdr, map, ppm, shp, snd, tga, wav}}; machdr, map, ppm, shp, snd, tga, wav};
use std::{fs, io, slice::from_ref}; use std::{collections::HashSet, fs, io, slice::from_ref};
fn open(path: &str) -> ResultS<memmap::Mmap> fn open(path: &str) -> ResultS<memmap::Mmap>
{ {
@ -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) fn each_value<F>(opt: &clap::ArgMatches<'_>,
-> ResultS<()> name: &str,
where F: FnMut(&'a str) -> ResultS<()> mut f: F) -> ResultS<()>
where F: FnMut(&str) -> ResultS<()>
{ {
if let Some(values) = opt.values_of(name) { if let Some(values) = opt.values_of(name) {
for value in values { for value in values {
@ -40,26 +41,53 @@ fn each_value<'a, F>(opt: &'a clap::ArgMatches<'a>, name: &str, mut f: F)
Ok(()) Ok(())
} }
fn dump_info(data: impl std::fmt::Debug) fn dbg_info(data: impl std::fmt::Debug)
{ {
println!("{:#?}", data); 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!(); unimplemented!();
} }
fn sub_dump_c<'a>(_opt: &clap::ArgMatches<'a>) -> ResultS<()> fn dump_snd(opt: &clap::ArgMatches<'_>, f: &str) -> ResultS<()>
{ {
unimplemented!(); 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)?)))?; unimplemented!();
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)?)))?;
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(()) Ok(())
} }
@ -74,16 +102,22 @@ fn main() -> ResultS<()>
let sub_dump = let sub_dump =
clap_app!(@subcommand 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 = let sub_info =
clap_app!(@subcommand info => clap_app!(@subcommand info =>
(about: "Outputs debug info") (about: "Outputs debug info")
(@group files => (@group files =>
(@attributes +required +multiple) (@attributes +required +multiple)
(@arg map: -m --map [file]... {exists} "Loads a Map file") (@arg map: -m --map [file]... {exists} "Loads Map files")
(@arg shp: -s --shp [file]... {exists} "Loads a Shapes file") (@arg shp: -s --shp [file]... {exists} "Loads Shapes files")
(@arg snd: -n --snd [file]... {exists} "Loads a Sounds file"))); (@arg snd: -n --snd [file]... {exists} "Loads Sounds files")));
let opt = let opt =
clap_app!((env!("CARGO_PKG_NAME")) => clap_app!((env!("CARGO_PKG_NAME")) =>

View File

@ -48,7 +48,26 @@
#![deny(clippy::used_underscore_binding)] #![deny(clippy::used_underscore_binding)]
#[macro_use] #[macro_use]
pub mod durandal; pub mod ffi;
pub mod marathon; #[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 // EOF

View File

@ -1,6 +1,6 @@
//! Macintosh archived format header utilities. //! Macintosh archived format header utilities.
use crate::durandal::bin::*; use crate::bin::*;
/// Checks for an `AppleSingle` header. Returns offset to the resource fork. /// Checks for an `AppleSingle` header. Returns offset to the resource fork.
pub fn check_apple_single(b: &[u8]) -> Option<usize> pub fn check_apple_single(b: &[u8]) -> Option<usize>

View File

@ -32,7 +32,7 @@ pub mod trmf;
pub mod trmg; pub mod trmg;
pub mod wppx; pub mod wppx;
use crate::{durandal::err::*, marathon::text::mac_roman_cstr}; use crate::{err::*, text::mac_roman_cstr};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Reads a Map file. /// Reads a Map file.
@ -66,9 +66,9 @@ pub fn read(b: &[u8]) -> ResultS<Wad>
bail!("invalid chunk size"); 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. /// A Map file containing entries.
@ -82,6 +82,9 @@ pub struct Wad
/// The size of each `Entry`'s `appdata` field. /// The size of each `Entry`'s `appdata` field.
pub siz_app: usize, pub siz_app: usize,
/// If the data is in Marathon 1 format.
pub old_dat: bool,
/// All of the entries in this `Wad`. /// All of the entries in this `Wad`.
pub entries: entr::EntryMap, pub entries: entr::EntryMap,
} }

View File

@ -1,6 +1,6 @@
//! `SoundAmbi` type. //! `SoundAmbi` type.
use crate::durandal::err::*; use crate::err::*;
/// Reads an `ambi` chunk. /// Reads an `ambi` chunk.
pub fn read(b: &[u8]) -> ResultS<(SoundAmbi, usize)> pub fn read(b: &[u8]) -> ResultS<(SoundAmbi, usize)>

View File

@ -1,8 +1,6 @@
//! `Attack` type. //! `Attack` type.
use crate::durandal::{bin::OptU16, use crate::{bin::OptU16, err::*, fixed::{Angle, Unit}};
err::*,
fixed::{Angle, Unit}};
/// Reads an `Attack` object. /// Reads an `Attack` object.
pub fn read(b: &[u8]) -> ResultS<Attack> pub fn read(b: &[u8]) -> ResultS<Attack>

View File

@ -1,7 +1,6 @@
//! `SoundRand` type. //! `SoundRand` type.
use crate::durandal::{err::*, use crate::{err::*, fixed::{Angle, Fixed}};
fixed::{Angle, Fixed}};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `bonk` chunk. /// Reads a `bonk` chunk.

View File

@ -1,18 +1,13 @@
//! Wad file chunk type. //! 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. /// Reads all chunks in an entry.
pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>> pub fn read(b: &[u8], siz_cnk: usize) -> ResultS<Vec<ChunkData>>
{ {
let mut chunks = Vec::new(); let mut chunks = Vec::new();
let mut p = 0; 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() { while p < b.len() {
read_data! { read_data! {
endian: BIG, buf: b, size: siz_cnk, start: p, 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<Vec<Chunk>>
let beg = p + siz_cnk; let beg = p + siz_cnk;
let end = beg + size; 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 { chunks.push(ChunkData{iden, data});
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()},
});
p = end; p = end;
} }
@ -58,38 +28,93 @@ pub fn read(b: &[u8], old: bool, siz_cnk: usize) -> ResultS<Vec<Chunk>>
Ok(chunks) Ok(chunks)
} }
/// Loads structured data from chunk data.
pub fn load(chunk_data: &[ChunkData], old: bool) -> ResultS<Vec<Chunk>>
{
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<u8>,
}
/// Any kind of chunk in an `Entry`. /// Any kind of chunk in an `Entry`.
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum Chunk pub enum Chunk
{ {
/** A `PICT` chunk. */ Pict(image::Image8), /** `EPNT` chunks. */ Epnt(Vec<map::epnt::Endpoint>),
/** A `Minf` chunk. */ Minf(map::minf::Minf), /** `FXpx` chunks. */ Fxpx(Vec<map::fxpx::Effect>),
/** An `iidx` chunk. */ Iidx(Vec<u16>), /** `LINS` chunks. */ Lins(Vec<map::lins::Line>),
/** An `EPNT` chunk. */ Epnt(Vec<map::epnt::Endpoint>), /** `LITE` chunks. */ Lite(Vec<map::lite::Light>),
/** A `PNTS` chunk. */ Pnts(Vec<map::pnts::Point>), /** `MNpx` chunks. */ Mnpx(Vec<map::mnpx::Monster>),
/** A `LINS` chunk. */ Lins(Vec<map::lins::Line>), /** `Minf` chunks. */ Minf(map::minf::Minf),
/** A `SIDS` chunk. */ Sids(Vec<map::sids::Side>), /** `NAME` chunks. */ Name(Vec<String>),
/** A `POLY` chunk. */ Poly(Vec<map::poly::Polygon>), /** `NOTE` chunks. */ Note(Vec<map::note::Note>),
/** A `LITE` chunk. */ Lite(Vec<map::lite::Light>), /** `OBJS` chunks. */ Objs(Vec<map::objs::Object>),
/** An `OBJS` chunk. */ Objs(Vec<map::objs::Object>), /** `PICT` chunks. */ Pict(image::Image8),
/** A `plac` chunk. */ Plac(Vec<map::plac::ObjectFreq>), /** `PNTS` chunks. */ Pnts(Vec<map::pnts::Point>),
/** An `ambi` chunk. */ Ambi(Vec<map::ambi::SoundAmbi>), /** `POLY` chunks. */ Poly(Vec<map::poly::Polygon>),
/** A `bonk` chunk. */ Bonk(Vec<map::bonk::SoundRand>), /** `PRpx` chunks. */ Prpx(Vec<map::prpx::Projectile>),
/** A `medi` chunk. */ Medi(Vec<map::medi::Media>), /** `PXpx` chunks. */ Pxpx(Vec<map::pxpx::Physics>),
/** A `plat` chunk. */ Plat(Vec<map::plat::Platform>), /** `SIDS` chunks. */ Sids(Vec<map::sids::Side>),
/** A `NAME` chunk. */ Name(Vec<String>), /** `WPpx` chunks. */ Wppx(Vec<map::wppx::Weapon>),
/** A `NOTE` chunk. */ Note(Vec<map::note::Note>), /** `ambi` chunks. */ Ambi(Vec<map::ambi::SoundAmbi>),
/** A `term` chunk. */ Term(Vec<map::term::Terminal>), /** `bonk` chunks. */ Bonk(Vec<map::bonk::SoundRand>),
/** A `FXpx` chunk. */ Fxpx(Vec<map::fxpx::Effect>), /** `iidx` chunks. */ Iidx(Vec<u16>),
/** A `MNpx` chunk. */ Mnpx(Vec<map::mnpx::Monster>), /** `medi` chunks. */ Medi(Vec<map::medi::Media>),
/** A `PRpx` chunk. */ Prpx(Vec<map::prpx::Projectile>), /** `plac` chunks. */ Plac(Vec<map::plac::ObjectFreq>),
/** A `PXpx` chunk. */ Pxpx(Vec<map::pxpx::Physics>), /** `plat` chunks. */ Plat(Vec<map::plat::Platform>),
/** A `WPpx` chunk. */ Wppx(Vec<map::wppx::Weapon>), /** `term` chunks. */ Term(Vec<map::term::Terminal>),
/** Unknown chunk. */ Data(ChunkData),
/// Any other type of chunk, which may have arbitrary data in it.
Data{/** The name of the chunk. */ iden: Ident,
/** The data. */ data: Vec<u8>},
} }
// EOF // EOF

View File

@ -1,6 +1,6 @@
//! `Damage` type. //! `Damage` type.
use crate::durandal::{err::*, fixed::Fixed}; use crate::{err::*, fixed::Fixed};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,13 +1,12 @@
//! Wad file entry type. //! Wad file entry type.
use crate::durandal::{bin::usize_from_u32, err::*}; use crate::{bin::usize_from_u32, err::*};
use super::chnk; use super::chnk;
use std::collections::BTreeMap; use std::collections::BTreeMap;
/// Reads all entries in a `Wad`. /// Reads all entries in a `Wad`.
pub fn read(b: &[u8], pub fn read(b: &[u8],
old_wad: bool, old_wad: bool,
old_dat: bool,
siz_app: usize, siz_app: usize,
siz_ent: usize, siz_ent: usize,
siz_cnk: usize) -> ResultS<EntryMap> siz_cnk: usize) -> ResultS<EntryMap>
@ -33,7 +32,7 @@ pub fn read(b: &[u8],
let index = if old_wad {i as u16} else {index}; 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(); let appdata = b[p..p + siz_app].to_vec();
entries.insert(index, Entry{chunks, appdata}); entries.insert(index, Entry{chunks, appdata});
@ -50,7 +49,7 @@ pub fn read(b: &[u8],
pub struct Entry pub struct Entry
{ {
/// All of the chunks in this `Entry`. /// All of the chunks in this `Entry`.
pub chunks: Vec<chnk::Chunk>, pub chunks: Vec<chnk::ChunkData>,
/// The application specific data for this Entry. /// The application specific data for this Entry.
pub appdata: Vec<u8>, pub appdata: Vec<u8>,

View File

@ -1,7 +1,7 @@
//! `Endpoint` type. //! `Endpoint` type.
use super::pnts; use super::pnts;
use crate::durandal::{err::*, fixed::Unit}; use crate::{err::*, fixed::Unit};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads an `EPNT` chunk. /// Reads an `EPNT` chunk.

View File

@ -1,6 +1,6 @@
//! `Effect` type. //! `Effect` type.
use crate::durandal::{bin::OptU16, err::*, fixed::Fixed}; use crate::{bin::OptU16, err::*, fixed::Fixed};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `FXpx` chunk. /// Reads a `FXpx` chunk.

View File

@ -1,6 +1,6 @@
//! `iidx` chunk. //! `iidx` chunk.
use crate::durandal::{bin::u16b, err::*}; use crate::{bin::u16b, err::*};
/// Reads an `iidx` chunk. /// Reads an `iidx` chunk.
pub fn read(b: &[u8]) -> ResultS<(u16, usize)> pub fn read(b: &[u8]) -> ResultS<(u16, usize)>

View File

@ -1,6 +1,6 @@
//! `Line` type. //! `Line` type.
use crate::durandal::{bin::OptU16, err::*}; use crate::{bin::OptU16, err::*};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `LINS` chunk. /// Reads a `LINS` chunk.

View File

@ -1,7 +1,7 @@
//! `Light` type. //! `Light` type.
use super::{ltfn, TICKS_PER_SECOND}; use super::{ltfn, TICKS_PER_SECOND};
use crate::durandal::{err::*, fixed::Fixed}; use crate::{err::*, fixed::Fixed};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `LightFunc` type. //! `LightFunc` type.
use crate::durandal::{err::*, fixed::Fixed}; use crate::{err::*, fixed::Fixed};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Reads a `LightFunc` object. /// Reads a `LightFunc` object.

View File

@ -1,10 +1,10 @@
//! `Light` type. //! `Light` type.
use super::pnts; use super::pnts;
use crate::{durandal::{bin::OptU16, use crate::{bin::OptU16,
err::*, err::*,
fixed::{Angle, Fixed, Unit}}, fixed::{Angle, Fixed, Unit},
marathon::xfer::TransferMode}; xfer::TransferMode};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `Minf` type. //! `Minf` type.
use crate::{durandal::err::*, marathon::text::*}; use crate::{err::*, text::*};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `Minf` chunk. /// Reads a `Minf` chunk.

View File

@ -1,8 +1,6 @@
//! `Monster` type. //! `Monster` type.
use crate::durandal::{bin::OptU16, use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}};
err::*,
fixed::{Fixed, Unit}};
use bitflags::bitflags; use bitflags::bitflags;
use super::{attk, damg}; use super::{attk, damg};

View File

@ -1,6 +1,6 @@
//! `NAME` chunk. //! `NAME` chunk.
use crate::{durandal::err::*, marathon::text::mac_roman_cstr}; use crate::{err::*, text::mac_roman_cstr};
/// Reads a `NAME` chunk. /// Reads a `NAME` chunk.
pub fn read(b: &[u8]) -> ResultS<(String, usize)> pub fn read(b: &[u8]) -> ResultS<(String, usize)>

View File

@ -1,7 +1,7 @@
//! `Note` type. //! `Note` type.
use super::pnts; use super::pnts;
use crate::{durandal::err::*, marathon::text::*}; use crate::{err::*, text::*};
/// Reads a `NOTE` chunk. /// Reads a `NOTE` chunk.
pub fn read(b: &[u8]) -> ResultS<(Note, usize)> pub fn read(b: &[u8]) -> ResultS<(Note, usize)>

View File

@ -1,7 +1,6 @@
//! `Object` type. //! `Object` type.
use crate::durandal::{err::*, use crate::{err::*, fixed::{Angle, Unit}};
fixed::{Angle, Unit}};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads an `OBJS` chunk. /// Reads an `OBJS` chunk.

View File

@ -1,6 +1,6 @@
//! `ObjectFreq` type. //! `ObjectFreq` type.
use crate::durandal::err::*; use crate::err::*;
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `plac` chunk. /// Reads a `plac` chunk.

View File

@ -1,6 +1,6 @@
//! `Platform` type. //! `Platform` type.
use crate::durandal::{err::*, fixed::Unit}; use crate::{err::*, fixed::Unit};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `plat` chunk. /// Reads a `plat` chunk.

View File

@ -1,6 +1,6 @@
//! `Point` type. //! `Point` type.
use crate::durandal::{err::*, fixed::Unit}; use crate::{err::*, fixed::Unit};
/// Reads a `Point` object. /// Reads a `Point` object.
pub fn read_o(b: &[u8]) -> ResultS<Point> pub fn read_o(b: &[u8]) -> ResultS<Point>

View File

@ -1,8 +1,7 @@
//! `Polygon` type. //! `Polygon` type.
use super::pnts; use super::pnts;
use crate::{durandal::{bin::OptU16, err::*, fixed::Unit}, use crate::{bin::OptU16, err::*, fixed::Unit, xfer::TransferMode};
marathon::xfer::TransferMode};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,8 +1,6 @@
//! `Projectile` type. //! `Projectile` type.
use crate::durandal::{bin::OptU16, use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}};
err::*,
fixed::{Fixed, Unit}};
use bitflags::bitflags; use bitflags::bitflags;
use super::damg; use super::damg;

View File

@ -1,6 +1,6 @@
//! `Physics` type. //! `Physics` type.
use crate::durandal::{err::*, fixed::Fixed}; use crate::{err::*, fixed::Fixed};
/// Reads a `PXpx` chunk. /// Reads a `PXpx` chunk.
pub fn read(b: &[u8]) -> ResultS<(Physics, usize)> pub fn read(b: &[u8]) -> ResultS<(Physics, usize)>

View File

@ -1,8 +1,7 @@
//! `Side` type. //! `Side` type.
use super::stex; use super::stex;
use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed}, use crate::{bin::OptU16, err::*, fixed::Fixed, xfer::TransferMode};
marathon::xfer::TransferMode};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! `SideTex` type. //! `SideTex` type.
use crate::durandal::{bin::OptU16, err::*}; use crate::{bin::OptU16, err::*};
use super::pnts; use super::pnts;
/// Reads a `SideTex` object. /// Reads a `SideTex` object.

View File

@ -1,8 +1,7 @@
//! `Terminal` type. //! `Terminal` type.
use super::{trmf, trmg}; use super::{trmf, trmg};
use crate::{durandal::{bin, err::*}, use crate::{bin, err::*, text};
marathon::text};
/// Reads a `term` chunk. /// Reads a `term` chunk.
pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)> pub fn read(b: &[u8]) -> ResultS<(Terminal, usize)>

View File

@ -1,6 +1,6 @@
//! `Monster` type. //! `Monster` type.
use crate::durandal::{bin::OptU16, err::*, fixed::Unit}; use crate::{bin::OptU16, err::*, fixed::Unit};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Reads a `Trigger` object. /// Reads a `Trigger` object.

View File

@ -1,6 +1,6 @@
//! `Face` type. //! `Face` type.
use crate::durandal::err::*; use crate::err::*;
/// Reads a `Face`. /// Reads a `Face`.
pub fn read(b: &[u8]) -> ResultS<(Face, usize)> pub fn read(b: &[u8]) -> ResultS<(Face, usize)>

View File

@ -1,6 +1,6 @@
//! `Group` type. //! `Group` type.
use crate::durandal::err::*; use crate::err::*;
use bitflags::bitflags; use bitflags::bitflags;
/// Reads an `InterGroup`. /// Reads an `InterGroup`.

View File

@ -1,6 +1,6 @@
//! `Weapon` type. //! `Weapon` type.
use crate::durandal::{bin::OptU16, err::*, fixed::Fixed}; use crate::{bin::OptU16, err::*, fixed::Fixed};
use bitflags::bitflags; use bitflags::bitflags;
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -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

View File

@ -6,7 +6,7 @@ pub mod coll;
pub mod fram; pub mod fram;
pub mod sequ; 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. /// Reads a collection at an offset provided by the Shapes header.
pub fn read_coll_at_offset(b: &[u8], pub fn read_coll_at_offset(b: &[u8],

View File

@ -1,6 +1,6 @@
//! Shapes file bitmap type. //! Shapes file bitmap type.
use crate::durandal::{err::*, image::Image}; use crate::{err::*, image::Image};
use super::clut; use super::clut;
use bitflags::bitflags; use bitflags::bitflags;

View File

@ -1,6 +1,6 @@
//! Shapes file color lookup tables. //! 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`. /// Reads a color from a color table into `clut`.
pub fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()> pub fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()>

View File

@ -1,6 +1,6 @@
//! Shapes file collection type. //! 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 super::{bmap, clut, fram, sequ};
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -1,6 +1,6 @@
//! Shapes file frame type. //! Shapes file frame type.
use crate::durandal::{err::*, fixed::*}; use crate::{err::*, fixed::*};
use bitflags::bitflags; use bitflags::bitflags;
/// Reads a `Frame`. /// Reads a `Frame`.

View File

@ -1,8 +1,8 @@
//! Shapes file sequence type. //! Shapes file sequence type.
use crate::{durandal::{bin::OptU16, err::*}, use crate::{bin::OptU16, err::*,
marathon::{text::{mac_roman_conv, pascal_str}, text::{mac_roman_conv, pascal_str},
xfer::TransferMode}}; xfer::TransferMode};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Reads a `Sequence`. /// Reads a `Sequence`.

View File

@ -3,7 +3,7 @@
pub mod defs; pub mod defs;
pub mod snds; pub mod snds;
use crate::durandal::{bin::Ident, err::*}; use crate::{bin::Ident, err::*};
use std::collections::BTreeMap; use std::collections::BTreeMap;
/// Reads all sounds from a Sound file. /// Reads all sounds from a Sound file.

View File

@ -1,9 +1,6 @@
//! Sounds format definition type. //! Sounds format definition type.
use crate::durandal::{bin::{u32b, usize_from_u32}, use crate::{bin::{u32b, usize_from_u32}, err::*, fixed::*, sound::Sound16};
err::*,
fixed::*,
sound::Sound16};
use std::convert::TryFrom; use std::convert::TryFrom;
use bitflags::bitflags; use bitflags::bitflags;

View File

@ -1,6 +1,6 @@
//! Sounds file audio type. //! 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. /// Reads a sound.
pub fn read(b: &[u8]) -> ResultS<Sound16> pub fn read(b: &[u8]) -> ResultS<Sound16>

View File

@ -1,5 +1,7 @@
//! Sound representation. //! Sound representation.
pub mod wav;
/// Any PCM stream which may be represented as a 16-bit PCM stream. /// Any PCM stream which may be represented as a 16-bit PCM stream.
pub trait Sound pub trait Sound
{ {

View File

@ -1,6 +1,6 @@
//! RIFF WAVE format sounds. //! RIFF WAVE format sounds.
use crate::durandal::{err::*, sound::*}; use crate::{err::*, sound::*};
use std::io; use std::io;
/// Writes a WAVE file from a sound. /// Writes a WAVE file from a sound.

View File

@ -5,7 +5,7 @@
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::marathon::text::to_binsize; /// use maraiah::text::to_binsize;
/// ///
/// assert_eq!(to_binsize(5000), "5kB".to_string()); /// assert_eq!(to_binsize(5000), "5kB".to_string());
/// ``` /// ```
@ -57,7 +57,7 @@ pub fn fuck_string(s: &[u8]) -> Vec<u8>
/// # Examples /// # 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"\x0bhello world"), b"hello world"[..].into());
/// assert_eq!(pascal_str(b"\x0chello world"), None); /// assert_eq!(pascal_str(b"\x0chello world"), None);
@ -74,7 +74,7 @@ pub fn pascal_str(b: &[u8]) -> Option<&[u8]>
/// # Examples /// # 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"p\x8cth"), "påth");
/// assert_eq!(mac_roman_conv(b"I\xd5ve"), "Ive"); /// assert_eq!(mac_roman_conv(b"I\xd5ve"), "Ive");
@ -101,7 +101,7 @@ pub fn mac_roman_conv(s: &[u8]) -> String
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use maraiah::marathon::text::mac_roman_cstr; /// use maraiah::text::mac_roman_cstr;
/// ///
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed"), "Ive awaken"); /// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0ed"), "Ive awaken");
/// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "Ive awaken"); /// assert_eq!(mac_roman_cstr(b"I\xd5ve awaken\0"), "Ive awaken");
@ -122,7 +122,7 @@ pub fn mac_roman_cstr(s: &[u8]) -> String
/// # Examples /// # 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("påth"), b"p\x8cth".to_vec());
/// assert_eq!(to_mac_roman("Ive\n"), b"I\xd5ve\r".to_vec()); /// assert_eq!(to_mac_roman("Ive\n"), b"I\xd5ve\r".to_vec());
@ -155,7 +155,7 @@ pub fn to_mac_roman(s: &str) -> Vec<u8>
/// # Examples /// # 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"); /// let s = to_mac_roman("påth");
/// ///

View File

@ -1,4 +1,4 @@
use maraiah::marathon::defl; use maraiah::defl;
include!("data/rand.rs"); include!("data/rand.rs");

View File

@ -1,5 +1,4 @@
use maraiah::{durandal::{bin, fixed::*}, use maraiah::{bin, fixed::*, map};
marathon::map};
include!("data/rand.rs"); include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::marathon::machdr; use maraiah::machdr;
include!("data/rand.rs"); include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::{durandal::image::Color8, marathon::pict}; use maraiah::{image::{Color8, pict}};
include!("data/rand.rs"); include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::marathon::shp; use maraiah::shp;
include!("data/rand.rs"); include!("data/rand.rs");

View File

@ -1,4 +1,4 @@
use maraiah::marathon::snd; use maraiah::snd;
include!("data/rand.rs"); include!("data/rand.rs");