diff --git a/Core/Game/GameInstance.cpp b/Core/Game/GameInstance.cpp index 43c5f37..9a61a4b 100644 --- a/Core/Game/GameInstance.cpp +++ b/Core/Game/GameInstance.cpp @@ -19,13 +19,6 @@ GameInstance::GameInstance(CoreInstance& core) : core(core) // Init directories std::filesystem::create_directories(std::filesystem::path("./Resources")); - std::ifstream file("./Worlds/" + base_world + ".world"); - if (file.fail()) - throw std::runtime_error("Can't open world file"); - - std::string data; - std::getline(file, data); - for (auto& factories : world_factories) { if (factories.world_name == base_world) @@ -38,7 +31,6 @@ GameInstance::GameInstance(CoreInstance& core) : core(core) if (world == nullptr) throw std::runtime_error("Can't find world"); - world->load(std::make_shared(data)); } GameInstance::~GameInstance() diff --git a/Core/Game/WorldFactory.h b/Core/Game/WorldFactory.h index 9f29920..29e7dbb 100644 --- a/Core/Game/WorldFactory.h +++ b/Core/Game/WorldFactory.h @@ -1,6 +1,9 @@ #pragma once #include +#include +#include +#include "Game/SaveMap/SaveMap.h" class GameInstance; class World; @@ -16,7 +19,17 @@ struct WorldFactory #define WORLDS_LIST std::vector world_factories = // Генерирует элемент списка -#define GENERATE_WORLD_FACTORY(Class, WorldName) WorldFactory{#WorldName, [](GameInstance& game_insance)->World* { return new Class(game_insance); }}, +#define GENERATE_WORLD_FACTORY(Class, WorldName) WorldFactory{#WorldName,\ +[](GameInstance& game_insance)->World* {\ + Class* world = new Class(game_insance);\ + std::ifstream config_file("./Worlds/" #WorldName ".world");\ + if (config_file.fail())\ + throw std::runtime_error("Can't open world file");\ + std::string data;\ + std::getline(config_file, data);\ + world->load(std::make_shared(data));\ + return world;\ +}}, /* * Пример использования: