Skip to content
Snippets Groups Projects
Verified Commit 92dc2ed5 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: improved image naming

parent 9d97e26d
No related branches found
No related tags found
No related merge requests found
Pipeline #2857 passed
......@@ -340,7 +340,7 @@ impl Emulator {
Event::KeyDown {
keycode: Some(Keycode::I),
..
} => self.save_image("screen.png"),
} => self.save_image(&self.image_name(Some("png"))),
Event::KeyDown {
keycode: Some(Keycode::T),
..
......@@ -626,6 +626,31 @@ impl Emulator {
thread::sleep(ten_millis);
}
}
fn rom_name(&self) -> &str {
Path::new(&self.rom_path)
.file_stem()
.unwrap()
.to_str()
.unwrap()
}
fn image_name(&self, ext: Option<&str>) -> String {
let ext = ext.unwrap_or("png");
self.best_name(self.rom_name(), ext)
}
fn best_name(&self, base: &str, ext: &str) -> String {
let mut index = 0_usize;
let mut name = format!("{}.{}", base, ext);
while Path::new(&name).exists() {
index += 1;
name = format!("{}-{}.{}", base, index, ext);
}
name
}
}
#[derive(Parser, Debug)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment