f3fe696e78c5b8b35b20084f19c0f905ecf44864 — Leinnan 7 months ago c8c0c4e
Move parsing entity to separate function
2 files changed, 16 insertions(+), 3 deletions(-)

M src/utils/JsonParser.cpp
M src/utils/JsonParser.hpp
M src/utils/JsonParser.cpp => src/utils/JsonParser.cpp +13 -3
@@ 242,9 242,14 @@ void Components::readFromFile(entt::registry<> &registry, const char *filename) 
     std::ifstream file(filename);
     file >> jsonReader;
 
-    for(nlohmann::json &object : jsonReader) {
+    for(nlohmann::json &object : jsonReader)
+        createEntityFromJson(registry,object);
+    }
+
+    uint32_t Components::createEntityFromJson(entt::registry<> &registry, json &object)
+    {
         if(!object.is_array())
-            continue;
+            return 0;
 
         auto entity = registry.create();
 


@@ 281,5 286,10 @@ void Components::readFromFile(entt::registry<> &registry, const char *filename) 
                 registry.assign<Components::Destroyable>(entity, component.get<Components::Destroyable>());
             }
         }
+        return entity;
+    }
+
+    uint32_t Components::createEntityFromJson(entt::registry<> &registry, const std::string &s)
+    {
+        return createEntityFromJson(registry,json::parse(s));
     }
-}

M src/utils/JsonParser.hpp => src/utils/JsonParser.hpp +3 -0
@@ 69,6 69,9 @@ void from_json(const json &j, Components::Destroyable &t);
 
 void parseToFile(entt::registry<> &registry, const char *filename);
 void readFromFile(entt::registry<> &registry, const char *filename);
+
+uint32_t createEntityFromJson(entt::registry<> &registry, json &j);
+uint32_t createEntityFromJson(entt::registry<> &registry, const std::string &s);
 }; // namespace Components
 
 #endif