1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

introduce toResourceType

This commit is contained in:
Laserlicht
2025-09-15 00:08:18 +02:00
parent acd067e587
commit d808bd6412
34 changed files with 160 additions and 102 deletions

View File

@@ -23,7 +23,7 @@ ResourceSet::ResourceSet() = default;
ResourceSet::ResourceSet(const JsonNode & node)
{
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
container[i] = static_cast<int>(node[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()].Float());
container[i] = static_cast<int>(node[i.toResource()->getJsonKey()].Float());
}
void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
@@ -38,7 +38,7 @@ void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string
if(idx == EGameResID::MITHRIL)
continue;
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), this->operator[](idx), 0);
handler.serializeInt(idx.toResource()->getJsonKey(), this->operator[](idx), 0);
}
}
@@ -102,7 +102,7 @@ TResourceCap ResourceSet::marketValue() const
{
TResourceCap total = 0;
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
total += static_cast<TResourceCap>(LIBRARY->resourceTypeHandler->getById(i)->getPrice()) * static_cast<TResourceCap>(operator[](i));
total += static_cast<TResourceCap>(i.toResource()->getPrice()) * static_cast<TResourceCap>(operator[](i));
return total;
}