Fixed an issue where using a text rating without a rating element in the gamelist view would crash the application.

This commit is contained in:
Leon Styhre 2022-06-06 22:28:24 +02:00
parent ed0837824e
commit 2e3ac5bf0e
3 changed files with 6 additions and 5 deletions

View file

@ -698,7 +698,7 @@ void GamelistView::updateInfoPanel(const CursorState& state)
continue;
if (metadata == "rating") {
text->setValue(mRatingComponents.front()->getRatingValue());
text->setValue(RatingComponent::getRatingValue(file->metadata.get("rating")));
continue;
}
else if (metadata == "controller") {
@ -717,7 +717,7 @@ void GamelistView::updateInfoPanel(const CursorState& state)
continue;
if (metadata == "rating") {
text->setValue(mRatingComponents.front()->getRatingValue());
text->setValue(RatingComponent::getRatingValue(file->metadata.get("rating")));
continue;
}
else if (metadata == "controller") {

View file

@ -76,10 +76,10 @@ std::string RatingComponent::getValue() const
return ss.str();
}
std::string RatingComponent::getRatingValue() const
std::string RatingComponent::getRatingValue(const std::string& rating)
{
std::stringstream ss;
ss << mValue * NUM_RATING_STARS;
ss << (std::round(stof(rating) / 0.1f) / 10.0f) * NUM_RATING_STARS;
return ss.str();
}

View file

@ -23,7 +23,8 @@ public:
RatingComponent(bool colorizeChanges = false);
std::string getValue() const override;
std::string getRatingValue() const;
// Returns a rating value between 0 and 5 as a string.
static std::string getRatingValue(const std::string& rating);
// Should be a normalized float (in the range [0..1]) - if it's not, it will be clamped.
void setValue(const std::string& value) override;