comparison 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
comparison
equal deleted inserted replaced
184:09492158bcc5 185:62e336597bb7
38 } 38 }
39 39
40 int Anime::GetUserScore() const { 40 int Anime::GetUserScore() const {
41 assert(list_info_.get()); 41 assert(list_info_.get());
42 return list_info_->score; 42 return list_info_->score;
43 }
44
45 std::string Anime::GetUserPresentableScore() const {
46 assert(list_info_.get());
47 const int score = list_info_->score;
48 if (score == 0)
49 return "";
50
51 switch (session.config.anime_list.score_format) {
52 case ScoreFormat::POINT_10_DECIMAL: {
53 std::ostringstream out;
54 out.precision(1);
55 out << std::fixed << (static_cast<double>(score) / 10);
56 return std::move(out).str();
57 }
58 case ScoreFormat::POINT_10:
59 return std::to_string(score / 10);
60 case ScoreFormat::POINT_5: {
61 std::string stars = "";
62
63 for (int i = 0; i < 100; i += 20)
64 stars.append((i <= score) ? "★" : "☆");
65
66 return stars;
67 }
68 case ScoreFormat::POINT_3: {
69 if (score >= 100)
70 return ":)";
71 else if (score >= 66)
72 return ":|";
73 else if (score >= 33)
74 return ":(";
75 else
76 return "";
77 }
78 default:
79 case ScoreFormat::POINT_100:
80 return std::to_string(score);
81 }
43 } 82 }
44 83
45 Date Anime::GetUserDateStarted() const { 84 Date Anime::GetUserDateStarted() const {
46 assert(list_info_.get()); 85 assert(list_info_.get());
47 return list_info_->started; 86 return list_info_->started;