move pos to module

This commit is contained in:
Crispy 2024-10-10 17:09:41 +02:00
parent e22f568d2f
commit bc4cd5ccc9
5 changed files with 67 additions and 62 deletions

View file

@ -11,7 +11,8 @@ use crate::{
draw_scaled_texture, draw_usize, draw_scaled_texture, draw_usize,
level::Level, level::Level,
marble_engine::{ marble_engine::{
board::{Board, Pos}, board::Board,
pos::Pos,
tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType}, tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType},
Machine, Machine,
}, },

View file

@ -1,8 +1,10 @@
use raylib::prelude::*; use raylib::prelude::*;
pub mod board; pub mod board;
pub mod pos;
pub mod tile; pub mod tile;
use board::{Board, Pos}; use board::Board;
use pos::*;
use tile::*; use tile::*;
#[derive(Debug)] #[derive(Debug)]

View file

@ -1,67 +1,9 @@
use std::ops::Add;
use crate::{draw_scaled_texture, Textures}; use crate::{draw_scaled_texture, Textures};
use super::tile::*; use super::tile::*;
use super::Pos;
use raylib::prelude::*; 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<Vector2> 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)] #[derive(Debug, Clone)]
pub struct Board { pub struct Board {
rows: Vec<Vec<Tile>>, rows: Vec<Vec<Tile>>,

60
src/marble_engine/pos.rs Normal file
View file

@ -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<Vector2> 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,
}
}
}

View file

@ -1,4 +1,4 @@
use super::board::Pos; use crate::marble_engine::Pos;
pub type MarbleValue = u32; pub type MarbleValue = u32;