Mercurial > minori
diff src/core/anime.cc @ 185:62e336597bb7
anime list: add support for different score formats
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 05 Dec 2023 13:45:23 -0500 |
parents | 01d259b9c89f |
children | 6ef31dbb90ca |
line wrap: on
line diff
--- a/src/core/anime.cc Mon Dec 04 13:44:42 2023 -0500 +++ b/src/core/anime.cc Tue Dec 05 13:45:23 2023 -0500 @@ -42,6 +42,45 @@ return list_info_->score; } +std::string Anime::GetUserPresentableScore() const { + assert(list_info_.get()); + const int score = list_info_->score; + if (score == 0) + return ""; + + switch (session.config.anime_list.score_format) { + case ScoreFormat::POINT_10_DECIMAL: { + std::ostringstream out; + out.precision(1); + out << std::fixed << (static_cast<double>(score) / 10); + return std::move(out).str(); + } + case ScoreFormat::POINT_10: + return std::to_string(score / 10); + case ScoreFormat::POINT_5: { + std::string stars = ""; + + for (int i = 0; i < 100; i += 20) + stars.append((i <= score) ? "★" : "☆"); + + return stars; + } + case ScoreFormat::POINT_3: { + if (score >= 100) + return ":)"; + else if (score >= 66) + return ":|"; + else if (score >= 33) + return ":("; + else + return ""; + } + default: + case ScoreFormat::POINT_100: + return std::to_string(score); + } +} + Date Anime::GetUserDateStarted() const { assert(list_info_.get()); return list_info_->started;