wow_wmo/version_detection.rs
1use crate::chunk_discovery::ChunkDiscovery;
2
3/// WMO version based on expansion and chunk patterns
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum WmoVersion {
6 /// Classic/Vanilla (1.12.1) and TBC (2.4.3)
7 Classic,
8 /// Wrath of the Lich King (3.3.5)
9 WotLK,
10 /// Cataclysm (4.3.4) - introduced MCVP chunk
11 Cataclysm,
12 /// Mists of Pandaria (5.4.8)
13 MoP,
14 /// Warlords of Draenor (6.2.4) - introduced GFID chunk
15 Warlords,
16 /// Legion and later
17 Legion,
18}
19
20/// Detect WMO version based on chunk patterns
21///
22/// Note: All versions use format version 17, so we detect by chunk presence:
23/// - MCVP → Cataclysm or later
24/// - GFID → Warlords or later
25/// - Otherwise → Classic/TBC/WotLK
26pub fn detect_version(discovery: &ChunkDiscovery) -> WmoVersion {
27 // Collect chunk IDs for pattern matching
28 let chunk_ids: Vec<&str> = discovery.chunks.iter().map(|c| c.id.as_str()).collect();
29
30 // Check for version-specific chunks
31 if chunk_ids.contains(&"GFID") {
32 // GFID was introduced in Warlords of Draenor
33 WmoVersion::Warlords
34 } else if chunk_ids.contains(&"MCVP") {
35 // MCVP was introduced in Cataclysm for vertex painting
36 WmoVersion::Cataclysm
37 } else {
38 // No version-specific chunks - likely Classic, TBC, or WotLK
39 // These can't be distinguished by chunks alone
40 WmoVersion::Classic
41 }
42}
43
44impl WmoVersion {
45 /// Check if this version supports a specific feature
46 pub fn supports_feature(&self, feature: WmoFeature) -> bool {
47 match feature {
48 WmoFeature::VertexPainting => {
49 matches!(
50 self,
51 WmoVersion::Cataclysm
52 | WmoVersion::MoP
53 | WmoVersion::Warlords
54 | WmoVersion::Legion
55 )
56 }
57 WmoFeature::FileDataId => {
58 matches!(self, WmoVersion::Warlords | WmoVersion::Legion)
59 }
60 }
61 }
62
63 /// Get the earliest expansion that supports this version
64 pub fn expansion_name(&self) -> &'static str {
65 match self {
66 WmoVersion::Classic => "Classic/TBC",
67 WmoVersion::WotLK => "Wrath of the Lich King",
68 WmoVersion::Cataclysm => "Cataclysm",
69 WmoVersion::MoP => "Mists of Pandaria",
70 WmoVersion::Warlords => "Warlords of Draenor",
71 WmoVersion::Legion => "Legion+",
72 }
73 }
74}
75
76/// WMO feature flags for version compatibility
77#[derive(Debug, Clone, Copy, PartialEq, Eq)]
78pub enum WmoFeature {
79 /// Vertex painting support (Cataclysm+)
80 VertexPainting,
81 /// File data ID support (Warlords+)
82 FileDataId,
83}