impl cmp<str> for FString, so comparing to other string types will be as easy as now it is. Add get_type_idx for EntityList
This commit is contained in:
parent
88003c2997
commit
676b7b598f
3 changed files with 15 additions and 7 deletions
|
|
@ -44,6 +44,10 @@ impl EntityList {
|
||||||
self.types.len() - 1
|
self.types.len() - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_type_idx(&self, type_name: &str) -> Option<usize> {
|
||||||
|
self.types.iter().position(|f| f.eq(type_name))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_or_get_type(&mut self, type_name: FString) -> usize {
|
pub fn add_or_get_type(&mut self, type_name: FString) -> usize {
|
||||||
match self.types.iter().position(|f| f.eq(&type_name)) {
|
match self.types.iter().position(|f| f.eq(&type_name)) {
|
||||||
Some(idx) => idx,
|
Some(idx) => idx,
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,12 @@ impl PartialEq for FString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::cmp::PartialEq<str> for FString {
|
||||||
|
fn eq(&self, other: &str) -> bool {
|
||||||
|
self.str == other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Hash for FString {
|
impl Hash for FString {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.str.hash(state);
|
self.str.hash(state);
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,11 @@ impl World {
|
||||||
const WORLD_HDR_LEN: usize = 0x13;
|
const WORLD_HDR_LEN: usize = 0x13;
|
||||||
|
|
||||||
pub fn test(&mut self) -> Result<()> {
|
pub fn test(&mut self) -> Result<()> {
|
||||||
/*self.entlist.convert(EntityEncoding::File);
|
let actor_type = self.entlist.get_type_idx("Actor").unwrap();
|
||||||
self.entlist
|
println!("Actor type {}", actor_type);
|
||||||
.encode(EntityEncoding::File)?
|
//for (id, ent) in &self.entlist {
|
||||||
.dump(Path::new("D:\\entlist.ent"))?;*/
|
// println!("{} {}", id, ent.type_idx);
|
||||||
for (id, ent) in &self.entlist {
|
//}
|
||||||
println!("{} {}", id, ent.type_idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue