4e72ee9f65abf88a86ed32eead8cb56a895744bc — Leinnan 7 months ago 3f649f3
Fix loading units
2 files changed, 8 insertions(+), 2 deletions(-)

M src/factories/UnitFactory.hpp
M src/main.cpp
M src/factories/UnitFactory.hpp => src/factories/UnitFactory.hpp +6 -2
@@ 15,6 15,7 @@ struct UnitLoader final: entt::resource_loader<UnitLoader, Presets::Unit> {
     std::shared_ptr<Presets::Unit> load(nlohmann::json j) const
     {
         std::shared_ptr<Presets::Unit> unit = std::make_shared<Presets::Unit>();
+        unit->speed = j.at("scale").get<float>();
         unit->speed = j.at("speed").get<float>();
         unit->name= j.at("name").get<std::string>();
         unit->modelPath= j.at("modelPath").get<std::string>();


@@ 25,20 26,23 @@ struct UnitLoader final: entt::resource_loader<UnitLoader, Presets::Unit> {
     }
 };
 
-class UnitFactory final: public Controllers::Controller<UnitFactory> {
+class UnitFactory final {
   public:
     UnitFactory(){};
     void loadFromFile(std::string path)
     {
         nlohmann::json jsonReader;
-        std::ifstream file(path);
+        std::ifstream file(path.c_str());
         file >> jsonReader;
 
         for(nlohmann::json &object : jsonReader)
         {
+            std::cout << object << '\n';
             const auto hashedPath = entt::hashed_string(object.at("id").get<std::string>().c_str());
             unitCache.load<UnitLoader>(hashedPath,object);
         }
+        const auto size = unitCache.size();
+        std::cout << "Size of unitCache: " << size << '\n';
     }
   private:
     entt::resource_cache<Presets::Unit> unitCache;

M src/main.cpp => src/main.cpp +2 -0
@@ 37,6 37,7 @@ Camera camera;
 
 int main(int argc, char **argv) {
     INIReader reader(argc == 2 ? argv[1] : CONFIG_PATH);
+    Factories::UnitFactory unitFactory;
 
     if (reader.ParseError() != 0) {
         std::cout << "Can't load "<< (argc == 2 ? argv[1] : CONFIG_PATH) <<"\n";


@@ 59,6 60,7 @@ int main(int argc, char **argv) {
     collisionSystem.Init(registry);
     aiSystem.Init(registry);
     damageSystem.Init();
+    unitFactory.loadFromFile("data/units.json");
     Components::readFromFile(registry, jsonFile.c_str());
 
     camera = {0};