mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #4429 from Laserlicht/regions
defining own regions extend
This commit is contained in:
		| @@ -2,7 +2,7 @@ | ||||
| 	"campaign_regions": [ | ||||
| 		{ | ||||
| 			"prefix": "G1", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 57, "y": 314 }, | ||||
| 				{ "infix": "B", "x": 137, "y": 309 }, | ||||
| @@ -12,7 +12,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "G2", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 56, "y": 90 }, | ||||
| 				{ "infix": "B", "x": 316, "y": 49 }, | ||||
| @@ -23,7 +23,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "G3", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 289, "y": 376 }, | ||||
| 				{ "infix": "B", "x": 60, "y": 147 }, | ||||
| @@ -33,7 +33,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "E1", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 270, "y": 332 }, | ||||
| 				{ "infix": "B", "x": 138, "y": 113 }, | ||||
| @@ -47,7 +47,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "E2", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 131, "y": 202 }, | ||||
| 				{ "infix": "B", "x": 60, "y": 145 }, | ||||
| @@ -58,7 +58,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "N1", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 42, "y": 94 }, | ||||
| 				{ "infix": "B", "x": 309, "y": 290 }, | ||||
| @@ -68,7 +68,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "S1", | ||||
| 			"color_suffix_length": 1, | ||||
| 			"colorSuffixLength": 1, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 263, "y": 199 }, | ||||
| 				{ "infix": "B", "x": 182, "y": 210 }, | ||||
| @@ -78,7 +78,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "BR", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 18, "y": 233 }, | ||||
| 				{ "infix": "B", "x": 125, "y": 381 }, | ||||
| @@ -89,7 +89,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "IS", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 294, "y": 399 }, | ||||
| 				{ "infix": "B", "x": 183, "y": 293 }, | ||||
| @@ -100,7 +100,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "KR", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 148, "y": 323 }, | ||||
| 				{ "infix": "B", "x": 192, "y": 235 }, | ||||
| @@ -111,7 +111,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "NI", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 118, "y": 111 }, | ||||
| 				{ "infix": "B", "x": 223, "y": 145 }, | ||||
| @@ -122,7 +122,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "TA", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 228, "y": 233 }, | ||||
| 				{ "infix": "B", "x": 147, "y": 194 }, | ||||
| @@ -132,7 +132,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "AR", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 135, "y": 238 }, | ||||
| 				{ "infix": "B", "x": 135, "y": 121 }, | ||||
| @@ -147,7 +147,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "HS", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 141, "y": 326 }, | ||||
| 				{ "infix": "B", "x": 238, "y": 275 }, | ||||
| @@ -158,7 +158,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "BB", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 167, "y": 342 }, | ||||
| 				{ "infix": "B", "x": 217, "y": 263 }, | ||||
| @@ -170,7 +170,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "NB", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 6, "y": 292 }, | ||||
| 				{ "infix": "B", "x": 161, "y": 334 }, | ||||
| @@ -181,7 +181,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "EL", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 11, "y": 73 }, | ||||
| 				{ "infix": "B", "x": 0, "y": 241 }, | ||||
| @@ -192,7 +192,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "RN", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 84, "y": 319 }, | ||||
| 				{ "infix": "B", "x": 194, "y": 275 }, | ||||
| @@ -203,7 +203,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "UA", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 157, "y": 409 }, | ||||
| 				{ "infix": "B", "x": 62, "y": 346 }, | ||||
| @@ -222,7 +222,7 @@ | ||||
|  | ||||
| 		{ | ||||
| 			"prefix": "SP", | ||||
| 			"color_suffix_length": 2, | ||||
| 			"colorSuffixLength": 2, | ||||
| 			"desc": [ | ||||
| 				{ "infix": "A", "x": 7, "y": 295 }, | ||||
| 				{ "infix": "B", "x": 44, "y": 141 }, | ||||
|   | ||||
| @@ -182,8 +182,10 @@ Predefined campaign regions are located in file `campaign_regions.json` | ||||
|  | ||||
| ```js | ||||
| { | ||||
|     "background": "ownRegionBackground.png", | ||||
| 		"suffix": ["Enabled", "Selected", "Conquered"], | ||||
|     "prefix": "G3", | ||||
|     "color_suffix_length": 1, | ||||
|     "colorSuffixLength": 1, | ||||
|     "desc": [ | ||||
|         { "infix": "A", "x": 289, "y": 376 }, | ||||
|         { "infix": "B", "x": 60, "y": 147 }, | ||||
| @@ -192,9 +194,11 @@ Predefined campaign regions are located in file `campaign_regions.json` | ||||
| }, | ||||
| ``` | ||||
|  | ||||
| - `"prefix"` used to identify all images related to campaign. In this example, background picture will be `G3_BG` | ||||
| - `"inflix"` ised to identify all images related to region. In this example, it will be pictures starting from `G3A_..., G3B_..., G3C_..."`  | ||||
| - `"color_suffix_length"` identifies suffix length for region colourful frames. 1 is used for `R, B, N, G, O, V, T, P`, value 2 is used for `Re, Bl, Br, Gr, Or, Vi, Te, Pi` | ||||
| - `"background"` optional - use own image name for background instead of adding "_BG" to the prefix as name | ||||
| - `"prefix"` used to identify all images related to campaign. In this example (if background parameter wouldn't exists), background picture will be `G3_BG` | ||||
| - `"suffix"` optional - use other suffixes than the default `En`, `Se` and `Co` for the three different images | ||||
| - `"infix"` used to identify all images related to region. In this example, it will be pictures whose files names begin with `G3A_..., G3B_..., G3C_..."`  | ||||
| - `"colorSuffixLength"` identifies suffix length for region colourful frames. 0 is no color suffix (no colorisation), 1 is used for `R, B, N, G, O, V, T, P`, value 2 is used for `Re, Bl, Br, Gr, Or, Vi, Te, Pi` | ||||
|  | ||||
| ## Packing campaign | ||||
|  | ||||
|   | ||||
| @@ -45,7 +45,9 @@ CampaignRegions CampaignRegions::fromJson(const JsonNode & node) | ||||
| { | ||||
| 	CampaignRegions cr; | ||||
| 	cr.campPrefix = node["prefix"].String(); | ||||
| 	cr.colorSuffixLength = static_cast<int>(node["color_suffix_length"].Float()); | ||||
| 	cr.colorSuffixLength = static_cast<int>(node["colorSuffixLength"].Float()); | ||||
| 	cr.campSuffix = node["suffix"].isNull() ? std::vector<std::string>() : std::vector<std::string>{node["suffix"].Vector()[0].String(), node["suffix"].Vector()[1].String(), node["suffix"].Vector()[2].String()}; | ||||
| 	cr.campBackground = node["background"].isNull() ? "" : node["background"].String(); | ||||
|  | ||||
| 	for(const JsonNode & desc : node["desc"].Vector()) | ||||
| 		cr.regions.push_back(CampaignRegions::RegionDescription::fromJson(desc)); | ||||
| @@ -68,7 +70,10 @@ CampaignRegions CampaignRegions::getLegacy(int campId) | ||||
|  | ||||
| ImagePath CampaignRegions::getBackgroundName() const | ||||
| { | ||||
| 	return ImagePath::builtin(campPrefix + "_BG.BMP"); | ||||
| 	if(campBackground.empty()) | ||||
| 		return ImagePath::builtin(campPrefix + "_BG.BMP"); | ||||
| 	else | ||||
| 		return ImagePath::builtin(campBackground); | ||||
| } | ||||
|  | ||||
| Point CampaignRegions::getPosition(CampaignScenarioID which) const | ||||
| @@ -81,30 +86,39 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, | ||||
| { | ||||
| 	auto const & region = regions[which.getNum()]; | ||||
|  | ||||
| 	static const std::string colors[2][8] = | ||||
| 	{ | ||||
| 		{"R", "B", "N", "G", "O", "V", "T", "P"}, | ||||
| 		{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"} | ||||
| 	}; | ||||
| 	static const std::array<std::array<std::string, 8>, 3> colors = {{ | ||||
| 		{ "", "", "", "", "", "", "", "" }, | ||||
| 		{ "R", "B", "N", "G", "O", "V", "T", "P" }, | ||||
| 		{ "Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi" } | ||||
| 	}}; | ||||
|  | ||||
| 	std::string color = colors[colorSuffixLength - 1][colorIndex]; | ||||
| 	std::string color = colors[colorSuffixLength][colorIndex]; | ||||
|  | ||||
| 	return ImagePath::builtin(campPrefix + region.infix + "_" + type + color + ".BMP"); | ||||
| } | ||||
|  | ||||
| ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const | ||||
| { | ||||
| 	return getNameFor(which, color, "En"); | ||||
| 	if(campSuffix.empty()) | ||||
| 		return getNameFor(which, color, "En"); | ||||
| 	else | ||||
| 		return getNameFor(which, color, campSuffix[0]); | ||||
| } | ||||
|  | ||||
| ImagePath CampaignRegions::getSelectedName(CampaignScenarioID which, int color) const | ||||
| { | ||||
| 	return getNameFor(which, color, "Se"); | ||||
| 	if(campSuffix.empty()) | ||||
| 		return getNameFor(which, color, "Se"); | ||||
| 	else | ||||
| 		return getNameFor(which, color, campSuffix[1]); | ||||
| } | ||||
|  | ||||
| ImagePath CampaignRegions::getConqueredName(CampaignScenarioID which, int color) const | ||||
| { | ||||
| 	return getNameFor(which, color, "Co"); | ||||
| 	if(campSuffix.empty()) | ||||
| 		return getNameFor(which, color, "Co"); | ||||
| 	else | ||||
| 		return getNameFor(which, color, campSuffix[2]); | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -33,6 +33,8 @@ class IGameCallback; | ||||
| class DLL_LINKAGE CampaignRegions | ||||
| { | ||||
| 	std::string campPrefix; | ||||
| 	std::vector<std::string> campSuffix; | ||||
| 	std::string campBackground; | ||||
| 	int colorSuffixLength; | ||||
|  | ||||
| 	struct DLL_LINKAGE RegionDescription | ||||
| @@ -67,6 +69,11 @@ public: | ||||
| 		h & campPrefix; | ||||
| 		h & colorSuffixLength; | ||||
| 		h & regions; | ||||
| 		if (h.version >= Handler::Version::CAMPAIGN_REGIONS) | ||||
| 		{ | ||||
| 			h & campSuffix; | ||||
| 			h & campBackground; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	static CampaignRegions fromJson(const JsonNode & node); | ||||
|   | ||||
| @@ -58,8 +58,9 @@ enum class ESerializationVersion : int32_t | ||||
| 	MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format | ||||
| 	REMOVE_LIB_RNG, // 849 - removed random number generators from library classes | ||||
| 	HIGHSCORE_PARAMETERS, // 850 - saves parameter for campaign | ||||
|   PLAYER_HANDICAP, // 851 - player handicap selection at game start | ||||
| 	PLAYER_HANDICAP, // 851 - player handicap selection at game start | ||||
| 	STATISTICS, // 852 - removed random number generators from library classes | ||||
| 	CAMPAIGN_REGIONS, // 853 - configurable campaign regions | ||||
|  | ||||
| 	CURRENT = STATISTICS | ||||
| 	CURRENT = CAMPAIGN_REGIONS | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user