diff --git a/src/editor.rs b/src/editor.rs index 457170b..90f2b29 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -13,7 +13,7 @@ use crate::{ level::Level, marble_engine::{ board::Board, - pos::Pos, + pos::{Pos, PosInt}, tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType}, Machine, }, @@ -28,7 +28,7 @@ const HEADER_HEIGHT: i32 = 40; const FOOTER_HEIGHT: i32 = 95; const SIDEBAR_WIDTH: i32 = 200 + 32 * 2 + 5 * 4; const MAX_ZOOM_IN: i32 = 3; -const BOARD_MARGIN: isize = 3; +const BOARD_MARGIN: PosInt = 3; const MAX_SPEED_POWER: u8 = 16; const SPEED_DIGITS: u8 = 5; const MAX_FRAME_TIME_MICROS: u128 = 1_000_000 / 30; diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 9f69ceb..7a401d3 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -2,6 +2,7 @@ use crate::{draw_scaled_texture, Textures}; use super::tile::*; use super::Pos; +use super::PosInt; use raylib::prelude::*; #[derive(Debug, Clone)] @@ -73,7 +74,7 @@ impl Board { } fn in_bounds(&self, p: Pos) -> bool { - p.x >= 0 && p.y >= 0 && p.x < self.width as isize && p.y < self.height as isize + p.x >= 0 && p.y >= 0 && p.x < self.width as PosInt && p.y < self.height as PosInt } pub fn get(&self, p: Pos) -> Option { @@ -116,11 +117,11 @@ impl Board { } } - pub fn grow_to_include(&mut self, p: Pos) -> (isize, isize) { + pub fn grow_to_include(&mut self, p: Pos) -> (PosInt,PosInt) { let mut offset_x = 0; let mut offset_y = 0; if p.x < 0 { - let len = p.x.unsigned_abs(); + let len = p.x.unsigned_abs() as usize; for row in &mut self.rows { let mut new_row = vec![Tile::Blank; len]; new_row.append(row); @@ -137,7 +138,7 @@ impl Board { } if p.y < 0 { - let len = p.y.unsigned_abs(); + let len = p.y.unsigned_abs() as usize; let mut new_rows = vec![vec![Tile::Blank; self.width]; len]; new_rows.append(&mut self.rows); self.rows = new_rows; @@ -148,7 +149,7 @@ impl Board { self.rows.resize(new_height, vec![Tile::Blank; self.width]); self.height = new_height; } - (offset_x as isize, offset_y as isize) + (offset_x as PosInt, offset_y as PosInt) } pub fn trim_size(&mut self, margin: usize) -> (usize, usize) { diff --git a/src/marble_engine/pos.rs b/src/marble_engine/pos.rs index 3979b3a..9eea35c 100644 --- a/src/marble_engine/pos.rs +++ b/src/marble_engine/pos.rs @@ -2,10 +2,12 @@ use std::ops::Add; use raylib::prelude::*; +pub type PosInt = i16; + #[derive(Debug, Default, Clone, Copy, PartialEq)] pub struct Pos { - pub x: isize, - pub y: isize, + pub x: PosInt, + pub y: PosInt, } impl Pos { @@ -34,8 +36,8 @@ impl Pos { impl From<(usize, usize)> for Pos { fn from(value: (usize, usize)) -> Self { Self { - x: value.0 as isize, - y: value.1 as isize, + x: value.0 as PosInt, + y: value.1 as PosInt, } } } @@ -43,8 +45,8 @@ impl From<(usize, usize)> for Pos { impl From<(i32, i32)> for Pos { fn from(value: (i32, i32)) -> Self { Self { - x: value.0 as isize, - y: value.1 as isize, + x: value.0 as PosInt, + y: value.1 as PosInt, } } } @@ -52,8 +54,8 @@ impl From<(i32, i32)> for Pos { impl From for Pos { fn from(vec: Vector2) -> Self { Self { - x: vec.x as isize, - y: vec.y as isize, + x: vec.x as PosInt, + y: vec.y as PosInt, } } }