From 8fa3fa881bc3b954e136295fe6cc7022737ae9db Mon Sep 17 00:00:00 2001
From: Guillaume Pasquet <guillaume.pasquet@eggplant.io>
Date: Tue, 12 Nov 2019 14:22:19 +0100
Subject: Refactor all the things!

---
 src/tiling.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 src/tiling.rs

(limited to 'src/tiling.rs')

diff --git a/src/tiling.rs b/src/tiling.rs
new file mode 100644
index 0000000..139af24
--- /dev/null
+++ b/src/tiling.rs
@@ -0,0 +1,52 @@
+pub struct TileGrid {
+    grid: Vec<Vec<TileType>>
+}
+
+impl<'a> TileGrid {
+    pub fn new(xsize: usize, ysize: usize) -> TileGrid {
+        let mut grid = TileGrid {
+            grid: Vec::with_capacity(ysize)
+        };
+
+        for _ in 0..ysize {
+            let mut subvec = Vec::with_capacity(xsize);
+            for _ in 0..xsize {
+                subvec.push(TileType::Empty);
+            }
+            grid.grid.push(subvec);
+        }
+
+        return grid;
+    }
+
+    pub fn set_tile(&mut self, x: usize, y: usize, tile: TileType) {
+        self.grid[y][x] = tile;
+    }
+
+    /// Sets a tile if nothing lies underneath it.
+    pub fn set_empty_tile(&mut self, x: usize, y: usize, tile: TileType) {
+        self.set_tile(x, y, match self.grid[y][x] {
+            TileType::Empty => tile,
+            _ => self.grid[y][x].clone()
+        })
+    }
+
+    pub fn raw_data(&'a self) -> &'a Vec<Vec<TileType>> {
+        &self.grid
+    }
+}
+
+pub trait Tileable {
+    fn tile(&self, grid: &mut TileGrid) -> Result<(), String>;
+}
+
+#[derive(Clone)]
+pub enum TileType {
+    Empty,
+    Wall,
+    Floor,
+    StairsUp,
+    StairsDown,
+    Character,
+    Player
+}
-- 
cgit v1.2.3