1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-13 22:06:58 +02:00

Style cleanup

This commit is contained in:
Ivan Savenko 2023-02-08 13:56:09 +02:00
parent 62151cd20c
commit ab8b407294
9 changed files with 32 additions and 33 deletions

View File

@ -726,17 +726,18 @@ namespace vstd
} }
/// converts number into string using metric system prefixes, e.g. 'k' or 'M' to keep resulting strings within specified size /// converts number into string using metric system prefixes, e.g. 'k' or 'M' to keep resulting strings within specified size
template<typename IntType> /// Note that resulting string may have more symbols than digits: minus sign and prefix symbol
std::string formatMetric(IntType number, int maxLength) template<typename Arithmetic>
std::string formatMetric(Arithmetic number, int maxDigits)
{ {
IntType max = pow(10, maxLength); Arithmetic max = std::pow(10, maxDigits);
if (std::abs(number) < max) if (std::abs(number) < max)
return boost::lexical_cast<std::string>(number); return std::to_string(number);
std::string symbols = " kMGTPE"; std::string symbols = " kMGTPE";
auto iter = symbols.begin(); auto iter = symbols.begin();
while (number >= max) while (std::abs(number) >= max)
{ {
number /= 1000; number /= 1000;
iter++; iter++;
@ -745,8 +746,6 @@ namespace vstd
} }
return std::to_string(number) + *iter; return std::to_string(number) + *iter;
} }
using boost::math::round;
} }
using vstd::operator-=; using vstd::operator-=;

View File

@ -77,9 +77,9 @@ std::string CResDataBar::buildDateString()
std::string pattern = "%s: %d, %s: %d, %s: %d"; std::string pattern = "%s: %d, %s: %d, %s: %d";
auto formatted = boost::format(pattern) auto formatted = boost::format(pattern)
% CGI->generaltexth->allTexts[62] % LOCPLINT->cb->getDate(Date::MONTH) % CGI->generaltexth->translate("core.genrltxt.62") % LOCPLINT->cb->getDate(Date::MONTH)
% CGI->generaltexth->allTexts[63] % LOCPLINT->cb->getDate(Date::WEEK) % CGI->generaltexth->translate("core.genrltxt.63") % LOCPLINT->cb->getDate(Date::WEEK)
% CGI->generaltexth->allTexts[64] % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK); % CGI->generaltexth->translate("core.genrltxt.64") % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
return boost::str(formatted); return boost::str(formatted);
} }

View File

@ -525,9 +525,9 @@ void BattleInterface::setAnimSpeed(int set)
int BattleInterface::getAnimSpeed() const int BattleInterface::getAnimSpeed() const
{ {
if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-battle-speed"].isNull()) if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-battle-speed"].isNull())
return static_cast<int>(vstd::round(settings["session"]["spectate-battle-speed"].Float())); return static_cast<int>(std::round(settings["session"]["spectate-battle-speed"].Float()));
return static_cast<int>(vstd::round(settings["battle"]["speedFactor"].Float())); return static_cast<int>(std::round(settings["battle"]["speedFactor"].Float()));
} }
CPlayerInterface *BattleInterface::getCurrentPlayerInterface() const CPlayerInterface *BattleInterface::getCurrentPlayerInterface() const

View File

@ -312,7 +312,7 @@ void CreatureAnimation::playOnce( ECreatureAnimType type )
inline int getBorderStrength(float time) inline int getBorderStrength(float time)
{ {
float borderStrength = fabs(vstd::round(time) - time) * 2; // generate value in range 0-1 float borderStrength = fabs(std::round(time) - time) * 2; // generate value in range 0-1
return static_cast<int>(borderStrength * 155 + 100); // scale to 0-255 return static_cast<int>(borderStrength * 155 + 100); // scale to 0-255
} }

View File

@ -187,9 +187,9 @@ std::string CMinorResDataBar::buildDateString()
std::string pattern = "%s: %d, %s: %d, %s: %d"; std::string pattern = "%s: %d, %s: %d, %s: %d";
auto formatted = boost::format(pattern) auto formatted = boost::format(pattern)
% CGI->generaltexth->allTexts[62] % LOCPLINT->cb->getDate(Date::MONTH) % CGI->generaltexth->translate("core.genrltxt.62") % LOCPLINT->cb->getDate(Date::MONTH)
% CGI->generaltexth->allTexts[63] % LOCPLINT->cb->getDate(Date::WEEK) % CGI->generaltexth->translate("core.genrltxt.63") % LOCPLINT->cb->getDate(Date::WEEK)
% CGI->generaltexth->allTexts[64] % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK); % CGI->generaltexth->translate("core.genrltxt.64") % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
return boost::str(formatted); return boost::str(formatted);
} }