1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

use resolveidentifier

This commit is contained in:
Laserlicht
2025-09-28 19:17:39 +02:00
parent 1ac2dba509
commit 5da8a7a4dc
10 changed files with 44 additions and 25 deletions

View File

@@ -27,16 +27,18 @@ class ResourceSet
{
private:
std::vector<TResource> container = {};
DLL_LINKAGE void resizeContainer();
public:
// read resources set from json. Format example: { "gold": 500, "wood":5 }
DLL_LINKAGE ResourceSet(const JsonNode & node);
DLL_LINKAGE ResourceSet();
DLL_LINKAGE ResourceSet(const ResourceSet& rhs);
DLL_LINKAGE void resolveFromJson(const JsonNode & node);
#define scalarOperator(OPSIGN) \
ResourceSet& operator OPSIGN ## =(const TResource &rhs) \
{ \
resizeContainer(); \
for(auto i = 0; i < container.size(); i++) \
container.at(i) OPSIGN ## = rhs; \
\
@@ -46,6 +48,7 @@ public:
#define vectorOperator(OPSIGN) \
ResourceSet& operator OPSIGN ## =(const ResourceSet &rhs) \
{ \
resizeContainer(); \
for(auto i = 0; i < container.size(); i++) \
container.at(i) OPSIGN ## = rhs[i]; \
\
@@ -85,24 +88,31 @@ public:
// Array-like interface
TResource & operator[](GameResID index)
{
resizeContainer();
return operator[](index.getNum());
}
const TResource & operator[](GameResID index) const
{
if (index.getNum() >= container.size()) {
static const TResource defaultValue{};
return defaultValue;
}
return operator[](index.getNum());
}
TResource & operator[](size_t index)
{
resizeContainer();
return container.at(index);
}
const TResource & operator[](size_t index) const
{
if(index >= container.size())
logGlobal->error("Try to access resource which is not existing! Maybe new resources in mod not marked as modType=Resources?");
if (index >= container.size()) {
static const TResource defaultValue{};
return defaultValue;
}
return container.at(index);
}