summaryrefslogtreecommitdiff
path: root/graphics/src/assets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/assets.rs')
-rw-r--r--graphics/src/assets.rs124
1 files changed, 0 insertions, 124 deletions
diff --git a/graphics/src/assets.rs b/graphics/src/assets.rs
deleted file mode 100644
index bb989a3..0000000
--- a/graphics/src/assets.rs
+++ /dev/null
@@ -1,124 +0,0 @@
-//! The `assets` crate stores all audio and image assets that need to be
-//! loaded during runtime
-
-use dungeon::Item;
-use raylib::{RaylibHandle, RaylibThread, audio::RaylibAudio, texture::Texture2D};
-
-#[expect(dead_code)]
-type Sound = raylib::audio::Sound<'static>;
-
-/// The `AudioData` container initalizes the audio subsystem
-/// for raylib, leaks it (to gurentee audio is statically loaded),
-/// then loads all needed audio samples
-#[derive(Debug)]
-pub struct AudioData {}
-impl AudioData {
- pub(crate) fn load() -> crate::Result<Self> {
- // Phantom handle to the raylib audio subsystem
- // Raylib doesnt use a handle, but the rust bindings
- // have one to ensure memory safety.
- //
- // We must leak this handle after allocating it,
- // if we dont then all audio will be unloaded :(
- //
- // NOTE: would this cause issues if `AudioData::load` was
- // called multiple times?
- let _handle = Box::leak(Box::new(RaylibAudio::init_audio_device()?));
-
- // TODO: load audio samples
-
- //let example = handle.new_sound("example.ogg")?;
-
- Ok(Self {})
- }
-}
-
-/// The baseline size of all ingame sprites and tile textures
-pub(crate) const BASE_TILE_SIZE: i32 = 32;
-
-/// The height of the wall (offset between tile layers)
-pub(crate) const WALL_HEIGHT: i32 = 13;
-
-/// Texture indexes into the atlas
-#[derive(Clone, Copy, Debug)]
-pub(crate) enum AtlasTexture {
- Wall,
- FloorFull,
- FloorEmpty,
- WallBase,
- WallEdgeNorth,
- WallEdgeEast,
- WallEdgeSouth,
- WallEdgeWest,
- Player,
- InvTopLayer,
- InvBottomLayer,
- Error,
-}
-impl AtlasTexture {
- /// Returns the x,y position of the sprite on the atlas.bmp texture
- #[must_use]
- pub(crate) const fn xy(&self) -> (i32, i32) {
- match self {
- Self::Wall => (0, 0),
- Self::FloorFull => (1, 0),
- Self::FloorEmpty => (2, 0),
- Self::WallBase => (3, 0),
- Self::WallEdgeNorth => (0, 1),
- Self::WallEdgeEast => (1, 1),
- Self::WallEdgeSouth => (2, 1),
- Self::WallEdgeWest => (3, 1),
- Self::Player => (0, 2),
- Self::InvTopLayer => (1, 2),
- Self::InvBottomLayer => (2, 2),
- Self::Error => (3, 3),
- }
- }
-
- /// Returns the x position of the sprite on the atlas.bmp texture
- #[must_use]
- pub(crate) const fn x(&self) -> i32 {
- self.xy().0
- }
-
- /// Returns the y position of the sprite on the atlas.bmp texture
- #[must_use]
- pub(crate) const fn y(&self) -> i32 {
- self.xy().1
- }
-}
-
-/// The `ImageData` container loads all game sprites, and other images into memory.
-#[derive(Debug)]
-pub(crate) struct ImageData {
- pub(crate) atlas: Texture2D,
- pub(crate) heart_full: Texture2D,
- pub(crate) heart_half: Texture2D,
- pub(crate) heart_empty: Texture2D,
- pub(crate) error: Texture2D,
-}
-impl ImageData {
- pub(crate) fn load(
- handle: &mut RaylibHandle,
- thread: &RaylibThread,
- ) -> crate::Result<Self> {
- let atlas = handle.load_texture(thread, "assets/atlas.bmp")?;
- let heart_full = handle.load_texture(thread, "assets/heart_full.bmp")?;
- let heart_half = handle.load_texture(thread, "assets/heart_half.bmp")?;
- let heart_empty = handle.load_texture(thread, "assets/heart_empty.bmp")?;
- let error = handle.load_texture(thread, "assets/error.bmp")?;
-
- Ok(Self {
- atlas,
- heart_full,
- heart_half,
- heart_empty,
- error,
- })
- }
-
- pub(crate) fn get_item_texture(&self, _item: &Item) -> &Texture2D {
- // TODO: make item textures
- &self.error
- }
-}