From 987643f3343a26ad6da568c449721f068bd2bc38 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Tue, 24 Dec 2024 23:18:41 +0100 Subject: [PATCH] cleanup --- src/blueprint.rs | 2 +- src/editor.rs | 8 ++------ src/main.rs | 17 +++++++++-------- src/marble_engine/board.rs | 2 +- src/ui.rs | 9 ++------- src/util.rs | 4 ++++ 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/blueprint.rs b/src/blueprint.rs index 5cc6d4b..5cdb6e2 100644 --- a/src/blueprint.rs +++ b/src/blueprint.rs @@ -22,7 +22,7 @@ impl Blueprint { Self { id, name: format!("Blueprint {id}"), - board: content.to_string(), + board: content.serialize(), tile_board: Some(content.clone()), } } diff --git a/src/editor.rs b/src/editor.rs index 77ea49e..384a7ad 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -688,12 +688,8 @@ impl Editor { } self.tooltip.add(42 + 205, y, 32, 32, "Select"); simple_option_button( - d, - &self.mouse, - 42 + 205, - y, - 32, - 32, + (d, &self.mouse), + rect(42 + 205, y, 32, 32), i, &mut self.selected_blueprint, ); diff --git a/src/main.rs b/src/main.rs index 77ff9f8..f592705 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ impl Game { ExitState::ExitAndSave => { let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap() [self.selected_solution]; - solution.board = editor.source_board().to_string(); + solution.board = editor.source_board().serialize(); solution.score = editor.score(); solution.save(); self.open_editor = None; @@ -100,7 +100,7 @@ impl Game { ExitState::Save => { let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap() [self.selected_solution]; - solution.board = editor.source_board().to_string(); + solution.board = editor.source_board().serialize(); solution.score = editor.score(); solution.save(); } @@ -212,12 +212,13 @@ impl Game { let mut solution_y = y; for (solution_index, solution) in solutions.iter().enumerate() { if simple_option_button( - d, - &mouse, - level_list_width + 10, - solution_y, - entry_width, - solution_entry_height, + (d, &mouse), + rect( + level_list_width + 10, + solution_y, + entry_width, + solution_entry_height, + ), solution_index, &mut self.selected_solution, ) { diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 10b56fe..6aa6c7b 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -48,7 +48,7 @@ impl Board { } } - pub fn to_string(&self) -> String { + pub fn serialize(&self) -> String { let mut out = String::new(); for y in 0..self.height { for x in 0..self.width { diff --git a/src/ui.rs b/src/ui.rs index 24ab370..7dc0cc8 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -208,19 +208,14 @@ pub fn tex32_button( } pub fn simple_option_button( - d: &mut RaylibDrawHandle, - mouse: &MouseInput, - x: i32, - y: i32, - width: i32, - height: i32, + (d, mouse): (&mut RaylibDrawHandle, &MouseInput), + bounds: Rectangle, option: T, current: &mut T, ) -> bool where T: PartialEq, { - let bounds = Rectangle::new(x as f32, y as f32, width as f32, height as f32); d.draw_rectangle_rec(bounds, widget_bg(&option == current)); let mut changed = false; if mouse.left_click() && mouse.is_over(bounds) && current != &option { diff --git a/src/util.rs b/src/util.rs index e5b6d87..b3b5d45 100644 --- a/src/util.rs +++ b/src/util.rs @@ -145,3 +145,7 @@ pub fn get_scroll(rl: &RaylibHandle) -> Option { None } } + +pub fn rect(x: i32, y: i32, width: i32, height: i32) -> Rectangle{ + Rectangle::new(x as f32, y as f32, width as f32, height as f32) +} \ No newline at end of file