From 038bf365c4d14a169ad78f97cbd19d151f9f31d4 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 7 Oct 2024 13:16:26 +0200 Subject: [PATCH] show step count --- assets/digits/digit_0.png | Bin 0 -> 110 bytes assets/digits/digit_1.png | Bin 0 -> 98 bytes assets/digits/digit_2.png | Bin 0 -> 125 bytes assets/digits/digit_3.png | Bin 0 -> 121 bytes assets/digits/digit_4.png | Bin 0 -> 114 bytes assets/digits/digit_5.png | Bin 0 -> 124 bytes assets/digits/digit_6.png | Bin 0 -> 126 bytes assets/digits/digit_7.png | Bin 0 -> 108 bytes assets/digits/digit_8.png | Bin 0 -> 115 bytes assets/digits/digit_9.png | Bin 0 -> 126 bytes .../tiles/{digit_0.png => tile_digit_0.png} | Bin .../tiles/{digit_1.png => tile_digit_1.png} | Bin .../tiles/{digit_2.png => tile_digit_2.png} | Bin .../tiles/{digit_3.png => tile_digit_3.png} | Bin .../tiles/{digit_4.png => tile_digit_4.png} | Bin .../tiles/{digit_5.png => tile_digit_5.png} | Bin .../tiles/{digit_6.png => tile_digit_6.png} | Bin .../tiles/{digit_7.png => tile_digit_7.png} | Bin .../tiles/{digit_8.png => tile_digit_8.png} | Bin .../tiles/{digit_9.png => tile_digit_9.png} | Bin src/editor.rs | 6 ++-- src/main.rs | 3 +- src/marble_engine/tile.rs | 2 +- src/util.rs | 28 +++++++++++++++++- 24 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 assets/digits/digit_0.png create mode 100644 assets/digits/digit_1.png create mode 100644 assets/digits/digit_2.png create mode 100644 assets/digits/digit_3.png create mode 100644 assets/digits/digit_4.png create mode 100644 assets/digits/digit_5.png create mode 100644 assets/digits/digit_6.png create mode 100644 assets/digits/digit_7.png create mode 100644 assets/digits/digit_8.png create mode 100644 assets/digits/digit_9.png rename assets/tiles/{digit_0.png => tile_digit_0.png} (100%) rename assets/tiles/{digit_1.png => tile_digit_1.png} (100%) rename assets/tiles/{digit_2.png => tile_digit_2.png} (100%) rename assets/tiles/{digit_3.png => tile_digit_3.png} (100%) rename assets/tiles/{digit_4.png => tile_digit_4.png} (100%) rename assets/tiles/{digit_5.png => tile_digit_5.png} (100%) rename assets/tiles/{digit_6.png => tile_digit_6.png} (100%) rename assets/tiles/{digit_7.png => tile_digit_7.png} (100%) rename assets/tiles/{digit_8.png => tile_digit_8.png} (100%) rename assets/tiles/{digit_9.png => tile_digit_9.png} (100%) diff --git a/assets/digits/digit_0.png b/assets/digits/digit_0.png new file mode 100644 index 0000000000000000000000000000000000000000..7e82ea38b75be036b5234dbc2f054ee94be9c961 GIT binary patch literal 110 zcmeAS@N?(olHy`uVBq!ia0vp^96&6&#}|0~~CoPZ=1PR}09T7X2>-G=Ra=)z4*} HQ$iB}6%`;K literal 0 HcmV?d00001 diff --git a/assets/digits/digit_1.png b/assets/digits/digit_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fb46b47eeb81a0f30940f4108a6bfc764d03e0fe GIT binary patch literal 98 zcmeAS@N?(olHy`uVBq!ia0vp^96&6)78&qol`;+0PO=9M*si- literal 0 HcmV?d00001 diff --git a/assets/digits/digit_2.png b/assets/digits/digit_2.png new file mode 100644 index 0000000000000000000000000000000000000000..f85cbb046601d36bf5a55676b2ed916d4210a6ad GIT binary patch literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^96&6>V~EDYs0yU>Rg%u5~)0I2T7_}EPDi>N#Xl(3QuuO)5q4T!#KdGnI RzCg1WJYD@<);T3K0RVj@Bq{&^ literal 0 HcmV?d00001 diff --git a/assets/digits/digit_4.png b/assets/digits/digit_4.png new file mode 100644 index 0000000000000000000000000000000000000000..b329613f2516bddd9f662f3ddf3b201f37fb0c5d GIT binary patch literal 114 zcmeAS@N?(olHy`uVBq!ia0vp^96&6D}~>eJ%0EQXQWtlH2gAtfb6B}Itq2S2OJ&c-5Ei@Off+}1EKT)!v(ljY0vLZBfG Mp00i_>zopr0B?yR8UO$Q literal 0 HcmV?d00001 diff --git a/assets/digits/digit_5.png b/assets/digits/digit_5.png new file mode 100644 index 0000000000000000000000000000000000000000..58af1ae94181c8faa1f9437b8266b9eb28aa2c2a GIT binary patch literal 124 zcmeAS@N?(olHy`uVBq!ia0vp^96&6s0yU>R2}Q0AOfibyatsXh(jx51AJ4x6YG?3t^>bP0l+XkK DfQubc literal 0 HcmV?d00001 diff --git a/assets/digits/digit_8.png b/assets/digits/digit_8.png new file mode 100644 index 0000000000000000000000000000000000000000..a952a7198746be7c6640cf0cfe730ed8eb645667 GIT binary patch literal 115 zcmeAS@N?(olHy`uVBq!ia0vp^96&6 MboFyt=akR{0Hj19!2kdN literal 0 HcmV?d00001 diff --git a/assets/digits/digit_9.png b/assets/digits/digit_9.png new file mode 100644 index 0000000000000000000000000000000000000000..d44e1021a8012ef361ca3b15a44201edaceaba1f GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^96&6sqev)HFl5rvSu a=}f=R%7|Q(>o5fx$l&Sf=d#Wzp$PyL>?=h8 literal 0 HcmV?d00001 diff --git a/assets/tiles/digit_0.png b/assets/tiles/tile_digit_0.png similarity index 100% rename from assets/tiles/digit_0.png rename to assets/tiles/tile_digit_0.png diff --git a/assets/tiles/digit_1.png b/assets/tiles/tile_digit_1.png similarity index 100% rename from assets/tiles/digit_1.png rename to assets/tiles/tile_digit_1.png diff --git a/assets/tiles/digit_2.png b/assets/tiles/tile_digit_2.png similarity index 100% rename from assets/tiles/digit_2.png rename to assets/tiles/tile_digit_2.png diff --git a/assets/tiles/digit_3.png b/assets/tiles/tile_digit_3.png similarity index 100% rename from assets/tiles/digit_3.png rename to assets/tiles/tile_digit_3.png diff --git a/assets/tiles/digit_4.png b/assets/tiles/tile_digit_4.png similarity index 100% rename from assets/tiles/digit_4.png rename to assets/tiles/tile_digit_4.png diff --git a/assets/tiles/digit_5.png b/assets/tiles/tile_digit_5.png similarity index 100% rename from assets/tiles/digit_5.png rename to assets/tiles/tile_digit_5.png diff --git a/assets/tiles/digit_6.png b/assets/tiles/tile_digit_6.png similarity index 100% rename from assets/tiles/digit_6.png rename to assets/tiles/tile_digit_6.png diff --git a/assets/tiles/digit_7.png b/assets/tiles/tile_digit_7.png similarity index 100% rename from assets/tiles/digit_7.png rename to assets/tiles/tile_digit_7.png diff --git a/assets/tiles/digit_8.png b/assets/tiles/tile_digit_8.png similarity index 100% rename from assets/tiles/digit_8.png rename to assets/tiles/tile_digit_8.png diff --git a/assets/tiles/digit_9.png b/assets/tiles/tile_digit_9.png similarity index 100% rename from assets/tiles/digit_9.png rename to assets/tiles/tile_digit_9.png diff --git a/src/editor.rs b/src/editor.rs index 84f05b7..7664e9b 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -3,7 +3,7 @@ use std::{mem::transmute, ops::Rem}; use raylib::prelude::*; use crate::{ - draw_scaled_texture, + draw_scaled_texture, draw_usize, level::Level, marble_engine::{ board::{Board, Pos}, @@ -128,7 +128,7 @@ impl Editor { self.machine.set_board(self.source_board.clone()); } - fn step_pressed(&mut self){ + fn step_pressed(&mut self) { match self.sim_state { SimState::Editing => { self.start_sim(); @@ -419,6 +419,8 @@ impl Editor { } draw_scaled_texture(d, textures.get("step"), 332, 4, 2.); + draw_usize(d, textures, self.machine.step_count(), 372, 4, 5, 2); + let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string(); let width = d.get_screen_width(); d.draw_text("input:", width - 260, 10, 20, Color::WHITE); diff --git a/src/main.rs b/src/main.rs index 6c312bc..6a41bdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ impl Game { let mut textures = Textures::default(); textures.load_dir("assets", rl, thread); textures.load_dir("assets/tiles", rl, thread); + textures.load_dir("assets/digits", rl, thread); Self { levels: get_levels(), @@ -237,7 +238,7 @@ fn get_levels() -> Vec { levels.push(level); } } - levels.sort_by(|a, b| a.sort_order().cmp(&b.sort_order())); + levels.sort_by_key(Level::sort_order); levels } diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index c2c3e89..0d793ef 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -165,7 +165,7 @@ impl Tile { Tile::Blank => "", Tile::Block => "block", Tile::Marble { value: _, dir: _ } => "marble", - Tile::Digit(n) => return format!("digit_{n}"), + Tile::Digit(n) => return format!("tile_digit_{n}"), Tile::Mirror(mirror) => mirror.texture_name(), Tile::Arrow(dir) => dir.arrow_texture_name(), Tile::Powerable(tile, state) => { diff --git a/src/util.rs b/src/util.rs index db83739..5e2f1aa 100644 --- a/src/util.rs +++ b/src/util.rs @@ -121,7 +121,8 @@ pub fn text_input( Color::WHITE, ); let mouse_pos = d.get_mouse_position(); - if editable && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) + if editable + && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) && (bounds.check_collision_point_rec(mouse_pos) || *is_selected) { *is_selected = !*is_selected; @@ -189,6 +190,31 @@ pub fn texture_option_button( } } +pub fn draw_usize( + d: &mut RaylibDrawHandle, + textures: &Textures, + number: usize, + x: i32, + y: i32, + digits: u8, + scale: u8, +) { + let digits = digits as i32; + let scale = scale as i32; + for i in 0..digits { + d.draw_rectangle(x + 10 * i * scale, y, 8 * scale, 16 * scale, Color::DIMGRAY); + } + let mut num = number; + let mut i = 0; + while (num != 0 || i == 0) && i < digits { + let texture = textures.get(&format!("digit_{}", num % 10)); + let x = x + (digits - i - 1) * 10 * scale; + draw_scaled_texture(d, texture, x, y, scale as f32); + num /= 10; + i += 1; + } +} + pub fn userdata_dir() -> PathBuf { PathBuf::from("user") }