|
@@ -27,16 +27,18 @@ class ResourceSet
|
|
{
|
|
{
|
|
private:
|
|
private:
|
|
std::vector<TResource> container = {};
|
|
std::vector<TResource> container = {};
|
|
|
|
+ DLL_LINKAGE void resizeContainer();
|
|
public:
|
|
public:
|
|
- // read resources set from json. Format example: { "gold": 500, "wood":5 }
|
|
|
|
- DLL_LINKAGE ResourceSet(const JsonNode & node);
|
|
|
|
DLL_LINKAGE ResourceSet();
|
|
DLL_LINKAGE ResourceSet();
|
|
DLL_LINKAGE ResourceSet(const ResourceSet& rhs);
|
|
DLL_LINKAGE ResourceSet(const ResourceSet& rhs);
|
|
|
|
|
|
|
|
+ DLL_LINKAGE void resolveFromJson(const JsonNode & node);
|
|
|
|
+
|
|
|
|
|
|
#define scalarOperator(OPSIGN) \
|
|
#define scalarOperator(OPSIGN) \
|
|
ResourceSet& operator OPSIGN ## =(const TResource &rhs) \
|
|
ResourceSet& operator OPSIGN ## =(const TResource &rhs) \
|
|
{ \
|
|
{ \
|
|
|
|
+ resizeContainer(); \
|
|
for(auto i = 0; i < container.size(); i++) \
|
|
for(auto i = 0; i < container.size(); i++) \
|
|
container.at(i) OPSIGN ## = rhs; \
|
|
container.at(i) OPSIGN ## = rhs; \
|
|
\
|
|
\
|
|
@@ -46,6 +48,7 @@ public:
|
|
#define vectorOperator(OPSIGN) \
|
|
#define vectorOperator(OPSIGN) \
|
|
ResourceSet& operator OPSIGN ## =(const ResourceSet &rhs) \
|
|
ResourceSet& operator OPSIGN ## =(const ResourceSet &rhs) \
|
|
{ \
|
|
{ \
|
|
|
|
+ resizeContainer(); \
|
|
for(auto i = 0; i < container.size(); i++) \
|
|
for(auto i = 0; i < container.size(); i++) \
|
|
container.at(i) OPSIGN ## = rhs[i]; \
|
|
container.at(i) OPSIGN ## = rhs[i]; \
|
|
\
|
|
\
|
|
@@ -85,24 +88,31 @@ public:
|
|
// Array-like interface
|
|
// Array-like interface
|
|
TResource & operator[](GameResID index)
|
|
TResource & operator[](GameResID index)
|
|
{
|
|
{
|
|
|
|
+ resizeContainer();
|
|
return operator[](index.getNum());
|
|
return operator[](index.getNum());
|
|
}
|
|
}
|
|
|
|
|
|
const TResource & operator[](GameResID index) const
|
|
const TResource & operator[](GameResID index) const
|
|
{
|
|
{
|
|
|
|
+ if (index.getNum() >= container.size()) {
|
|
|
|
+ static const TResource defaultValue{};
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
return operator[](index.getNum());
|
|
return operator[](index.getNum());
|
|
}
|
|
}
|
|
|
|
|
|
TResource & operator[](size_t index)
|
|
TResource & operator[](size_t index)
|
|
{
|
|
{
|
|
|
|
+ resizeContainer();
|
|
return container.at(index);
|
|
return container.at(index);
|
|
}
|
|
}
|
|
|
|
|
|
const TResource & operator[](size_t index) const
|
|
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);
|
|
return container.at(index);
|
|
}
|
|
}
|
|
|
|
|