diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-03 13:58:38 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-03 13:58:38 -0400 |
commit | 95cc88ad5f6c2abb4890d00a57ae4ad0db030e9b (patch) | |
tree | 77228c3f7ddb0e8358e9940fe851cb05b1c4f606 | |
parent | 752438f0be9e4940556ebcc633165cd0b9c17c6f (diff) |
added load message
-rw-r--r-- | src/engine.cpp | 5 | ||||
-rw-r--r-- | src/gamestate.hpp | 24 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 9c0b09b..e959f21 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -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; } diff --git a/src/gamestate.hpp b/src/gamestate.hpp index 196c6b7..55f4e47 100644 --- a/src/gamestate.hpp +++ b/src/gamestate.hpp @@ -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: |