wow_alchemy_wmo/
lib.rs

1pub mod chunk;
2pub mod converter;
3pub mod error;
4pub mod group_parser;
5pub mod parser;
6pub mod types;
7pub mod validator;
8pub mod version;
9pub mod wmo_group_types;
10pub mod wmo_types;
11pub mod writer;
12
13// Additional modules
14pub mod editor;
15pub mod visualizer;
16
17pub use converter::WmoConverter;
18pub use editor::WmoEditor;
19pub use error::{Result, WmoError};
20pub use group_parser::WmoGroupParser;
21pub use parser::{WmoParser, chunks};
22pub use types::{BoundingBox, ChunkId, Color, Vec3};
23pub use validator::{ValidationError, ValidationReport, ValidationWarning, WmoValidator};
24pub use version::{WmoFeature, WmoVersion};
25pub use visualizer::WmoVisualizer;
26// Re-export all types from wmo_types
27pub use wmo_types::{
28    WmoConvexVolumePlane, WmoConvexVolumePlanes, WmoDoodadDef, WmoDoodadSet, WmoFlags,
29    WmoGroupInfo, WmoHeader, WmoLight, WmoLightProperties, WmoLightType, WmoMaterial,
30    WmoMaterialFlags, WmoPortal, WmoPortalReference, WmoRoot,
31};
32
33// Re-export all types from wmo_group_types (except WmoGroupFlags which conflicts)
34pub use wmo_group_types::{
35    TexCoord, WmoBatch, WmoBspNode, WmoGroup, WmoGroupFlags, WmoGroupHeader, WmoLiquid,
36    WmoLiquidVertex, WmoMaterialInfo, WmoPlane,
37};
38pub use writer::WmoWriter;
39
40/// Re-export of chunk-related types
41pub use chunk::{Chunk, ChunkHeader};
42
43/// Parse a WMO root file from a reader
44pub fn parse_wmo<R: std::io::Read + std::io::Seek>(reader: &mut R) -> Result<WmoRoot> {
45    let parser = WmoParser::new();
46    parser.parse_root(reader)
47}
48
49/// Parse a WMO group file from a reader
50pub fn parse_wmo_group<R: std::io::Read + std::io::Seek>(
51    reader: &mut R,
52    group_index: u32,
53) -> Result<WmoGroup> {
54    let parser = WmoGroupParser::new();
55    parser.parse_group(reader, group_index)
56}
57
58/// Validate a WMO file from a reader
59pub fn validate_wmo<R: std::io::Read + std::io::Seek>(reader: &mut R) -> Result<bool> {
60    // A simple validation just checks if we can parse the file without errors
61    match parse_wmo(reader) {
62        Ok(_) => Ok(true),
63        Err(e) => {
64            // If it's a format error, return false. Otherwise, propagate the error.
65            match e {
66                WmoError::InvalidFormat(_)
67                | WmoError::InvalidMagic { .. }
68                | WmoError::InvalidVersion(_)
69                | WmoError::MissingRequiredChunk(_) => Ok(false),
70                _ => Err(e),
71            }
72        }
73    }
74}
75
76/// Perform detailed validation on a WMO root file
77pub fn validate_wmo_detailed<R: std::io::Read + std::io::Seek>(
78    reader: &mut R,
79) -> Result<ValidationReport> {
80    let wmo = parse_wmo(reader)?;
81    let validator = WmoValidator::new();
82    validator.validate_root(&wmo)
83}
84
85/// Perform detailed validation on a WMO group file
86pub fn validate_wmo_group_detailed<R: std::io::Read + std::io::Seek>(
87    reader: &mut R,
88    group_index: u32,
89) -> Result<ValidationReport> {
90    let group = parse_wmo_group(reader, group_index)?;
91    let validator = WmoValidator::new();
92    validator.validate_group(&group)
93}
94
95/// Convert a WMO file from one version to another
96pub fn convert_wmo<R, W>(reader: &mut R, writer: &mut W, target_version: WmoVersion) -> Result<()>
97where
98    R: std::io::Read + std::io::Seek,
99    W: std::io::Write + std::io::Seek,
100{
101    let mut wmo = parse_wmo(reader)?;
102
103    // Convert WMO to target version
104    let converter = WmoConverter::new();
105    converter.convert_root(&mut wmo, target_version)?;
106
107    // Write converted WMO
108    let writer_obj = WmoWriter::new();
109    writer_obj.write_root(writer, &wmo, target_version)?;
110
111    Ok(())
112}
113
114/// Convert a WMO group file from one version to another
115pub fn convert_wmo_group<R, W>(
116    reader: &mut R,
117    writer: &mut W,
118    target_version: WmoVersion,
119    group_index: u32,
120) -> Result<()>
121where
122    R: std::io::Read + std::io::Seek,
123    W: std::io::Write + std::io::Seek,
124{
125    // Read root file first to get current version
126    let wmo = parse_wmo(reader)?;
127    let current_version = wmo.version;
128
129    // Now read group file
130    reader.rewind()?;
131    let mut group = parse_wmo_group(reader, group_index)?;
132
133    // Convert group to target version
134    let converter = WmoConverter::new();
135    converter.convert_group(&mut group, target_version, current_version)?;
136
137    // Write converted group
138    let writer_obj = WmoWriter::new();
139    writer_obj.write_group(writer, &group, target_version)?;
140
141    Ok(())
142}