summaryrefslogtreecommitdiff
path: root/engine/src/texture.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-14 12:34:52 +0200
committerHampusM <hampus@hampusmat.com>2024-04-14 12:35:28 +0200
commit101b455e51f9b702da5517cabe2c3b1086fcb2e7 (patch)
tree470e28acd7a3777dbb4be0208f9cd3177bba52a9 /engine/src/texture.rs
parentef7b76ff39d501028852835649f618fcbe17a003 (diff)
feat(engine): use ECS architecture
Diffstat (limited to 'engine/src/texture.rs')
-rw-r--r--engine/src/texture.rs32
1 files changed, 32 insertions, 0 deletions
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<u32>
{
&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<Id, Texture>,
+}
+
+impl FromIterator<(Id, Texture)> for Map
+{
+ fn from_iter<Iter>(iter: Iter) -> Self
+ where
+ Iter: IntoIterator<Item = (Id, Texture)>,
+ {
+ Self { inner: iter.into_iter().collect() }
+ }
+}