mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Remove old code
This commit is contained in:
@@ -176,7 +176,7 @@ JsonNode CampaignHandler::writeHeaderToJson(CampaignHeader & header)
|
||||
{
|
||||
JsonNode node;
|
||||
node["version"].Integer() = static_cast<ui64>(CampaignVersion::VCMI);
|
||||
node["regions"] = CampaignRegions::toJson(header.campaignRegions);
|
||||
node["regions"] = header.campaignRegions.toJson();
|
||||
node["name"].String() = header.name.toString();
|
||||
node["description"].String() = header.description.toString();
|
||||
node["author"].String() = header.author.toString();
|
||||
|
||||
@@ -14,28 +14,26 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
CampaignRegions::RegionDescription CampaignRegions::RegionDescription::fromJson(const JsonNode & node)
|
||||
CampaignRegions::RegionDescription::RegionDescription(const JsonNode & node)
|
||||
{
|
||||
CampaignRegions::RegionDescription rd;
|
||||
rd.infix = node["infix"].String();
|
||||
rd.pos = Point(static_cast<int>(node["x"].Float()), static_cast<int>(node["y"].Float()));
|
||||
infix = node["infix"].String();
|
||||
pos = Point(static_cast<int>(node["x"].Float()), static_cast<int>(node["y"].Float()));
|
||||
if(!node["labelPos"].isNull())
|
||||
rd.labelPos = Point(static_cast<int>(node["labelPos"]["x"].Float()), static_cast<int>(node["labelPos"]["y"].Float()));
|
||||
labelPos = Point(static_cast<int>(node["labelPos"]["x"].Float()), static_cast<int>(node["labelPos"]["y"].Float()));
|
||||
else
|
||||
rd.labelPos = std::nullopt;
|
||||
return rd;
|
||||
labelPos = std::nullopt;
|
||||
}
|
||||
|
||||
JsonNode CampaignRegions::RegionDescription::toJson(CampaignRegions::RegionDescription & rd)
|
||||
JsonNode CampaignRegions::RegionDescription::toJson() const
|
||||
{
|
||||
JsonNode node;
|
||||
node["infix"].String() = rd.infix;
|
||||
node["x"].Float() = rd.pos.x;
|
||||
node["y"].Float() = rd.pos.y;
|
||||
if(rd.labelPos != std::nullopt)
|
||||
node["infix"].String() = infix;
|
||||
node["x"].Float() = pos.x;
|
||||
node["y"].Float() = pos.y;
|
||||
if(labelPos != std::nullopt)
|
||||
{
|
||||
node["labelPos"]["x"].Float() = (*rd.labelPos).x;
|
||||
node["labelPos"]["y"].Float() = (*rd.labelPos).y;
|
||||
node["labelPos"]["x"].Float() = (*labelPos).x;
|
||||
node["labelPos"]["y"].Float() = (*labelPos).y;
|
||||
}
|
||||
else
|
||||
node["labelPos"].clear();
|
||||
@@ -50,41 +48,28 @@ CampaignRegions::CampaignRegions(const JsonNode & node)
|
||||
campBackground = node["background"].isNull() ? "" : node["background"].String();
|
||||
|
||||
for(const JsonNode & desc : node["desc"].Vector())
|
||||
regions.push_back(CampaignRegions::RegionDescription::fromJson(desc));
|
||||
regions.push_back(CampaignRegions::RegionDescription(desc));
|
||||
}
|
||||
|
||||
JsonNode CampaignRegions::toJson(CampaignRegions cr)
|
||||
JsonNode CampaignRegions::toJson() const
|
||||
{
|
||||
JsonNode node;
|
||||
node["prefix"].String() = cr.campPrefix;
|
||||
node["colorSuffixLength"].Float() = cr.colorSuffixLength;
|
||||
if(cr.campSuffix.empty())
|
||||
node["prefix"].String() = campPrefix;
|
||||
node["colorSuffixLength"].Float() = colorSuffixLength;
|
||||
if(campSuffix.empty())
|
||||
node["suffix"].clear();
|
||||
else
|
||||
node["suffix"].Vector() = JsonVector{ JsonNode(cr.campSuffix[0]), JsonNode(cr.campSuffix[1]), JsonNode(cr.campSuffix[2]) };
|
||||
if(cr.campBackground.empty())
|
||||
node["suffix"].Vector() = JsonVector{ JsonNode(campSuffix[0]), JsonNode(campSuffix[1]), JsonNode(campSuffix[2]) };
|
||||
if(campBackground.empty())
|
||||
node["background"].clear();
|
||||
else
|
||||
node["background"].String() = cr.campBackground;
|
||||
node["background"].String() = campBackground;
|
||||
node["desc"].Vector() = JsonVector();
|
||||
for(auto & region : cr.regions)
|
||||
node["desc"].Vector().push_back(CampaignRegions::RegionDescription::toJson(region));
|
||||
for(const auto & region : regions)
|
||||
node["desc"].Vector().push_back(region.toJson());
|
||||
return node;
|
||||
}
|
||||
|
||||
CampaignRegions CampaignRegions::getLegacy(int campId)
|
||||
{
|
||||
static std::vector<CampaignRegions> campDescriptions;
|
||||
if(campDescriptions.empty()) //read once
|
||||
{
|
||||
const JsonNode config(JsonPath::builtin("config/campaign_regions.json"));
|
||||
for(const JsonNode & campaign : config["campaign_regions"].Vector())
|
||||
campDescriptions.push_back(CampaignRegions(campaign));
|
||||
}
|
||||
|
||||
return campDescriptions.at(campId);
|
||||
}
|
||||
|
||||
ImagePath CampaignRegions::getBackgroundName() const
|
||||
{
|
||||
if(campBackground.empty())
|
||||
|
||||
@@ -22,9 +22,13 @@ class DLL_LINKAGE CampaignRegions
|
||||
friend class CampaignProperties;
|
||||
friend class ScenarioProperties;
|
||||
|
||||
/// Shared prefix for all campaign images
|
||||
std::string campPrefix;
|
||||
/// Suffix for enabled/selected/completed campaign region maps
|
||||
std::vector<std::string> campSuffix;
|
||||
/// Custom background name for campaign
|
||||
std::string campBackground;
|
||||
/// Lookup scheme for colored campaign images location
|
||||
int colorSuffixLength = 0;
|
||||
|
||||
struct DLL_LINKAGE RegionDescription
|
||||
@@ -40,8 +44,9 @@ class DLL_LINKAGE CampaignRegions
|
||||
h & labelPos;
|
||||
}
|
||||
|
||||
static CampaignRegions::RegionDescription fromJson(const JsonNode & node);
|
||||
static JsonNode toJson(CampaignRegions::RegionDescription & rd);
|
||||
RegionDescription() = default;
|
||||
explicit RegionDescription(const JsonNode & node);
|
||||
JsonNode toJson() const;
|
||||
};
|
||||
|
||||
std::vector<RegionDescription> regions;
|
||||
@@ -69,9 +74,7 @@ public:
|
||||
h & campBackground;
|
||||
}
|
||||
|
||||
|
||||
static JsonNode toJson(CampaignRegions cr);
|
||||
static CampaignRegions getLegacy(int campId);
|
||||
JsonNode toJson() const;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "../../lib/VCMIDirs.h"
|
||||
#include "../../lib/json/JsonNode.h"
|
||||
#include "../../lib/campaign/CampaignRegionsHandler.h"
|
||||
#include "../../lib/campaign/CampaignState.h"
|
||||
#include "../../lib/mapping/CMap.h"
|
||||
|
||||
@@ -200,7 +201,7 @@ void CampaignEditor::on_actionNew_triggered()
|
||||
return;
|
||||
|
||||
campaignState = std::make_unique<CampaignState>();
|
||||
campaignState->campaignRegions = CampaignRegions::getLegacy(0);
|
||||
campaignState->campaignRegions = *LIBRARY->campaignRegions->getByIndex(0);
|
||||
for (int i = 0; i < campaignState->campaignRegions.regions.size(); i++)
|
||||
{
|
||||
CampaignScenario s;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "../../lib/GameLibrary.h"
|
||||
#include "../../lib/texts/CGeneralTextHandler.h"
|
||||
#include "../../lib/campaign/CampaignRegionsHandler.h"
|
||||
#include "../../lib/campaign/CampaignState.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
#include "../../lib/json/JsonNode.h"
|
||||
@@ -89,7 +90,7 @@ void CampaignProperties::on_buttonBox_clicked(QAbstractButton * button)
|
||||
void CampaignProperties::on_comboBoxRegionPreset_currentIndexChanged(int index)
|
||||
{
|
||||
if(ui->comboBoxRegionPreset->count() == 21 && ui->comboBoxRegionPreset->currentIndex() != 20)
|
||||
regions = CampaignRegions::getLegacy(ui->comboBoxRegionPreset->currentIndex());
|
||||
regions = *LIBRARY->campaignRegions->getByIndex(index);
|
||||
|
||||
loadRegion();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user