cleanup
This commit is contained in:
parent
db7a2b2418
commit
9bee7c0e10
5 changed files with 11 additions and 13 deletions
|
@ -111,7 +111,7 @@ impl Editor {
|
|||
}
|
||||
|
||||
pub fn level_id(&self) -> &str {
|
||||
&self.level.id()
|
||||
self.level.id()
|
||||
}
|
||||
|
||||
pub fn source_board(&self) -> &Board {
|
||||
|
|
14
src/main.rs
14
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<Level> {
|
|||
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<String, Vec<Solution>> {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue