From 2e3ac5bf0edb6234b50ce084dae47a08a8ca9275 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 6 Jun 2022 22:28:24 +0200 Subject: [PATCH] Fixed an issue where using a text rating without a rating element in the gamelist view would crash the application. --- es-app/src/views/GamelistView.cpp | 4 ++-- es-core/src/components/RatingComponent.cpp | 4 ++-- es-core/src/components/RatingComponent.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index 6134e6f48..2fa833cca 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -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") { diff --git a/es-core/src/components/RatingComponent.cpp b/es-core/src/components/RatingComponent.cpp index ccb47a56a..bf72b7c62 100644 --- a/es-core/src/components/RatingComponent.cpp +++ b/es-core/src/components/RatingComponent.cpp @@ -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(); } diff --git a/es-core/src/components/RatingComponent.h b/es-core/src/components/RatingComponent.h index a8efac586..d7b5b2bf9 100644 --- a/es-core/src/components/RatingComponent.h +++ b/es-core/src/components/RatingComponent.h @@ -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;