aboutsummaryrefslogtreecommitdiff
path: root/stockton-levels
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:24 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:24 +0100
commit6367a9ba5a549b62f01da61fb50323877b9f52ff (patch)
treeeb83ed6487f2ec35f9ea1e97124c9a173b8ceef0 /stockton-levels
parentf84ec1a3e077fa0f2e9cd310b6e32e81f1bc1129 (diff)
refactor(all): move types to -skeleton
Diffstat (limited to 'stockton-levels')
-rw-r--r--stockton-levels/Cargo.toml3
-rw-r--r--stockton-levels/src/parts/mod.rs2
-rw-r--r--stockton-levels/src/parts/textures.rs37
-rw-r--r--stockton-levels/src/parts/visdata.rs2
4 files changed, 40 insertions, 4 deletions
diff --git a/stockton-levels/Cargo.toml b/stockton-levels/Cargo.toml
index b70268b..448a8ba 100644
--- a/stockton-levels/Cargo.toml
+++ b/stockton-levels/Cargo.toml
@@ -10,4 +10,5 @@ edition = "2018"
[dependencies]
nalgebra = "^0.20"
serde = { version = "1.0", features = ["derive"] }
-stockton-types = { path = "../stockton-types" }
+stockton-skeleton = { path = "../stockton-skeleton" }
+image = "0.23.11"
diff --git a/stockton-levels/src/parts/mod.rs b/stockton-levels/src/parts/mod.rs
index 05697f0..d164bc3 100644
--- a/stockton-levels/src/parts/mod.rs
+++ b/stockton-levels/src/parts/mod.rs
@@ -13,5 +13,5 @@ pub mod data {
pub use entities::{HasEntities, IsEntity};
pub use faces::{HasFaces, IsFace};
-pub use textures::{HasTextures, IsTexture};
+pub use textures::{HasTextures, IsTexture, FsResolver};
pub use visdata::HasVisData;
diff --git a/stockton-levels/src/parts/textures.rs b/stockton-levels/src/parts/textures.rs
index 8e6cb9a..ae946fd 100644
--- a/stockton-levels/src/parts/textures.rs
+++ b/stockton-levels/src/parts/textures.rs
@@ -11,7 +11,9 @@
// 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;
+use std::{iter::Iterator, path::Path, sync::{Arc, RwLock}};
+use image::{RgbaImage, io::Reader};
+use stockton_skeleton::texture::TextureResolver;
pub type TextureRef = u32;
@@ -46,3 +48,36 @@ impl<'a, T: HasTextures> Iterator for Textures<'a, T> {
res
}
}
+
+
+/// A basic filesystem resolver which gets the texture name from any HasTextures Object.
+pub struct FsResolver<'a, T: HasTextures> {
+ path: &'a Path,
+ map_lock: Arc<RwLock<T>>,
+}
+
+impl<'a, T: HasTextures> FsResolver<'a, T> {
+ pub fn new(path: &'a Path, map_lock: Arc<RwLock<T>>) -> Self {
+ FsResolver { path, map_lock }
+ }
+}
+
+impl<'a, T: HasTextures> TextureResolver for FsResolver<'a, T> {
+ type Image = RgbaImage;
+
+ fn resolve(&mut self, tex: u32) -> Option<Self::Image> {
+ let map = self.map_lock.read().unwrap();
+ let tex = map.get_texture(tex)?;
+ let path = self.path.join(&tex.name());
+
+ if let Ok(file) = Reader::open(path) {
+ if let Ok(guessed) = file.with_guessed_format() {
+ if let Ok(decoded) = guessed.decode() {
+ return Some(decoded.into_rgba8());
+ }
+ }
+ }
+
+ None
+ }
+}
diff --git a/stockton-levels/src/parts/visdata.rs b/stockton-levels/src/parts/visdata.rs
index aa2ec3d..3e58d4c 100644
--- a/stockton-levels/src/parts/visdata.rs
+++ b/stockton-levels/src/parts/visdata.rs
@@ -1,6 +1,6 @@
use super::faces::FaceRef;
use std::iter::Iterator;
-use stockton_types::components::{CameraSettings, Transform};
+use stockton_skeleton::components::{CameraSettings, Transform};
pub trait HasVisData<'a> {
type Faces: Iterator<Item = FaceRef>;