From 101b455e51f9b702da5517cabe2c3b1086fcb2e7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 14 Apr 2024 12:34:52 +0200 Subject: feat(engine): use ECS architecture --- engine/src/texture.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'engine/src/texture.rs') diff --git a/engine/src/texture.rs b/engine/src/texture.rs index 2d7ba51..b0f0278 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -1,5 +1,8 @@ +use std::collections::HashMap; +use std::fmt::Display; use std::path::Path; +use ecs::Component; use image::io::Reader as ImageReader; use image::{DynamicImage, ImageError, Rgb, RgbImage}; @@ -74,6 +77,7 @@ impl Texture } } + #[must_use] pub fn properties(&self) -> &Properties { &self.properties @@ -84,16 +88,19 @@ impl Texture &mut self.properties } + #[must_use] pub fn dimensions(&self) -> &Vec2 { &self.dimensions } + #[must_use] pub fn pixel_data_format(&self) -> PixelDataFormat { self.pixel_data_format } + #[must_use] pub fn image(&self) -> &DynamicImage { &self.image @@ -157,3 +164,28 @@ impl Id self.id } } + +impl Display for Id +{ + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result + { + self.id.fmt(formatter) + } +} + +/// Texture map. +#[derive(Component)] +pub struct Map +{ + pub inner: HashMap, +} + +impl FromIterator<(Id, Texture)> for Map +{ + fn from_iter(iter: Iter) -> Self + where + Iter: IntoIterator, + { + Self { inner: iter.into_iter().collect() } + } +} -- cgit v1.2.3-18-g5258