diff --git a/src/editor.rs b/src/editor.rs index 0e8db05..1af0ef3 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -111,7 +111,7 @@ impl Editor { } pub fn level_id(&self) -> &str { - &self.level.id() + self.level.id() } pub fn source_board(&self) -> &Board { diff --git a/src/main.rs b/src/main.rs index 37f9e09..0f5f4d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,8 +44,8 @@ fn main() { impl Game { fn new(rl: &mut RaylibHandle, thread: &RaylibThread) -> Self { let mut textures = Textures::default(); - textures.load_dir("assets", rl, &thread); - textures.load_dir("assets/tiles", rl, &thread); + textures.load_dir("assets", rl, thread); + textures.load_dir("assets/tiles", rl, thread); Self { levels: get_levels(), @@ -60,7 +60,7 @@ impl Game { fn run(&mut self, rl: &mut RaylibHandle, thread: &RaylibThread) { while !rl.window_should_close() { - let mut d = rl.begin_drawing(&thread); + let mut d = rl.begin_drawing(thread); if let Some(editor) = &mut self.open_editor { editor.update(&d); editor.draw(&mut d, &self.textures); @@ -181,7 +181,7 @@ impl Game { if simple_button(d, level_list_width + 10, solution_y, entry_width, 30) { let n = solutions.len(); - solutions.push(Solution::new(&level, n)); + solutions.push(Solution::new(level, n)); } d.draw_text( "new solution", @@ -224,8 +224,7 @@ fn get_levels() -> Vec { let l = read_to_string(d.path()) .ok() .as_deref() - .map(|s| serde_json::from_str(s).ok()) - .flatten(); + .and_then(|s| serde_json::from_str(s).ok()); if let Some(level) = l { levels.push(level); } @@ -248,8 +247,7 @@ fn get_solutions() -> HashMap> { let s = read_to_string(file.path()) .ok() .as_deref() - .map(|s| serde_json::from_str(s).ok()) - .flatten(); + .and_then(|s| serde_json::from_str(s).ok()); if let Some(solution) = s { solutions.push(solution) } diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 884d905..90c0518 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -174,7 +174,7 @@ impl Board { pub fn grow_to_include(&mut self, p: Pos) { let p = self.transform(p); if p.x < 0 { - let len = p.x.abs() as usize; + let len = p.x.unsigned_abs(); for row in &mut self.rows { let mut new_row = vec![Tile::Blank; len]; new_row.append(row); @@ -191,7 +191,7 @@ impl Board { } if p.y < 0 { - let len = p.y.abs() as usize; + let len = p.y.unsigned_abs(); let mut new_rows = vec![vec![Tile::Blank; self.width]; len]; new_rows.append(&mut self.rows); self.rows = new_rows; diff --git a/src/solution.rs b/src/solution.rs index a25ebef..ac55307 100644 --- a/src/solution.rs +++ b/src/solution.rs @@ -38,7 +38,7 @@ impl Solution { pub fn save(&self) { let dir = userdata_dir().join("solutions").join(&self.level_id); fs::create_dir_all(&dir).unwrap(); - let path = dir.join(&format!("{}.json", &self.solution_id)); + let path = dir.join(format!("{}.json", &self.solution_id)); let json = serde_json::to_string_pretty(self).unwrap(); let mut file = File::create(path).unwrap(); diff --git a/src/util.rs b/src/util.rs index 5cd412a..f5a2d8f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -110,7 +110,7 @@ pub fn text_input( let drawn_text = if *is_selected { &format!("{text}_") } else { - &text + text.as_str() }; d.draw_text( drawn_text,