summaryrefslogtreecommitdiff
path: root/graphics/src/lib.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-10-18 13:21:40 -0400
committerFreya Murphy <freya@freyacat.org>2025-10-18 13:21:40 -0400
commit8e7268c661e8df25224c907ba68eeb5a9cc5ff11 (patch)
tree27db2f024ae85d95ca5ba7ead9e637ac3c9c9ee7 /graphics/src/lib.rs
parentgraphics: remove anyhow (it was not being used) (diff)
downloadDungeonCrawl-8e7268c661e8df25224c907ba68eeb5a9cc5ff11.tar.gz
DungeonCrawl-8e7268c661e8df25224c907ba68eeb5a9cc5ff11.tar.bz2
DungeonCrawl-8e7268c661e8df25224c907ba68eeb5a9cc5ff11.zip
graphics: add audio/texture subsytem
Diffstat (limited to 'graphics/src/lib.rs')
-rw-r--r--graphics/src/lib.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 6e5eb91..1ca03b3 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -2,12 +2,15 @@
//! rendering using the `raylib` library.
use std::cell::RefCell;
+use std::error::Error;
use raylib::prelude::*;
+use crate::assets::{Assets, AudioData};
use crate::render::{FrameInfo, Renderer};
-pub mod render;
+mod assets;
+mod render;
/// The `KeyCode` type represents different keys being pressed on the users keyboard
pub use raylib::consts::KeyboardKey as KeyCode;
@@ -15,8 +18,11 @@ pub use raylib::consts::KeyboardKey as KeyCode;
/// The `Window` type represents the game window
#[derive(Debug)]
pub struct Window {
+ // core raylib handles
handle: RefCell<RaylibHandle>,
thread: RaylibThread,
+ // static assets
+ assets: Assets,
}
impl Window {
@@ -27,20 +33,25 @@ impl Window {
/// ```no_run
/// use graphics::Window;
///
- /// let window = Window::new(800, 600, "Dungeon Crawl");
+ /// let window = Window::new(800, 600, "Dungeon Crawl").unwrap();
/// ```
- pub fn new(width: i32, height: i32, title: &str) -> Self {
- let (handle, thread) = raylib::init()
+ pub fn new(width: i32, height: i32, title: &str) -> Result<Self, Box<dyn Error>> {
+ let (mut handle, thread) = raylib::init()
.size(width, height)
.title(title)
.resizable()
.log_level(TraceLogLevel::LOG_WARNING)
.vsync()
.build();
- Self {
+
+ // we will now initalize all assets
+ let assets = Assets::load(&mut handle, &thread)?;
+
+ Ok(Self {
handle: RefCell::new(handle),
thread,
- }
+ assets,
+ })
}
/// Returns if the window should be closed.
@@ -55,11 +66,11 @@ impl Window {
/// ```no_run
/// use graphics::Window;
///
- /// let mut window = Window::new(800, 600, "Dungeon Crawl");
+ /// let mut window = Window::new(800, 600, "Dungeon Crawl").unwrap();
/// let mut renderer = window.renderer();
/// ```
pub fn renderer(&mut self) -> Renderer<'_> {
- let info = FrameInfo::new(self.handle.get_mut());
+ let info = FrameInfo::new(self.handle.get_mut(), &self.assets.image);
let handle = self.handle.get_mut().begin_drawing(&self.thread);
Renderer::new(handle, info)
}
@@ -88,4 +99,9 @@ impl Window {
pub fn get_key_pressed(&self) -> Option<KeyCode> {
self.handle.borrow_mut().get_key_pressed()
}
+
+ /// Get audio data for the window
+ pub fn audio(&self) -> &AudioData {
+ &self.assets.audio
+ }
}