Skip to content

Commit

Permalink
Update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
benhall-7 committed Aug 13, 2020
1 parent 1deb79a commit 6333962
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -17,10 +17,10 @@ path = "src/yamlist/main.rs"

[dependencies]
byteorder = "^1.3"
diff-struct = { path = "../diff-struct" }
diff-struct = "0.2"
serde = { version = "^1", features = ["derive"] }
serde_yaml = "0.8"
indexmap = { version = "^1.2", features = ["serde-1"] }
lazy_static = "^1.4"
structopt = "^0.3"
hash40 = { path = "../hash40-rs" }
hash40 = "0.4"
10 changes: 5 additions & 5 deletions src/motion_lib/mlist.rs
Expand Up @@ -13,7 +13,7 @@ pub struct MList {
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Diff)]
#[diff(attr(#[derive(Debug, Serialize)]))]
#[diff(attr(#[derive(Debug, Serialize, Deserialize)]))]
pub struct Motion {
pub game_script: Hash40,
pub flags: Flags,
Expand All @@ -24,14 +24,14 @@ pub struct Motion {
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Diff)]
#[diff(attr(#[derive(Debug, PartialEq, Serialize)]))]
#[diff(attr(#[derive(Debug, PartialEq, Serialize, Deserialize)]))]
pub struct Animation {
pub name: Hash40,
pub unk: u8,
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Diff)]
#[diff(attr(#[derive(Debug, PartialEq, Serialize)]))]
#[diff(attr(#[derive(Debug, PartialEq, Serialize, Deserialize)]))]
pub struct Extra {
pub xlu_start: u8,
pub xlu_end: u8,
Expand All @@ -42,7 +42,7 @@ pub struct Extra {
macro_rules! make_flags {
($first:ident, $($names:ident),*) => {
#[derive(Debug, Default, PartialEq, Copy, Clone, Serialize, Deserialize, Diff)]
#[diff(attr(#[derive(Debug, Serialize)]))]
#[diff(attr(#[derive(Debug, Serialize, Deserialize)]))]
pub struct Flags {
pub $first: bool,
$(pub $names: bool),*
Expand Down Expand Up @@ -78,7 +78,7 @@ make_flags!(
turn, r#loop, r#move, fix_trans, fix_rot, fix_scale, unk_40, unk_80, unk_100, unk_200, unk_400
);

#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct MListDiff {
motion_path: <Hash40 as Diff>::Repr,
altered: IndexMap<Hash40, <Motion as Diff>::Repr>,
Expand Down
11 changes: 6 additions & 5 deletions src/yamlist/args.rs
Expand Up @@ -24,14 +24,15 @@ pub enum Mode {
file: String,
},

Patch {
file: String,
patch: String,
},

#[structopt(about = "Take two motion_lists, and produce a yaml file of their difference")]
Diff {
a: String,
b: String,
},

#[structopt(about = "Take a motion_list and apply a yaml patch to create a new motion_list")]
Patch {
file: String,
patch: String,
},
}
17 changes: 12 additions & 5 deletions src/yamlist/main.rs
Expand Up @@ -30,21 +30,28 @@ fn main() {
Mode::Asm { file, .. } => {
convert_to_bin(&file, &args.out.as_ref().map_or("out.bin", String::as_str))
}
Mode::Patch { .. } => patch_motion_bin(),
Mode::Diff { a, b } => {
diff_files(a, b, &args.out.as_ref().map_or("diff.yml", String::as_str))
}
Mode::Patch { file, patch } => {
patch_motion_bin(file, patch, &args.out.as_ref().map_or("patched.bin", String::as_str))
}
} {
println!("ERROR: {}", y);
}
}

// TODO: args/implementation
fn patch_motion_bin() -> Result<()> {
Err(ErrorString("Patching not supported").into())
fn patch_motion_bin(file: &str, patch: &str, out_path: &str) -> Result<()> {
let a = motion_lib::open(file)?;
let mut contents: String = String::default();
File::open(patch)?.read_to_string(&mut contents)?;
let diff = from_str(&contents)?;

let out = a.apply_new(&diff);
motion_lib::save(out_path, &out)?;
Ok(())
}

// TODO: args/implementation
fn diff_files(a: &str, b: &str, out_path: &str) -> Result<()> {
let a = motion_lib::open(a)?;
let b = motion_lib::open(b)?;
Expand Down

0 comments on commit 6333962

Please sign in to comment.