1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

code review

This commit is contained in:
Laserlicht
2023-09-25 18:06:40 +02:00
committed by GitHub
parent 68e536c290
commit c3373ea34c
7 changed files with 29 additions and 25 deletions

View File

@@ -1706,7 +1706,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won)
if(!ps->checkVanquished()) if(!ps->checkVanquished())
param.allDefeated = false; param.allDefeated = false;
} }
param.land = cb->getMapHeader()->name; param.scenarioName = cb->getMapHeader()->name;
HighScoreCalculation highScoreCalc; HighScoreCalculation highScoreCalc;
highScoreCalc.parameters.push_back(param); highScoreCalc.parameters.push_back(param);
highScoreCalc.isCampaign = false; highScoreCalc.isCampaign = false;

View File

@@ -684,7 +684,7 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
highScoreCalc->isCampaign = true; highScoreCalc->isCampaign = true;
highScoreCalc->parameters.clear(); highScoreCalc->parameters.clear();
} }
param.campaign = cs->getName(); param.campaignName = cs->getName();
highScoreCalc->parameters.push_back(param); highScoreCalc->parameters.push_back(param);
GH.dispatchMainThread([ourCampaign, this]() GH.dispatchMainThread([ourCampaign, this]()

View File

@@ -156,7 +156,7 @@ void CHighScoreScreen::addHighScores()
if(highscorepage == HighScorePage::SCENARIO) if(highscorepage == HighScorePage::SCENARIO)
{ {
std::string tmp = curData["land"].String(); std::string tmp = curData["scenarioName"].String();
TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25)); TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25));
texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp)); texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp));
texts.push_back(std::make_shared<CLabel>(557, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["days"].Integer()))); texts.push_back(std::make_shared<CLabel>(557, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["days"].Integer())));
@@ -164,7 +164,7 @@ void CHighScoreScreen::addHighScores()
} }
else else
{ {
std::string tmp = curData["campaign"].String(); std::string tmp = curData["campaignName"].String();
TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25)); TextOperations::trimRightUnicode(tmp, std::max(0, (int)TextOperations::getUnicodeCharactersCount(tmp) - 25));
texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp)); texts.push_back(std::make_shared<CLabel>(405, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, tmp));
texts.push_back(std::make_shared<CLabel>(592, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["points"].Integer()))); texts.push_back(std::make_shared<CLabel>(592, y + i * 50, FONT_MEDIUM, ETextAlignment::CENTER, color, std::to_string(curData["points"].Integer())));
@@ -259,9 +259,9 @@ int CHighScoreInputScreen::addEntry(std::string text) {
JsonNode newNode = JsonNode(); JsonNode newNode = JsonNode();
newNode["player"].String() = text; newNode["player"].String() = text;
if(calc.isCampaign) if(calc.isCampaign)
newNode["campaign"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].campaign; newNode["campaignName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].campaignName;
else else
newNode["land"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].land; newNode["scenarioName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].scenarioName;
newNode["days"].Integer() = calc.calculate().sumDays; newNode["days"].Integer() = calc.calculate().sumDays;
newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total; newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total;
newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(0)); newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(0));

View File

@@ -27,8 +27,8 @@ public:
bool usedCheat; bool usedCheat;
bool hasGrail; bool hasGrail;
bool allDefeated; bool allDefeated;
std::string campaign; std::string campaignName;
std::string land; std::string scenarioName;
}; };
class HighScoreCalculation class HighScoreCalculation
@@ -68,7 +68,7 @@ private:
int highlighted; int highlighted;
public: public:
CHighScoreScreen(HighScorePage highscorepage = HighScorePage::SCENARIO, int highlighted = -1); CHighScoreScreen(HighScorePage highscorepage, int highlighted = -1);
}; };
class CHighScoreInput : public CWindowObject class CHighScoreInput : public CWindowObject

View File

@@ -392,7 +392,7 @@ void CMainMenu::startTutorial()
void CMainMenu::openHighScoreScreen() void CMainMenu::openHighScoreScreen()
{ {
GH.windows().createAndPushWindow<CHighScoreScreen>(); GH.windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
return; return;
} }

View File

@@ -109,11 +109,18 @@ bool PlayerMessageProcessor::handleHostCommand(PlayerColor player, const std::st
} }
if(words.size() == 2 && words[1] == "cheaters") if(words.size() == 2 && words[1] == "cheaters")
{ {
if (cheaters.empty()) int playersCheated = 0;
broadcastSystemMessage("No cheaters registered!"); for (const auto & player : gameHandler->gameState()->players)
{
if(player.second.cheated)
{
broadcastSystemMessage("Player " + player.first.toString() + " is cheater!");
playersCheated++;
}
}
for (auto const & entry : cheaters) if (!playersCheated)
broadcastSystemMessage("Player " + entry.toString() + " is cheater!"); broadcastSystemMessage("No cheaters registered!");
return true; return true;
} }
@@ -411,7 +418,10 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
std::vector<std::string> parameters = words; std::vector<std::string> parameters = words;
cheaters.insert(i.first); PlayerCheated pc;
pc.player = i.first;
gameHandler->sendAndApply(&pc);
playerTargetedCheat = true; playerTargetedCheat = true;
parameters.erase(parameters.begin()); parameters.erase(parameters.begin());
@@ -430,7 +440,10 @@ bool PlayerMessageProcessor::handleCheatCode(const std::string & cheat, PlayerCo
if (!playerTargetedCheat) if (!playerTargetedCheat)
executeCheatCode(cheatName, player, currObj, words); executeCheatCode(cheatName, player, currObj, words);
cheaters.insert(player); PlayerCheated pc;
pc.player = player;
gameHandler->sendAndApply(&pc);
return true; return true;
} }
@@ -513,14 +526,8 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla
assert(callbacks.count(cheatName)); assert(callbacks.count(cheatName));
if (callbacks.count(cheatName)) if (callbacks.count(cheatName))
{
PlayerCheated pc;
pc.player = player;
gameHandler->sendAndApply(&pc);
callbacks.at(cheatName)(); callbacks.at(cheatName)();
} }
}
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message) void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
{ {

View File

@@ -21,8 +21,6 @@ class CGameHandler;
class PlayerMessageProcessor class PlayerMessageProcessor
{ {
std::set<PlayerColor> cheaters;
void executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & arguments ); void executeCheatCode(const std::string & cheatName, PlayerColor player, ObjectInstanceID currObj, const std::vector<std::string> & arguments );
bool handleCheatCode(const std::string & cheatFullCommand, PlayerColor player, ObjectInstanceID currObj); bool handleCheatCode(const std::string & cheatFullCommand, PlayerColor player, ObjectInstanceID currObj);
bool handleHostCommand(PlayerColor player, const std::string & message); bool handleHostCommand(PlayerColor player, const std::string & message);
@@ -60,6 +58,5 @@ public:
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & cheaters;
} }
}; };