diff --git a/src/lib.rs b/src/lib.rs index 01dcf50..9465702 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,3 +11,8 @@ pub mod utils; lazy_static::lazy_static! { static ref COUNTER: utils::counter::Counter = utils::counter::Counter::new(); } + +/// Returns a reference to the global counter instance. +pub fn get_counter() -> &'static utils::counter::Counter { + &COUNTER +} diff --git a/src/scripts/circus/archive/crm.rs b/src/scripts/circus/archive/crm.rs index d8d69bc..d44b4ac 100644 --- a/src/scripts/circus/archive/crm.rs +++ b/src/scripts/circus/archive/crm.rs @@ -1,3 +1,4 @@ +//! Circus Image Archive File (.crm) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -7,9 +8,11 @@ use std::io::{Read, Seek, SeekFrom}; use std::sync::{Arc, Mutex}; #[derive(Debug)] +/// Circus CRM Archive Builder pub struct CrmArchiveBuilder {} impl CrmArchiveBuilder { + /// Creates a new instance of `CrmArchiveBuilder`. pub fn new() -> Self { Self {} } @@ -178,12 +181,18 @@ impl Seek for Entry { } #[derive(Debug)] +/// Circus CRM Archive pub struct CrmArchive { reader: Arc>, entries: Vec, } impl CrmArchive { + /// Creates a new `CrmArchive` from a reader. + /// + /// * `reader` - The reader to read the CRM archive from. + /// * `encoding` - The encoding to use for string fields. + /// * `config` - Extra configuration options. pub fn new(mut reader: T, encoding: Encoding, _config: &ExtraConfig) -> Result { let mut magic = [0u8; 4]; reader.read_exact(&mut magic)?; diff --git a/src/scripts/circus/archive/dat.rs b/src/scripts/circus/archive/dat.rs index d6f4bcb..ff997d1 100644 --- a/src/scripts/circus/archive/dat.rs +++ b/src/scripts/circus/archive/dat.rs @@ -1,3 +1,4 @@ +//! Circus Archive File (.dat) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -6,9 +7,11 @@ use std::io::{Read, Seek, SeekFrom}; use std::sync::{Arc, Mutex}; #[derive(Debug)] +/// Circus DAT Archive Builder pub struct DatArchiveBuilder {} impl DatArchiveBuilder { + /// Creates a new instance of `DatArchiveBuilder`. pub fn new() -> Self { Self {} } @@ -174,11 +177,14 @@ impl Seek for Entry { } #[derive(Debug)] +/// Extra information for the DAT archive. pub struct DatExtraInfo { + /// Maximum length of file names in the DAT archive. pub name_len: usize, } #[derive(Debug)] +/// Circus DAT Archive pub struct DatArchive { reader: Arc>, entries: Vec, @@ -188,6 +194,11 @@ pub struct DatArchive { const NAME_LEN: [usize; 3] = [0x24, 0x30, 0x3C]; impl DatArchive { + /// Creates a new `DatArchive` from a reader. + /// + /// * `reader` - The reader to read the DAT archive from. + /// * `encoding` - The encoding to use for string fields. + /// * `config` - Extra configuration options. pub fn new(mut reader: T, encoding: Encoding, _config: &ExtraConfig) -> Result { let (name_len, entries) = Self::read_all_index(&mut reader, encoding)?; let reader = Arc::new(Mutex::new(reader)); @@ -365,6 +376,9 @@ fn is_this_format_name_len(buf: &[u8], name_len: usize) -> Result { Ok(score) } +/// Checks if the buffer is a valid DAT archive format. +/// +/// * `buf` - The buffer to check. pub fn is_this_format(buf: &[u8]) -> Result { for &name_len in &NAME_LEN { match is_this_format_name_len(buf, name_len) { diff --git a/src/scripts/circus/archive/mod.rs b/src/scripts/circus/archive/mod.rs index 6af54e9..055e566 100644 --- a/src/scripts/circus/archive/mod.rs +++ b/src/scripts/circus/archive/mod.rs @@ -1,3 +1,4 @@ +//! Circus Archive pub mod crm; pub mod dat; pub mod pck; diff --git a/src/scripts/circus/archive/pck.rs b/src/scripts/circus/archive/pck.rs index 9ff1c5c..6ee3092 100644 --- a/src/scripts/circus/archive/pck.rs +++ b/src/scripts/circus/archive/pck.rs @@ -1,3 +1,4 @@ +//! Circus Archive File (.pck/.dat) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -10,9 +11,11 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::sync::{Arc, Mutex}; #[derive(Debug)] +/// Circus PCK Archive Builder pub struct PckArchiveBuilder {} impl PckArchiveBuilder { + /// Creates a new instance of `PckArchiveBuilder`. pub const fn new() -> Self { Self {} } @@ -193,12 +196,18 @@ impl Seek for Entry { } #[derive(Debug)] +/// PCK Archive pub struct PckArchive { reader: Arc>, entries: Vec, } impl PckArchive { + /// Creates a new `PckArchive` from a reader. + /// + /// * `reader` - The reader to read the PCK archive from. + /// * `archive_encoding` - The encoding to use for string fields in the archive. + /// * `config` - Extra configuration options. pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { let file_count = reader.read_u32()?; // (offset, size) @@ -315,6 +324,7 @@ fn detect_script_type(_buf: &[u8], _buf_len: usize, _filename: &str) -> Option { writer: T, headers: HashMap, @@ -322,6 +332,12 @@ pub struct PckArchiveWriter { } impl PckArchiveWriter { + /// Creates a new `PckArchiveWriter` for writing a PCK archive. + /// + /// * `writer` - The writer to write the PCK archive to. + /// * `files` - A list of file names to include in the archive. + /// * `encoding` - The encoding to use for string fields in the archive. + /// * `config` - Extra configuration options. pub fn new( mut writer: T, files: &[&str], @@ -386,6 +402,7 @@ impl Archive for PckArchiveWriter { } } +/// PCK Archive File pub struct PckArchiveFile<'a, T: Write + Seek> { header: &'a mut PckFileHeader, writer: &'a mut T, @@ -443,6 +460,7 @@ impl<'a, T: Write + Seek> Seek for PckArchiveFile<'a, T> { } } +/// Checks if the buffer is a valid PCK archive format. pub fn is_this_format(buf: &[u8]) -> Result { let mut reader = MemReaderRef::new(buf); let count = reader.read_u32()? as usize; diff --git a/src/scripts/circus/audio/mod.rs b/src/scripts/circus/audio/mod.rs index fac9bf7..47d7089 100644 --- a/src/scripts/circus/audio/mod.rs +++ b/src/scripts/circus/audio/mod.rs @@ -1 +1,2 @@ +//! Circus Audio pub mod pcm; diff --git a/src/scripts/circus/audio/pcm.rs b/src/scripts/circus/audio/pcm.rs index 5eca444..75b8d38 100644 --- a/src/scripts/circus/audio/pcm.rs +++ b/src/scripts/circus/audio/pcm.rs @@ -1,3 +1,4 @@ +//! Circus Audio File (.pcm) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -10,9 +11,11 @@ use overf::wrapping; use std::io::{Read, Seek, Write}; #[derive(Debug)] +/// Circus PCM Builder pub struct PcmBuilder {} impl PcmBuilder { + /// Creates a new instance of `PcmBuilder`. pub fn new() -> Self { Self {} } @@ -110,12 +113,17 @@ impl Header { } #[derive(Debug)] +/// Circus PCM Script pub struct Pcm { header: Header, data: MemReader, } impl Pcm { + /// Creates a new `Pcm` instance from a reader and configuration. + /// + /// * `reader` - The reader to read the PCM data from. + /// * `config` - Extra configuration options. pub fn new(mut reader: R, _config: &ExtraConfig) -> Result { let mut magic = [0u8; 4]; reader.read_exact(&mut magic)?; diff --git a/src/scripts/circus/image/crx.rs b/src/scripts/circus/image/crx.rs index a2bcc68..6ebd9db 100644 --- a/src/scripts/circus/image/crx.rs +++ b/src/scripts/circus/image/crx.rs @@ -1,3 +1,4 @@ +//! Circus Image File (.crx) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -11,10 +12,15 @@ use overf::wrapping; use std::io::{Read, Seek, Write}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] +/// Circus CRX Row Encoding Mode pub enum CircusCrxMode { + /// Encoding all rows with a fixed type. Fixed(u8), + /// When importing, use origin mode; when creating, use best mode. Auto, + /// Use origin mode for importing; when creating, fallback to best mode. Origin, + /// Try to use the best mode for encoding. Best, } @@ -25,6 +31,7 @@ impl Default for CircusCrxMode { } impl CircusCrxMode { + /// Returns mode for importing. pub fn for_importing(&self) -> Self { match self { CircusCrxMode::Auto => CircusCrxMode::Origin, @@ -32,6 +39,7 @@ impl CircusCrxMode { } } + /// Returns mode for creating. pub fn for_creating(&self) -> Self { match self { CircusCrxMode::Auto => CircusCrxMode::Best, @@ -40,10 +48,12 @@ impl CircusCrxMode { } } + /// Checks if the mode is best. pub fn is_best(&self) -> bool { matches!(self, CircusCrxMode::Best) } + /// Checks if the mode is origin. pub fn is_origin(&self) -> bool { matches!(self, CircusCrxMode::Origin) } @@ -81,9 +91,11 @@ impl ValueEnum for CircusCrxMode { } #[derive(Debug)] +/// Circus CRX Image Builder pub struct CrxImageBuilder {} impl CrxImageBuilder { + /// Creates a new instance of `CrxImageBuilder`. pub const fn new() -> Self { CrxImageBuilder {} } @@ -166,6 +178,7 @@ struct Header { clips: Vec, } +/// Circus CRX Image pub struct CrxImage { header: Header, color_type: ImageColorType, @@ -189,6 +202,10 @@ impl std::fmt::Debug for CrxImage { } impl CrxImage { + /// Creates a new `CrxImage` from the given data and configuration. + /// + /// * `data` - The reader to read the CRX image from. + /// * `config` - Extra configuration options. pub fn new(data: T, config: &ExtraConfig) -> Result { let mut reader = data; let mut magic = [0; 4]; @@ -241,11 +258,15 @@ impl CrxImage { }) } + /// Whether to draw image on canvas if canvas's width and height are specified in image. pub fn with_canvas(mut self, canvas: bool) -> Self { self.canvas = canvas; self } + /// Draws another image on this image. + /// + /// Returns a new `ImageData` with the combined image. pub fn draw_diff(&self, diff: &Self) -> Result { let base_header = &self.header; let diff_header = &diff.header; @@ -703,6 +724,11 @@ impl CrxImage { Ok(dst) } + /// Creates a CRX image file from the given image data and writes it to the specified writer. + /// + /// * `data` - The input image data. + /// * `writer` - The writer to write the CRX image to. + /// * `config` - Extra configuration options. pub fn create_image( mut data: ImageData, mut writer: T, diff --git a/src/scripts/circus/image/crxd.rs b/src/scripts/circus/image/crxd.rs index e68137b..070c76f 100644 --- a/src/scripts/circus/image/crxd.rs +++ b/src/scripts/circus/image/crxd.rs @@ -1,3 +1,4 @@ +//! Circus Differential Image File (.crx) use super::crx::CrxImage; use crate::ext::io::*; use crate::scripts::base::*; @@ -6,9 +7,11 @@ use anyhow::Result; use std::io::{Read, Seek}; #[derive(Debug)] +/// Circus CRXD Image Builder pub struct CrxdImageBuilder {} impl CrxdImageBuilder { + /// Creates a new instance of `CrxdImageBuilder`. pub fn new() -> Self { Self {} } @@ -58,12 +61,20 @@ impl ScriptBuilder for CrxdImageBuilder { } #[derive(Debug)] +/// Circus CRXD Image pub struct CrxdImage { base: CrxImage, diff: CrxImage, } impl CrxdImage { + /// Creates a new `CrxdImage` from the given data and configuration. + /// + /// * `data` - The reader to read the CRXD image from. + /// * `filename` - The name of the file to read. + /// * `encoding` - The encoding to use for string fields. + /// * `config` - Extra configuration options. + /// * `archive` - Optional archive to read the image from. pub fn new( data: T, filename: &str, diff --git a/src/scripts/circus/image/mod.rs b/src/scripts/circus/image/mod.rs index 292923c..20caf31 100644 --- a/src/scripts/circus/image/mod.rs +++ b/src/scripts/circus/image/mod.rs @@ -1,2 +1,3 @@ +//! Circus Image pub mod crx; pub mod crxd; diff --git a/src/scripts/circus/mod.rs b/src/scripts/circus/mod.rs index 98c00ff..7ff273d 100644 --- a/src/scripts/circus/mod.rs +++ b/src/scripts/circus/mod.rs @@ -1,3 +1,4 @@ +//! Circus Scripts #[cfg(feature = "circus-arc")] pub mod archive; #[cfg(feature = "circus-audio")] diff --git a/src/scripts/circus/script.rs b/src/scripts/circus/script.rs index 39bccf6..cc2323d 100644 --- a/src/scripts/circus/script.rs +++ b/src/scripts/circus/script.rs @@ -1,3 +1,4 @@ +//! Circus Script File (.mes) use super::info::*; use crate::scripts::base::*; use crate::types::*; @@ -5,9 +6,11 @@ use crate::utils::encoding::{decode_to_string, encode_string}; use anyhow::Result; #[derive(Debug)] +/// Circus MES Script Builder pub struct CircusMesScriptBuilder {} impl CircusMesScriptBuilder { + /// Creates a new instance of `CircusMesScriptBuilder`. pub const fn new() -> Self { CircusMesScriptBuilder {} } @@ -46,6 +49,7 @@ struct Token { value: u8, } +/// Circus MES Script pub struct CircusMesScript { data: Vec, encoding: Encoding, @@ -58,6 +62,11 @@ pub struct CircusMesScript { } impl CircusMesScript { + /// Creates a new `CircusMesScript` from the given data and configuration. + /// + /// * `data` - The data to read the MES script from. + /// * `encoding` - The encoding to use for string fields. + /// * `config` - Extra configuration options. pub fn new(data: Vec, encoding: Encoding, config: &ExtraConfig) -> Result { let head0 = i32::from_le_bytes(data[0..4].try_into()?); let head1 = i32::from_le_bytes(data[4..8].try_into()?);