From bc4cd5ccc90fe904f0e3219ec37a7ad50824ec4e Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Thu, 10 Oct 2024 17:09:41 +0200 Subject: [PATCH] move pos to module --- src/editor.rs | 3 +- src/marble_engine.rs | 4 ++- src/marble_engine/board.rs | 60 +------------------------------------- src/marble_engine/pos.rs | 60 ++++++++++++++++++++++++++++++++++++++ src/marble_engine/tile.rs | 2 +- 5 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 src/marble_engine/pos.rs diff --git a/src/editor.rs b/src/editor.rs index 8692957..ab4cfb7 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -11,7 +11,8 @@ use crate::{ draw_scaled_texture, draw_usize, level::Level, marble_engine::{ - board::{Board, Pos}, + board::Board, + pos::Pos, tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType}, Machine, }, diff --git a/src/marble_engine.rs b/src/marble_engine.rs index bff51b6..3b60659 100644 --- a/src/marble_engine.rs +++ b/src/marble_engine.rs @@ -1,8 +1,10 @@ use raylib::prelude::*; pub mod board; +pub mod pos; pub mod tile; -use board::{Board, Pos}; +use board::Board; +use pos::*; use tile::*; #[derive(Debug)] diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 0a2f18d..aa7fa8f 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -1,67 +1,9 @@ -use std::ops::Add; - use crate::{draw_scaled_texture, Textures}; use super::tile::*; +use super::Pos; use raylib::prelude::*; -#[derive(Debug, Default, Clone, Copy, PartialEq)] -pub struct Pos { - pub x: isize, - pub y: isize, -} - -impl Pos { - pub const fn to_vec(self) -> Vector2 { - Vector2 { - x: self.x as f32, - y: self.y as f32, - } - } - - pub fn min(self, other: Self) -> Self { - Self { - x: self.x.min(other.x), - y: self.y.min(other.y), - } - } - - pub fn max(self, other: Self) -> Self { - Self { - x: self.x.max(other.x), - y: self.y.max(other.y), - } - } -} - -impl From<(usize, usize)> for Pos { - fn from(value: (usize, usize)) -> Self { - Self { - x: value.0 as isize, - y: value.1 as isize, - } - } -} - -impl From for Pos { - fn from(vec: Vector2) -> Self { - Self { - x: vec.x as isize, - y: vec.y as isize, - } - } -} - -impl Add for Pos { - type Output = Self; - fn add(self, rhs: Self) -> Self::Output { - Self { - x: self.x + rhs.x, - y: self.y + rhs.y, - } - } -} - #[derive(Debug, Clone)] pub struct Board { rows: Vec>, diff --git a/src/marble_engine/pos.rs b/src/marble_engine/pos.rs new file mode 100644 index 0000000..35c945b --- /dev/null +++ b/src/marble_engine/pos.rs @@ -0,0 +1,60 @@ +use std::ops::Add; + +use raylib::prelude::*; + +#[derive(Debug, Default, Clone, Copy, PartialEq)] +pub struct Pos { + pub x: isize, + pub y: isize, +} + +impl Pos { + pub const fn to_vec(self) -> Vector2 { + Vector2 { + x: self.x as f32, + y: self.y as f32, + } + } + + pub fn min(self, other: Self) -> Self { + Self { + x: self.x.min(other.x), + y: self.y.min(other.y), + } + } + + pub fn max(self, other: Self) -> Self { + Self { + x: self.x.max(other.x), + y: self.y.max(other.y), + } + } +} + +impl From<(usize, usize)> for Pos { + fn from(value: (usize, usize)) -> Self { + Self { + x: value.0 as isize, + y: value.1 as isize, + } + } +} + +impl From for Pos { + fn from(vec: Vector2) -> Self { + Self { + x: vec.x as isize, + y: vec.y as isize, + } + } +} + +impl Add for Pos { + type Output = Self; + fn add(self, rhs: Self) -> Self::Output { + Self { + x: self.x + rhs.x, + y: self.y + rhs.y, + } + } +} diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index 6de8e11..4209f47 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -1,4 +1,4 @@ -use super::board::Pos; +use crate::marble_engine::Pos; pub type MarbleValue = u32;