save/load: prevent crash on failure to save/load
TODO: Impl. save/load for wasm target.
This commit is contained in:
parent
ed72c751a9
commit
a2597a1c5c
1 changed files with 14 additions and 2 deletions
|
@ -2227,10 +2227,22 @@ impl GameState {
|
||||||
// check pressed keys
|
// check pressed keys
|
||||||
if window.get_gi_mut().get_key_pressed('s')? {
|
if window.get_gi_mut().get_key_pressed('s')? {
|
||||||
if self.state == 10 {
|
if self.state == 10 {
|
||||||
self.save().map_err(|e| e.to_string())?;
|
let save_result = self.save().map_err(|e| e.to_string());
|
||||||
|
if let Err(s) = save_result {
|
||||||
|
self.save_load_notification = Some(SaveLoadNotification::Save {
|
||||||
|
text: Some(format!("Failed to save! {}", s)),
|
||||||
|
timer: SL_NOTIF_TIME,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if window.get_gi_mut().get_key_pressed('l')? {
|
} else if window.get_gi_mut().get_key_pressed('l')? {
|
||||||
self.load().map_err(|e| e.to_string())?;
|
let load_result = self.load().map_err(|e| e.to_string());
|
||||||
|
if let Err(s) = load_result {
|
||||||
|
self.save_load_notification = Some(SaveLoadNotification::Load {
|
||||||
|
text: Some(format!("Failed to load! {}", s)),
|
||||||
|
timer: SL_NOTIF_TIME,
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if window.get_gi_mut().get_key_pressed('r')? && self.state == 10 {
|
} else if window.get_gi_mut().get_key_pressed('r')? && self.state == 10 {
|
||||||
self.state = 0;
|
self.state = 0;
|
||||||
self.state_dirty = true;
|
self.state_dirty = true;
|
||||||
|
|
Loading…
Reference in a new issue