2013-08-17 15:46:48 +03:00
|
|
|
/*
|
|
|
|
* CRmgTemplateStorage.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
2018-03-09 20:11:20 +02:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
#include "CRmgTemplateStorage.h"
|
2018-03-09 20:11:20 +02:00
|
|
|
#include "CRmgTemplate.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
#include "../serializer/JsonDeserializer.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
using namespace rmg;
|
|
|
|
|
2015-05-26 15:12:24 +02:00
|
|
|
void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
|
|
|
{
|
|
|
|
//unused
|
|
|
|
loadObject(scope, name, data);
|
|
|
|
}
|
|
|
|
|
2023-07-02 09:28:51 +02:00
|
|
|
void CRmgTemplateStorage::afterLoadFinalization()
|
|
|
|
{
|
|
|
|
for (auto& temp : templates)
|
|
|
|
{
|
2023-08-25 20:42:02 +02:00
|
|
|
temp.second->afterLoad();
|
2023-07-02 09:28:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 15:12:24 +02:00
|
|
|
void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2015-05-26 15:12:24 +02:00
|
|
|
try
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
JsonDeserializer handler(nullptr, data);
|
2023-01-18 23:56:01 +02:00
|
|
|
auto fullKey = scope + ":" + name; //actually it's not used
|
2023-09-04 23:58:08 +02:00
|
|
|
templates[fullKey] = std::make_shared<CRmgTemplate>();
|
2023-08-25 20:42:02 +02:00
|
|
|
templates[fullKey]->setId(fullKey);
|
|
|
|
templates[fullKey]->serializeJson(handler);
|
|
|
|
templates[fullKey]->setName(name);
|
|
|
|
templates[fullKey]->validate();
|
2015-05-26 15:12:24 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception & e)
|
|
|
|
{
|
2022-05-28 15:03:50 +02:00
|
|
|
logGlobal->error("Template %s has errors. Message: %s.", name, std::string(e.what()));
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:34:29 +02:00
|
|
|
std::vector<JsonNode> CRmgTemplateStorage::loadLegacyData()
|
2015-05-26 15:12:24 +02:00
|
|
|
{
|
|
|
|
return std::vector<JsonNode>();
|
|
|
|
//it would be cool to load old rmg.txt files
|
2017-07-12 21:01:10 +02:00
|
|
|
}
|
2022-05-28 15:03:50 +02:00
|
|
|
|
2022-09-19 00:46:01 +02:00
|
|
|
const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateName) const
|
2022-05-28 15:03:50 +02:00
|
|
|
{
|
2022-09-19 00:46:01 +02:00
|
|
|
auto iter = templates.find(templateName);
|
2022-05-28 15:03:50 +02:00
|
|
|
if(iter==templates.end())
|
|
|
|
return nullptr;
|
2023-08-25 20:42:02 +02:00
|
|
|
return iter->second.get();
|
2022-05-28 15:03:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
|
|
|
|
{
|
|
|
|
std::vector<const CRmgTemplate *> result;
|
2023-02-11 18:05:02 +02:00
|
|
|
result.reserve(templates.size());
|
|
|
|
for(const auto & i : templates)
|
2022-05-28 15:03:50 +02:00
|
|
|
{
|
2023-08-25 20:42:02 +02:00
|
|
|
result.push_back(i.second.get());
|
2022-05-28 15:03:50 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|