Fix load configs
This commit is contained in:
@@ -34,11 +34,18 @@ CoreInstance::CoreInstance()
|
||||
memorySize_ = System::getMemorySize();
|
||||
|
||||
std::ifstream main_config_file(main_config_name);
|
||||
std::string payload;
|
||||
|
||||
if (main_config_file.fail())
|
||||
throw std::runtime_error("Fail open main config file");
|
||||
|
||||
std::string payload;
|
||||
std::getline(main_config_file, payload);
|
||||
main_config_file.seekg(0, std::ios::end);
|
||||
size_t size_config = main_config_file.tellg();
|
||||
main_config_file.seekg(0, std::ios::beg);
|
||||
payload.resize(size_config);
|
||||
|
||||
main_config_file.read(payload.data(), payload.size());
|
||||
main_config_file.close();
|
||||
SaveMap load_main_config(payload);
|
||||
|
||||
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
||||
|
||||
@@ -37,6 +37,8 @@ SaveMap::SaveMap(const std::string& json_data)
|
||||
{
|
||||
size_t key_begin = i = json_data_blank.find_first_of('\"', i) + 1;
|
||||
size_t key_end = i = json_data_blank.find_first_of('\"', i);
|
||||
if (0 == key_begin)
|
||||
return;
|
||||
|
||||
std::string name = json_data_blank.substr(key_begin, key_end - key_begin);
|
||||
|
||||
|
||||
@@ -25,8 +25,12 @@ struct WorldFactory
|
||||
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;\
|
||||
std::getline(config_file, data);\
|
||||
data.resize(file_size);\
|
||||
config_file.read(data.data(), file_size);\
|
||||
world->load(std::make_shared<SaveMap>(data));\
|
||||
return world;\
|
||||
}},
|
||||
|
||||
Reference in New Issue
Block a user