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
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
using namespace rmg;
|
|
|
|
|
2015-05-26 15:12:24 +02:00
|
|
|
const std::map<std::string, CRmgTemplate *> & CRmgTemplateStorage::getTemplates() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
return templates;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
auto tpl = new CRmgTemplate();
|
|
|
|
try
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
JsonDeserializer handler(nullptr, data);
|
|
|
|
auto fullKey = normalizeIdentifier(scope, "core", name);
|
|
|
|
tpl->setId(name);
|
|
|
|
tpl->serializeJson(handler);
|
2015-05-26 15:12:24 +02:00
|
|
|
tpl->validate();
|
2018-03-09 20:11:20 +02:00
|
|
|
templates[fullKey] = tpl;
|
2015-05-26 15:12:24 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception & e)
|
|
|
|
{
|
2017-08-10 19:17:10 +02:00
|
|
|
logGlobal->error("Template %s has errors. Message: %s.", tpl->getName(), std::string(e.what()));
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CRmgTemplateStorage::CRmgTemplateStorage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CRmgTemplateStorage::~CRmgTemplateStorage()
|
|
|
|
{
|
|
|
|
for (auto & pair : templates) delete pair.second;
|
2014-10-02 18:43:46 +03:00
|
|
|
}
|
2015-05-26 15:12:24 +02:00
|
|
|
|
|
|
|
std::vector<bool> CRmgTemplateStorage::getDefaultAllowed() const
|
|
|
|
{
|
|
|
|
//all templates are allowed
|
|
|
|
return std::vector<bool>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<JsonNode> CRmgTemplateStorage::loadLegacyData(size_t dataSize)
|
|
|
|
{
|
|
|
|
return std::vector<JsonNode>();
|
|
|
|
//it would be cool to load old rmg.txt files
|
2017-07-12 21:01:10 +02:00
|
|
|
}
|