From ff900bf123bbdcc3499748012fdbdee247e70ffd Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Mon, 4 Sep 2023 02:52:18 +0300 Subject: [PATCH] implement basic functionality of EntityList --- src/fot/entity.rs | 18 ++++++++++++++---- src/fot/entitylist.rs | 24 ++++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/fot/entity.rs b/src/fot/entity.rs index 67f4e43..24e2c4b 100644 --- a/src/fot/entity.rs +++ b/src/fot/entity.rs @@ -23,14 +23,24 @@ impl DecoderCtx<&mut EntityList> for Entity { let type_idx = ctx.add_or_get_type(rd.read(0)?); let esh: ESH = rd.read(0)?; let enc_size = rd.offset() - offset; - Entity { flags, type_idx, esh, enc_size } - }, + Entity { + flags, + type_idx, + esh, + enc_size, + } + } EntityEncoding::World => { let flags = rd.read_u32()?; let type_idx = rd.read_u16()? as usize; let esh: ESH = rd.read(0)?; 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_type_name(self.type_idx))?; wd.write(&self.esh)?; - }, + } EntityEncoding::World => { wd.write_u32(self.flags)?; wd.write_u16(self.type_idx as u16)?; diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index 494e1c5..5c58641 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -8,31 +8,43 @@ use super::tag::Tag; use anyhow::anyhow; use anyhow::Result; +#[derive(Clone, Copy)] pub enum EntityEncoding { File, World, } -pub struct EntityList {} +pub struct EntityList { + encoding: EntityEncoding, + entity_file_tag: Option, + entity_tag: Option, + + types: Vec, + entities: Vec +} impl EntityList { pub fn get_entity_encoding(&self) -> EntityEncoding { - todo!(); + self.encoding } 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 { - todo!(); + self.types.push(type_name); + self.types.len() - 1 } 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 { - todo!(); + &self.types[type_idx] } }