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,
|
addictions,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return Err(FE::AttributesNoESBIN);
|
return Err(FE::ValueNoESBIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl Entity {
|
||||||
pub fn get_attributes(&self) -> Result<Attributes, FE> {
|
pub fn get_attributes(&self) -> Result<Attributes, FE> {
|
||||||
let value = match self.get_esh()?.get("Attributes") {
|
let value = match self.get_esh()?.get("Attributes") {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => return Err(FE::EntityNoAttributes),
|
None => return Err(FE::NoESHValue),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let ESHValue::Binary(bin) = value {
|
if let ESHValue::Binary(bin) = value {
|
||||||
|
|
@ -53,7 +53,7 @@ impl Entity {
|
||||||
pub fn get_modifiers(&self) -> Result<Attributes, FE> {
|
pub fn get_modifiers(&self) -> Result<Attributes, FE> {
|
||||||
let value = match self.get_esh()?.get("Modifiers") {
|
let value = match self.get_esh()?.get("Modifiers") {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => return Err(FE::EntityNoModifiers),
|
None => return Err(FE::NoESHValue),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let ESHValue::Binary(bin) = value {
|
if let ESHValue::Binary(bin) = value {
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,31 @@ impl ESH {
|
||||||
pub fn set(&mut self, name: &str, value: ESHValue) {
|
pub fn set(&mut self, name: &str, value: ESHValue) {
|
||||||
self.props[name] = value;
|
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 {
|
impl Decoder for ESH {
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ pub enum FError {
|
||||||
StreamOverflow(usize, usize, usize),
|
StreamOverflow(usize, usize, usize),
|
||||||
NoZeroTerminator,
|
NoZeroTerminator,
|
||||||
EntityNoESH,
|
EntityNoESH,
|
||||||
EntityNoAttributes,
|
NoESHValue,
|
||||||
EntityNoModifiers,
|
ESHValueNonBinary,
|
||||||
AttributesNonBinary,
|
AttributesNonBinary,
|
||||||
AttributesNoESBIN,
|
ValueNoESBIN
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for FError {
|
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::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::NoESHValue => write!(f, "Entity has no specific ESH value"),
|
||||||
FE::EntityNoModifiers => write!(f, "Entity has no Modifiers"),
|
FE::ESHValueNonBinary => write!(f, "ESH value is not binary"),
|
||||||
FE::AttributesNonBinary => write!(f, "Attributes Binary != true"),
|
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> {
|
pub fn test(&mut self) -> Result<(), FE> {
|
||||||
//let actor_type = self.entlist.get_type_idx("Actor").unwrap();
|
//let actor_type = self.entlist.get_type_idx("Actor").unwrap();
|
||||||
//let ent = self.entlist.get_entity_mut(2122);
|
//let ent = self.entlist.get_entity_mut(2122);
|
||||||
for (id, ent) in &mut self.entlist {
|
let ent = self.entlist.get_entity_mut(2122);
|
||||||
ent.flags = 1;
|
let esh = ent.get_esh_mut()?;
|
||||||
}
|
|
||||||
|
|
||||||
let ent = self.entlist.get_entity_mut(2158);
|
|
||||||
let esh = ent.get_esh()?;
|
|
||||||
for (name, value) in &esh.props {
|
for (name, value) in &esh.props {
|
||||||
println!("{} {}", name, value);
|
println!("{} {}", name, value);
|
||||||
}
|
}
|
||||||
//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_modifiers()?;
|
let mut attribs = esh.get_nested("Current Attributes")?;
|
||||||
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
for (name, value) in &attribs.props {
|
||||||
dbg!(bin.len());
|
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()?;
|
attribs.set("hitPoints", ESHValue::Int(999));
|
||||||
if let ESHValue::Binary(bin) = &esh.get("Modifiers").unwrap() {
|
attribs.set("poisonPoints", ESHValue::Int(0));
|
||||||
dbg!(bin.len());
|
|
||||||
}
|
esh.set_nested("Current Attributes", attribs)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue