|
|
@@ -61,113 +61,219 @@ void ObjectConfig::serializeJson(JsonSerializeFormat & handler)
|
|
|
{ "seerHut", EObjectCategory::SEER_HUT}
|
|
|
};
|
|
|
|
|
|
- const JsonNode & config = handler.getCurrent();
|
|
|
- const JsonNode & configBannedCategories = config["bannedCategories"];
|
|
|
- const JsonNode & configBannedObjects = config["bannedObjects"];
|
|
|
- const JsonNode & configCommonObjects = config["commonObjects"];
|
|
|
-
|
|
|
- for(const auto & node : configBannedCategories.Vector())
|
|
|
+ // Serialize banned categories
|
|
|
+ if (handler.saving)
|
|
|
{
|
|
|
- auto it = OBJECT_CATEGORY_STRINGS.find(node.String());
|
|
|
- if(it != OBJECT_CATEGORY_STRINGS.end())
|
|
|
- bannedObjectCategories.push_back(it->second);
|
|
|
+ auto categoriesArray = handler.enterArray("bannedCategories");
|
|
|
+ categoriesArray.syncSize(bannedObjectCategories, JsonNode::JsonType::DATA_STRING);
|
|
|
+
|
|
|
+ for(size_t i = 0; i < bannedObjectCategories.size(); ++i)
|
|
|
+ {
|
|
|
+ for(const auto & [key, value] : OBJECT_CATEGORY_STRINGS)
|
|
|
+ {
|
|
|
+ if(value == bannedObjectCategories[i])
|
|
|
+ {
|
|
|
+ std::string categoryName = key;
|
|
|
+ categoriesArray.serializeString(i, categoryName);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- if(configBannedObjects.isVector())
|
|
|
+ else
|
|
|
{
|
|
|
- // MOD COMPATIBILITY - 1.6 format
|
|
|
+ const JsonNode & config = handler.getCurrent();
|
|
|
+ const JsonNode & configBannedCategories = config["bannedCategories"];
|
|
|
|
|
|
- for(const auto & node : configBannedObjects.Vector())
|
|
|
+ for(const auto & node : configBannedCategories.Vector())
|
|
|
{
|
|
|
- LIBRARY->objtypeh->resolveObjectCompoundId(node.String(),
|
|
|
- [this](CompoundMapObjectID objid)
|
|
|
+ auto it = OBJECT_CATEGORY_STRINGS.find(node.String());
|
|
|
+ if(it != OBJECT_CATEGORY_STRINGS.end())
|
|
|
+ bannedObjectCategories.push_back(it->second);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Serialize banned objects
|
|
|
+ if (handler.saving)
|
|
|
+ {
|
|
|
+ // Group banned objects by primary ID
|
|
|
+ std::map<int, std::set<int>> groupedBanned;
|
|
|
+ for(const auto & objid : bannedObjects)
|
|
|
+ {
|
|
|
+ groupedBanned[objid.primaryID].insert(objid.secondaryID);
|
|
|
+ }
|
|
|
+
|
|
|
+ auto bannedObjectsStruct = handler.enterStruct("bannedObjects");
|
|
|
+
|
|
|
+ for(const auto & [primaryID, secondaryIDs] : groupedBanned)
|
|
|
+ {
|
|
|
+ const std::string jsonKey = LIBRARY->objtypeh->getJsonKey(primaryID);
|
|
|
+
|
|
|
+ if(secondaryIDs.size() == 1 && *secondaryIDs.begin() == -1)
|
|
|
+ {
|
|
|
+ // Ban entire object type - write as boolean true
|
|
|
+ bool allBanned = true;
|
|
|
+ bannedObjectsStruct->serializeBool(jsonKey, allBanned);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Ban specific subtypes
|
|
|
+ auto objStruct = bannedObjectsStruct->enterStruct(jsonKey);
|
|
|
+ for(int secondaryID : secondaryIDs)
|
|
|
{
|
|
|
- addBannedObject(objid);
|
|
|
+ if(secondaryID != -1)
|
|
|
+ {
|
|
|
+ auto handler = LIBRARY->objtypeh->getHandlerFor(MapObjectID(primaryID), MapObjectSubID(secondaryID));
|
|
|
+ const std::string subtypeKey = handler->getSubTypeName();
|
|
|
+ bool banned = true;
|
|
|
+ objStruct->serializeBool(subtypeKey, banned);
|
|
|
+ }
|
|
|
}
|
|
|
- );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- for(const auto & node : configBannedObjects.Struct())
|
|
|
+ const JsonNode & config = handler.getCurrent();
|
|
|
+ const JsonNode & configBannedObjects = config["bannedObjects"];
|
|
|
+
|
|
|
+ if(configBannedObjects.isVector())
|
|
|
{
|
|
|
- LIBRARY->identifiers()->requestIdentifierIfFound(node.second.getModScope(), "object", node.first, [this, node](int primaryID)
|
|
|
+ // MOD COMPATIBILITY - 1.6 format
|
|
|
+
|
|
|
+ for(const auto & node : configBannedObjects.Vector())
|
|
|
{
|
|
|
- if (node.second.isBool())
|
|
|
- {
|
|
|
- if (node.second.Bool())
|
|
|
- addBannedObject(CompoundMapObjectID(primaryID, -1));
|
|
|
- }
|
|
|
- else
|
|
|
+ LIBRARY->objtypeh->resolveObjectCompoundId(node.String(),
|
|
|
+ [this](CompoundMapObjectID objid)
|
|
|
+ {
|
|
|
+ addBannedObject(objid);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for(const auto & node : configBannedObjects.Struct())
|
|
|
+ {
|
|
|
+ LIBRARY->identifiers()->requestIdentifierIfFound(node.second.getModScope(), "object", node.first, [this, node](int primaryID)
|
|
|
{
|
|
|
- for (const auto & subNode : node.second.Struct())
|
|
|
+ if (node.second.isBool())
|
|
|
{
|
|
|
- const std::string jsonKey = LIBRARY->objtypeh->getJsonKey(primaryID);
|
|
|
-
|
|
|
- LIBRARY->identifiers()->requestIdentifierIfFound(node.second.getModScope(), jsonKey, subNode.first, [this, primaryID](int secondaryID)
|
|
|
+ if (node.second.Bool())
|
|
|
+ addBannedObject(CompoundMapObjectID(primaryID, -1));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (const auto & subNode : node.second.Struct())
|
|
|
{
|
|
|
- addBannedObject(CompoundMapObjectID(primaryID, secondaryID));
|
|
|
- });
|
|
|
+ const std::string jsonKey = LIBRARY->objtypeh->getJsonKey(primaryID);
|
|
|
+
|
|
|
+ LIBRARY->identifiers()->requestIdentifierIfFound(node.second.getModScope(), jsonKey, subNode.first, [this, primaryID](int secondaryID)
|
|
|
+ {
|
|
|
+ addBannedObject(CompoundMapObjectID(primaryID, secondaryID));
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (const auto & objectConfig : configCommonObjects.Vector())
|
|
|
+ // Serialize common objects
|
|
|
+ if (handler.saving)
|
|
|
{
|
|
|
- auto rmg = objectConfig["rmg"].Struct();
|
|
|
+ auto commonObjectsArray = handler.enterArray("commonObjects");
|
|
|
+ commonObjectsArray.syncSize(customObjects, JsonNode::JsonType::DATA_STRUCT);
|
|
|
+
|
|
|
+ for(size_t i = 0; i < customObjects.size(); ++i)
|
|
|
+ {
|
|
|
+ auto objectStruct = commonObjectsArray.enterStruct(i);
|
|
|
+ const auto & object = customObjects[i];
|
|
|
+
|
|
|
+ // Serialize object type/subtype
|
|
|
+ std::string objectType = LIBRARY->objtypeh->getJsonKey(object.primaryID);
|
|
|
+ objectStruct->serializeString("type", objectType);
|
|
|
+
|
|
|
+ if(object.secondaryID != 0)
|
|
|
+ {
|
|
|
+ auto handler = LIBRARY->objtypeh->getHandlerFor(MapObjectID(object.primaryID), MapObjectSubID(object.secondaryID));
|
|
|
+ std::string subtypeName = handler->getSubTypeName();
|
|
|
+ objectStruct->serializeString("subtype", subtypeName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Serialize RMG properties
|
|
|
+ {
|
|
|
+ auto rmgStruct = objectStruct->enterStruct("rmg");
|
|
|
+ int value = object.value;
|
|
|
+ int rarity = object.probability;
|
|
|
+ int zoneLimit = (object.maxPerZone == std::numeric_limits<int>::max()) ? 0 : object.maxPerZone;
|
|
|
+
|
|
|
+ rmgStruct->serializeInt("value", value);
|
|
|
+ rmgStruct->serializeInt("rarity", rarity);
|
|
|
+ rmgStruct->serializeInt("zoneLimit", zoneLimit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ const JsonNode & config = handler.getCurrent();
|
|
|
+ const JsonNode & configCommonObjects = config["commonObjects"];
|
|
|
+
|
|
|
+ for (const auto & objectConfig : configCommonObjects.Vector())
|
|
|
+ {
|
|
|
+ auto rmg = objectConfig["rmg"].Struct();
|
|
|
|
|
|
- // TODO: Use common code with default rmg config
|
|
|
+ // TODO: Use common code with default rmg config
|
|
|
|
|
|
- ObjectInfo object;
|
|
|
+ ObjectInfo object;
|
|
|
|
|
|
- // TODO: Configure basic generateObject function
|
|
|
- object.value = rmg["value"].Integer();
|
|
|
- object.probability = rmg["rarity"].Integer();
|
|
|
- object.maxPerZone = rmg["zoneLimit"].Integer();
|
|
|
- if (object.maxPerZone == 0)
|
|
|
- object.maxPerZone = std::numeric_limits<int>::max();
|
|
|
+ // TODO: Configure basic generateObject function
|
|
|
+ object.value = rmg["value"].Integer();
|
|
|
+ object.probability = rmg["rarity"].Integer();
|
|
|
+ object.maxPerZone = rmg["zoneLimit"].Integer();
|
|
|
+ if (object.maxPerZone == 0)
|
|
|
+ object.maxPerZone = std::numeric_limits<int>::max();
|
|
|
|
|
|
- if (objectConfig["id"].isNull())
|
|
|
- {
|
|
|
- LIBRARY->identifiers()->requestIdentifierIfFound("object", objectConfig["type"], [this, object, objectConfig](int primaryID)
|
|
|
+ if (objectConfig["id"].isNull())
|
|
|
{
|
|
|
- if (objectConfig["subtype"].isNull())
|
|
|
- {
|
|
|
- auto objectWithID = object;
|
|
|
- objectWithID.primaryID = primaryID;
|
|
|
- objectWithID.secondaryID = 0;
|
|
|
- addCustomObject(objectWithID);
|
|
|
- }
|
|
|
- else
|
|
|
+ LIBRARY->identifiers()->requestIdentifierIfFound("object", objectConfig["type"], [this, object, objectConfig](int primaryID)
|
|
|
{
|
|
|
- const std::string jsonKey = LIBRARY->objtypeh->getJsonKey(primaryID);
|
|
|
-
|
|
|
- LIBRARY->identifiers()->requestIdentifierIfFound(jsonKey, objectConfig["subtype"], [this, primaryID, object](int secondaryID)
|
|
|
+ if (objectConfig["subtype"].isNull())
|
|
|
{
|
|
|
auto objectWithID = object;
|
|
|
objectWithID.primaryID = primaryID;
|
|
|
- objectWithID.secondaryID = secondaryID;
|
|
|
+ objectWithID.secondaryID = 0;
|
|
|
addCustomObject(objectWithID);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // MOD COMPATIBILITY - 1.6 format
|
|
|
- auto objectName = objectConfig["id"].String();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ const std::string jsonKey = LIBRARY->objtypeh->getJsonKey(primaryID);
|
|
|
|
|
|
- LIBRARY->objtypeh->resolveObjectCompoundId(objectName, [this, object](CompoundMapObjectID objid)
|
|
|
+ LIBRARY->identifiers()->requestIdentifierIfFound(jsonKey, objectConfig["subtype"], [this, primaryID, object](int secondaryID)
|
|
|
+ {
|
|
|
+ auto objectWithID = object;
|
|
|
+ objectWithID.primaryID = primaryID;
|
|
|
+ objectWithID.secondaryID = secondaryID;
|
|
|
+ addCustomObject(objectWithID);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- auto objectWithID = object;
|
|
|
- objectWithID.primaryID = objid.primaryID;
|
|
|
- objectWithID.secondaryID = objid.secondaryID;
|
|
|
- if (objectWithID.secondaryID == -1)
|
|
|
- objectWithID.secondaryID = 0;
|
|
|
- addCustomObject(objectWithID);
|
|
|
- });
|
|
|
+ // MOD COMPATIBILITY - 1.6 format
|
|
|
+ auto objectName = objectConfig["id"].String();
|
|
|
+
|
|
|
+ LIBRARY->objtypeh->resolveObjectCompoundId(objectName, [this, object](CompoundMapObjectID objid)
|
|
|
+ {
|
|
|
+ auto objectWithID = object;
|
|
|
+ objectWithID.primaryID = objid.primaryID;
|
|
|
+ objectWithID.secondaryID = objid.secondaryID;
|
|
|
+ if (objectWithID.secondaryID == -1)
|
|
|
+ objectWithID.secondaryID = 0;
|
|
|
+ addCustomObject(objectWithID);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|