mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
code review
This commit is contained in:
@@ -522,6 +522,9 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
|||||||
handler.serializeInt("visiblePositionX", visiblePosition.x);
|
handler.serializeInt("visiblePositionX", visiblePosition.x);
|
||||||
handler.serializeInt("visiblePositionY", visiblePosition.y);
|
handler.serializeInt("visiblePositionY", visiblePosition.y);
|
||||||
handler.serializeFloat("visibleSize", visibleSize);
|
handler.serializeFloat("visibleSize", visibleSize);
|
||||||
|
|
||||||
|
if(!handler.saving && visibleSize < 0.01)
|
||||||
|
visibleSize = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneConnection::ZoneConnection():
|
ZoneConnection::ZoneConnection():
|
||||||
|
|||||||
@@ -27,13 +27,13 @@
|
|||||||
#include "../lib/serializer/JsonDeserializer.h"
|
#include "../lib/serializer/JsonDeserializer.h"
|
||||||
#include "../lib/serializer/CSaveFile.h"
|
#include "../lib/serializer/CSaveFile.h"
|
||||||
|
|
||||||
std::unique_ptr<CMap> Helper::openMapInternal(const QString & filenameSelect, IGameInfoCallback * cb)
|
ResourcePath addFilesystemAndGetResource(const QString & filenameSelect, EResType type, const std::string & typeName)
|
||||||
{
|
{
|
||||||
QFileInfo fi(filenameSelect);
|
QFileInfo fi(filenameSelect);
|
||||||
std::string fname = fi.fileName().toStdString();
|
std::string fname = fi.fileName().toStdString();
|
||||||
std::string fdir = fi.dir().path().toStdString();
|
std::string fdir = fi.dir().path().toStdString();
|
||||||
|
|
||||||
ResourcePath resId("MAPEDITOR/" + fname, EResType::MAP);
|
ResourcePath resId("MAPEDITOR/" + fname, type);
|
||||||
|
|
||||||
//addFilesystem takes care about memory deallocation if case of failure, no memory leak here
|
//addFilesystem takes care about memory deallocation if case of failure, no memory leak here
|
||||||
auto mapEditorFilesystem = std::make_unique<CFilesystemLoader>("MAPEDITOR/", fdir, 0);
|
auto mapEditorFilesystem = std::make_unique<CFilesystemLoader>("MAPEDITOR/", fdir, 0);
|
||||||
@@ -41,7 +41,14 @@ std::unique_ptr<CMap> Helper::openMapInternal(const QString & filenameSelect, IG
|
|||||||
CResourceHandler::addFilesystem("local", "mapEditor", std::move(mapEditorFilesystem));
|
CResourceHandler::addFilesystem("local", "mapEditor", std::move(mapEditorFilesystem));
|
||||||
|
|
||||||
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
||||||
throw std::runtime_error("Cannot open map from this folder");
|
throw std::runtime_error("Cannot open " + typeName + " from this folder");
|
||||||
|
|
||||||
|
return resId;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<CMap> Helper::openMapInternal(const QString & filenameSelect, IGameInfoCallback * cb)
|
||||||
|
{
|
||||||
|
auto resId = addFilesystemAndGetResource(filenameSelect, EResType::MAP, "map");
|
||||||
|
|
||||||
CMapService mapService;
|
CMapService mapService;
|
||||||
if(auto header = mapService.loadMapHeader(resId))
|
if(auto header = mapService.loadMapHeader(resId))
|
||||||
@@ -62,19 +69,8 @@ std::unique_ptr<CMap> Helper::openMapInternal(const QString & filenameSelect, IG
|
|||||||
|
|
||||||
std::shared_ptr<CampaignState> Helper::openCampaignInternal(const QString & filenameSelect)
|
std::shared_ptr<CampaignState> Helper::openCampaignInternal(const QString & filenameSelect)
|
||||||
{
|
{
|
||||||
QFileInfo fi(filenameSelect);
|
auto resId = addFilesystemAndGetResource(filenameSelect, EResType::CAMPAIGN, "campaign");
|
||||||
std::string fname = fi.fileName().toStdString();
|
|
||||||
std::string fdir = fi.dir().path().toStdString();
|
|
||||||
|
|
||||||
ResourcePath resId("MAPEDITOR/" + fname, EResType::CAMPAIGN);
|
|
||||||
|
|
||||||
//addFilesystem takes care about memory deallocation if case of failure, no memory leak here
|
|
||||||
auto mapEditorFilesystem = std::make_unique<CFilesystemLoader>("MAPEDITOR/", fdir, 0);
|
|
||||||
CResourceHandler::removeFilesystem("local", "mapEditor");
|
|
||||||
CResourceHandler::addFilesystem("local", "mapEditor", std::move(mapEditorFilesystem));
|
|
||||||
|
|
||||||
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
|
||||||
throw std::runtime_error("Cannot open campaign from this folder");
|
|
||||||
if(auto campaign = CampaignHandler::getCampaign(resId.getName()))
|
if(auto campaign = CampaignHandler::getCampaign(resId.getName()))
|
||||||
return campaign;
|
return campaign;
|
||||||
else
|
else
|
||||||
@@ -83,19 +79,7 @@ std::shared_ptr<CampaignState> Helper::openCampaignInternal(const QString & file
|
|||||||
|
|
||||||
std::map<std::string, std::shared_ptr<CRmgTemplate>> Helper::openTemplateInternal(const QString & filenameSelect)
|
std::map<std::string, std::shared_ptr<CRmgTemplate>> Helper::openTemplateInternal(const QString & filenameSelect)
|
||||||
{
|
{
|
||||||
QFileInfo fi(filenameSelect);
|
auto resId = addFilesystemAndGetResource(filenameSelect, EResType::JSON, "template");
|
||||||
std::string fname = fi.fileName().toStdString();
|
|
||||||
std::string fdir = fi.dir().path().toStdString();
|
|
||||||
|
|
||||||
ResourcePath resId("MAPEDITOR/" + fname, EResType::JSON);
|
|
||||||
|
|
||||||
//addFilesystem takes care about memory deallocation if case of failure, no memory leak here
|
|
||||||
auto mapEditorFilesystem = std::make_unique<CFilesystemLoader>("MAPEDITOR/", fdir, 0);
|
|
||||||
CResourceHandler::removeFilesystem("local", "mapEditor");
|
|
||||||
CResourceHandler::addFilesystem("local", "mapEditor", std::move(mapEditorFilesystem));
|
|
||||||
|
|
||||||
if(!CResourceHandler::get("mapEditor")->existsResource(resId))
|
|
||||||
throw std::runtime_error("Cannot open template from this folder");
|
|
||||||
|
|
||||||
auto data = CResourceHandler::get()->load(resId)->readAll();
|
auto data = CResourceHandler::get()->load(resId)->readAll();
|
||||||
JsonNode nodes(reinterpret_cast<std::byte *>(data.first.get()), data.second, resId.getName());
|
JsonNode nodes(reinterpret_cast<std::byte *>(data.first.get()), data.second, resId.getName());
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../lib/filesystem/ResourcePath.h"
|
||||||
|
|
||||||
class CMap;
|
class CMap;
|
||||||
class CampaignState;
|
class CampaignState;
|
||||||
class CRmgTemplate;
|
class CRmgTemplate;
|
||||||
|
|||||||
@@ -154,46 +154,46 @@
|
|||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="4.0261083"
|
x="4.0261083"
|
||||||
y="21.015579"
|
y="21.015579"
|
||||||
id="textWood"
|
id="textwood"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="8.2191515"
|
x="8.2191515"
|
||||||
y="21.010046"
|
y="21.010046"
|
||||||
id="textOre"
|
id="textore"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="12.484079"
|
x="12.484079"
|
||||||
y="21.049248"
|
y="21.049248"
|
||||||
id="textMercury"
|
id="textmercury"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="16.661751"
|
x="16.661751"
|
||||||
y="21.020365"
|
y="21.020365"
|
||||||
id="textSulfur"
|
id="textsulfur"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="20.896933"
|
x="20.896933"
|
||||||
y="21.078743"
|
y="21.078743"
|
||||||
id="textCrystal"
|
id="textcrystal"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="25.133026"
|
x="25.133026"
|
||||||
y="21.049547"
|
y="21.049547"
|
||||||
id="textGems"
|
id="textgems"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<text
|
<text
|
||||||
style="font-size:3.07692px;fill:#ffffff;"
|
style="font-size:3.07692px;fill:#ffffff;"
|
||||||
x="4.0413303"
|
x="4.0413303"
|
||||||
y="27.417381"
|
y="27.417381"
|
||||||
id="textGold"
|
id="textgold"
|
||||||
text-anchor="middle">99</text>
|
text-anchor="middle">99</text>
|
||||||
<g
|
<g
|
||||||
id="iconSulfur"
|
id="iconsulfur"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-76.735738,-145.67812)">
|
transform="matrix(0.87219868,0,0,0.87219868,-76.735738,-145.67812)">
|
||||||
<path
|
<path
|
||||||
@@ -218,7 +218,7 @@
|
|||||||
id="path3" />
|
id="path3" />
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconGold"
|
id="icongold"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-90.060712,-144.27231)">
|
transform="matrix(0.87219868,0,0,0.87219868,-90.060712,-144.27231)">
|
||||||
<path
|
<path
|
||||||
@@ -329,7 +329,7 @@
|
|||||||
transform="translate(-84.553401,34.893164)" />
|
transform="translate(-84.553401,34.893164)" />
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconOre"
|
id="iconore"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-97.429655,-129.12754)">
|
transform="matrix(0.87219868,0,0,0.87219868,-97.429655,-129.12754)">
|
||||||
<path
|
<path
|
||||||
@@ -406,7 +406,7 @@
|
|||||||
id="path47" />
|
id="path47" />
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconWood"
|
id="iconwood"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.95215139,5.818528e-4,-0.16788999,0.88218099,-70.889511,-135.64427)"
|
transform="matrix(0.95215139,5.818528e-4,-0.16788999,0.88218099,-70.889511,-135.64427)"
|
||||||
style="stroke-width:0.951609">
|
style="stroke-width:0.951609">
|
||||||
@@ -682,7 +682,7 @@
|
|||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconGems"
|
id="icongems"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-74.159393,-117.99296)">
|
transform="matrix(0.87219868,0,0,0.87219868,-74.159393,-117.99296)">
|
||||||
<path
|
<path
|
||||||
@@ -771,7 +771,7 @@
|
|||||||
id="path73" />
|
id="path73" />
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconMercury"
|
id="iconmercury"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-64.001803,-150.87368)">
|
transform="matrix(0.87219868,0,0,0.87219868,-64.001803,-150.87368)">
|
||||||
<path
|
<path
|
||||||
@@ -876,7 +876,7 @@
|
|||||||
id="path91" />
|
id="path91" />
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
id="iconCrystal"
|
id="iconcrystal"
|
||||||
opacity="1.0"
|
opacity="1.0"
|
||||||
transform="matrix(0.87219868,0,0,0.87219868,-78.871113,-144.49622)">
|
transform="matrix(0.87219868,0,0,0.87219868,-78.871113,-144.49622)">
|
||||||
<path
|
<path
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
@@ -14,6 +14,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "../../../lib/constants/EntityIdentifiers.h"
|
#include "../../../lib/constants/EntityIdentifiers.h"
|
||||||
|
#include "../../../lib/constants/StringConstants.h"
|
||||||
#include "../../../lib/rmg/CRmgTemplate.h"
|
#include "../../../lib/rmg/CRmgTemplate.h"
|
||||||
|
|
||||||
QDomElement CardItem::getElementById(const QDomDocument& doc, const QString& id)
|
QDomElement CardItem::getElementById(const QDomDocument& doc, const QString& id)
|
||||||
@@ -148,21 +149,11 @@ int CardItem::getId()
|
|||||||
|
|
||||||
void CardItem::setResAmount(GameResID res, int val)
|
void CardItem::setResAmount(GameResID res, int val)
|
||||||
{
|
{
|
||||||
std::map<GameResID, QString> names =
|
auto textElem = getElementById(doc, "text" + QString::fromStdString(GameConstants::RESOURCE_NAMES[res]));
|
||||||
{
|
|
||||||
{ GameResID::WOOD, "Wood" },
|
|
||||||
{ GameResID::ORE, "Ore" },
|
|
||||||
{ GameResID::MERCURY, "Mercury" },
|
|
||||||
{ GameResID::SULFUR, "Sulfur" },
|
|
||||||
{ GameResID::CRYSTAL, "Crystal" },
|
|
||||||
{ GameResID::GEMS, "Gems" },
|
|
||||||
{ GameResID::GOLD, "Gold" },
|
|
||||||
};
|
|
||||||
auto textElem = getElementById(doc, "text" + names[res]);
|
|
||||||
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
||||||
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
||||||
|
|
||||||
auto iconElem = getElementById(doc, "icon" + names[res]);
|
auto iconElem = getElementById(doc, "icon" + QString::fromStdString(GameConstants::RESOURCE_NAMES[res]));
|
||||||
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,10 +129,6 @@ void TemplateEditor::loadContent(bool autoPosition)
|
|||||||
auto & zones = templates[selectedTemplate]->getZones();
|
auto & zones = templates[selectedTemplate]->getZones();
|
||||||
if(autoPosition || std::all_of(zones.begin(), zones.end(), [](auto & item){ return item.second->getVisiblePosition().x == 0 && item.second->getVisiblePosition().y == 0; }))
|
if(autoPosition || std::all_of(zones.begin(), zones.end(), [](auto & item){ return item.second->getVisiblePosition().x == 0 && item.second->getVisiblePosition().y == 0; }))
|
||||||
autoPositionZones();
|
autoPositionZones();
|
||||||
|
|
||||||
for(auto & zone : zones)
|
|
||||||
if(zone.second->getVisibleSize() < 0.01)
|
|
||||||
zone.second->setVisibleSize(1.0);
|
|
||||||
|
|
||||||
for(auto & zone : zones)
|
for(auto & zone : zones)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user