From a2597a1c5cd973da9b2390f48bd470cf82811091 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 15 Feb 2024 16:08:27 +0900 Subject: [PATCH] save/load: prevent crash on failure to save/load TODO: Impl. save/load for wasm target. --- src/original_impl.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/original_impl.rs b/src/original_impl.rs index 0ec9c79..e8d9500 100644 --- a/src/original_impl.rs +++ b/src/original_impl.rs @@ -2227,10 +2227,22 @@ impl GameState { // check pressed keys if window.get_gi_mut().get_key_pressed('s')? { 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')? { - 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 { self.state = 0; self.state_dirty = true;