#pragma once #include #include #include #include "Game/SaveMap/SaveMap.hpp" class GameInstance; class World; struct WorldFactory { const char* world_name; std::shared_ptr(*factory)(GameInstance&); }; // Создаёт ассоцеативный список // В нём соспоставляются имина уровней и фабрики их классов #define WORLDS_LIST std::vector world_factories = // Генерирует элемент списка #define GENERATE_WORLD_FACTORY(Class, WorldName) WorldFactory{#WorldName,\ [](GameInstance& game_insance)->std::shared_ptr {\ std::shared_ptr world = std::make_shared(game_insance);\ std::ifstream config_file("./Worlds/" #WorldName ".world");\ if (config_file.fail())\ throw std::runtime_error("Can't open world file");\ config_file.seekg(0, std::ios::end);\ size_t file_size = config_file.tellg();\ config_file.seekg(0, std::ios::beg);\ std::string data;\ data.resize(file_size);\ config_file.read(data.data(), file_size);\ world->load(std::make_shared(data));\ return std::static_pointer_cast(world);\ }}, /* * Пример использования: WORLDS_LIST { GENERATE_WORLD_FACTORY(Sometime_class_world_One, WorldName_One) GENERATE_WORLD_FACTORY(Sometime_class_world_Two, WorldName_Two) }; */