1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

Merge pull request #4429 from Laserlicht/regions

defining own regions extend
This commit is contained in:
Ivan Savenko 2024-08-14 17:04:13 +03:00 committed by GitHub
commit 1fb8ab5f70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 37 deletions

View File

@ -2,7 +2,7 @@
"campaign_regions": [ "campaign_regions": [
{ {
"prefix": "G1", "prefix": "G1",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 57, "y": 314 }, { "infix": "A", "x": 57, "y": 314 },
{ "infix": "B", "x": 137, "y": 309 }, { "infix": "B", "x": 137, "y": 309 },
@ -12,7 +12,7 @@
{ {
"prefix": "G2", "prefix": "G2",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 56, "y": 90 }, { "infix": "A", "x": 56, "y": 90 },
{ "infix": "B", "x": 316, "y": 49 }, { "infix": "B", "x": 316, "y": 49 },
@ -23,7 +23,7 @@
{ {
"prefix": "G3", "prefix": "G3",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 289, "y": 376 }, { "infix": "A", "x": 289, "y": 376 },
{ "infix": "B", "x": 60, "y": 147 }, { "infix": "B", "x": 60, "y": 147 },
@ -33,7 +33,7 @@
{ {
"prefix": "E1", "prefix": "E1",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 270, "y": 332 }, { "infix": "A", "x": 270, "y": 332 },
{ "infix": "B", "x": 138, "y": 113 }, { "infix": "B", "x": 138, "y": 113 },
@ -47,7 +47,7 @@
{ {
"prefix": "E2", "prefix": "E2",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 131, "y": 202 }, { "infix": "A", "x": 131, "y": 202 },
{ "infix": "B", "x": 60, "y": 145 }, { "infix": "B", "x": 60, "y": 145 },
@ -58,7 +58,7 @@
{ {
"prefix": "N1", "prefix": "N1",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 42, "y": 94 }, { "infix": "A", "x": 42, "y": 94 },
{ "infix": "B", "x": 309, "y": 290 }, { "infix": "B", "x": 309, "y": 290 },
@ -68,7 +68,7 @@
{ {
"prefix": "S1", "prefix": "S1",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 263, "y": 199 }, { "infix": "A", "x": 263, "y": 199 },
{ "infix": "B", "x": 182, "y": 210 }, { "infix": "B", "x": 182, "y": 210 },
@ -78,7 +78,7 @@
{ {
"prefix": "BR", "prefix": "BR",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 18, "y": 233 }, { "infix": "A", "x": 18, "y": 233 },
{ "infix": "B", "x": 125, "y": 381 }, { "infix": "B", "x": 125, "y": 381 },
@ -89,7 +89,7 @@
{ {
"prefix": "IS", "prefix": "IS",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 294, "y": 399 }, { "infix": "A", "x": 294, "y": 399 },
{ "infix": "B", "x": 183, "y": 293 }, { "infix": "B", "x": 183, "y": 293 },
@ -100,7 +100,7 @@
{ {
"prefix": "KR", "prefix": "KR",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 148, "y": 323 }, { "infix": "A", "x": 148, "y": 323 },
{ "infix": "B", "x": 192, "y": 235 }, { "infix": "B", "x": 192, "y": 235 },
@ -111,7 +111,7 @@
{ {
"prefix": "NI", "prefix": "NI",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 118, "y": 111 }, { "infix": "A", "x": 118, "y": 111 },
{ "infix": "B", "x": 223, "y": 145 }, { "infix": "B", "x": 223, "y": 145 },
@ -122,7 +122,7 @@
{ {
"prefix": "TA", "prefix": "TA",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 228, "y": 233 }, { "infix": "A", "x": 228, "y": 233 },
{ "infix": "B", "x": 147, "y": 194 }, { "infix": "B", "x": 147, "y": 194 },
@ -132,7 +132,7 @@
{ {
"prefix": "AR", "prefix": "AR",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 135, "y": 238 }, { "infix": "A", "x": 135, "y": 238 },
{ "infix": "B", "x": 135, "y": 121 }, { "infix": "B", "x": 135, "y": 121 },
@ -147,7 +147,7 @@
{ {
"prefix": "HS", "prefix": "HS",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 141, "y": 326 }, { "infix": "A", "x": 141, "y": 326 },
{ "infix": "B", "x": 238, "y": 275 }, { "infix": "B", "x": 238, "y": 275 },
@ -158,7 +158,7 @@
{ {
"prefix": "BB", "prefix": "BB",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 167, "y": 342 }, { "infix": "A", "x": 167, "y": 342 },
{ "infix": "B", "x": 217, "y": 263 }, { "infix": "B", "x": 217, "y": 263 },
@ -170,7 +170,7 @@
{ {
"prefix": "NB", "prefix": "NB",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 6, "y": 292 }, { "infix": "A", "x": 6, "y": 292 },
{ "infix": "B", "x": 161, "y": 334 }, { "infix": "B", "x": 161, "y": 334 },
@ -181,7 +181,7 @@
{ {
"prefix": "EL", "prefix": "EL",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 11, "y": 73 }, { "infix": "A", "x": 11, "y": 73 },
{ "infix": "B", "x": 0, "y": 241 }, { "infix": "B", "x": 0, "y": 241 },
@ -192,7 +192,7 @@
{ {
"prefix": "RN", "prefix": "RN",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 84, "y": 319 }, { "infix": "A", "x": 84, "y": 319 },
{ "infix": "B", "x": 194, "y": 275 }, { "infix": "B", "x": 194, "y": 275 },
@ -203,7 +203,7 @@
{ {
"prefix": "UA", "prefix": "UA",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 157, "y": 409 }, { "infix": "A", "x": 157, "y": 409 },
{ "infix": "B", "x": 62, "y": 346 }, { "infix": "B", "x": 62, "y": 346 },
@ -222,7 +222,7 @@
{ {
"prefix": "SP", "prefix": "SP",
"color_suffix_length": 2, "colorSuffixLength": 2,
"desc": [ "desc": [
{ "infix": "A", "x": 7, "y": 295 }, { "infix": "A", "x": 7, "y": 295 },
{ "infix": "B", "x": 44, "y": 141 }, { "infix": "B", "x": 44, "y": 141 },

View File

@ -182,8 +182,10 @@ Predefined campaign regions are located in file `campaign_regions.json`
```js ```js
{ {
"background": "ownRegionBackground.png",
"suffix": ["Enabled", "Selected", "Conquered"],
"prefix": "G3", "prefix": "G3",
"color_suffix_length": 1, "colorSuffixLength": 1,
"desc": [ "desc": [
{ "infix": "A", "x": 289, "y": 376 }, { "infix": "A", "x": 289, "y": 376 },
{ "infix": "B", "x": 60, "y": 147 }, { "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` - `"background"` optional - use own image name for background instead of adding "_BG" to the prefix as name
- `"inflix"` ised to identify all images related to region. In this example, it will be pictures starting from `G3A_..., G3B_..., G3C_..."` - `"prefix"` used to identify all images related to campaign. In this example (if background parameter wouldn't exists), background picture will be `G3_BG`
- `"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` - `"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 ## Packing campaign

View File

@ -45,7 +45,9 @@ CampaignRegions CampaignRegions::fromJson(const JsonNode & node)
{ {
CampaignRegions cr; CampaignRegions cr;
cr.campPrefix = node["prefix"].String(); 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()) for(const JsonNode & desc : node["desc"].Vector())
cr.regions.push_back(CampaignRegions::RegionDescription::fromJson(desc)); cr.regions.push_back(CampaignRegions::RegionDescription::fromJson(desc));
@ -68,7 +70,10 @@ CampaignRegions CampaignRegions::getLegacy(int campId)
ImagePath CampaignRegions::getBackgroundName() const 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 Point CampaignRegions::getPosition(CampaignScenarioID which) const
@ -81,30 +86,39 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex,
{ {
auto const & region = regions[which.getNum()]; auto const & region = regions[which.getNum()];
static const std::string colors[2][8] = static const std::array<std::array<std::string, 8>, 3> colors = {{
{ { "", "", "", "", "", "", "", "" },
{"R", "B", "N", "G", "O", "V", "T", "P"}, { "R", "B", "N", "G", "O", "V", "T", "P" },
{"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"} { "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"); return ImagePath::builtin(campPrefix + region.infix + "_" + type + color + ".BMP");
} }
ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const 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 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 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]);
} }

View File

@ -33,6 +33,8 @@ class IGameCallback;
class DLL_LINKAGE CampaignRegions class DLL_LINKAGE CampaignRegions
{ {
std::string campPrefix; std::string campPrefix;
std::vector<std::string> campSuffix;
std::string campBackground;
int colorSuffixLength; int colorSuffixLength;
struct DLL_LINKAGE RegionDescription struct DLL_LINKAGE RegionDescription
@ -67,6 +69,11 @@ public:
h & campPrefix; h & campPrefix;
h & colorSuffixLength; h & colorSuffixLength;
h & regions; h & regions;
if (h.version >= Handler::Version::CAMPAIGN_REGIONS)
{
h & campSuffix;
h & campBackground;
}
} }
static CampaignRegions fromJson(const JsonNode & node); static CampaignRegions fromJson(const JsonNode & node);

View File

@ -58,8 +58,9 @@ enum class ESerializationVersion : int32_t
MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format MAP_FORMAT_ADDITIONAL_INFOS, // 848 - serialize new infos in map format
REMOVE_LIB_RNG, // 849 - removed random number generators from library classes REMOVE_LIB_RNG, // 849 - removed random number generators from library classes
HIGHSCORE_PARAMETERS, // 850 - saves parameter for campaign 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 STATISTICS, // 852 - removed random number generators from library classes
CAMPAIGN_REGIONS, // 853 - configurable campaign regions
CURRENT = STATISTICS CURRENT = CAMPAIGN_REGIONS
}; };