Skip to content

Commit 59eb073

Browse files
authored
Merge pull request #28 from LeagueToolkit/alan/fix/docs
feat: docs + public api improvements
2 parents 4bb7277 + f2e55af commit 59eb073

File tree

22 files changed

+74
-59
lines changed

22 files changed

+74
-59
lines changed

crates/league-toolkit/src/core/animation/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Skeletons (rigs, joints) & animations
12
pub mod joint;
23

34
pub use joint::*;

crates/league-toolkit/src/core/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! League memory primitives (index / vertex buffers, etc)
12
pub mod index_buffer;
23
pub use index_buffer::*;
34
pub mod vertex_buffer;

crates/league-toolkit/src/core/mesh/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Skinned & static meshes
12
mod r#static;
23

34
use error::ParseError;

crates/league-toolkit/src/core/meta/bin_tree/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use std::collections::HashMap;
22

33
mod object;
4-
use super::error::ParseError;
54
pub use object::*;
65

7-
pub mod read;
8-
pub mod write;
6+
mod read;
7+
mod write;
98

109
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1110
#[derive(Debug, PartialEq)]
11+
/// The top level tree of a bin file
1212
pub struct BinTree {
1313
pub is_override: bool,
1414
pub version: u32,

crates/league-toolkit/src/core/meta/bin_tree/object.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use std::{collections::HashMap, io};
22

33
use io_ext::{measure, window};
44

5-
use super::{super::BinProperty, ParseError};
5+
use super::super::{BinProperty, Error};
66
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
77

88
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99
#[derive(Debug, PartialEq)]
10+
/// A node in the bin tree
1011
pub struct BinTreeObject {
1112
pub path_hash: u32,
1213
pub class_hash: u32,
@@ -25,7 +26,7 @@ impl BinTreeObject {
2526
reader: &mut R,
2627
class_hash: u32,
2728
legacy: bool,
28-
) -> Result<Self, ParseError> {
29+
) -> Result<Self, Error> {
2930
let size = reader.read_u32::<LE>()?;
3031
let (real_size, value) = measure(reader, |reader| {
3132
let path_hash = reader.read_u32::<LE>()?;
@@ -37,15 +38,15 @@ impl BinTreeObject {
3738
properties.insert(prop.name_hash, prop);
3839
}
3940

40-
Ok::<_, ParseError>(Self {
41+
Ok::<_, Error>(Self {
4142
path_hash,
4243
class_hash,
4344
properties,
4445
})
4546
})?;
4647

4748
if size as u64 != real_size {
48-
return Err(ParseError::InvalidSize(size as _, real_size));
49+
return Err(Error::InvalidSize(size as _, real_size));
4950
}
5051
Ok(value)
5152
}

crates/league-toolkit/src/core/meta/bin_tree/read.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{collections::HashMap, io};
22

3-
use crate::core::meta::ParseError;
3+
use crate::core::meta::Error;
44

55
use super::{BinTree, BinTreeObject};
66
use byteorder::{ReadBytesExt, LE};
@@ -17,14 +17,14 @@ impl BinTree {
1717
/// * `reader` - A reader that implements io::Read and io::Seek.
1818
pub fn from_reader<R: io::Read + std::io::Seek + ?Sized>(
1919
reader: &mut R,
20-
) -> Result<Self, ParseError> {
20+
) -> Result<Self, Error> {
2121
let magic = reader.read_u32::<LE>()?;
2222
let is_override = match magic {
2323
Self::PROP => false,
2424
Self::PTCH => {
2525
let override_version = reader.read_u32::<LE>()?;
2626
if override_version != 1 {
27-
return Err(ParseError::InvalidFileVersion(override_version));
27+
return Err(Error::InvalidFileVersion(override_version));
2828
}
2929

3030
// It might be possible to create an override property bin
@@ -41,17 +41,17 @@ impl BinTree {
4141
Self::PTCH,
4242
magic
4343
);
44-
return Err(ParseError::InvalidFileSignature);
44+
return Err(Error::InvalidFileSignature);
4545
}
4646
true
4747
}
48-
_ => return Err(ParseError::InvalidFileSignature),
48+
_ => return Err(Error::InvalidFileSignature),
4949
};
5050

5151
let version = reader.read_u32::<LE>()?;
5252
if !matches!(version, 1..=3) {
5353
// TODO (alan): distinguish override/non-override version
54-
return Err(ParseError::InvalidFileVersion(version));
54+
return Err(Error::InvalidFileVersion(version));
5555
}
5656

5757
let dependencies = match version {
@@ -75,7 +75,7 @@ impl BinTree {
7575
let mut objects = HashMap::with_capacity(obj_count);
7676
match Self::try_read_objects(reader, &obj_classes, &mut objects, false) {
7777
Ok(_) => {}
78-
Err(ParseError::InvalidPropertyTypePrimitive(kind)) => {
78+
Err(Error::InvalidPropertyTypePrimitive(kind)) => {
7979
log::warn!("Invalid prop type {kind}. Trying reading objects as legacy.");
8080
Self::try_read_objects(reader, &obj_classes, &mut objects, true)?;
8181
}
@@ -108,7 +108,7 @@ impl BinTree {
108108
obj_classes: &[u32],
109109
objects: &mut HashMap<u32, BinTreeObject>,
110110
legacy: bool,
111-
) -> Result<(), ParseError> {
111+
) -> Result<(), Error> {
112112
objects.clear();
113113
for &class_hash in obj_classes {
114114
let tree_obj = BinTreeObject::from_reader(reader, class_hash, legacy)?;

crates/league-toolkit/src/core/meta/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use miette::Diagnostic;
33
use super::property::BinPropertyKind;
44

55
#[derive(Debug, thiserror::Error, Diagnostic)]
6-
pub enum ParseError {
6+
pub enum Error {
77
#[error("Invalid file signature")]
88
InvalidFileSignature,
99
#[error("Invalid file version '{0}'")]
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
pub mod property;
2-
pub use property::BinProperty;
1+
//! Bin file & properties
2+
mod property;
3+
pub use property::*;
34

45
mod bin_tree;
56
pub use bin_tree::*;
67

7-
pub mod error;
8+
mod error;
89
pub use error::*;
910

1011
pub mod traits;

crates/league-toolkit/src/core/meta/property/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use num_enum::{IntoPrimitive, TryFromPrimitive};
22
use std::io;
3-
use value::PropertyValueEnum;
43

5-
use super::ParseError;
4+
use super::Error;
65

76
pub mod value;
7+
pub use value::PropertyValueEnum;
88

99
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1010
#[derive(
@@ -45,22 +45,23 @@ pub enum BinPropertyKind {
4545
}
4646

4747
impl BinPropertyKind {
48+
/// Converts a u8 into a BinPropertyKind, accounting for pre/post WadChunkLink.
49+
///
4850
/// The WadChunkLink bin property type was newly added by Riot. For some reason they decided to put it in the middle of the enum,
4951
/// so we need to handle cases from before and after it existed.
5052
///
5153
/// "Legacy" property types need to be fudged around to pretend like WadChunkLink always existed, from our pov.
5254
///
5355
/// "Non-legacy" property types can just be used as is.
5456
///
55-
pub fn unpack(raw: u8, legacy: bool) -> Result<BinPropertyKind, ParseError> {
57+
pub fn unpack(raw: u8, legacy: bool) -> Result<BinPropertyKind, Error> {
5658
use BinPropertyKind as BPK;
5759
if !legacy {
58-
// TODO (alan): don't panic here
5960
return Ok(BPK::try_from_primitive(raw)?);
6061
}
6162
let mut fudged = raw;
6263

63-
// if the prop type comes after where WadChunkLink is now, we need to
64+
// if the prop type comes after where WadChunkLink is now, we need to fudge it
6465
if fudged >= BPK::WadChunkLink.into() && fudged < BPK::Container.into() {
6566
fudged -= Into::<u8>::into(BPK::WadChunkLink);
6667
fudged |= Into::<u8>::into(BPK::Container);
@@ -73,6 +74,7 @@ impl BinPropertyKind {
7374
Ok(BinPropertyKind::try_from_primitive(fudged)?)
7475
}
7576

77+
/// Whether this property kind is a primitive type. (i8, u8, .. u32, u64, f32, Vector2, Vector3, Vector4, Matrix44, Color, String, Hash, WadChunkLink),
7678
pub fn is_primitive(&self) -> bool {
7779
use BinPropertyKind::*;
7880
matches!(
@@ -98,6 +100,7 @@ impl BinPropertyKind {
98100
)
99101
}
100102

103+
/// Whether this property kind is a container type (container, unordered container, optional, map).
101104
pub fn is_container(&self) -> bool {
102105
use BinPropertyKind::*;
103106
matches!(self, Container | UnorderedContainer | Optional | Map)
@@ -107,7 +110,7 @@ impl BinPropertyKind {
107110
self,
108111
reader: &mut R,
109112
legacy: bool,
110-
) -> Result<PropertyValueEnum, super::ParseError> {
113+
) -> Result<PropertyValueEnum, super::Error> {
111114
PropertyValueEnum::from_reader(reader, self, legacy)
112115
}
113116
}
@@ -122,10 +125,11 @@ pub struct BinProperty {
122125

123126
use super::traits::PropertyValue as _;
124127
impl BinProperty {
128+
/// Read a BinProperty from a reader. This will read the name_hash, prop kind and then value, in that order.
125129
pub fn from_reader<R: io::Read + std::io::Seek + ?Sized>(
126130
reader: &mut R,
127131
legacy: bool,
128-
) -> Result<Self, ParseError> {
132+
) -> Result<Self, Error> {
129133
use super::traits::ReaderExt;
130134
use byteorder::{ReadBytesExt as _, LE};
131135
let name_hash = reader.read_u32::<LE>()?;

crates/league-toolkit/src/core/meta/property/value/container.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io;
33
use crate::core::meta::{
44
property::BinPropertyKind,
55
traits::{PropertyValue as Value, ReadProperty, ReaderExt, WriteProperty, WriterExt},
6-
ParseError,
6+
Error,
77
};
88

99
use super::PropertyValueEnum;
@@ -27,10 +27,10 @@ impl ReadProperty for ContainerValue {
2727
fn from_reader<R: std::io::Read + std::io::Seek + ?Sized>(
2828
reader: &mut R,
2929
legacy: bool,
30-
) -> Result<Self, ParseError> {
30+
) -> Result<Self, Error> {
3131
let item_kind = reader.read_property_kind(legacy)?;
3232
if item_kind.is_container() {
33-
return Err(ParseError::InvalidNesting(item_kind));
33+
return Err(Error::InvalidNesting(item_kind));
3434
}
3535

3636
let size = reader.read_u32::<LE>()?;
@@ -41,11 +41,11 @@ impl ReadProperty for ContainerValue {
4141
let prop = PropertyValueEnum::from_reader(reader, item_kind, legacy)?;
4242
items.push(prop);
4343
}
44-
Ok::<_, ParseError>(items)
44+
Ok::<_, Error>(items)
4545
})?;
4646

4747
if size as u64 != real_size {
48-
return Err(ParseError::InvalidSize(size as _, real_size));
48+
return Err(Error::InvalidSize(size as _, real_size));
4949
}
5050

5151
Ok(Self { item_kind, items })

0 commit comments

Comments
 (0)