use crate::techblox::{hashname, brute_force, Parsable, blocks::lookup_name_by_hash};
use libfj_parsable_macro_derive::*;
#[derive(Clone, Copy, Parsable)]
pub struct EntityHeader {
pub hash: u32,
pub entity_id: u32,
pub group_id: u32,
pub component_count: u8,
}
impl EntityHeader {
pub fn guess_name(&self) -> String {
brute_force(self.hash)
}
pub fn lookup_name(&self) -> Option<String> {
if let Some(name) = lookup_name_by_hash(self.hash) {
return Some(name.to_string());
}
None
}
pub fn from_name(name: &str, entity_id: u32, group_id: u32, component_count: u8) -> Self {
Self {
hash: hashname(name),
entity_id,
group_id,
component_count,
}
}
}
impl std::convert::Into<EntityGroupID> for EntityHeader {
fn into(self) -> EntityGroupID {
EntityGroupID {
entity_id: self.entity_id,
group_id: self.group_id,
}
}
}
#[derive(Clone, Copy, Parsable)]
pub struct EntityGroupID {
pub entity_id: u32,
pub group_id: u32
}