1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

Merge pull request #4951 from IvanSavenko/sonar_fix

Fix several new issues detected by SonarCloud
This commit is contained in:
Ivan Savenko 2024-11-25 13:39:56 +02:00 committed by GitHub
commit 7d8b753971
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 12 deletions

View File

@ -55,7 +55,7 @@ std::shared_ptr<CDefFile> RenderHandler::getAnimationFile(const AnimationPath &
return result;
}
std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(ResourcePath path, std::string factor)
std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(const ResourcePath & path, const std::string & factor)
{
if(path.getType() == EResType::IMAGE)
{
@ -80,7 +80,7 @@ std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(ResourcePath pa
return std::nullopt;
}
std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p)
std::pair<ResourcePath, int> RenderHandler::getScalePath(const ResourcePath & p)
{
auto path = p;
int scaleFactor = 1;

View File

@ -29,8 +29,8 @@ class RenderHandler : public IRenderHandler
std::map<EFonts, std::shared_ptr<const IFont>> fonts;
std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
std::optional<ResourcePath> getPathForScaleFactor(ResourcePath path, std::string factor);
std::pair<ResourcePath, int> getScalePath(ResourcePath p);
std::optional<ResourcePath> getPathForScaleFactor(const ResourcePath & path, const std::string & factor);
std::pair<ResourcePath, int> getScalePath(const ResourcePath & p);
AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);

View File

@ -283,7 +283,10 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
if (factor <= 0)
throw std::runtime_error("Unable to scale by integer value of " + std::to_string(factor));
if (palette && surf && surf->format->palette)
if (!surf)
return shared_from_this();
if (palette && surf->format->palette)
SDL_SetSurfacePalette(surf, palette);
SDL_Surface * scaled = nullptr;
@ -306,7 +309,7 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
// erase our own reference
SDL_FreeSurface(scaled);
if (surf && surf->format->palette)
if (surf->format->palette)
SDL_SetSurfacePalette(surf, originalPalette);
return ret;
@ -314,8 +317,8 @@ std::shared_ptr<const ISharedImage> SDLImageShared::scaleInteger(int factor, SDL
std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
{
float scaleX = float(size.x) / fullSize.x;
float scaleY = float(size.y) / fullSize.y;
float scaleX = static_cast<float>(size.x) / fullSize.x;
float scaleY = static_cast<float>(size.y) / fullSize.y;
if (palette && surf->format->palette)
SDL_SetSurfacePalette(surf, palette);

View File

@ -725,7 +725,7 @@ int CStackInstance::getExpRank() const
int CStackInstance::getLevel() const
{
return std::max(1, static_cast<int>(getType()->getLevel()));
return std::max(1, getType()->getLevel());
}
void CStackInstance::giveStackExp(TExpType exp)

View File

@ -544,8 +544,8 @@ void CSpell::serializeJson(JsonSerializeFormat & handler)
///CSpell::AnimationInfo
CSpell::AnimationItem::AnimationItem() :
verticalPosition(VerticalPosition::TOP),
pause(0),
transparency(1)
transparency(1),
pause(0)
{
}

View File

@ -917,7 +917,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
handleAttackBeforeCasting(battle, ranged, attacker, defender);
// If the attacker or defender is not alive before the attack action, the action should be skipped.
if((attacker && !attacker->alive()) || (defender && !defender->alive()))
if((!attacker->alive()) || (defender && !defender->alive()))
return;
FireShieldInfo fireShield;