1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

sonar cloud fixes

This commit is contained in:
Laserlicht
2024-08-15 23:09:04 +02:00
parent ba77107e71
commit 00692888df
10 changed files with 31 additions and 31 deletions

View File

@@ -143,7 +143,7 @@ InputMode InputHandler::getCurrentInputMode()
return currentInputMode; return currentInputMode;
} }
void InputHandler::copyToClipBoard(std::string text) void InputHandler::copyToClipBoard(const std::string & text)
{ {
SDL_SetClipboardText(text.c_str()); SDL_SetClipboardText(text.c_str());
} }

View File

@@ -104,5 +104,5 @@ public:
InputMode getCurrentInputMode(); InputMode getCurrentInputMode();
void copyToClipBoard(std::string text); void copyToClipBoard(const std::string & text);
}; };

View File

@@ -172,7 +172,7 @@ void CHighScoreScreen::buttonExitClick()
close(); close();
} }
CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc, StatisticDataSet statistic) CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc, const StatisticDataSet & statistic)
: CWindowObject(BORDERED), won(won), calc(calc), stat(statistic) : CWindowObject(BORDERED), won(won), calc(calc), stat(statistic)
{ {
addUsedEvents(LCLICK | KEYBOARD); addUsedEvents(LCLICK | KEYBOARD);

View File

@@ -78,12 +78,12 @@ class CHighScoreInputScreen : public CWindowObject
std::shared_ptr<CFilledTexture> backgroundAroundMenu; std::shared_ptr<CFilledTexture> backgroundAroundMenu;
std::shared_ptr<CButton> statisticButton; std::shared_ptr<CButton> statisticButton;
StatisticDataSet stat;
bool won; bool won;
HighScoreCalculation calc; HighScoreCalculation calc;
StatisticDataSet stat;
public: public:
CHighScoreInputScreen(bool won, HighScoreCalculation calc, StatisticDataSet statistic); CHighScoreInputScreen(bool won, HighScoreCalculation calc, const StatisticDataSet & statistic);
int addEntry(std::string text); int addEntry(std::string text);

View File

@@ -42,7 +42,7 @@ std::string CStatisticScreen::getDay(int d)
return std::to_string(CGameState::getDate(d, Date::MONTH)) + "/" + std::to_string(CGameState::getDate(d, Date::WEEK)) + "/" + std::to_string(CGameState::getDate(d, Date::DAY_OF_WEEK)); return std::to_string(CGameState::getDate(d, Date::MONTH)) + "/" + std::to_string(CGameState::getDate(d, Date::WEEK)) + "/" + std::to_string(CGameState::getDate(d, Date::DAY_OF_WEEK));
} }
CStatisticScreen::CStatisticScreen(StatisticDataSet & stat) CStatisticScreen::CStatisticScreen(const StatisticDataSet & stat)
: CWindowObject(BORDERED), statistic(stat) : CWindowObject(BORDERED), statistic(stat)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
@@ -79,7 +79,7 @@ void CStatisticScreen::onSelectButton()
auto content = static_cast<Content>(selectedIndex); auto content = static_cast<Content>(selectedIndex);
auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS}; auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
std::vector<std::string> resourceText; std::vector<std::string> resourceText;
for(auto & res : possibleRes) for(const auto & res : possibleRes)
resourceText.emplace_back(CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get())); resourceText.emplace_back(CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()));
GH.windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index) GH.windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
@@ -91,16 +91,16 @@ void CStatisticScreen::onSelectButton()
}); });
} }
TData CStatisticScreen::extractData(StatisticDataSet & stat, ExtractFunctor selector) TData CStatisticScreen::extractData(const StatisticDataSet & stat, const ExtractFunctor & selector)
{ {
auto tmpData = stat.data; auto tmpData = stat.data;
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry & v1, StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; }); std::sort(tmpData.begin(), tmpData.end(), [](const StatisticDataSetEntry & v1, const StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
PlayerColor tmpColor = PlayerColor::NEUTRAL; PlayerColor tmpColor = PlayerColor::NEUTRAL;
std::vector<float> tmpColorSet; std::vector<float> tmpColorSet;
TData plotData; TData plotData;
EPlayerStatus statusLastRound = EPlayerStatus::INGAME; EPlayerStatus statusLastRound = EPlayerStatus::INGAME;
for(auto & val : tmpData) for(const auto & val : tmpData)
{ {
if(tmpColor != val.player) if(tmpColor != val.player)
{ {
@@ -122,12 +122,12 @@ TData CStatisticScreen::extractData(StatisticDataSet & stat, ExtractFunctor sele
return plotData; return plotData;
} }
TIcons CStatisticScreen::extractIcons() TIcons CStatisticScreen::extractIcons() const
{ {
TIcons icons; TIcons icons;
auto tmpData = statistic.data; auto tmpData = statistic.data;
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry & v1, StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; }); std::sort(tmpData.begin(), tmpData.end(), [](const StatisticDataSetEntry & v1, const StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
auto imageTown = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY); auto imageTown = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY);
imageTown->scaleFast(Point(CHART_ICON_SIZE, CHART_ICON_SIZE)); imageTown->scaleFast(Point(CHART_ICON_SIZE, CHART_ICON_SIZE));
@@ -141,7 +141,7 @@ TIcons CStatisticScreen::extractIcons()
std::map<PlayerColor, bool> foundDefeated; std::map<PlayerColor, bool> foundDefeated;
std::map<PlayerColor, bool> foundGrail; std::map<PlayerColor, bool> foundGrail;
for(auto & val : tmpData) for(const auto & val : tmpData)
{ {
if(val.eventCapturedTown) if(val.eventCapturedTown)
icons.push_back({ graphics->playerColors[val.player], val.day, imageTown, CGI->generaltexth->translate("vcmi.statisticWindow.icon.townCaptured") }); icons.push_back({ graphics->playerColors[val.player], val.day, imageTown, CGI->generaltexth->translate("vcmi.statisticWindow.icon.townCaptured") });
@@ -224,7 +224,7 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
return nullptr; return nullptr;
} }
StatisticSelector::StatisticSelector(std::vector<std::string> & texts, std::function<void(int selectedIndex)> cb) StatisticSelector::StatisticSelector(const std::vector<std::string> & texts, const std::function<void(int selectedIndex)> & cb)
: CWindowObject(BORDERED | NEEDS_ANIMATED_BACKGROUND), texts(texts), cb(cb) : CWindowObject(BORDERED | NEEDS_ANIMATED_BACKGROUND), texts(texts), cb(cb)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
@@ -254,7 +254,7 @@ void StatisticSelector::update(int to)
} }
} }
OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet & stat) OverviewPanel::OverviewPanel(Rect position, std::string title, const StatisticDataSet & stat)
: CIntObject(), data(stat) : CIntObject(), data(stat)
{ {
OBJECT_CONSTRUCTION; OBJECT_CONSTRUCTION;
@@ -291,7 +291,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
if(!val.numBattlesPlayer) if(!val.numBattlesPlayer)
return std::string(""); return std::string("");
float tmp = (static_cast<float>(val.numWinBattlesPlayer) / static_cast<float>(val.numBattlesPlayer)) * 100; float tmp = (static_cast<float>(val.numWinBattlesPlayer) / static_cast<float>(val.numBattlesPlayer)) * 100;
return std::to_string((int)tmp) + " %"; return std::to_string(static_cast<int>(tmp)) + " %";
} }
}, },
{ {
@@ -300,7 +300,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
if(!val.numWinBattlesNeutral) if(!val.numWinBattlesNeutral)
return std::string(""); return std::string("");
float tmp = (static_cast<float>(val.numWinBattlesNeutral) / static_cast<float>(val.numBattlesNeutral)) * 100; float tmp = (static_cast<float>(val.numWinBattlesNeutral) / static_cast<float>(val.numBattlesNeutral)) * 100;
return std::to_string((int)tmp) + " %"; return std::to_string(static_cast<int>(tmp)) + " %";
} }
}, },
{ {
@@ -318,7 +318,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
{ {
CGI->generaltexth->translate("vcmi.statisticWindow.param.obeliskVisited"), [this](PlayerColor color){ CGI->generaltexth->translate("vcmi.statisticWindow.param.obeliskVisited"), [this](PlayerColor color){
auto val = playerDataFilter(color).back(); auto val = playerDataFilter(color).back();
return std::to_string((int)(val.obeliskVisitedRatio * 100)) + " %"; return std::to_string(static_cast<int>(val.obeliskVisitedRatio * 100)) + " %";
} }
}, },
{ {
@@ -397,7 +397,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
std::vector<StatisticDataSetEntry> OverviewPanel::playerDataFilter(PlayerColor color) std::vector<StatisticDataSetEntry> OverviewPanel::playerDataFilter(PlayerColor color)
{ {
std::vector<StatisticDataSetEntry> tmpData; std::vector<StatisticDataSetEntry> tmpData;
std::copy_if(data.data.begin(), data.data.end(), std::back_inserter(tmpData), [color](StatisticDataSetEntry e){ return e.player == color; }); std::copy_if(data.data.begin(), data.data.end(), std::back_inserter(tmpData), [color](const StatisticDataSetEntry & e){ return e.player == color; });
return tmpData; return tmpData;
} }
@@ -441,7 +441,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h)); canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h));
statusBar = CGStatusBar::create(0, 0, ImagePath::builtin("radialMenu/statusBar")); statusBar = CGStatusBar::create(0, 0, ImagePath::builtin("radialMenu/statusBar"));
((std::shared_ptr<CIntObject>)statusBar)->setEnabled(false); static_cast<std::shared_ptr<CIntObject>>(statusBar)->setEnabled(false);
// additional calculations // additional calculations
bool skipMaxValCalc = maxY > 0; bool skipMaxValCalc = maxY > 0;
@@ -458,7 +458,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
// draw // draw
for(auto & line : data) for(auto & line : data)
{ {
Point lastPoint = Point(-1, -1); Point lastPoint(-1, -1);
for(int i = 0; i < line.second.size(); i++) for(int i = 0; i < line.second.size(); i++)
{ {
float x = (static_cast<float>(chartArea.w) / static_cast<float>(maxDay - 1)) * static_cast<float>(i); float x = (static_cast<float>(chartArea.w) / static_cast<float>(maxDay - 1)) * static_cast<float>(i);
@@ -503,7 +503,7 @@ void LineChart::updateStatusBar(const Point & cursorPosition)
{ {
float x = (static_cast<float>(maxDay) / static_cast<float>(chartArea.w)) * (static_cast<float>(cursorPosition.x) - static_cast<float>(r.x)) + 1.0f; float x = (static_cast<float>(maxDay) / static_cast<float>(chartArea.w)) * (static_cast<float>(cursorPosition.x) - static_cast<float>(r.x)) + 1.0f;
float y = maxVal - (static_cast<float>(maxVal) / static_cast<float>(chartArea.h)) * (static_cast<float>(cursorPosition.y) - static_cast<float>(r.y)); float y = maxVal - (static_cast<float>(maxVal) / static_cast<float>(chartArea.h)) * (static_cast<float>(cursorPosition.y) - static_cast<float>(r.y));
statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + ((int)y > 0 ? std::to_string((int)y) : std::to_string(y))); statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + (static_cast<int>(y) > 0 ? std::to_string(static_cast<int>(y)) : std::to_string(y)));
} }
GH.windows().totalRedraw(); GH.windows().totalRedraw();
} }

View File

@@ -68,12 +68,12 @@ class CStatisticScreen : public CWindowObject
Rect contentArea; Rect contentArea;
using ExtractFunctor = std::function<float(StatisticDataSetEntry val)>; using ExtractFunctor = std::function<float(StatisticDataSetEntry val)>;
TData extractData(StatisticDataSet & stat, ExtractFunctor selector); TData extractData(const StatisticDataSet & stat, const ExtractFunctor & selector);
TIcons extractIcons(); TIcons extractIcons() const;
std::shared_ptr<CIntObject> getContent(Content c, EGameResID res); std::shared_ptr<CIntObject> getContent(Content c, EGameResID res);
void onSelectButton(); void onSelectButton();
public: public:
CStatisticScreen(StatisticDataSet & stat); CStatisticScreen(const StatisticDataSet & stat);
static std::string getDay(int day); static std::string getDay(int day);
}; };
@@ -90,7 +90,7 @@ class StatisticSelector : public CWindowObject
void update(int to); void update(int to);
public: public:
StatisticSelector(std::vector<std::string> & texts, std::function<void(int selectedIndex)> cb); StatisticSelector(const std::vector<std::string> & texts, const std::function<void(int selectedIndex)> & cb);
}; };
class OverviewPanel : public CIntObject class OverviewPanel : public CIntObject
@@ -111,7 +111,7 @@ class OverviewPanel : public CIntObject
std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color); std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color);
void update(int to); void update(int to);
public: public:
OverviewPanel(Rect position, std::string title, StatisticDataSet & stat); OverviewPanel(Rect position, std::string title, const StatisticDataSet & stat);
}; };
class LineChart : public CIntObject class LineChart : public CIntObject

View File

@@ -127,7 +127,7 @@ void CPicture::setPlayerColor(PlayerColor player)
bg->playerColored(player); bg->playerColored(player);
} }
void CPicture::addRClickCallback(std::function<void()> callback) void CPicture::addRClickCallback(const std::function<void()> & callback)
{ {
rCallback = callback; rCallback = callback;
} }

View File

@@ -58,7 +58,7 @@ public:
void scaleTo(Point size); void scaleTo(Point size);
void setPlayerColor(PlayerColor player); void setPlayerColor(PlayerColor player);
void addRClickCallback(std::function<void()> callback); void addRClickCallback(const std::function<void()> & callback);
void show(Canvas & to) override; void show(Canvas & to) override;
void showAll(Canvas & to) override; void showAll(Canvas & to) override;

View File

@@ -669,7 +669,7 @@ void CGameHandler::onPlayerTurnEnded(PlayerColor which)
heroPool->onNewWeek(which); heroPool->onNewWeek(which);
} }
void CGameHandler::addStatistics(StatisticDataSet &stat) void CGameHandler::addStatistics(StatisticDataSet &stat) const
{ {
for (const auto & elem : gs->players) for (const auto & elem : gs->players)
{ {

View File

@@ -228,7 +228,7 @@ public:
void onPlayerTurnStarted(PlayerColor which); void onPlayerTurnStarted(PlayerColor which);
void onPlayerTurnEnded(PlayerColor which); void onPlayerTurnEnded(PlayerColor which);
void onNewTurn(); void onNewTurn();
void addStatistics(StatisticDataSet &stat); void addStatistics(StatisticDataSet &stat) const;
void handleTimeEvents(PlayerColor player); void handleTimeEvents(PlayerColor player);
void handleTownEvents(CGTownInstance *town); void handleTownEvents(CGTownInstance *town);