implement decoding and encoding of Modifiers (they're same as Attributes but with different ESH name)
This commit is contained in:
parent
eff42b2605
commit
5709e81df0
4 changed files with 30 additions and 8 deletions
|
|
@ -49,6 +49,26 @@ impl Entity {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_modifiers(&self) -> Result<Attributes, FE> {
|
||||||
|
let value = match self.get_esh()?.get("Modifiers") {
|
||||||
|
Some(value) => value,
|
||||||
|
None => return Err(FE::EntityNoModifiers),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let ESHValue::Binary(bin) = value {
|
||||||
|
Ok(Attributes::from_binary(&bin)?)
|
||||||
|
} else {
|
||||||
|
Err(FE::AttributesNonBinary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_modifiers(&mut self, attrs: Attributes) -> Result<(), FE> {
|
||||||
|
self.get_esh_mut()?
|
||||||
|
.set("Modifiers", ESHValue::Binary(attrs.into_binary()?));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DecoderCtx<&mut EntityList, &EntityList> for Entity {
|
impl DecoderCtx<&mut EntityList, &EntityList> for Entity {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub enum FError {
|
||||||
NoZeroTerminator,
|
NoZeroTerminator,
|
||||||
EntityNoESH,
|
EntityNoESH,
|
||||||
EntityNoAttributes,
|
EntityNoAttributes,
|
||||||
|
EntityNoModifiers,
|
||||||
AttributesNonBinary,
|
AttributesNonBinary,
|
||||||
AttributesNoESBIN,
|
AttributesNoESBIN,
|
||||||
}
|
}
|
||||||
|
|
@ -32,6 +33,7 @@ impl std::fmt::Display for FError {
|
||||||
FE::NoZeroTerminator => write!(f, "No zero-terminator when String::decode"),
|
FE::NoZeroTerminator => write!(f, "No zero-terminator when String::decode"),
|
||||||
FE::EntityNoESH => write!(f, "Entity has no ESH"),
|
FE::EntityNoESH => write!(f, "Entity has no ESH"),
|
||||||
FE::EntityNoAttributes => write!(f, "Entity has no Attributes"),
|
FE::EntityNoAttributes => write!(f, "Entity has no Attributes"),
|
||||||
|
FE::EntityNoModifiers => write!(f, "Entity has no Modifiers"),
|
||||||
FE::AttributesNonBinary => write!(f, "Attributes Binary != true"),
|
FE::AttributesNonBinary => write!(f, "Attributes Binary != true"),
|
||||||
FE::AttributesNoESBIN => write!(f, "Attributes has no esbin"),
|
FE::AttributesNoESBIN => write!(f, "Attributes has no esbin"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ impl World {
|
||||||
//self.entlist.dump_to_entfile(ent, Path::new("D:\\actor.ent"))?;
|
//self.entlist.dump_to_entfile(ent, Path::new("D:\\actor.ent"))?;
|
||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
let mut attributes = ent.get_attributes()?;
|
let mut attributes = ent.get_modifiers()?;
|
||||||
if let ESHValue::Binary(bin) = &esh.get("Attributes").unwrap() {
|
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
||||||
dbg!(bin.len());
|
dbg!(bin.len());
|
||||||
}
|
}
|
||||||
attributes.stats["strength"] = 10;
|
attributes.stats["strength"] = 10;
|
||||||
|
|
@ -54,10 +54,10 @@ impl World {
|
||||||
for (_, value) in attributes.skills.iter_mut() {
|
for (_, value) in attributes.skills.iter_mut() {
|
||||||
*value = 300;
|
*value = 300;
|
||||||
}
|
}
|
||||||
ent.set_attributes(attributes)?;
|
ent.set_modifiers(attributes)?;
|
||||||
|
|
||||||
let esh = ent.get_esh()?;
|
let esh = ent.get_esh()?;
|
||||||
if let ESHValue::Binary(bin) = &esh.get("Attributes").unwrap() {
|
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
||||||
dbg!(bin.len());
|
dbg!(bin.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ use fot::save::Save;
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<_> = env::args().collect();
|
let args: Vec<_> = env::args().collect();
|
||||||
let save_path = args.get(1).unwrap();
|
let save_path = args.get(1).unwrap();
|
||||||
/*let out_path = match args.get(2) {
|
let out_path = match args.get(2) {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => "out.bin"
|
None => "out.sav"
|
||||||
};*/
|
};
|
||||||
|
|
||||||
let mut save = Save::load(Path::new(save_path)).expect("load save");
|
let mut save = Save::load(Path::new(save_path)).expect("load save");
|
||||||
save.world.test().expect("test");
|
save.world.test().expect("test");
|
||||||
save.save(Path::new("out.sav")).expect("failed to save");
|
save.save(Path::new(out_path)).expect("failed to save");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue