瀏覽代碼

json validation & mithril remove

Laserlicht 1 月之前
父節點
當前提交
3ec731ef6e

+ 4 - 11
config/schemas/creature.json

@@ -93,17 +93,10 @@
 		},
 		"cost" : {
 			"type" : "object",
-			"additionalProperties" : false,
-			"description" : "Cost to recruit this creature",
-			"properties" : {
-				"gold" :    { "type" : "number"},
-				"wood" :    { "type" : "number"},
-				"ore" :     { "type" : "number"},
-				"mercury" : { "type" : "number"},
-				"sulfur" :  { "type" : "number"},
-				"crystal" : { "type" : "number"},
-				"gems" :    { "type" : "number"}
-			}
+			"additionalProperties" : {
+				"type" : "number"
+			},
+			"description" : "Cost to recruit this creature"
 		},
 		"speed" :     { "type" : "number" },
 		"hitPoints" : { "type" : "number" },

+ 3 - 10
config/schemas/flaggable.json

@@ -35,17 +35,10 @@
 
 		"dailyIncome" : {
 			"type" : "object",
-			"additionalProperties" : false,
+			"additionalProperties" : {
+				"type" : "number"
+			},
 			"description" : "Daily income that this building provides to owner, if any",
-			"properties" : {
-				"gold" :    { "type" : "number"},
-				"wood" :    { "type" : "number"},
-				"ore" :     { "type" : "number"},
-				"mercury" : { "type" : "number"},
-				"sulfur" :  { "type" : "number"},
-				"crystal" : { "type" : "number"},
-				"gems" :    { "type" : "number"}
-			}
 		},
 
 		// Properties that might appear since this node is shared with object config

+ 2 - 9
config/schemas/template.json

@@ -139,15 +139,8 @@
 		},
 		"mines" : {
 			"type" : "object",
-			"additionalProperties" : false,
-			"properties" : {
-				"gold" :    { "type" : "number"},
-				"wood" :    { "type" : "number"},
-				"ore" :     { "type" : "number"},
-				"mercury" : { "type" : "number"},
-				"sulfur" :  { "type" : "number"},
-				"crystal" : { "type" : "number"},
-				"gems" :    { "type" : "number"}
+			"additionalProperties" : {
+				"type" : "number"
 			}
 		},
 		"connection" :

+ 8 - 22
config/schemas/townBuilding.json

@@ -86,31 +86,17 @@
 		},
 		"cost" : {
 			"type" : "object",
-			"additionalProperties" : false,
-			"description" : "Resources needed to build building",
-			"properties" : {
-				"gold" :    { "type" : "number"},
-				"wood" :    { "type" : "number"},
-				"ore" :     { "type" : "number"},
-				"mercury" : { "type" : "number"},
-				"sulfur" :  { "type" : "number"},
-				"crystal" : { "type" : "number"},
-				"gems" :    { "type" : "number"}
-			}
+			"additionalProperties" : {
+				"type" : "number"
+			},
+			"description" : "Resources needed to build building"
 		},
 		"produce" : {
 			"type" : "object",
-			"additionalProperties" : false,
-			"description" : "Resources produced each day by this building",
-			"properties" : {
-				"gold" :    { "type" : "number"},
-				"wood" :    { "type" : "number"},
-				"ore" :     { "type" : "number"},
-				"mercury" : { "type" : "number"},
-				"sulfur" :  { "type" : "number"},
-				"crystal" : { "type" : "number"},
-				"gems" :    { "type" : "number"}
-			}
+			"additionalProperties" : {
+				"type" : "number"
+			},
+			"description" : "Resources produced each day by this building"
 		},
 		"warMachine" : {
 			"type" : "string",

+ 0 - 4
lib/ResourceSet.cpp

@@ -34,10 +34,6 @@ void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string
 
 	for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
 	{
-		//TODO: add proper support for mithril to map format
-		if(idx == EGameResID::MITHRIL)
-			continue;
-
 		handler.serializeInt(idx.toResource()->getJsonKey(), this->operator[](idx), 0);
 	}
 }

+ 0 - 2
lib/entities/faction/CTownHandler.cpp

@@ -57,8 +57,6 @@ JsonNode readBuilding(CLegacyConfigParser & parser)
 	for(const std::string & resID : GameConstants::RESOURCE_NAMES)
 		cost[resID].Float() = parser.readNumber();
 
-	cost.Struct().erase("mithril"); // erase mithril to avoid confusing validator
-
 	parser.endLine();
 
 	return ret;

+ 1 - 2
lib/gameState/GameStatistics.cpp

@@ -107,8 +107,7 @@ void StatisticDataSetEntry::serializeJson(JsonSerializeFormat & handler)
 	{
 		auto zonesData = handler.enterStruct("numMines");
 		for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
-			if(idx != GameResID::MITHRIL)
-				handler.serializeInt(idx.toResource()->getJsonKey(), numMines[idx], 0);
+			handler.serializeInt(idx.toResource()->getJsonKey(), numMines[idx], 0);
 	}
 	handler.serializeInt("score", score);
 	handler.serializeInt("maxHeroLevel", maxHeroLevel);

+ 1 - 2
lib/mapObjects/CQuest.cpp

@@ -375,8 +375,7 @@ void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fi
 			auto r = handler.enterStruct("resources");
 			
 			for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
-				if(idx != GameResID::MITHRIL)
-					handler.serializeInt(idx.toResource()->getJsonKey(), mission.resources[idx], 0);
+				handler.serializeInt(idx.toResource()->getJsonKey(), mission.resources[idx], 0);
 		}
 		
 		if(missionType == "Hero")

+ 1 - 2
lib/rmg/CRmgTemplate.cpp

@@ -536,8 +536,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
 		auto minesData = handler.enterStruct("mines");
 
 		for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
-			if(idx != GameResID::MITHRIL)
-				handler.serializeInt(idx.toResource()->getJsonKey(), mines[idx], 0);
+			handler.serializeInt(idx.toResource()->getJsonKey(), mines[idx], 0);
 	}
 
 	handler.serializeStruct("customObjects", objectConfig);

+ 0 - 5
mapeditor/inspector/questwidget.cpp

@@ -44,9 +44,6 @@ QuestWidget::QuestWidget(MapController & _controller, CQuest & _sh, QWidget *par
 	ui->lResources->setRowCount(LIBRARY->resourceTypeHandler->getAllObjects().size() - 1);
 	for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
 	{
-		if(i == EGameResID::MITHRIL)
-			continue;
-
 		MetaString str;
 		str.appendName(GameResID(i));
 		auto * item = new QTableWidgetItem(QString::fromStdString(str.toString()));
@@ -459,8 +456,6 @@ void QuestDelegate::updateModelData(QAbstractItemModel * model, const QModelInde
 	QStringList resourcesList;
 	for(GameResID resource = GameResID::WOOD; resource < GameResID::COUNT ; resource++)
 	{
-		if(resource == GameResID::MITHRIL)
-			continue;
 		if(quest.mission.resources[resource] == 0)
 			continue;
 		MetaString str;

+ 0 - 5
mapeditor/inspector/rewardswidget.cpp

@@ -60,9 +60,6 @@ RewardsWidget::RewardsWidget(CMap & m, CRewardableObject & p, QWidget *parent) :
 	ui->lResources->setRowCount(LIBRARY->resourceTypeHandler->getAllObjects().size() - 1);
 	for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
 	{
-		if(i == EGameResID::MITHRIL)
-			continue;
-
 		MetaString str;
 		str.appendName(GameResID(i));
 		for(auto * w : {ui->rResources, ui->lResources})
@@ -783,8 +780,6 @@ void RewardsDelegate::updateModelData(QAbstractItemModel * model, const QModelIn
 		QStringList resourcesList;
 		for(GameResID resource = GameResID::WOOD; resource < GameResID::COUNT ; resource++)
 		{
-			if(resource == GameResID::MITHRIL)
-				continue; // translated as "Abandoned"?
 			if(vinfo.reward.resources[resource] == 0)
 				continue;
 			MetaString str;