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
|
|
|
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
|
|
|
try
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
JsonDeserializer handler(nullptr, data);
|
2022-05-28 15:03:50 +02:00
|
|
|
auto fullKey = normalizeIdentifier(scope, "core", name); //actually it's not used
|
|
|
|
templates[fullKey].setId(name);
|
|
|
|
templates[fullKey].serializeJson(handler);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2022-05-28 15:03:50 +02:00
|
|
|
|
|
|
|
const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateName) const
|
|
|
|
{
|
|
|
|
auto iter = templates.find(templateName);
|
|
|
|
if(iter==templates.end())
|
|
|
|
return nullptr;
|
|
|
|
return &iter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
|
|
|
|
{
|
|
|
|
std::vector<const CRmgTemplate *> result;
|
|
|
|
for(auto i=templates.cbegin(); i!=templates.cend(); ++i)
|
|
|
|
{
|
|
|
|
result.push_back(&i->second);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|