//! The `assets` crate stores all audio and image assets that need to be //! loaded during runtime 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 { // 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, 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::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, } impl ImageData { pub(crate) fn load( handle: &mut RaylibHandle, thread: &RaylibThread, ) -> crate::Result { let atlas = handle.load_texture(thread, "assets/atlas.bmp")?; Ok(Self { atlas }) } }