]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
added load message
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 3 Sep 2019 17:58:38 +0000 (13:58 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 3 Sep 2019 17:58:38 +0000 (13:58 -0400)
src/engine.cpp
src/gamestate.hpp

index 9c0b09b5d6222dafbc32cebcc562bdb4dc1b319d..e959f218dbb00c13346dfe030700469dfc884faf 100644 (file)
@@ -48,7 +48,10 @@ int Engine::init(void)
 
     // Load game script and entity data
     systems.system<ScriptSystem>()->init();
-    GameState::load("save.json", entities);
+    if (GameState::load("save.json", entities)) {
+        std::cout << "Loaded from save.json. Delete the file if you don't want "
+                     "it." << std::endl;
+    }
 
     return 0;
 }
index 196c6b7421f6acd0422d30d4dcfa907406e6b0fc..55f4e474ea6dc0178fcd73f6280485545886347a 100644 (file)
@@ -43,13 +43,19 @@ public:
      *
      * @param file The file to load from
      * @param entities The entity manager to load into
+     * @return True if successful load
      */
-    static void load(const std::string& file, entityx::EntityManager &entities)
+    static bool load(const std::string& file, entityx::EntityManager &entities)
     {
-        if (std::ifstream saveFile (file); saveFile.good()) {
+        std::ifstream saveFile (file);
+        bool opened = saveFile.good();
+
+        if (opened) {
             cereal::JSONInputArchive archive (saveFile);
-           serializeEntities(archive, false, entities);
+            serializeEntities(archive, false, entities);
         }
+
+        return opened;
     }
 
     /**
@@ -58,13 +64,19 @@ public:
      *
      * @param file The file to load from
      * @param entities The entity manager to get entity data from
+     * @return True if successful save
      */
-    static void save(const std::string& file, entityx::EntityManager &entities)
+    static bool save(const std::string& file, entityx::EntityManager &entities)
     {
-        if (std::ofstream saveFile (file); saveFile.good()) {
+        std::ofstream saveFile (file);
+        bool opened = saveFile.good();
+
+        if (opened) {
             cereal::JSONOutputArchive archive (saveFile);
-           serializeEntities(archive, true, entities);
+            serializeEntities(archive, true, entities);
         }
+
+        return opened;
     }
 
 private: