Add document

This commit is contained in:
2025-08-10 16:58:44 +08:00
parent f602ddb4b5
commit cfc1dbf507
43 changed files with 516 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
//! Basic types
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@@ -26,6 +27,7 @@ impl Default for Encoding {
}
impl Encoding {
/// Returns true if the encoding is Shift-JIS (CP932).
pub fn is_jis(&self) -> bool {
match self {
Self::Cp932 => true,
@@ -37,7 +39,7 @@ impl Encoding {
}
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// Text Encoding
/// Text Encoding (for CLI)
pub enum TextEncoding {
/// Use script's default encoding
Default,
@@ -67,12 +69,14 @@ pub enum OutputScriptType {
}
impl OutputScriptType {
/// Returns true if the script type is custom.
pub fn is_custom(&self) -> bool {
matches!(self, OutputScriptType::Custom)
}
}
impl AsRef<str> for OutputScriptType {
/// Returns the extension for the script type.
fn as_ref(&self) -> &str {
match self {
OutputScriptType::M3t => "m3t",
@@ -85,6 +89,7 @@ impl AsRef<str> for OutputScriptType {
#[cfg(feature = "circus")]
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// Circus MES game
pub enum CircusMesType {
/// fortissimo//Akkord:Bsusvier
Ffexa,
@@ -152,6 +157,7 @@ pub enum CircusMesType {
#[cfg(feature = "circus")]
impl AsRef<str> for CircusMesType {
/// Returns the name.
fn as_ref(&self) -> &str {
match self {
CircusMesType::Ffexa => "ffexa",
@@ -189,84 +195,133 @@ impl AsRef<str> for CircusMesType {
}
}
/// Extra configuration options for the script.
#[derive(Debug, Clone, Default)]
pub struct ExtraConfig {
#[cfg(feature = "circus")]
/// Circus Game for circus MES script.
pub circus_mes_type: Option<CircusMesType>,
#[cfg(feature = "escude-arc")]
/// Whether to use fake compression for Escude archive
pub escude_fake_compress: bool,
#[cfg(feature = "escude")]
/// The path to the Escude enum script file (enum_scr.bin)
pub escude_enum_scr: Option<String>,
#[cfg(feature = "bgi")]
/// Duplicate same strings when importing into BGI scripts.
/// Enable this will cause BGI scripts to become very large.
pub bgi_import_duplicate: bool,
#[cfg(feature = "bgi")]
/// Disable appending new strings to the end of BGI scripts.
/// Disable may cause BGI scripts broken.
pub bgi_disable_append: bool,
#[cfg(feature = "image")]
/// Output image type
pub image_type: Option<ImageOutputType>,
#[cfg(all(feature = "bgi-arc", feature = "bgi-img"))]
/// Detect all files in BGI archive as SysGrp Images. By default, only files which name is `sysgrp.arc` will enabled this.
pub bgi_is_sysgrp_arc: Option<bool>,
#[cfg(feature = "bgi-img")]
/// Whether to create scrambled SysGrp images. When in import mode, the default value depends on the original image.
/// When in creation mode, it is not enabled by default.
pub bgi_img_scramble: Option<bool>,
#[cfg(feature = "cat-system-arc")]
/// CatSystem2 engine int archive password
pub cat_system_int_encrypt_password: Option<String>,
#[cfg(feature = "cat-system-img")]
/// Draw CatSystem2 image on canvas (if canvas width and height are specified in file)
pub cat_system_image_canvas: bool,
#[cfg(feature = "kirikiri")]
/// Kirikiri language index in script. If not specified, the first language will be used.
pub kirikiri_language_index: Option<usize>,
#[cfg(feature = "kirikiri")]
/// Export COMU message to extra json file. (for Kirikiri SCN script.)
/// Only CIRCUS's game have COMU message.
pub kirikiri_export_comumode: bool,
#[cfg(feature = "kirikiri")]
/// Kirikiri COMU message translation. key is original text, value is translated text.
pub kirikiri_comumode_json: Option<std::sync::Arc<HashMap<String, String>>>,
#[cfg(feature = "kirikiri")]
/// Remove empty lines in Kirikiri KS script.
pub kirikiri_remove_empty_lines: bool,
#[cfg(feature = "kirikiri")]
/// Kirikiri name commands, used to extract names from ks script.
pub kirikiri_name_commands: std::sync::Arc<std::collections::HashSet<String>>,
#[cfg(feature = "kirikiri")]
/// Kirikiri message commands, used to extract more message from ks script.
pub kirikiri_message_commands: std::sync::Arc<std::collections::HashSet<String>>,
#[cfg(feature = "bgi-arc")]
/// Whether to compress files in BGI archive when packing BGI archive.
pub bgi_compress_file: bool,
#[cfg(feature = "bgi-arc")]
/// Minimum length of match size for DSC compression. Possible values are 2-256.
pub bgi_compress_min_len: usize,
#[cfg(feature = "kirikiri-img")]
/// Whether to overlay PIMG images. (By default, true if all layers are not group layers.)
pub kirikiri_pimg_overlay: Option<bool>,
#[cfg(feature = "artemis-arc")]
/// Disable Artemis archive (.pfs) XOR encryption when packing.
pub artemis_arc_disable_xor: bool,
#[cfg(feature = "artemis")]
/// Artemis script indent size, used to format Artemis script.
/// Default is 4 spaces.
pub artemis_indent: Option<usize>,
#[cfg(feature = "artemis")]
/// Disable Artemis script indent, used to format Artemis script.
pub artemis_no_indent: bool,
#[cfg(feature = "artemis")]
/// Max line width in Artemis script, used to format Artemis script.
pub artemis_max_line_width: usize,
#[cfg(feature = "artemis")]
/// Specify the language of Artemis AST script.
/// If not specified, the first language will be used.
pub artemis_ast_lang: Option<String>,
#[cfg(feature = "cat-system")]
/// CatSystem2 CSTL script language, used to extract messages from CSTL script.
/// If not specified, the first language will be used.
pub cat_system_cstl_lang: Option<String>,
#[cfg(feature = "flate2")]
/// Zlib compression level. 0 means no compression, 9 means best compression.
pub zlib_compression_level: u32,
#[cfg(feature = "image")]
/// PNG compression level.
pub png_compression_level: PngCompressionLevel,
#[cfg(feature = "circus-img")]
/// Keep original BPP when importing Circus CRX images.
pub circus_crx_keep_original_bpp: bool,
#[cfg(feature = "circus-img")]
/// Use zstd compression for Circus CRX images. (CIRCUS Engine don't support this. Hook is required.)
pub circus_crx_zstd: bool,
#[cfg(feature = "zstd")]
/// Zstd compression level. 0 means default compression level (3), 22 means best compression.
pub zstd_compression_level: i32,
#[cfg(feature = "circus-img")]
/// Circus CRX image row type mode
pub circus_crx_mode: crate::scripts::circus::image::crx::CircusCrxMode,
#[cfg(feature = "ex-hibit")]
/// ExHibit xor key for rld script.
/// Use [ReExHIBIT](https://github.com/ZQF-ReVN/RxExHIBIT) to find the key.
pub ex_hibit_rld_xor_key: Option<u32>,
#[cfg(feature = "ex-hibit")]
/// ExHibit def.rld xor key.
pub ex_hibit_rld_def_xor_key: Option<u32>,
#[cfg(feature = "ex-hibit")]
/// ExHibit rld xor keys.
pub ex_hibit_rld_keys: Option<Box<[u32; 0x100]>>,
#[cfg(feature = "ex-hibit")]
/// ExHibit def.rld xor keys.
pub ex_hibit_rld_def_keys: Option<Box<[u32; 0x100]>>,
#[cfg(feature = "mozjpeg")]
/// JPEG quality for output images, 0-100. 100 means best quality.
pub jpeg_quality: u8,
#[cfg(feature = "webp")]
/// Use WebP lossless compression for output images.
pub webp_lossless: bool,
#[cfg(feature = "webp")]
/// WebP quality for output images, 0-100. 100 means best quality.
pub webp_quality: u8,
#[cfg(feature = "circus-img")]
/// Draw Circus CRX images on canvas (if canvas width and height are specified in file)
pub circus_crx_canvas: bool,
}
@@ -409,25 +464,33 @@ pub enum ScriptType {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
/// Message structure for scripts
pub struct Message {
#[serde(skip_serializing_if = "Option::is_none")]
/// Optional name for the message, used in some scripts.
pub name: Option<String>,
/// The actual message content.
pub message: String,
}
impl Message {
/// Creates a new `Message` instance.
pub fn new(message: String, name: Option<String>) -> Self {
Message { message, name }
}
}
/// Result of script operation.
pub enum ScriptResult {
/// Operation completed successfully.
Ok,
/// Operation completed without any changes.
/// For example, no messages found in the script.
Ignored,
}
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// Format type
/// Format type (for CLI)
pub enum FormatType {
/// Wrap line with fixed length
Fixed,
@@ -449,33 +512,46 @@ pub enum FormatOptions {
}
#[derive(Debug, Serialize, Deserialize)]
/// Name table cell
pub struct NameTableCell {
#[serde(rename = "JP_Name")]
/// Original name
pub jp_name: String,
#[serde(rename = "CN_Name")]
/// Translated name
pub cn_name: String,
#[serde(rename = "Count")]
/// Number of times this name appears in the script
pub count: usize,
}
#[derive(Debug, Serialize, Deserialize)]
/// Replacement table for string replacements
pub struct ReplacementTable {
#[serde(flatten)]
/// Map of original strings to their replacements
pub map: HashMap<String, String>,
}
#[cfg(feature = "image")]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
/// Image color type
pub enum ImageColorType {
/// Grayscale image
Grayscale,
/// RGB image
Rgb,
/// RGBA image
Rgba,
/// BGR image
Bgr,
/// BGRA image
Bgra,
}
#[cfg(feature = "image")]
impl ImageColorType {
/// Returns the number of bytes per pixel for the color type and depth.
pub fn bpp(&self, depth: u8) -> u16 {
match self {
ImageColorType::Grayscale => depth as u16,
@@ -489,11 +565,15 @@ impl ImageColorType {
#[cfg(feature = "image")]
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// Image output type
pub enum ImageOutputType {
/// PNG image
Png,
#[cfg(feature = "image-jpg")]
/// JPEG image
Jpg,
#[cfg(feature = "image-webp")]
/// WebP image
Webp,
}
@@ -532,6 +612,7 @@ impl TryFrom<&std::path::Path> for ImageOutputType {
#[cfg(feature = "image")]
impl AsRef<str> for ImageOutputType {
/// Returns the extension for the image output type.
fn as_ref(&self) -> &str {
match self {
ImageOutputType::Png => "png",
@@ -545,30 +626,45 @@ impl AsRef<str> for ImageOutputType {
#[cfg(feature = "image")]
#[derive(Clone, Debug)]
/// Image data
pub struct ImageData {
/// Image width in pixels
pub width: u32,
/// Image height in pixels
pub height: u32,
/// Image color type
pub color_type: ImageColorType,
/// Image depth in bits per channel
pub depth: u8,
/// Image data
pub data: Vec<u8>,
}
#[cfg(feature = "image")]
#[derive(Clone, Debug)]
/// Image data with name
pub struct ImageDataWithName {
/// Image name
pub name: String,
/// Image data
pub data: ImageData,
}
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// BOM type
pub enum BomType {
/// No BOM
None,
/// UTF-8 BOM
Utf8,
/// UTF-16 Little Endian BOM
Utf16LE,
/// UTF-16 Big Endian BOM
Utf16BE,
}
impl BomType {
/// Returns the byte sequence for the BOM type.
pub fn as_bytes(&self) -> &'static [u8] {
match self {
BomType::None => &[],
@@ -581,6 +677,7 @@ impl BomType {
#[cfg(feature = "image")]
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// PNG compression level
pub enum PngCompressionLevel {
#[value(alias = "d")]
/// Default level
@@ -597,8 +694,16 @@ pub enum PngCompressionLevel {
Best,
}
#[cfg(feature = "image")]
impl Default for PngCompressionLevel {
fn default() -> Self {
PngCompressionLevel::Default
}
}
#[cfg(feature = "image")]
impl PngCompressionLevel {
/// Converts the [PngCompressionLevel] to a [png::Compression] enum.
pub fn to_compression(&self) -> png::Compression {
match self {
PngCompressionLevel::Default => png::Compression::Default,