summaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/Cargo.toml15
-rw-r--r--graphics/src/lib.rs31
2 files changed, 46 insertions, 0 deletions
diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml
new file mode 100644
index 0000000..0842f90
--- /dev/null
+++ b/graphics/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "graphics"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+anyhow = "1"
+dungeon = { path = "../dungeon" }
+raylib = "5.5"
+
+[target.'cfg(target_os = "linux")'.dependencies]
+raylib = { version = "5.5", features = ["wayland"] }
+
+[lints]
+workspace = true
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
new file mode 100644
index 0000000..c0b0019
--- /dev/null
+++ b/graphics/src/lib.rs
@@ -0,0 +1,31 @@
+use dungeon::Dungeon;
+use raylib::prelude::*;
+
+pub struct Window {
+ handle: RaylibHandle,
+ thread: RaylibThread,
+}
+impl Window {
+ /// Instantiates a new window provided with the default
+ /// window `width`, `height`, and `title`.
+ pub fn new(width: i32, height: i32, title: &str) -> Self {
+ let (handle, thread) = raylib::init()
+ .size(width, height)
+ .title(title)
+ .resizable()
+ .log_level(TraceLogLevel::LOG_WARNING)
+ .build();
+ Self { handle, thread }
+ }
+
+ /// Returns if the window should be closed.
+ /// This usually means the 'x' button has been pressed.
+ pub fn is_open(&self) -> bool {
+ !self.handle.window_should_close()
+ }
+
+ /// Draws a frame provided with the game state `Dungeon`
+ pub fn draw(&mut self, _dungeon: &Dungeon) {
+ let _draw = self.handle.begin_drawing(&self.thread);
+ }
+}