fix: error setting new sub patch id
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -713,7 +713,7 @@ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mhws-tex-decompressor"
|
name = "mhws-tex-decompressor"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"colored",
|
"colored",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mhws-tex-decompressor"
|
name = "mhws-tex-decompressor"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@@ -405,7 +405,7 @@ I'm sure I've checked the list, press Enter to continue"#,
|
|||||||
let new_patch_id = max_patch_id + 1;
|
let new_patch_id = max_patch_id + 1;
|
||||||
|
|
||||||
// Create a new chunk name
|
// Create a new chunk name
|
||||||
let output_chunk_name = chunk_name.with_sub_patch(new_patch_id);
|
let output_chunk_name = chunk_name.set_sub_patch(new_patch_id);
|
||||||
|
|
||||||
// Add the new patch to the chunk list so it can be found in subsequent processing
|
// Add the new patch to the chunk list so it can be found in subsequent processing
|
||||||
all_chunk_names.push(output_chunk_name.clone());
|
all_chunk_names.push(output_chunk_name.clone());
|
||||||
|
20
src/chunk.rs
20
src/chunk.rs
@@ -123,10 +123,20 @@ impl ChunkName {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a sub patch component with the given ID
|
/// Add or replace a sub patch component with the given ID
|
||||||
pub fn with_sub_patch(&self, patch_id: u32) -> Self {
|
pub fn set_sub_patch(&self, patch_id: u32) -> Self {
|
||||||
let mut new_components = self.components.clone();
|
let mut new_components = self.components.clone();
|
||||||
new_components.push(ChunkComponent::SubPatch(patch_id));
|
|
||||||
|
// Check if SubPatch already exists and replace it
|
||||||
|
if let Some(pos) = new_components
|
||||||
|
.iter()
|
||||||
|
.position(|c| matches!(c, ChunkComponent::SubPatch(_)))
|
||||||
|
{
|
||||||
|
new_components[pos] = ChunkComponent::SubPatch(patch_id);
|
||||||
|
} else {
|
||||||
|
new_components.push(ChunkComponent::SubPatch(patch_id));
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
components: new_components,
|
components: new_components,
|
||||||
}
|
}
|
||||||
@@ -289,9 +299,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_with_sub_patch() {
|
fn test_set_sub_patch() {
|
||||||
let base = ChunkName::try_from_str("re_chunk_000.pak.sub_001.pak").unwrap();
|
let base = ChunkName::try_from_str("re_chunk_000.pak.sub_001.pak").unwrap();
|
||||||
let with_patch = base.with_sub_patch(99);
|
let with_patch = base.set_sub_patch(99);
|
||||||
|
|
||||||
assert_eq!(with_patch.major_id(), Some(0));
|
assert_eq!(with_patch.major_id(), Some(0));
|
||||||
assert_eq!(with_patch.sub_id(), Some(1));
|
assert_eq!(with_patch.sub_id(), Some(1));
|
||||||
|
Reference in New Issue
Block a user