|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +League Toolkit is a Rust workspace for parsing, editing, and writing League of Legends file formats. It consists of 13 individual `ltk_*` crates plus one umbrella `league-toolkit` crate that re-exports them via feature flags. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +cargo build --verbose # Build all crates |
| 13 | +cargo test --verbose # Run all tests |
| 14 | +cargo fmt -- --check # Check formatting |
| 15 | +cargo clippy --all-targets -- -D warnings # Lint (CI denies all warnings) |
| 16 | +``` |
| 17 | + |
| 18 | +Run a single crate's tests: |
| 19 | +```bash |
| 20 | +cargo test -p ltk_meta --verbose |
| 21 | +``` |
| 22 | + |
| 23 | +Run a specific test: |
| 24 | +```bash |
| 25 | +cargo test -p ltk_meta test_name |
| 26 | +``` |
| 27 | + |
| 28 | +Snapshot tests use `cargo-insta`. To review snapshot changes: |
| 29 | +```bash |
| 30 | +cargo insta review |
| 31 | +``` |
| 32 | + |
| 33 | +## Workspace Structure |
| 34 | + |
| 35 | +All crates live under `crates/`. The dependency graph flows upward: |
| 36 | + |
| 37 | +- **Foundation**: `ltk_hash`, `ltk_primitives` (no internal deps) |
| 38 | +- **I/O layer**: `ltk_io_ext` (depends on `ltk_primitives`) |
| 39 | +- **Format crates**: `ltk_wad`, `ltk_texture`, `ltk_mesh`, `ltk_anim`, `ltk_meta`, `ltk_file` (depend on foundation + I/O) |
| 40 | +- **Higher-level**: `ltk_mapgeo` (depends on `ltk_mesh`), `ltk_ritobin` (depends on `ltk_meta`), `ltk_shader` (depends on `ltk_wad`) |
| 41 | +- **Umbrella**: `league-toolkit` re-exports everything behind feature flags |
| 42 | + |
| 43 | +## Key Patterns |
| 44 | + |
| 45 | +**Reading/Writing**: Most types implement `from_reader(&mut impl Read)` and `to_writer(&mut impl Write)`. WAD mounting requires `Read + Seek`. |
| 46 | + |
| 47 | +**Builder pattern**: Complex types use builders — `BinTree::builder()`, `BinTreeObject::builder()`, `RigResource::builder()`, `WadBuilder`. |
| 48 | + |
| 49 | +**Error handling**: Each crate defines its own error type via `thiserror` and a `Result<T>` type alias. `ltk_meta` additionally uses `miette` for diagnostic errors. |
| 50 | + |
| 51 | +**Math**: All vector/matrix types use `glam` (Vec2, Vec3, Vec4, Mat4, Quat). |
| 52 | + |
| 53 | +**Hashing**: WAD paths are XXHash64 (64-bit) of lowercased paths. Bin object/property names are FNV-1a (32-bit) hashes via `ltk_hash::fnv1a::hash_lower()`. |
| 54 | + |
| 55 | +## Crate Layout Convention |
| 56 | + |
| 57 | +Each crate typically follows: |
| 58 | +``` |
| 59 | +crates/ltk_*/ |
| 60 | +├── src/ |
| 61 | +│ ├── lib.rs # Re-exports + module declarations |
| 62 | +│ ├── error.rs # Error enum (thiserror) |
| 63 | +│ └── ... # Type modules |
| 64 | +├── tests/ # Integration tests (some crates) |
| 65 | +└── Cargo.toml |
| 66 | +``` |
| 67 | + |
| 68 | +Snapshot test data lives in `crates/*/src/**/snapshots/` or `crates/*/tests/snapshots/`. |
| 69 | + |
| 70 | +## Testing Approach |
| 71 | + |
| 72 | +- Unit tests inline in source files |
| 73 | +- Integration tests in `crates/*/tests/` (ltk_anim, ltk_meta, ltk_mapgeo, ltk_ritobin) |
| 74 | +- Round-trip tests (parse → write → parse → assert equal) are the primary verification pattern |
| 75 | +- Snapshot tests use `insta` with `.ron` format |
| 76 | +- `approx` crate for floating-point comparisons |
| 77 | + |
| 78 | +## Workspace Dependencies |
| 79 | + |
| 80 | +Shared dependency versions are declared in the root `Cargo.toml` under `[workspace.dependencies]`. Individual crates reference them with `workspace = true`. When adding dependencies, prefer adding them at workspace level. |
| 81 | + |
| 82 | +## Additional Context |
| 83 | + |
| 84 | +The `docs/LTK_GUIDE.md` file contains detailed crate-by-crate API documentation with usage examples, file format references, and hash algorithm details. Consult it for format-specific questions. |
0 commit comments