diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 439219e74090c7158f8dbc33fed4107a5eb7c003 (patch) | |
tree | 7ba62254b2d888578ff6c1c8de4f0f35c01c75dd /stockton-levels/src/parts/entities.rs | |
parent | 04f17923d38171f07f72603a54237f20ca3572dd (diff) |
refactor(levels): no longer q3 specific
Diffstat (limited to 'stockton-levels/src/parts/entities.rs')
-rw-r--r-- | stockton-levels/src/parts/entities.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/stockton-levels/src/parts/entities.rs b/stockton-levels/src/parts/entities.rs new file mode 100644 index 0000000..7a5ac74 --- /dev/null +++ b/stockton-levels/src/parts/entities.rs @@ -0,0 +1,36 @@ +use std::iter::Iterator; + +pub type EntityRef = u32; + +/// A game entity +pub trait IsEntity<C: HasEntities + ?Sized> { + fn get_attr(&self, container: &C) -> Option<&str>; +} + +pub trait HasEntities { + type Entity: IsEntity<Self>; + + fn get_entity(&self, idx: EntityRef) -> Option<&Self::Entity>; + fn iter_entities(&self) -> Entities<Self> { + Entities { + next: 0, + container: self, + } + } +} + +#[derive(Debug, Clone, Copy)] +pub struct Entities<'a, T: HasEntities + ?Sized> { + next: EntityRef, + container: &'a T, +} + +impl<'a, T: HasEntities> Iterator for Entities<'a, T> { + type Item = &'a T::Entity; + + fn next(&mut self) -> Option<Self::Item> { + let res = self.container.get_entity(self.next); + self.next += 1; + res + } +} |