Browse Source

sonar cloud fixes

Laserlicht 1 year ago
parent
commit
00692888df

+ 1 - 1
client/eventsSDL/InputHandler.cpp

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

+ 1 - 1
client/eventsSDL/InputHandler.h

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

+ 1 - 1
client/mainmenu/CHighScoreScreen.cpp

@@ -172,7 +172,7 @@ void CHighScoreScreen::buttonExitClick()
 	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)
 {
 	addUsedEvents(LCLICK | KEYBOARD);

+ 2 - 2
client/mainmenu/CHighScoreScreen.h

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

+ 17 - 17
client/mainmenu/CStatisticScreen.cpp

@@ -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));
 }
 
-CStatisticScreen::CStatisticScreen(StatisticDataSet & stat)
+CStatisticScreen::CStatisticScreen(const StatisticDataSet & stat)
 	: CWindowObject(BORDERED), statistic(stat)
 {
 	OBJECT_CONSTRUCTION;
@@ -79,7 +79,7 @@ void CStatisticScreen::onSelectButton()
 			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};
 			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()));
 			
 			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;
-	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;
 	std::vector<float> tmpColorSet;
 	TData plotData;
 	EPlayerStatus statusLastRound = EPlayerStatus::INGAME;
-	for(auto & val : tmpData)
+	for(const auto & val : tmpData)
 	{
 		if(tmpColor != val.player)
 		{
@@ -122,12 +122,12 @@ TData CStatisticScreen::extractData(StatisticDataSet & stat, ExtractFunctor sele
 	return plotData;
 }
 
-TIcons CStatisticScreen::extractIcons()
+TIcons CStatisticScreen::extractIcons() const
 {
 	TIcons icons;
 
 	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);
 	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> foundGrail;
 
-	for(auto & val : tmpData)
+	for(const auto & val : tmpData)
 	{
 		if(val.eventCapturedTown)
 			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;
 }
 
-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)
 {
 	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)
 {
 	OBJECT_CONSTRUCTION;
@@ -291,7 +291,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
 				if(!val.numBattlesPlayer)
 					return std::string("");
 				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)
 					return std::string("");
 				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){
 				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> 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;
 }
 
@@ -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));
 
 	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
 	bool skipMaxValCalc = maxY > 0;
@@ -458,7 +458,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
 	// draw
 	for(auto & line : data)
 	{
-		Point lastPoint = Point(-1, -1);
+		Point lastPoint(-1, -1);
 		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);
@@ -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 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();
 }

+ 5 - 5
client/mainmenu/CStatisticScreen.h

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

+ 1 - 1
client/widgets/Images.cpp

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

+ 1 - 1
client/widgets/Images.h

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

+ 1 - 1
server/CGameHandler.cpp

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

+ 1 - 1
server/CGameHandler.h

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