From ed956ffbe4dd55b916ec3d300f608c1aa1fd4d87 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 12 Oct 2024 23:27:28 +0200 Subject: [PATCH] cleanup --- assets/digits_small.png | Bin 167 -> 168 bytes src/marble_engine.rs | 6 +++--- src/marble_engine/board.rs | 8 +++----- src/marble_engine/pos.rs | 9 +++++++++ src/util.rs | 19 +++++++------------ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/assets/digits_small.png b/assets/digits_small.png index a60337877466ea5997d942e55ce3c18b15c5de96..bf31aa003a824f8bdfe9ab8237872001c762eef2 100644 GIT binary patch delta 140 zcmV;70CWGR0jL3xB!6#7L_t(2k z3;=ST`wH`U`@+f9PkV34&D!Lgp-{E}<7P@!~7R7>L0SZDkcth{Tugp@c@x`cRLNg@<{*y002ovP6b4+LSTY`#yg7u delta 139 zcmV;60CfMT0jB|wB!6y6L_t(2k+SIrMZvc0f6(xTjjzKXHE-4>`VXKh&@j9{>OV07*qoL 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, + } + } +} + impl From for Pos { fn from(vec: Vector2) -> Self { Self { diff --git a/src/util.rs b/src/util.rs index 1c05fe5..0f07167 100644 --- a/src/util.rs +++ b/src/util.rs @@ -224,26 +224,21 @@ pub fn draw_usize_small( mut num: usize, mut x: i32, y: i32, - scale: u8, + scale: f32, ) { const MAX_DIGITS: usize = 8; - let mut digits = [0u8; MAX_DIGITS]; + let mut digits = [0; MAX_DIGITS]; let mut i = 0; while (num != 0 || i == 0) && i < MAX_DIGITS { - digits[MAX_DIGITS - i - 1] = (num % 10) as u8; + digits[MAX_DIGITS - i - 1] = num % 10; num /= 10; i += 1; } let texture = textures.get("digits_small"); - for digit in (MAX_DIGITS - i)..MAX_DIGITS { - d.draw_texture_pro( - texture, - Rectangle::new(4. * digits[digit] as f32, 0., 4., 6.), - Rectangle::new(x as f32, y as f32, 4. * scale as f32, 6. * scale as f32), - Vector2::zero(), - 0., - Color::RED, - ); + for &digit in &digits[(MAX_DIGITS - i)..] { + let source = Rectangle::new(4. * digit as f32, 0., 4., 6.); + let dest = Rectangle::new(x as f32, y as f32, 4. * scale, 6. * scale); + d.draw_texture_pro(texture, source, dest, Vector2::zero(), 0., Color::RED); x += 4 * scale as i32; } }