From 676b7b598f87a9922046701954a827febaca4a86 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:23:59 +0300 Subject: [PATCH] impl cmp for FString, so comparing to other string types will be as easy as now it is. Add get_type_idx for EntityList --- src/fot/entitylist.rs | 4 ++++ src/fot/fstring.rs | 6 ++++++ src/fot/world.rs | 12 +++++------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index 7e86058..8643e64 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -44,6 +44,10 @@ impl EntityList { self.types.len() - 1 } + pub fn get_type_idx(&self, type_name: &str) -> Option { + self.types.iter().position(|f| f.eq(type_name)) + } + pub fn add_or_get_type(&mut self, type_name: FString) -> usize { match self.types.iter().position(|f| f.eq(&type_name)) { Some(idx) => idx, diff --git a/src/fot/fstring.rs b/src/fot/fstring.rs index 439ba15..84f0539 100644 --- a/src/fot/fstring.rs +++ b/src/fot/fstring.rs @@ -89,6 +89,12 @@ impl PartialEq for FString { } } +impl std::cmp::PartialEq for FString { + fn eq(&self, other: &str) -> bool { + self.str == other + } +} + impl Hash for FString { fn hash(&self, state: &mut H) { self.str.hash(state); diff --git a/src/fot/world.rs b/src/fot/world.rs index 1f56e4f..1569717 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -33,13 +33,11 @@ impl World { const WORLD_HDR_LEN: usize = 0x13; pub fn test(&mut self) -> Result<()> { - /*self.entlist.convert(EntityEncoding::File); - self.entlist - .encode(EntityEncoding::File)? - .dump(Path::new("D:\\entlist.ent"))?;*/ - for (id, ent) in &self.entlist { - println!("{} {}", id, ent.type_idx); - } + let actor_type = self.entlist.get_type_idx("Actor").unwrap(); + println!("Actor type {}", actor_type); + //for (id, ent) in &self.entlist { + // println!("{} {}", id, ent.type_idx); + //} Ok(()) }