cleanup
This commit is contained in:
parent
2c522c1fe0
commit
987643f334
6 changed files with 19 additions and 23 deletions
|
@ -22,7 +22,7 @@ impl Blueprint {
|
|||
Self {
|
||||
id,
|
||||
name: format!("Blueprint {id}"),
|
||||
board: content.to_string(),
|
||||
board: content.serialize(),
|
||||
tile_board: Some(content.clone()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
17
src/main.rs
17
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,
|
||||
) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -208,19 +208,14 @@ pub fn tex32_button(
|
|||
}
|
||||
|
||||
pub fn simple_option_button<T>(
|
||||
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 {
|
||||
|
|
|
@ -145,3 +145,7 @@ pub fn get_scroll(rl: &RaylibHandle) -> Option<Scroll> {
|
|||
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)
|
||||
}
|
Loading…
Reference in a new issue