implement basic functionality of EntityList
This commit is contained in:
parent
226b8dcfb9
commit
ff900bf123
2 changed files with 32 additions and 10 deletions
|
|
@ -23,14 +23,24 @@ impl DecoderCtx<&mut EntityList> for Entity {
|
||||||
let type_idx = ctx.add_or_get_type(rd.read(0)?);
|
let type_idx = ctx.add_or_get_type(rd.read(0)?);
|
||||||
let esh: ESH = rd.read(0)?;
|
let esh: ESH = rd.read(0)?;
|
||||||
let enc_size = rd.offset() - offset;
|
let enc_size = rd.offset() - offset;
|
||||||
Entity { flags, type_idx, esh, enc_size }
|
Entity {
|
||||||
},
|
flags,
|
||||||
|
type_idx,
|
||||||
|
esh,
|
||||||
|
enc_size,
|
||||||
|
}
|
||||||
|
}
|
||||||
EntityEncoding::World => {
|
EntityEncoding::World => {
|
||||||
let flags = rd.read_u32()?;
|
let flags = rd.read_u32()?;
|
||||||
let type_idx = rd.read_u16()? as usize;
|
let type_idx = rd.read_u16()? as usize;
|
||||||
let esh: ESH = rd.read(0)?;
|
let esh: ESH = rd.read(0)?;
|
||||||
let enc_size = rd.offset() - offset;
|
let enc_size = rd.offset() - offset;
|
||||||
Entity { flags, type_idx, esh, enc_size }
|
Entity {
|
||||||
|
flags,
|
||||||
|
type_idx,
|
||||||
|
esh,
|
||||||
|
enc_size,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +52,7 @@ impl DecoderCtx<&mut EntityList> for Entity {
|
||||||
wd.write(ctx.get_entity_tag())?;
|
wd.write(ctx.get_entity_tag())?;
|
||||||
wd.write(ctx.get_type_name(self.type_idx))?;
|
wd.write(ctx.get_type_name(self.type_idx))?;
|
||||||
wd.write(&self.esh)?;
|
wd.write(&self.esh)?;
|
||||||
},
|
}
|
||||||
EntityEncoding::World => {
|
EntityEncoding::World => {
|
||||||
wd.write_u32(self.flags)?;
|
wd.write_u32(self.flags)?;
|
||||||
wd.write_u16(self.type_idx as u16)?;
|
wd.write_u16(self.type_idx as u16)?;
|
||||||
|
|
|
||||||
|
|
@ -8,31 +8,43 @@ use super::tag::Tag;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub enum EntityEncoding {
|
pub enum EntityEncoding {
|
||||||
File,
|
File,
|
||||||
World,
|
World,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EntityList {}
|
pub struct EntityList {
|
||||||
|
encoding: EntityEncoding,
|
||||||
|
entity_file_tag: Option<Tag>,
|
||||||
|
entity_tag: Option<Tag>,
|
||||||
|
|
||||||
|
types: Vec<FString>,
|
||||||
|
entities: Vec<Entity>
|
||||||
|
}
|
||||||
|
|
||||||
impl EntityList {
|
impl EntityList {
|
||||||
pub fn get_entity_encoding(&self) -> EntityEncoding {
|
pub fn get_entity_encoding(&self) -> EntityEncoding {
|
||||||
todo!();
|
self.encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_entity_tag(&self) -> &Tag {
|
pub fn get_entity_tag(&self) -> &Tag {
|
||||||
todo!();
|
self.entity_tag.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_new_type(&mut self, type_name: FString) -> usize {
|
pub fn add_new_type(&mut self, type_name: FString) -> usize {
|
||||||
todo!();
|
self.types.push(type_name);
|
||||||
|
self.types.len() - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_or_get_type(&mut self, type_name: FString) -> usize {
|
pub fn add_or_get_type(&mut self, type_name: FString) -> usize {
|
||||||
todo!();
|
match self.types.iter().position(|f| f.eq(&type_name)) {
|
||||||
|
Some(idx) => idx,
|
||||||
|
None => self.add_new_type(type_name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_type_name(&self, type_idx: usize) -> &FString {
|
pub fn get_type_name(&self, type_idx: usize) -> &FString {
|
||||||
todo!();
|
&self.types[type_idx]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue