1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00
Files
vcmi/lib/entities/ResourceTypeHandler.cpp

83 lines
2.2 KiB
C++
Raw Normal View History

2025-09-14 14:36:02 +02:00
/*
* ResourceTypeHandler.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"
#include "ResourceTypeHandler.h"
#include "../GameLibrary.h"
#include "../json/JsonNode.h"
#include "../texts/CGeneralTextHandler.h"
#include "../texts/TextIdentifier.h"
VCMI_LIB_NAMESPACE_BEGIN
2025-09-15 00:08:18 +02:00
std::string Resource::getNameTextID() const
2025-09-14 14:36:02 +02:00
{
2025-09-15 00:44:11 +02:00
if(id.getNum() < 7) // OH3 resources
return TextIdentifier("core.restypes", id).get();
2025-09-14 15:04:02 +02:00
return TextIdentifier( "resources", modScope, identifier, "name" ).get();
2025-09-14 14:36:02 +02:00
}
2025-09-15 00:08:18 +02:00
std::string Resource::getNameTranslated() const
2025-09-14 14:36:02 +02:00
{
return LIBRARY->generaltexth->translate(getNameTextID());
}
2025-09-15 00:08:18 +02:00
void Resource::registerIcons(const IconRegistar & cb) const
2025-09-14 17:05:48 +02:00
{
cb(getIconIndex(), 0, "SMALRES", iconSmall);
cb(getIconIndex(), 0, "RESOURCE", iconMedium);
cb(getIconIndex(), 0, "RESOUR82", iconLarge);
}
2025-09-14 14:36:02 +02:00
std::vector<JsonNode> ResourceTypeHandler::loadLegacyData()
{
2025-09-16 02:28:37 +02:00
objects.resize(GameConstants::RESOURCE_QUANTITY);
2025-09-14 14:36:02 +02:00
2025-09-16 02:28:37 +02:00
return std::vector<JsonNode>(GameConstants::RESOURCE_QUANTITY, JsonNode(JsonMap()));
2025-09-14 14:36:02 +02:00
}
2025-09-15 00:08:18 +02:00
std::shared_ptr<Resource> ResourceTypeHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
2025-09-14 14:36:02 +02:00
{
2025-09-15 00:08:18 +02:00
auto ret = std::make_shared<Resource>();
2025-09-14 14:36:02 +02:00
ret->id = GameResID(index);
ret->modScope = scope;
2025-09-15 00:08:18 +02:00
ret->identifier = identifier;
2025-09-14 14:36:02 +02:00
2025-09-15 00:08:18 +02:00
ret->price = json["price"].Integer();
ret->iconSmall = json["images"]["small"].String();
ret->iconMedium = json["images"]["medium"].String();
ret->iconLarge = json["images"]["large"].String();
2025-09-14 14:36:02 +02:00
2025-09-15 00:44:11 +02:00
if(ret->id.getNum() >= 7) // not OH3 resources
LIBRARY->generaltexth->registerString(scope, ret->getNameTextID(), json["name"]);
2025-09-14 14:36:02 +02:00
return ret;
}
2025-09-15 00:08:18 +02:00
const std::vector<std::string> & ResourceTypeHandler::getTypeNames() const
2025-09-14 14:36:02 +02:00
{
2025-09-16 01:29:54 +02:00
static const std::vector<std::string> types = { "resource" };
2025-09-15 00:08:18 +02:00
return types;
2025-09-14 14:36:02 +02:00
}
std::vector<GameResID> ResourceTypeHandler::getAllObjects() const
{
std::vector<GameResID> result;
2025-09-14 15:04:02 +02:00
for (const auto & resource : objects)
2025-09-15 00:08:18 +02:00
result.push_back(resource->getId());
2025-09-14 14:36:02 +02:00
return result;
}
VCMI_LIB_NAMESPACE_END