Skip to main content

rgpre/import/
mod.rs

1/// Parser for Deluxe Paint LPF animations.
2pub mod anm;
3/// Parser for BSI/TEXBSI image archives.
4pub mod bsi;
5pub mod cdrom;
6/// Parser for REDGUARD.CHT cheat persistence files.
7pub mod cht;
8/// Typed COMBAT.INI attacks, defenses, and taunts.
9pub mod combat_ini;
10/// Reader and writer for REDGUARD.CPF console preferences.
11pub mod cpf;
12/// Parser for FNT bitmap font files.
13pub mod fnt;
14/// Export helpers for FNT assets.
15pub mod fnt_export;
16/// FNT to TrueType font conversion.
17pub mod fnt_ttf;
18/// Parser for Glide FOG.INI density tables.
19pub mod fog_ini;
20/// Extract authored splash data from the installed Glide overlay.
21pub mod glide_splash;
22/// Extract authored splash data from the installed Windows Glide DLL.
23pub mod glide_splash_dll;
24/// Parser for GXA bitmap archives.
25pub mod gxa;
26/// Shared indexed bitmap representation.
27pub mod indexed_image;
28mod ini;
29/// Typed ITEM.INI inventory settings and item definitions.
30pub mod item_ini;
31/// Parser for KEYS.INI player keyboard bindings.
32pub mod keys_ini;
33/// Parser for IFF PBM bitmaps.
34pub mod lbm;
35pub mod menu_ini;
36pub mod menu_movies;
37pub mod menu_settings;
38/// Parser for 3D and 3DC model files.
39pub mod model3d;
40/// Parser for COL palette files.
41pub mod palette;
42/// Export helpers for COL palette assets.
43pub mod palette_export;
44/// Parser for 8-bit PCX images.
45pub mod pcx;
46pub mod player_ini;
47/// Shared PNG save helper with compression control.
48pub mod png;
49/// Parser for PVO octree collision files.
50pub mod pvo;
51/// Asset registry and directory scanning helpers.
52pub mod registry;
53/// Parser and model extraction for RGM scene files.
54pub mod rgm;
55/// Parser and model extraction for ROB archives.
56pub mod rob;
57/// Parser for RTX dialogue/audio container files.
58pub mod rtx;
59/// Read-only SAV/TSG containers and save-slot loading.
60pub mod savegame;
61/// Parser for SFX sound effect files.
62pub mod sfx;
63pub mod smacker;
64pub mod software_texture;
65pub mod soup_def;
66pub mod soup_ini;
67pub mod surface_ini;
68/// Typed SYSTEM.INI engine configuration.
69pub mod system_ini;
70/// Parser and export helpers for WLD world files.
71pub mod wld;
72/// Parser for WORLD.INI world/level database.
73pub mod world_ini;
74
75use std::path::Path;
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, clap::ValueEnum)]
78/// Supported Redguard file types recognized by this crate.
79pub enum FileType {
80    Texture,
81    Shade,
82    Haze,
83    Bsi,      // .bsi
84    Cht,      // .cht
85    Col,      // .col
86    Model3d,  // .3d
87    Model3dc, // .3dc
88    Rob,      // .rob
89    Rgm,      // .rgm
90    Pvo,      // .pvo
91    Wld,      // .wld
92    Fnt,      // .fnt
93    Gxa,      // .gxa
94    Sfx,      // .sfx
95    Rtx,      // .rtx
96    Pcx,      // .pcx
97    Lbm,      // .lbm
98    Anm,      // .anm
99}
100
101const ALL_FILE_TYPES: [FileType; 19] = [
102    FileType::Texture,
103    FileType::Shade,
104    FileType::Haze,
105    FileType::Bsi,
106    FileType::Cht,
107    FileType::Col,
108    FileType::Model3d,
109    FileType::Model3dc,
110    FileType::Rob,
111    FileType::Rgm,
112    FileType::Pvo,
113    FileType::Wld,
114    FileType::Fnt,
115    FileType::Gxa,
116    FileType::Sfx,
117    FileType::Rtx,
118    FileType::Pcx,
119    FileType::Lbm,
120    FileType::Anm,
121];
122
123impl FileType {
124    #[must_use]
125    pub const fn all() -> &'static [Self] {
126        &ALL_FILE_TYPES
127    }
128
129    #[must_use]
130    pub const fn display_name(self) -> &'static str {
131        match self {
132            Self::Texture => "Software Texture",
133            Self::Shade => "Shade Lookup",
134            Self::Haze => "Haze Lookup",
135            Self::Bsi => "Texture BSI",
136            Self::Cht => "Cheat States",
137            Self::Col => "Palette",
138            Self::Model3d => "Model",
139            Self::Model3dc => "Animated Model",
140            Self::Rob => "ROB World",
141            Self::Rgm => "Map Data",
142            Self::Pvo => "PVO Data",
143            Self::Wld => "World Geometry",
144            Self::Fnt => "Font",
145            Self::Gxa => "GXA Bitmap",
146            Self::Sfx => "Sound Effects",
147            Self::Rtx => "Dialogue Audio",
148            Self::Pcx => "PCX Image",
149            Self::Lbm => "IFF Bitmap",
150            Self::Anm => "Deluxe Paint Animation",
151        }
152    }
153
154    #[must_use]
155    pub const fn extensions(self) -> &'static [&'static str] {
156        match self {
157            Self::Texture => &[".texture"],
158            Self::Shade => &[".shade"],
159            Self::Haze => &[".haze"],
160            Self::Bsi => &[".bsi"],
161            Self::Cht => &[".cht"],
162            Self::Col => &[".col"],
163            Self::Model3d => &[".3d"],
164            Self::Model3dc => &[".3dc"],
165            Self::Rob => &[".rob"],
166            Self::Rgm => &[".rgm"],
167            Self::Pvo => &[".pvo"],
168            Self::Wld => &[".wld"],
169            Self::Fnt => &[".fnt"],
170            Self::Gxa => &[".gxa"],
171            Self::Sfx => &[".sfx"],
172            Self::Rtx => &[".rtx"],
173            Self::Pcx => &[".pcx"],
174            Self::Lbm => &[".lbm"],
175            Self::Anm => &[".anm"],
176        }
177    }
178
179    /// Matches a bare extension string (case-insensitive, without leading dot).
180    #[must_use]
181    pub fn from_extension(ext: &str) -> Option<Self> {
182        let lower = ext.to_ascii_lowercase();
183        Self::all().iter().copied().find(|ft| {
184            ft.extensions()
185                .iter()
186                .any(|e| e.trim_start_matches('.') == lower)
187        })
188    }
189
190    /// Detects a supported Redguard file type from path extension or filename stem.
191    pub fn from_path<P: AsRef<Path>>(path: P) -> Option<Self> {
192        let p = path.as_ref();
193        if let Some(ext) = p.extension().and_then(|e| e.to_str())
194            && let Some(ft) = Self::from_extension(ext)
195        {
196            return Some(ft);
197        }
198        let stem = p.file_stem()?.to_str()?.to_ascii_uppercase();
199        match stem.as_str() {
200            "TEXBSI" => Some(Self::Bsi),
201            "TEXTURE" => Some(Self::Texture),
202            "SHADE" => Some(Self::Shade),
203            "HAZE" => Some(Self::Haze),
204            _ => None,
205        }
206    }
207}
208
209impl std::str::FromStr for FileType {
210    type Err = String;
211
212    fn from_str(s: &str) -> Result<Self, Self::Err> {
213        Self::from_extension(s.trim()).ok_or_else(|| {
214            let supported = Self::all()
215                .iter()
216                .flat_map(|ft| {
217                    ft.extensions()
218                        .iter()
219                        .map(|ext| ext.trim_start_matches('.').to_string())
220                })
221                .collect::<Vec<_>>()
222                .join(", ");
223            format!("Unknown file type: {s}. Supported types: {supported}")
224        })
225    }
226}
227
228/// Original terrain lighting configuration.
229pub mod world_lighting;