Skip to content

Commit

Permalink
Merge pull request #27 from dark0dave/fix/itemExtenderHeaderFeatureBl…
Browse files Browse the repository at this point in the history
…ocks

fix(item): Now parses embeded items correctly
  • Loading branch information
dark0dave authored Nov 13, 2024
2 parents 5686b33 + c6a33a4 commit 188889a
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "post_infinity"
version = "5.1.0"
version = "5.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
17 changes: 17 additions & 0 deletions Cargo.toml.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "post_infinity"
version = "5.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]

[dependencies]
binrw = "^0.14.1"
clap = { version = "^4.0", features = ["derive", "env"] }
env_logger = "^0.11.1"
erased-serde = "0.4"
log = "^0.4.22"
models = { path = "./models" }
serde_json = "^1.0"
30 changes: 21 additions & 9 deletions check-version.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail

release_tag=$(git describe --tags --abbrev=0);
trap "rm -f Cargo.toml.test" SIGINT;
sed "s/^version \= .*/version = \"${release_tag/v/}\"/" Cargo.toml > Cargo.toml.test;
diff -sd Cargo.toml.test Cargo.toml;
if [ $? -eq 0 ]; then
rm -f Cargo.toml.test;
exit 0;
else
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }

function main() {
local tag_version=$(git describe --tags --abbrev=0);
echo "Git tag version: ${tag_version}"
local current_version=$(head -3 Cargo.toml | tail -1 | sed -E "s/^version \= \"(.*)\"/\1/")
echo "Cargo.toml version: v${current_version}"
if [ "${tag_version}" == "v${current_version}" ]; then
echo "Versions are the same"
exit 0;
fi

if version_gt "v${current_version}" "${tag_version}"; then
echo "Current version greater than tag version"
exit 0;
fi

echo "Failed, tag version: ${tag_version} is greater than Cargo,toml: v${current_version}"
exit 1;
fi
}

main
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added models/fixtures/zbpdnote.itm
Binary file not shown.
8 changes: 4 additions & 4 deletions models/src/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ mod tests {

#[test]
fn test_ambients() {
let file = File::open("fixtures/AR0011.ARE").expect("Fixture missing");
let file = File::open("fixtures/ar0011.are").expect("Fixture missing");
let mut buffer = Vec::new();
BufReader::new(file)
.read_to_end(&mut buffer)
Expand All @@ -626,7 +626,7 @@ mod tests {

#[test]
fn test_projectile_traps() {
let file = File::open("fixtures/AR0002.ARE").expect("Fixture missing");
let file = File::open("fixtures/ar0002.are").expect("Fixture missing");
let mut buffer = Vec::new();
BufReader::new(file)
.read_to_end(&mut buffer)
Expand All @@ -637,7 +637,7 @@ mod tests {

#[test]
fn test_actors() {
let file = File::open("fixtures/AR0002.ARE").expect("Fixture missing");
let file = File::open("fixtures/ar0002.are").expect("Fixture missing");
let mut buffer = Vec::new();
BufReader::new(file)
.read_to_end(&mut buffer)
Expand Down Expand Up @@ -686,7 +686,7 @@ mod tests {

#[test]
fn test_spawn_point() {
let file = File::open("fixtures/AR0226.ARE").expect("Fixture missing");
let file = File::open("fixtures/ar0226.are").expect("Fixture missing");
let mut buffer = Vec::new();
BufReader::new(file)
.read_to_end(&mut buffer)
Expand Down
2 changes: 1 addition & 1 deletion models/src/biff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {

#[test]
fn valid_biff_file_parsed() {
let file = File::open("fixtures/Effects.bif").unwrap();
let file = File::open("fixtures/effects.bif").unwrap();
let mut reader = BufReader::new(file);
let biff = Biff::new(&mut reader);
assert_eq!(
Expand Down
10 changes: 5 additions & 5 deletions models/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ mod tests {

#[test]
fn valid_headers_parsed() {
let file = File::open("fixtures/BG2EEBALDUR.gam").unwrap();
let file = File::open("fixtures/bg2eebaldur.gam").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand All @@ -423,7 +423,7 @@ mod tests {

#[test]
fn valid_party_npc_parsed() {
let file = File::open("fixtures/BG2EEBALDUR.gam").unwrap();
let file = File::open("fixtures/bg2eebaldur.gam").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand Down Expand Up @@ -568,7 +568,7 @@ mod tests {

#[test]
fn valid_npc_parsed() {
let file = File::open("fixtures/BG2EEBALDUR.gam").unwrap();
let file = File::open("fixtures/bg2eebaldur.gam").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand Down Expand Up @@ -648,7 +648,7 @@ mod tests {

#[test]
fn valid_familar_parsed() {
let file = File::open("fixtures/BG2EEBALDUR.gam").unwrap();
let file = File::open("fixtures/bg2eebaldur.gam").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand Down Expand Up @@ -676,7 +676,7 @@ mod tests {

#[test]
fn valid_journal_entries_parsed() {
let file = File::open("fixtures/BG2EEBALDUR.gam").unwrap();
let file = File::open("fixtures/bg2eebaldur.gam").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand Down
17 changes: 17 additions & 0 deletions models/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ pub struct ItemExtendedHeader {
is_arrow: u16,
is_bolt: u16,
is_bullet: u16,
#[bw(ignore)]
#[br(count=feature_blocks_count)]
effects: Vec<FeatureBlock>,
}

// https://gibberlings3.github.io/iesdp/file_formats/ie_formats/itm_v1.htm#itmv1_Feature_Block
Expand Down Expand Up @@ -157,4 +160,18 @@ mod tests {
assert_eq!(item.extended_headers.len(), 1);
assert_eq!(item.equipping_feature_blocks.len(), 4);
}

#[test]
fn baeloth_book_parse() {
let file = File::open("fixtures/zbpdnote.itm").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
.read_to_end(&mut buffer)
.expect("Could not read to buffer");
let item = Item::new(&buffer);
assert_eq!(item.extended_headers.len(), 1);
assert_eq!(item.extended_headers[0].effects.len(), 1);
assert_eq!(item.equipping_feature_blocks.len(), 0);
}
}
4 changes: 2 additions & 2 deletions models/src/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {

#[test]
fn uncompress_files() {
let file = File::open("fixtures/BALDUR.SAV").unwrap();
let file = File::open("fixtures/baldur.sav").unwrap();
let mut reader = BufReader::new(file);
let save = Save::new(&mut reader);
let model = save.files[0].uncompressed_data.clone().unwrap();
Expand All @@ -102,7 +102,7 @@ mod tests {

#[test]
fn read_save() {
let file = File::open("fixtures/BALDUR.SAV").unwrap();
let file = File::open("fixtures/baldur.sav").unwrap();
let mut reader = BufReader::new(file);
let save = Save::new(&mut reader);
assert_eq!(save.files[0].compressed_data_length, 1316);
Expand Down
2 changes: 1 addition & 1 deletion models/src/world_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {

#[test]
fn world_test() {
let file = File::open("fixtures/WORLDMAP.WMP").unwrap();
let file = File::open("fixtures/worldmap.wmp").unwrap();
let mut reader = BufReader::new(file);
let mut buffer = Vec::new();
reader
Expand Down

0 comments on commit 188889a

Please sign in to comment.