show step count

This commit is contained in:
Crispy 2024-10-07 13:16:26 +02:00
parent 2c27d660b3
commit 038bf365c4
24 changed files with 34 additions and 5 deletions

BIN
assets/digits/digit_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

BIN
assets/digits/digit_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

BIN
assets/digits/digit_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

BIN
assets/digits/digit_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

BIN
assets/digits/digit_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

BIN
assets/digits/digit_5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

BIN
assets/digits/digit_6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

BIN
assets/digits/digit_7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

BIN
assets/digits/digit_8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

BIN
assets/digits/digit_9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

View file

Before

Width:  |  Height:  |  Size: 162 B

After

Width:  |  Height:  |  Size: 162 B

View file

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 163 B

View file

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 180 B

View file

Before

Width:  |  Height:  |  Size: 170 B

After

Width:  |  Height:  |  Size: 170 B

View file

Before

Width:  |  Height:  |  Size: 185 B

After

Width:  |  Height:  |  Size: 185 B

View file

Before

Width:  |  Height:  |  Size: 175 B

After

Width:  |  Height:  |  Size: 175 B

View file

Before

Width:  |  Height:  |  Size: 171 B

After

Width:  |  Height:  |  Size: 171 B

View file

Before

Width:  |  Height:  |  Size: 160 B

After

Width:  |  Height:  |  Size: 160 B

View file

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 163 B

View file

Before

Width:  |  Height:  |  Size: 168 B

After

Width:  |  Height:  |  Size: 168 B

View file

@ -3,7 +3,7 @@ use std::{mem::transmute, ops::Rem};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ use crate::{
draw_scaled_texture, draw_scaled_texture, draw_usize,
level::Level, level::Level,
marble_engine::{ marble_engine::{
board::{Board, Pos}, board::{Board, Pos},
@ -128,7 +128,7 @@ impl Editor {
self.machine.set_board(self.source_board.clone()); self.machine.set_board(self.source_board.clone());
} }
fn step_pressed(&mut self){ fn step_pressed(&mut self) {
match self.sim_state { match self.sim_state {
SimState::Editing => { SimState::Editing => {
self.start_sim(); self.start_sim();
@ -419,6 +419,8 @@ impl Editor {
} }
draw_scaled_texture(d, textures.get("step"), 332, 4, 2.); 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 mut input_text = String::from_utf8_lossy(self.machine.input()).to_string();
let width = d.get_screen_width(); let width = d.get_screen_width();
d.draw_text("input:", width - 260, 10, 20, Color::WHITE); d.draw_text("input:", width - 260, 10, 20, Color::WHITE);

View file

@ -46,6 +46,7 @@ impl Game {
let mut textures = Textures::default(); let mut textures = Textures::default();
textures.load_dir("assets", rl, thread); textures.load_dir("assets", rl, thread);
textures.load_dir("assets/tiles", rl, thread); textures.load_dir("assets/tiles", rl, thread);
textures.load_dir("assets/digits", rl, thread);
Self { Self {
levels: get_levels(), levels: get_levels(),
@ -237,7 +238,7 @@ fn get_levels() -> Vec<Level> {
levels.push(level); levels.push(level);
} }
} }
levels.sort_by(|a, b| a.sort_order().cmp(&b.sort_order())); levels.sort_by_key(Level::sort_order);
levels levels
} }

View file

@ -165,7 +165,7 @@ impl Tile {
Tile::Blank => "", Tile::Blank => "",
Tile::Block => "block", Tile::Block => "block",
Tile::Marble { value: _, dir: _ } => "marble", 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::Mirror(mirror) => mirror.texture_name(),
Tile::Arrow(dir) => dir.arrow_texture_name(), Tile::Arrow(dir) => dir.arrow_texture_name(),
Tile::Powerable(tile, state) => { Tile::Powerable(tile, state) => {

View file

@ -121,7 +121,8 @@ pub fn text_input(
Color::WHITE, Color::WHITE,
); );
let mouse_pos = d.get_mouse_position(); 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) && (bounds.check_collision_point_rec(mouse_pos) || *is_selected)
{ {
*is_selected = !*is_selected; *is_selected = !*is_selected;
@ -189,6 +190,31 @@ pub fn texture_option_button<T>(
} }
} }
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 { pub fn userdata_dir() -> PathBuf {
PathBuf::from("user") PathBuf::from("user")
} }