implemented nested ESH editing
This commit is contained in:
parent
b8d48483f1
commit
7c2fbba153
5 changed files with 43 additions and 33 deletions
|
|
@ -339,7 +339,7 @@ impl Attributes {
|
|||
addictions,
|
||||
})
|
||||
} else {
|
||||
return Err(FE::AttributesNoESBIN);
|
||||
return Err(FE::ValueNoESBIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl Entity {
|
|||
pub fn get_attributes(&self) -> Result<Attributes, FE> {
|
||||
let value = match self.get_esh()?.get("Attributes") {
|
||||
Some(value) => value,
|
||||
None => return Err(FE::EntityNoAttributes),
|
||||
None => return Err(FE::NoESHValue),
|
||||
};
|
||||
|
||||
if let ESHValue::Binary(bin) = value {
|
||||
|
|
@ -53,7 +53,7 @@ impl Entity {
|
|||
pub fn get_modifiers(&self) -> Result<Attributes, FE> {
|
||||
let value = match self.get_esh()?.get("Modifiers") {
|
||||
Some(value) => value,
|
||||
None => return Err(FE::EntityNoModifiers),
|
||||
None => return Err(FE::NoESHValue),
|
||||
};
|
||||
|
||||
if let ESHValue::Binary(bin) = value {
|
||||
|
|
|
|||
|
|
@ -263,6 +263,31 @@ impl ESH {
|
|||
pub fn set(&mut self, name: &str, value: ESHValue) {
|
||||
self.props[name] = value;
|
||||
}
|
||||
|
||||
pub fn get_nested(&self, name: &str) -> Result<ESH, FE> {
|
||||
let value = match self.get(name) {
|
||||
Some(value) => value,
|
||||
None => return Err(FE::NoESHValue)
|
||||
};
|
||||
|
||||
if let ESHValue::Binary(bin) = value {
|
||||
let mut rd = ReadStream::new(bin, 0);
|
||||
|
||||
let _ = rd.read_u32()?;
|
||||
rd.read::<ESH>()
|
||||
} else {
|
||||
Err(FE::ESHValueNonBinary)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_nested(&mut self, name: &str, value: ESH) -> Result<(), FE> {
|
||||
let mut wd = WriteStream::new(4 + value.get_enc_size());
|
||||
wd.write_u32(value.get_enc_size() as u32)?;
|
||||
wd.write(&value)?;
|
||||
|
||||
self.set(name, ESHValue::Binary(wd.into_vec()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for ESH {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ pub enum FError {
|
|||
StreamOverflow(usize, usize, usize),
|
||||
NoZeroTerminator,
|
||||
EntityNoESH,
|
||||
EntityNoAttributes,
|
||||
EntityNoModifiers,
|
||||
NoESHValue,
|
||||
ESHValueNonBinary,
|
||||
AttributesNonBinary,
|
||||
AttributesNoESBIN,
|
||||
ValueNoESBIN
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FError {
|
||||
|
|
@ -32,10 +32,10 @@ impl std::fmt::Display for FError {
|
|||
),
|
||||
FE::NoZeroTerminator => write!(f, "No zero-terminator when String::decode"),
|
||||
FE::EntityNoESH => write!(f, "Entity has no ESH"),
|
||||
FE::EntityNoAttributes => write!(f, "Entity has no Attributes"),
|
||||
FE::EntityNoModifiers => write!(f, "Entity has no Modifiers"),
|
||||
FE::NoESHValue => write!(f, "Entity has no specific ESH value"),
|
||||
FE::ESHValueNonBinary => write!(f, "ESH value is not binary"),
|
||||
FE::AttributesNonBinary => write!(f, "Attributes Binary != true"),
|
||||
FE::AttributesNoESBIN => write!(f, "Attributes has no esbin"),
|
||||
FE::ValueNoESBIN => write!(f, "Value has no esbin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,38 +32,23 @@ impl World {
|
|||
pub fn test(&mut self) -> Result<(), FE> {
|
||||
//let actor_type = self.entlist.get_type_idx("Actor").unwrap();
|
||||
//let ent = self.entlist.get_entity_mut(2122);
|
||||
for (id, ent) in &mut self.entlist {
|
||||
ent.flags = 1;
|
||||
}
|
||||
|
||||
let ent = self.entlist.get_entity_mut(2158);
|
||||
let esh = ent.get_esh()?;
|
||||
let ent = self.entlist.get_entity_mut(2122);
|
||||
let esh = ent.get_esh_mut()?;
|
||||
for (name, value) in &esh.props {
|
||||
println!("{} {}", name, value);
|
||||
}
|
||||
//self.entlist.dump_to_entfile(ent, Path::new("D:\\actor.ent"))?;
|
||||
|
||||
println!("");
|
||||
let mut attributes = ent.get_modifiers()?;
|
||||
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
||||
dbg!(bin.len());
|
||||
let mut attribs = esh.get_nested("Current Attributes")?;
|
||||
for (name, value) in &attribs.props {
|
||||
println!("{} {}", name, value);
|
||||
}
|
||||
attributes.stats["strength"] = 10;
|
||||
attributes.stats["perception"] = 10;
|
||||
attributes.stats["endurance"] = 10;
|
||||
attributes.stats["charisma"] = 10;
|
||||
attributes.stats["intelligence"] = 10;
|
||||
attributes.stats["agility"] = 10;
|
||||
attributes.stats["luck"] = 10;
|
||||
for (_, value) in attributes.skills.iter_mut() {
|
||||
*value = 300;
|
||||
}
|
||||
ent.set_modifiers(attributes)?;
|
||||
|
||||
let esh = ent.get_esh()?;
|
||||
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
||||
dbg!(bin.len());
|
||||
}
|
||||
attribs.set("hitPoints", ESHValue::Int(999));
|
||||
attribs.set("poisonPoints", ESHValue::Int(0));
|
||||
|
||||
esh.set_nested("Current Attributes", attribs)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue