mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
code review
This commit is contained in:
@@ -37,18 +37,11 @@ CampaignRegions::RegionDescription CampaignRegions::RegionDescription::fromJson(
|
|||||||
{
|
{
|
||||||
CampaignRegions::RegionDescription rd;
|
CampaignRegions::RegionDescription rd;
|
||||||
rd.infix = node["infix"].String();
|
rd.infix = node["infix"].String();
|
||||||
rd.xpos = static_cast<int>(node["x"].Float());
|
rd.pos = Point(static_cast<int>(node["x"].Float()), static_cast<int>(node["y"].Float()));
|
||||||
rd.ypos = static_cast<int>(node["y"].Float());
|
|
||||||
if(!node["labelPos"].isNull())
|
if(!node["labelPos"].isNull())
|
||||||
{
|
rd.labelPos = Point(static_cast<int>(node["labelPos"]["x"].Float()), static_cast<int>(node["labelPos"]["y"].Float()));
|
||||||
rd.xLabelpos = static_cast<int>(node["labelPos"]["x"].Float());
|
|
||||||
rd.yLabelpos = static_cast<int>(node["labelPos"]["y"].Float());
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
rd.labelPos = std::nullopt;
|
||||||
rd.xLabelpos = std::nullopt;
|
|
||||||
rd.yLabelpos = std::nullopt;
|
|
||||||
}
|
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,16 +83,13 @@ ImagePath CampaignRegions::getBackgroundName() const
|
|||||||
Point CampaignRegions::getPosition(CampaignScenarioID which) const
|
Point CampaignRegions::getPosition(CampaignScenarioID which) const
|
||||||
{
|
{
|
||||||
auto const & region = regions[which.getNum()];
|
auto const & region = regions[which.getNum()];
|
||||||
return Point(region.xpos, region.ypos);
|
return region.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Point> CampaignRegions::getLabelPosition(CampaignScenarioID which) const
|
std::optional<Point> CampaignRegions::getLabelPosition(CampaignScenarioID which) const
|
||||||
{
|
{
|
||||||
auto const & region = regions[which.getNum()];
|
auto const & region = regions[which.getNum()];
|
||||||
if(region.xLabelpos && region.yLabelpos)
|
return region.labelPos;
|
||||||
return Point(*region.xLabelpos, *region.yLabelpos);
|
|
||||||
else
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, std::string type) const
|
ImagePath CampaignRegions::getNameFor(CampaignScenarioID which, int colorIndex, std::string type) const
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include "CampaignConstants.h"
|
#include "CampaignConstants.h"
|
||||||
#include "CampaignScenarioPrologEpilog.h"
|
#include "CampaignScenarioPrologEpilog.h"
|
||||||
#include "../gameState/HighScore.h"
|
#include "../gameState/HighScore.h"
|
||||||
|
#include "../Point.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -27,7 +28,6 @@ class CMap;
|
|||||||
class CMapHeader;
|
class CMapHeader;
|
||||||
class CMapInfo;
|
class CMapInfo;
|
||||||
class JsonNode;
|
class JsonNode;
|
||||||
class Point;
|
|
||||||
class IGameCallback;
|
class IGameCallback;
|
||||||
|
|
||||||
class DLL_LINKAGE CampaignRegions
|
class DLL_LINKAGE CampaignRegions
|
||||||
@@ -40,20 +40,21 @@ class DLL_LINKAGE CampaignRegions
|
|||||||
struct DLL_LINKAGE RegionDescription
|
struct DLL_LINKAGE RegionDescription
|
||||||
{
|
{
|
||||||
std::string infix;
|
std::string infix;
|
||||||
int xpos;
|
Point pos;
|
||||||
int ypos;
|
std::optional<Point> labelPos;
|
||||||
std::optional<int> xLabelpos;
|
|
||||||
std::optional<int> yLabelpos;
|
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
h & infix;
|
h & infix;
|
||||||
h & xpos;
|
|
||||||
h & ypos;
|
|
||||||
if (h.version >= Handler::Version::REGION_LABEL)
|
if (h.version >= Handler::Version::REGION_LABEL)
|
||||||
{
|
{
|
||||||
h & xLabelpos;
|
h & pos;
|
||||||
h & yLabelpos;
|
h & labelPos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
h & pos.x;
|
||||||
|
h & pos.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user