Move load config for world to factory
This commit is contained in:
@@ -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<SaveMap>(data));
|
||||
}
|
||||
|
||||
GameInstance::~GameInstance()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "Game/SaveMap/SaveMap.h"
|
||||
|
||||
class GameInstance;
|
||||
class World;
|
||||
@@ -16,7 +19,17 @@ struct WorldFactory
|
||||
#define WORLDS_LIST std::vector<WorldFactory> 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<SaveMap>(data));\
|
||||
return world;\
|
||||
}},
|
||||
|
||||
/*
|
||||
* Пример использования:
|
||||
|
||||
Reference in New Issue
Block a user