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 {
|
Self {
|
||||||
id,
|
id,
|
||||||
name: format!("Blueprint {id}"),
|
name: format!("Blueprint {id}"),
|
||||||
board: content.to_string(),
|
board: content.serialize(),
|
||||||
tile_board: Some(content.clone()),
|
tile_board: Some(content.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -688,12 +688,8 @@ impl Editor {
|
||||||
}
|
}
|
||||||
self.tooltip.add(42 + 205, y, 32, 32, "Select");
|
self.tooltip.add(42 + 205, y, 32, 32, "Select");
|
||||||
simple_option_button(
|
simple_option_button(
|
||||||
d,
|
(d, &self.mouse),
|
||||||
&self.mouse,
|
rect(42 + 205, y, 32, 32),
|
||||||
42 + 205,
|
|
||||||
y,
|
|
||||||
32,
|
|
||||||
32,
|
|
||||||
i,
|
i,
|
||||||
&mut self.selected_blueprint,
|
&mut self.selected_blueprint,
|
||||||
);
|
);
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -92,7 +92,7 @@ impl Game {
|
||||||
ExitState::ExitAndSave => {
|
ExitState::ExitAndSave => {
|
||||||
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
||||||
[self.selected_solution];
|
[self.selected_solution];
|
||||||
solution.board = editor.source_board().to_string();
|
solution.board = editor.source_board().serialize();
|
||||||
solution.score = editor.score();
|
solution.score = editor.score();
|
||||||
solution.save();
|
solution.save();
|
||||||
self.open_editor = None;
|
self.open_editor = None;
|
||||||
|
@ -100,7 +100,7 @@ impl Game {
|
||||||
ExitState::Save => {
|
ExitState::Save => {
|
||||||
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
||||||
[self.selected_solution];
|
[self.selected_solution];
|
||||||
solution.board = editor.source_board().to_string();
|
solution.board = editor.source_board().serialize();
|
||||||
solution.score = editor.score();
|
solution.score = editor.score();
|
||||||
solution.save();
|
solution.save();
|
||||||
}
|
}
|
||||||
|
@ -212,12 +212,13 @@ impl Game {
|
||||||
let mut solution_y = y;
|
let mut solution_y = y;
|
||||||
for (solution_index, solution) in solutions.iter().enumerate() {
|
for (solution_index, solution) in solutions.iter().enumerate() {
|
||||||
if simple_option_button(
|
if simple_option_button(
|
||||||
d,
|
(d, &mouse),
|
||||||
&mouse,
|
rect(
|
||||||
level_list_width + 10,
|
level_list_width + 10,
|
||||||
solution_y,
|
solution_y,
|
||||||
entry_width,
|
entry_width,
|
||||||
solution_entry_height,
|
solution_entry_height,
|
||||||
|
),
|
||||||
solution_index,
|
solution_index,
|
||||||
&mut self.selected_solution,
|
&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();
|
let mut out = String::new();
|
||||||
for y in 0..self.height {
|
for y in 0..self.height {
|
||||||
for x in 0..self.width {
|
for x in 0..self.width {
|
||||||
|
|
|
@ -208,19 +208,14 @@ pub fn tex32_button(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simple_option_button<T>(
|
pub fn simple_option_button<T>(
|
||||||
d: &mut RaylibDrawHandle,
|
(d, mouse): (&mut RaylibDrawHandle, &MouseInput),
|
||||||
mouse: &MouseInput,
|
bounds: Rectangle,
|
||||||
x: i32,
|
|
||||||
y: i32,
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
option: T,
|
option: T,
|
||||||
current: &mut T,
|
current: &mut T,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
T: PartialEq,
|
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));
|
d.draw_rectangle_rec(bounds, widget_bg(&option == current));
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
if mouse.left_click() && mouse.is_over(bounds) && current != &option {
|
if mouse.left_click() && mouse.is_over(bounds) && current != &option {
|
||||||
|
|
|
@ -145,3 +145,7 @@ pub fn get_scroll(rl: &RaylibHandle) -> Option<Scroll> {
|
||||||
None
|
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