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/textures.rs | |
parent | 04f17923d38171f07f72603a54237f20ca3572dd (diff) |
refactor(levels): no longer q3 specific
Diffstat (limited to 'stockton-levels/src/parts/textures.rs')
-rw-r--r-- | stockton-levels/src/parts/textures.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/stockton-levels/src/parts/textures.rs b/stockton-levels/src/parts/textures.rs new file mode 100644 index 0000000..8e6cb9a --- /dev/null +++ b/stockton-levels/src/parts/textures.rs @@ -0,0 +1,48 @@ +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. + +use std::iter::Iterator; + +pub type TextureRef = u32; + +pub trait IsTexture { + fn name(&self) -> &str; +} + +pub trait HasTextures { + type Texture: IsTexture; + + fn get_texture(&self, idx: TextureRef) -> Option<&Self::Texture>; + fn iter_textures(&self) -> Textures<Self> { + Textures { + next: 0, + container: self, + } + } +} + +#[derive(Debug, Clone, Copy)] +pub struct Textures<'a, T: HasTextures + ?Sized> { + next: TextureRef, + container: &'a T, +} + +impl<'a, T: HasTextures> Iterator for Textures<'a, T> { + type Item = &'a T::Texture; + + fn next(&mut self) -> Option<Self::Item> { + let res = self.container.get_texture(self.next); + self.next += 1; + res + } +} |