wow-wdt 0.7.0

Parser, validator, and converter for World of Warcraft WDT (World Data Table) files
Documentation
# wow-wdt

A library for parsing, validating, and converting World of Warcraft WDT (World Data Table) files.

<div align="center">

[![Crates.io Version](https://img.shields.io/crates/v/wow-wdt)](https://crates.io/crates/wow-wdt)
[![docs.rs](https://img.shields.io/docsrs/wow-wdt)](https://docs.rs/wow-wdt)
[![License](https://img.shields.io/crates/l/wow-mpq.svg)](https://github.com/wowemulation-dev/warcraft-rs#license)

</div>

## Status

**Production Ready** - Complete WDT parser with 100% parsing success rate across all WoW versions

## Version Support

| WoW Version | Expansion | Status | Notes |
|-------------|-----------|--------|-------|
| 1.12.1      | Classic   | Complete | Full support |
| 2.4.3       | TBC       | Complete | Full support |
| 3.3.5a      | WotLK     | Complete | Full support |
| 4.3.4       | Cataclysm | Complete | Full support |
| 5.4.8       | MoP       | Complete | Full support |

## Features

- Parse WDT files from all WoW versions (Classic through MoP)
- Validate WDT structure with validation rules
- Create new WDT files programmatically
- Convert WDT files between different WoW versions
- Support for all chunk types (MVER, MPHD, MAIN, MAID, MWMO, MODF)
- Coordinate system conversion utilities
- 100% parsing success rate
- Tested with real WoW data files

## Quick Start

Add to your `Cargo.toml`:

```toml
[dependencies]
wow-wdt = "0.6"
```

Or use cargo add:

```bash
cargo add wow-wdt
```

### Basic Usage

```rust
use std::fs::File;
use std::io::BufReader;
use wow_wdt::{WdtReader, version::WowVersion};

// Parse a WDT file
let file = File::open("path/to/map.wdt")?;
let mut reader = WdtReader::new(BufReader::new(file), WowVersion::WotLK);
let wdt = reader.read()?;

// Get basic information
println!("Map type: {}", if wdt.is_wmo_only() { "WMO-only" } else { "Terrain" });
println!("Existing tiles: {}", wdt.count_existing_tiles());

// Check specific tile
if let Some(tile) = wdt.get_tile(32, 32) {
    println!("Center tile has ADT: {}", tile.has_adt);
    println!("Area ID: {}", tile.area_id);
}
```

### Creating WDT Files

```rust
use wow_wdt::{WdtFile, WdtWriter, version::WowVersion, chunks::MphdFlags};
use std::fs::File;
use std::io::BufWriter;

// Create a new terrain map
let mut wdt = WdtFile::new(WowVersion::WotLK);

// Configure as terrain map with height texturing
wdt.mphd.flags |= MphdFlags::ADT_HAS_HEIGHT_TEXTURING;

// Mark some tiles as having ADT data
wdt.main.get_mut(31, 31).unwrap().set_has_adt(true);
wdt.main.get_mut(31, 32).unwrap().set_has_adt(true);
wdt.main.get_mut(32, 31).unwrap().set_has_adt(true);
wdt.main.get_mut(32, 32).unwrap().set_has_adt(true);

// Write to file
let file = File::create("new_map.wdt")?;
let mut writer = WdtWriter::new(BufWriter::new(file));
writer.write(&wdt)?;
```

### Version Conversion

```rust
use wow_wdt::conversion::{convert_wdt, get_conversion_summary};

// Convert from WotLK to Cataclysm format
let changes = get_conversion_summary(
    WowVersion::WotLK,
    WowVersion::Cataclysm,
    wdt.is_wmo_only()
);

for change in changes {
    println!("Change: {}", change);
}

convert_wdt(&mut wdt, WowVersion::WotLK, WowVersion::Cataclysm)?;
```

### Coordinate Conversion

```rust
use wow_wdt::{tile_to_world, world_to_tile};

// Convert tile coordinates to world coordinates
let (world_x, world_y) = tile_to_world(32, 32);
println!("Tile [32, 32] is at world position ({:.2}, {:.2})", world_x, world_y);

// Convert world coordinates back to tile coordinates
let (tile_x, tile_y) = world_to_tile(world_x, world_y);
println!("World position maps to tile [{}, {}]", tile_x, tile_y);
```

## CLI Tool

WDT operations are available through the main `warcraft-rs` CLI tool:

```bash
# Get information about a WDT file
warcraft-rs wdt info Azeroth.wdt

# Validate WDT structure
warcraft-rs wdt validate Azeroth.wdt

# List all existing tiles
warcraft-rs wdt tiles Azeroth.wdt --format json

# Convert between versions
warcraft-rs wdt convert input.wdt output.wdt --to wotlk

# Visualize WDT structure as a tree
warcraft-rs wdt tree Azeroth.wdt --show-refs
```

## File Format Details

WDT files define which terrain tiles exist for a map and contain:

- **MVER**: Version chunk (always 18)
- **MPHD**: Map header with flags and FileDataIDs
- **MAIN**: 64x64 grid of tile information
- **MAID**: FileDataID mapping (BfA+ only)
- **MWMO**: WMO filename storage (WMO-only maps or pre-Cata terrain)
- **MODF**: WMO placement data (WMO-only maps)

## Testing

Basic tests are included:

```bash
# Run all tests
cargo test

# Benchmarks are planned but not yet implemented
```

## Documentation

- [Complete format specification]../../../docs/formats/world-data/wdt.md
- [API documentation]https://docs.rs/wow-wdt

## Related Crates

- [`wow-mpq`]../../archives/wow-mpq/ - MPQ archive support
- [`wow-adt`]../wow-adt/ - ADT terrain files
- [`wow-wdl`]../wow-wdl/ - WDL low-resolution terrain

## License

Licensed under either of [Apache License, Version 2.0](../../../LICENSE-APACHE) or [MIT license](../../../LICENSE-MIT) at your option.