]> git.seodisparate.com - LudumDare45_StartWithNothing/commitdiff
save/load: prevent crash on failure to save/load
authorStephen Seo <seo.disparate@gmail.com>
Thu, 15 Feb 2024 07:08:27 +0000 (16:08 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 15 Feb 2024 07:08:44 +0000 (16:08 +0900)
TODO:
    Impl. save/load for wasm target.

src/original_impl.rs

index 0ec9c797f8770217431ce2f63d93020c0d316482..e8d950064919c2cb50400e83bc56060fff5b078e 100644 (file)
@@ -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;