From 23438590c5de936885425b80c6d575c46b76cd86 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 10 Aug 2024 15:27:22 +0200 Subject: [PATCH 1/5] defining own regions --- lib/campaign/CampaignState.cpp | 27 ++++++++++++++++++++------ lib/campaign/CampaignState.h | 7 +++++++ lib/serializer/ESerializationVersion.h | 3 ++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index e69679f3a..1a7980fee 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -46,6 +46,8 @@ CampaignRegions CampaignRegions::fromJson(const JsonNode & node) CampaignRegions cr; cr.campPrefix = node["prefix"].String(); cr.colorSuffixLength = static_cast(node["color_suffix_length"].Float()); + cr.campSuffix = node["suffix"].isNull() ? std::vector() : std::vector{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,40 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, { auto const & region = regions[which.getNum()]; - static const std::string colors[2][8] = + static const std::string colors[3][8] = { + {"", "", "", "", "", "", "", ""}, {"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.size() == 0) + 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.size() == 0) + 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.size() == 0) + return getNameFor(which, color, "Co"); + else + return getNameFor(which, color, campSuffix[2]); } diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index 3da0ce4d9..c46382b2f 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -33,6 +33,8 @@ class IGameCallback; class DLL_LINKAGE CampaignRegions { std::string campPrefix; + std::vector 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); diff --git a/lib/serializer/ESerializationVersion.h b/lib/serializer/ESerializationVersion.h index 853bcde7e..0a47355c0 100644 --- a/lib/serializer/ESerializationVersion.h +++ b/lib/serializer/ESerializationVersion.h @@ -58,7 +58,8 @@ 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 + CAMPAIGN_REGIONS, // 852 - configurable campaign regions CURRENT = PLAYER_HANDICAP }; From d7211859e9dc109c2c79f417b31f6b4029474c7c Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 12 Aug 2024 00:01:09 +0200 Subject: [PATCH 2/5] docs --- docs/modders/Campaign_Format.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/modders/Campaign_Format.md b/docs/modders/Campaign_Format.md index 554e98566..2f8fdd580 100644 --- a/docs/modders/Campaign_Format.md +++ b/docs/modders/Campaign_Format.md @@ -182,6 +182,8 @@ Predefined campaign regions are located in file `campaign_regions.json` ```js { + "background": "own_region_background.bmp", + "suffix": ["Enabled", "Selected", "Conquered"], "prefix": "G3", "color_suffix_length": 1, "desc": [ @@ -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"` 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. 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 From a13d5fe3b7be2b7545894dbf76692ccb4f579f85 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 12 Aug 2024 01:16:06 +0200 Subject: [PATCH 3/5] review --- lib/campaign/CampaignState.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index 1a7980fee..d6d1571b1 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -86,12 +86,11 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, { auto const & region = regions[which.getNum()]; - static const std::string colors[3][8] = - { - {"", "", "", "", "", "", "", ""}, - {"R", "B", "N", "G", "O", "V", "T", "P"}, - {"Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi"} - }; + static const std::array, 3> colors = {{ + { "", "", "", "", "", "", "", "" }, + { "R", "B", "N", "G", "O", "V", "T", "P" }, + { "Re", "Bl", "Br", "Gr", "Or", "Vi", "Te", "Pi" } + }}; std::string color = colors[colorSuffixLength][colorIndex]; @@ -100,7 +99,7 @@ ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) const { - if(campSuffix.size() == 0) + if(campSuffix.empty()) return getNameFor(which, color, "En"); else return getNameFor(which, color, campSuffix[0]); @@ -108,7 +107,7 @@ ImagePath CampaignRegions::getAvailableName(CampaignScenarioID which, int color) ImagePath CampaignRegions::getSelectedName(CampaignScenarioID which, int color) const { - if(campSuffix.size() == 0) + if(campSuffix.empty()) return getNameFor(which, color, "Se"); else return getNameFor(which, color, campSuffix[1]); @@ -116,7 +115,7 @@ ImagePath CampaignRegions::getSelectedName(CampaignScenarioID which, int color) ImagePath CampaignRegions::getConqueredName(CampaignScenarioID which, int color) const { - if(campSuffix.size() == 0) + if(campSuffix.empty()) return getNameFor(which, color, "Co"); else return getNameFor(which, color, campSuffix[2]); From 79b5a3e99b9c253f4cef9c4a90375c89b31792cd Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 12 Aug 2024 01:39:55 +0200 Subject: [PATCH 4/5] Update docs/modders/Campaign_Format.md Co-authored-by: Alexander Wilms --- docs/modders/Campaign_Format.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modders/Campaign_Format.md b/docs/modders/Campaign_Format.md index 2f8fdd580..3b87de152 100644 --- a/docs/modders/Campaign_Format.md +++ b/docs/modders/Campaign_Format.md @@ -197,7 +197,7 @@ Predefined campaign regions are located in file `campaign_regions.json` - `"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"` ised to identify all images related to region. In this example, it will be pictures starting from `G3A_..., G3B_..., G3C_..."` +- `"infix"` used to identify all images related to region. In this example, it will be pictures whose files names begin with `G3A_..., G3B_..., G3C_..."` - `"color_suffix_length"` 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 From da38ad5f5c4ad7b520a53134f004d9dc638a77c7 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:57:34 +0200 Subject: [PATCH 5/5] code review --- config/campaign_regions.json | 40 ++++++++++++++++----------------- docs/modders/Campaign_Format.md | 6 ++--- lib/campaign/CampaignState.cpp | 2 +- lib/campaign/CampaignState.h | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/config/campaign_regions.json b/config/campaign_regions.json index 1ae7b89c1..bcba4875b 100644 --- a/config/campaign_regions.json +++ b/config/campaign_regions.json @@ -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 }, diff --git a/docs/modders/Campaign_Format.md b/docs/modders/Campaign_Format.md index 3b87de152..7a58b6608 100644 --- a/docs/modders/Campaign_Format.md +++ b/docs/modders/Campaign_Format.md @@ -182,10 +182,10 @@ Predefined campaign regions are located in file `campaign_regions.json` ```js { - "background": "own_region_background.bmp", + "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 }, @@ -198,7 +198,7 @@ Predefined campaign regions are located in file `campaign_regions.json` - `"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_..."` -- `"color_suffix_length"` 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` +- `"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 diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index d6d1571b1..c99637826 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -45,7 +45,7 @@ CampaignRegions CampaignRegions::fromJson(const JsonNode & node) { CampaignRegions cr; cr.campPrefix = node["prefix"].String(); - cr.colorSuffixLength = static_cast(node["color_suffix_length"].Float()); + cr.colorSuffixLength = static_cast(node["colorSuffixLength"].Float()); cr.campSuffix = node["suffix"].isNull() ? std::vector() : std::vector{node["suffix"].Vector()[0].String(), node["suffix"].Vector()[1].String(), node["suffix"].Vector()[2].String()}; cr.campBackground = node["background"].isNull() ? "" : node["background"].String(); diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index c46382b2f..bd6672da0 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -33,8 +33,8 @@ class IGameCallback; class DLL_LINKAGE CampaignRegions { std::string campPrefix; - std::vector campSuffix = {}; - std::string campBackground = ""; + std::vector campSuffix; + std::string campBackground; int colorSuffixLength; struct DLL_LINKAGE RegionDescription