use std::path::PathBuf;
pub type Gr2ExtractionProgressCallback<'a> = &'a (dyn Fn(&Gr2ExtractionProgress) + Sync + Send);
#[derive(Debug, Clone)]
pub struct Gr2ExtractionProgress {
pub phase: Gr2ExtractionPhase,
pub current: usize,
pub total: usize,
pub current_file: Option<String>,
}
impl Gr2ExtractionProgress {
#[must_use]
pub fn new(phase: Gr2ExtractionPhase, current: usize, total: usize) -> Self {
Self {
phase,
current,
total,
current_file: None,
}
}
#[must_use]
pub fn with_file(
phase: Gr2ExtractionPhase,
current: usize,
total: usize,
file: impl Into<String>,
) -> Self {
Self {
phase,
current,
total,
current_file: Some(file.into()),
}
}
#[must_use]
pub fn percentage(&self) -> f32 {
if self.total == 0 {
1.0
} else {
self.current as f32 / self.total as f32
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Gr2ExtractionPhase {
ConvertingGr2,
BuildingDatabase,
LookingUpTextures,
ExtractingDdsTextures,
ExtractingVirtualTextures,
ConvertingToPng,
Complete,
}
impl Gr2ExtractionPhase {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::ConvertingGr2 => "Converting GR2 to GLB",
Self::BuildingDatabase => "Building texture database",
Self::LookingUpTextures => "Looking up textures",
Self::ExtractingDdsTextures => "Extracting DDS textures",
Self::ExtractingVirtualTextures => "Extracting virtual textures",
Self::ConvertingToPng => "Converting to PNG",
Self::Complete => "Complete",
}
}
}
#[derive(Debug, Clone)]
pub struct Gr2ExtractionResult {
pub gr2_path: PathBuf,
pub glb_path: Option<PathBuf>,
pub texture_paths: Vec<PathBuf>,
pub warnings: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct Gr2ExtractionOptions {
pub convert_to_glb: bool,
pub extract_textures: bool,
pub extract_virtual_textures: bool,
pub bg3_path: Option<PathBuf>,
pub virtual_textures_path: Option<PathBuf>,
pub keep_original_gr2: bool,
pub convert_to_png: bool,
pub keep_original_dds: bool,
}
impl Default for Gr2ExtractionOptions {
fn default() -> Self {
Self {
convert_to_glb: true,
extract_textures: true,
extract_virtual_textures: false,
bg3_path: None,
virtual_textures_path: None,
keep_original_gr2: true,
convert_to_png: false,
keep_original_dds: false,
}
}
}
impl Gr2ExtractionOptions {
#[must_use]
pub fn new() -> Self {
Self {
convert_to_glb: false,
extract_textures: false,
extract_virtual_textures: false,
bg3_path: None,
virtual_textures_path: None,
keep_original_gr2: true,
convert_to_png: false,
keep_original_dds: false,
}
}
#[must_use]
pub fn bundle() -> Self {
Self {
convert_to_glb: true,
extract_textures: true,
extract_virtual_textures: true,
bg3_path: None,
virtual_textures_path: None,
keep_original_gr2: true,
convert_to_png: false,
keep_original_dds: false,
}
}
#[must_use]
pub fn has_gr2_processing(&self) -> bool {
self.convert_to_glb || self.extract_textures || self.extract_virtual_textures
}
#[must_use]
pub fn with_bg3_path<P: Into<PathBuf>>(mut self, path: Option<P>) -> Self {
self.bg3_path = path.map(Into::into);
self
}
#[must_use]
pub fn with_virtual_textures_path<P: Into<PathBuf>>(mut self, path: Option<P>) -> Self {
self.virtual_textures_path = path.map(Into::into);
self
}
#[must_use]
pub fn no_conversion(mut self) -> Self {
self.convert_to_glb = false;
self
}
#[must_use]
pub fn no_textures(mut self) -> Self {
self.extract_textures = false;
self
}
#[must_use]
pub fn with_png_conversion(mut self, convert: bool) -> Self {
self.convert_to_png = convert;
self
}
#[must_use]
pub fn with_convert_to_png(self, convert: bool) -> Self {
self.with_png_conversion(convert)
}
#[must_use]
pub fn with_convert_to_glb(mut self, convert: bool) -> Self {
self.convert_to_glb = convert;
self
}
#[must_use]
pub fn with_extract_textures(mut self, extract: bool) -> Self {
self.extract_textures = extract;
self
}
#[must_use]
pub fn with_extract_virtual_textures(mut self, extract: bool) -> Self {
self.extract_virtual_textures = extract;
self
}
#[must_use]
pub fn with_keep_original(mut self, keep: bool) -> Self {
self.keep_original_gr2 = keep;
self
}
#[must_use]
pub fn with_keep_original_dds(mut self, keep: bool) -> Self {
self.keep_original_dds = keep;
self
}
}