Mercurial > minori
comparison src/core/anime.cc @ 279:657fda1b9cac
*: clean up enums
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Fri, 19 Apr 2024 13:24:06 -0400 |
parents | ff0b2052b234 |
children | 9b6e12c14a1e |
comparison
equal
deleted
inserted
replaced
274:f6a756c19bfb | 279:657fda1b9cac |
---|---|
1 /* | 1 /* |
2 * anime.cpp: defining of custom anime-related | 2 * anime.cpp: defining of custom anime-related |
3 * datatypes & variables | 3 * datatypes & variables |
4 */ | 4 */ |
5 #include "core/anime.h" | 5 #include "core/anime.h" |
6 #include "core/anime_season.h" | |
6 #include "core/date.h" | 7 #include "core/date.h" |
7 #include "core/session.h" | 8 #include "core/session.h" |
8 #include "core/strings.h" | 9 #include "core/strings.h" |
9 | 10 |
10 #include <algorithm> | 11 #include <algorithm> |
44 return list_info_->score; | 45 return list_info_->score; |
45 } | 46 } |
46 | 47 |
47 std::string Anime::GetUserPresentableScore() const { | 48 std::string Anime::GetUserPresentableScore() const { |
48 assert(list_info_.has_value()); | 49 assert(list_info_.has_value()); |
50 | |
49 const int score = list_info_->score; | 51 const int score = list_info_->score; |
50 if (score == 0) | 52 if (score == 0) |
51 return ""; | 53 return ""; |
52 | 54 |
53 switch (session.config.anime_list.score_format) { | 55 switch (session.config.anime_list.score_format) { |
54 case ScoreFormat::POINT_10_DECIMAL: | 56 case ScoreFormat::Point10Decimal: |
55 return Strings::ToUtf8String(score / 10) + "." + Strings::ToUtf8String(score % 10); | 57 return Strings::ToUtf8String(score / 10) + "." + Strings::ToUtf8String(score % 10); |
56 case ScoreFormat::POINT_10: return Strings::ToUtf8String(score / 10); | 58 case ScoreFormat::Point10: return Strings::ToUtf8String(score / 10); |
57 case ScoreFormat::POINT_5: { | 59 case ScoreFormat::Point5: { |
58 std::string stars = ""; | 60 std::string stars = ""; |
59 | 61 |
60 for (int i = 0; i < 100; i += 20) | 62 for (int i = 0; i < 100; i += 20) |
61 stars.append((i <= score) ? "★" : "☆"); | 63 stars.append((i <= score) ? "★" : "☆"); |
62 | 64 |
63 return stars; | 65 return stars; |
64 } | 66 } |
65 case ScoreFormat::POINT_3: { | 67 case ScoreFormat::Point3: { |
66 if (score >= 100) | 68 if (score >= 100) |
67 return ":)"; | 69 return ":)"; |
68 else if (score >= 66) | 70 else if (score >= 66) |
69 return ":|"; | 71 return ":|"; |
70 else if (score >= 33) | 72 else if (score >= 33) |
71 return ":("; | 73 return ":("; |
72 else | 74 else |
73 return ""; | 75 return ""; |
74 } | 76 } |
75 default: | 77 default: |
76 case ScoreFormat::POINT_100: return Strings::ToUtf8String(score); | 78 case ScoreFormat::Point100: return Strings::ToUtf8String(score); |
77 } | 79 } |
78 } | 80 } |
79 | 81 |
80 Date Anime::GetUserDateStarted() const { | 82 Date Anime::GetUserDateStarted() const { |
81 assert(list_info_.has_value()); | 83 assert(list_info_.has_value()); |
220 SeriesFormat Anime::GetFormat() const { | 222 SeriesFormat Anime::GetFormat() const { |
221 return info_.format; | 223 return info_.format; |
222 } | 224 } |
223 | 225 |
224 SeriesSeason Anime::GetSeason() const { | 226 SeriesSeason Anime::GetSeason() const { |
225 return info_.season; | 227 std::optional<Date::Month> month = info_.air_date.GetMonth(); |
228 return (month.has_value() ? GetSeasonForMonth(month.value()) : SeriesSeason::Unknown); | |
226 } | 229 } |
227 | 230 |
228 int Anime::GetAudienceScore() const { | 231 int Anime::GetAudienceScore() const { |
229 return info_.audience_score; | 232 return info_.audience_score; |
230 } | 233 } |
241 return info_.poster_url; | 244 return info_.poster_url; |
242 } | 245 } |
243 | 246 |
244 std::string Anime::GetServiceUrl() const { | 247 std::string Anime::GetServiceUrl() const { |
245 /* todo: add support for other services... */ | 248 /* todo: add support for other services... */ |
246 return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); | 249 switch (session.config.service) { |
250 case Service::AniList: return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); | |
251 default: return ""; | |
252 } | |
247 } | 253 } |
248 | 254 |
249 void Anime::SetId(int id) { | 255 void Anime::SetId(int id) { |
250 info_.id = id; | 256 info_.id = id; |
251 } | 257 } |
292 | 298 |
293 void Anime::SetFormat(SeriesFormat format) { | 299 void Anime::SetFormat(SeriesFormat format) { |
294 info_.format = format; | 300 info_.format = format; |
295 } | 301 } |
296 | 302 |
297 void Anime::SetSeason(SeriesSeason season) { | |
298 info_.season = season; | |
299 } | |
300 | |
301 void Anime::SetAudienceScore(int audience_score) { | 303 void Anime::SetAudienceScore(int audience_score) { |
302 info_.audience_score = audience_score; | 304 info_.audience_score = audience_score; |
303 } | 305 } |
304 | 306 |
305 void Anime::SetSynopsis(std::string synopsis) { | 307 void Anime::SetSynopsis(std::string synopsis) { |
314 info_.poster_url = url; | 316 info_.poster_url = url; |
315 } | 317 } |
316 | 318 |
317 std::string Anime::GetUserPreferredTitle() const { | 319 std::string Anime::GetUserPreferredTitle() const { |
318 switch (session.config.anime_list.language) { | 320 switch (session.config.anime_list.language) { |
319 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | 321 case TitleLanguage::Native: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); |
320 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | 322 case TitleLanguage::Romaji: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); |
321 default: break; | 323 default: break; |
322 } | 324 } |
323 return GetRomajiTitle(); | 325 return GetRomajiTitle(); |
324 } | 326 } |
325 | 327 |