This commit is contained in:
Crispy 2024-10-06 23:37:21 +02:00
parent db7a2b2418
commit 9bee7c0e10
5 changed files with 11 additions and 13 deletions

View file

@ -111,7 +111,7 @@ impl Editor {
} }
pub fn level_id(&self) -> &str { pub fn level_id(&self) -> &str {
&self.level.id() self.level.id()
} }
pub fn source_board(&self) -> &Board { pub fn source_board(&self) -> &Board {

View file

@ -44,8 +44,8 @@ fn main() {
impl Game { impl Game {
fn new(rl: &mut RaylibHandle, thread: &RaylibThread) -> Self { fn new(rl: &mut RaylibHandle, thread: &RaylibThread) -> Self {
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);
Self { Self {
levels: get_levels(), levels: get_levels(),
@ -60,7 +60,7 @@ impl Game {
fn run(&mut self, rl: &mut RaylibHandle, thread: &RaylibThread) { fn run(&mut self, rl: &mut RaylibHandle, thread: &RaylibThread) {
while !rl.window_should_close() { 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 { if let Some(editor) = &mut self.open_editor {
editor.update(&d); editor.update(&d);
editor.draw(&mut d, &self.textures); 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) { if simple_button(d, level_list_width + 10, solution_y, entry_width, 30) {
let n = solutions.len(); let n = solutions.len();
solutions.push(Solution::new(&level, n)); solutions.push(Solution::new(level, n));
} }
d.draw_text( d.draw_text(
"new solution", "new solution",
@ -224,8 +224,7 @@ fn get_levels() -> Vec<Level> {
let l = read_to_string(d.path()) let l = read_to_string(d.path())
.ok() .ok()
.as_deref() .as_deref()
.map(|s| serde_json::from_str(s).ok()) .and_then(|s| serde_json::from_str(s).ok());
.flatten();
if let Some(level) = l { if let Some(level) = l {
levels.push(level); levels.push(level);
} }
@ -248,8 +247,7 @@ fn get_solutions() -> HashMap<String, Vec<Solution>> {
let s = read_to_string(file.path()) let s = read_to_string(file.path())
.ok() .ok()
.as_deref() .as_deref()
.map(|s| serde_json::from_str(s).ok()) .and_then(|s| serde_json::from_str(s).ok());
.flatten();
if let Some(solution) = s { if let Some(solution) = s {
solutions.push(solution) solutions.push(solution)
} }

View file

@ -174,7 +174,7 @@ impl Board {
pub fn grow_to_include(&mut self, p: Pos) { pub fn grow_to_include(&mut self, p: Pos) {
let p = self.transform(p); let p = self.transform(p);
if p.x < 0 { if p.x < 0 {
let len = p.x.abs() as usize; let len = p.x.unsigned_abs();
for row in &mut self.rows { for row in &mut self.rows {
let mut new_row = vec![Tile::Blank; len]; let mut new_row = vec![Tile::Blank; len];
new_row.append(row); new_row.append(row);
@ -191,7 +191,7 @@ impl Board {
} }
if p.y < 0 { 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]; let mut new_rows = vec![vec![Tile::Blank; self.width]; len];
new_rows.append(&mut self.rows); new_rows.append(&mut self.rows);
self.rows = new_rows; self.rows = new_rows;

View file

@ -38,7 +38,7 @@ impl Solution {
pub fn save(&self) { pub fn save(&self) {
let dir = userdata_dir().join("solutions").join(&self.level_id); let dir = userdata_dir().join("solutions").join(&self.level_id);
fs::create_dir_all(&dir).unwrap(); 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 json = serde_json::to_string_pretty(self).unwrap();
let mut file = File::create(path).unwrap(); let mut file = File::create(path).unwrap();

View file

@ -110,7 +110,7 @@ pub fn text_input(
let drawn_text = if *is_selected { let drawn_text = if *is_selected {
&format!("{text}_") &format!("{text}_")
} else { } else {
&text text.as_str()
}; };
d.draw_text( d.draw_text(
drawn_text, drawn_text,