From 8f1b043b93ae0a319feb7f8d4b3b5fc9f1f372e4 Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 1 Jul 2019 01:19:59 -0400 Subject: [PATCH] maraiah: add functions to EntryData for gathering info --- maraiah/map/data.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/maraiah/map/data.rs b/maraiah/map/data.rs index abfcc2a..fcbe0bd 100644 --- a/maraiah/map/data.rs +++ b/maraiah/map/data.rs @@ -76,6 +76,88 @@ pub fn read_all(head: &head::Header, Ok(data_map) } +impl EntryData +{ + pub fn get_type(&self) -> EntryType + { + if self.has_minf() { + EntryType::Map + } else if self.has_fxpx() || + self.has_mnpx() || + self.has_prpx() || + self.has_pxpx() || + self.has_wppx() { + EntryType::Physics + } else if self.has_pict() { + EntryType::Image + } else { + EntryType::Other + } + } + + pub fn has_epnt(&self) -> bool {self.epnt.is_some()} + pub fn has_fxpx(&self) -> bool {self.fxpx.is_some()} + pub fn has_lins(&self) -> bool {self.lins.is_some()} + pub fn has_lite(&self) -> bool {self.lite.is_some()} + pub fn has_mnpx(&self) -> bool {self.mnpx.is_some()} + pub fn has_minf(&self) -> bool {self.minf.is_some()} + pub fn has_name(&self) -> bool {self.name.is_some()} + pub fn has_note(&self) -> bool {self.note.is_some()} + pub fn has_objs(&self) -> bool {self.objs.is_some()} + pub fn has_pict(&self) -> bool {self.pict.is_some()} + pub fn has_pnts(&self) -> bool {self.pnts.is_some()} + pub fn has_poly(&self) -> bool {self.poly.is_some()} + pub fn has_prpx(&self) -> bool {self.prpx.is_some()} + pub fn has_pxpx(&self) -> bool {self.pxpx.is_some()} + pub fn has_sids(&self) -> bool {self.sids.is_some()} + pub fn has_wppx(&self) -> bool {self.wppx.is_some()} + pub fn has_ambi(&self) -> bool {self.ambi.is_some()} + pub fn has_bonk(&self) -> bool {self.bonk.is_some()} + pub fn has_iidx(&self) -> bool {self.iidx.is_some()} + pub fn has_medi(&self) -> bool {self.medi.is_some()} + pub fn has_plac(&self) -> bool {self.plac.is_some()} + pub fn has_plat(&self) -> bool {self.plat.is_some()} + pub fn has_term(&self) -> bool {self.term.is_some()} + + pub fn num_unknown(&self) -> usize {self.unkn.len()} + + pub fn len(&self) -> usize + { + let ret = if self.has_epnt() {1} else {0} + + if self.has_fxpx() {1} else {0} + + if self.has_lins() {1} else {0} + + if self.has_lite() {1} else {0} + + if self.has_mnpx() {1} else {0} + + if self.has_minf() {1} else {0} + + if self.has_name() {1} else {0} + + if self.has_note() {1} else {0} + + if self.has_objs() {1} else {0} + + if self.has_pict() {1} else {0} + + if self.has_pnts() {1} else {0} + + if self.has_poly() {1} else {0} + + if self.has_prpx() {1} else {0} + + if self.has_pxpx() {1} else {0} + + if self.has_sids() {1} else {0} + + if self.has_wppx() {1} else {0} + + if self.has_ambi() {1} else {0} + + if self.has_bonk() {1} else {0} + + if self.has_iidx() {1} else {0} + + if self.has_medi() {1} else {0} + + if self.has_plac() {1} else {0} + + if self.has_plat() {1} else {0} + + self.num_unknown(); + ret + } +} + +/// The abstract type of an entry. +pub enum EntryType { + Other, + Map, + Image, + Physics, +} + /// The loaded data of a Map file entry. #[cfg_attr(feature = "serde_obj", derive(serde::Serialize))] #[derive(Debug, Default, Eq, PartialEq)]