modify IntoIterator that now it yields (id, &Entity)

This commit is contained in:
mykola2312 2023-09-05 00:17:48 +03:00
parent 201b51e85c
commit 88003c2997
2 changed files with 7 additions and 7 deletions

View file

@ -26,8 +26,8 @@ pub struct EntityList {
unk1: u32, unk1: u32,
enc_size: usize, enc_size: usize,
pub types: Vec<FString>, types: Vec<FString>,
pub ents: Vec<Entity>, ents: Vec<Entity>,
} }
impl EntityList { impl EntityList {
@ -161,10 +161,10 @@ impl DecoderCtx<EntityEncoding, EntityEncoding> for EntityList {
} }
impl<'a> IntoIterator for &'a EntityList { impl<'a> IntoIterator for &'a EntityList {
type Item = &'a Entity; type Item = (usize, &'a Entity);
type IntoIter = std::slice::Iter<'a, Entity>; type IntoIter = std::iter::Zip<std::ops::RangeFrom<usize>, std::slice::Iter<'a, Entity>>;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.ents.iter() (1..).zip(&self.ents)
} }
} }

View file

@ -37,8 +37,8 @@ impl World {
self.entlist self.entlist
.encode(EntityEncoding::File)? .encode(EntityEncoding::File)?
.dump(Path::new("D:\\entlist.ent"))?;*/ .dump(Path::new("D:\\entlist.ent"))?;*/
for ent in &self.entlist { for (id, ent) in &self.entlist {
println!("{}", ent.type_idx); println!("{} {}", id, ent.type_idx);
} }
Ok(()) Ok(())