732f6a05062c8b8fb9c837c08aa560bea6a5484c — Leinnan 7 months ago 1a10788
Read units filepath from config
4 files changed, 27 insertions(+), 6 deletions(-)

M data/mod.ini
A data/units.json
M src/factories/UnitFactory.hpp
M src/main.cpp
M data/mod.ini => data/mod.ini +2 -0
@@ 1,7 1,9 @@
 [game]
+units = data/units.json
 firstJson = data/test.json
 name = Arkona
 
+
 [gfx]
 width = 1024
 height = 600

A data/units.json => data/units.json +20 -0
@@ 0,0 1,20 @@
+[
+  {
+    "id": "knight",
+    "name": "guard",
+    "isPlayer": 0,
+    "diffusePath": "data/gfx/knight.png",
+    "modelPath": "data/gfx/knight.obj",
+    "speed": 15,
+    "scale": 2
+  },
+  {
+    "id": "player",
+    "name": "Hero",
+    "isPlayer": 1,
+    "diffusePath": "data/gfx/knight.png",
+    "modelPath": "data/gfx/knight.obj",
+    "speed": 18,
+    "scale": 2
+  }
+]

M src/factories/UnitFactory.hpp => src/factories/UnitFactory.hpp +2 -3
@@ 10,7 10,7 @@
 #include "components/WorldScreenText.hpp"
 #include "components/Velocity.hpp"
 #include "presets/Unit.hpp"
-
+#include "controllers/Controller.hpp"
 
 #include <entt/entt.hpp>
 #include <json.hpp>


@@ 36,9 36,8 @@ struct UnitLoader final: entt::resource_loader<UnitLoader, Presets::Unit> {
     }
 };
 
-class UnitFactory final {
+class UnitFactory final: public Controllers::Controller<UnitFactory> {
   public:
-    UnitFactory(){};
     void loadFromFile(std::string path)
     {
         nlohmann::json jsonReader;

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


@@ 60,10 60,10 @@ int main(int argc, char **argv) {
     collisionSystem.Init(registry);
     aiSystem.Init(registry);
     damageSystem.Init();
-    unitFactory.loadFromFile("data/units.json");
+
+    unitFactory.loadFromFile(reader.Get("game","units","units.json"));
     auto result = unitFactory.spawnUnit(registry,entt::hashed_string("player"));
     Components::readFromFile(registry, jsonFile.c_str());
-    std::cout << "Spawn Unit result " << result << '\n';
 
     camera = {0};
     camera.target = (Vector3){0.0f, 0.5f, 0.0f};