Mercurial > minori
annotate 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 |
rev | line source |
---|---|
9 | 1 /* |
2 * anime.cpp: defining of custom anime-related | |
3 * datatypes & variables | |
4 */ | |
5 #include "core/anime.h" | |
279 | 6 #include "core/anime_season.h" |
9 | 7 #include "core/date.h" |
8 #include "core/session.h" | |
211
7cf53145de11
strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
9 #include "core/strings.h" |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
10 |
9 | 11 #include <algorithm> |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 namespace Anime { | |
16 | |
17 /* User list data */ | |
18 bool Anime::IsInUserList() const { | |
264 | 19 if (list_info_.has_value()) |
9 | 20 return true; |
21 return false; | |
22 } | |
23 | |
24 void Anime::AddToUserList() { | |
265
ff0b2052b234
*: add missing utf8proc files
Paper <paper@paper.us.eu.org>
parents:
264
diff
changeset
|
25 ListInformation list; |
264 | 26 list_info_.emplace(list); |
9 | 27 } |
28 | |
29 void Anime::RemoveFromUserList() { | |
30 list_info_.reset(); | |
31 } | |
32 | |
33 ListStatus Anime::GetUserStatus() const { | |
264 | 34 assert(list_info_.has_value()); |
9 | 35 return list_info_->status; |
36 } | |
37 | |
38 int Anime::GetUserProgress() const { | |
264 | 39 assert(list_info_.has_value()); |
9 | 40 return list_info_->progress; |
41 } | |
42 | |
43 int Anime::GetUserScore() const { | |
264 | 44 assert(list_info_.has_value()); |
9 | 45 return list_info_->score; |
46 } | |
47 | |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
48 std::string Anime::GetUserPresentableScore() const { |
264 | 49 assert(list_info_.has_value()); |
279 | 50 |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
51 const int score = list_info_->score; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
52 if (score == 0) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
53 return ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
54 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
55 switch (session.config.anime_list.score_format) { |
279 | 56 case ScoreFormat::Point10Decimal: |
211
7cf53145de11
strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
57 return Strings::ToUtf8String(score / 10) + "." + Strings::ToUtf8String(score % 10); |
279 | 58 case ScoreFormat::Point10: return Strings::ToUtf8String(score / 10); |
59 case ScoreFormat::Point5: { | |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
60 std::string stars = ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
61 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
62 for (int i = 0; i < 100; i += 20) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
63 stars.append((i <= score) ? "★" : "☆"); |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
64 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
65 return stars; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
66 } |
279 | 67 case ScoreFormat::Point3: { |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
68 if (score >= 100) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
69 return ":)"; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
70 else if (score >= 66) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
71 return ":|"; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
72 else if (score >= 33) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
73 return ":("; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
74 else |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
75 return ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
76 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
77 default: |
279 | 78 case ScoreFormat::Point100: return Strings::ToUtf8String(score); |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
79 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
80 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
81 |
9 | 82 Date Anime::GetUserDateStarted() const { |
264 | 83 assert(list_info_.has_value()); |
9 | 84 return list_info_->started; |
85 } | |
86 | |
87 Date Anime::GetUserDateCompleted() const { | |
264 | 88 assert(list_info_.has_value()); |
9 | 89 return list_info_->completed; |
90 } | |
91 | |
92 bool Anime::GetUserIsPrivate() const { | |
264 | 93 assert(list_info_.has_value()); |
9 | 94 return list_info_->is_private; |
95 } | |
96 | |
97 unsigned int Anime::GetUserRewatchedTimes() const { | |
264 | 98 assert(list_info_.has_value()); |
9 | 99 return list_info_->rewatched_times; |
100 } | |
101 | |
102 bool Anime::GetUserIsRewatching() const { | |
264 | 103 assert(list_info_.has_value()); |
9 | 104 return list_info_->rewatching; |
105 } | |
106 | |
107 uint64_t Anime::GetUserTimeUpdated() const { | |
264 | 108 assert(list_info_.has_value()); |
9 | 109 return list_info_->updated; |
110 } | |
111 | |
112 std::string Anime::GetUserNotes() const { | |
264 | 113 assert(list_info_.has_value()); |
9 | 114 return list_info_->notes; |
115 } | |
116 | |
117 void Anime::SetUserStatus(ListStatus status) { | |
264 | 118 assert(list_info_.has_value()); |
9 | 119 list_info_->status = status; |
120 } | |
121 | |
10 | 122 void Anime::SetUserScore(int score) { |
264 | 123 assert(list_info_.has_value()); |
10 | 124 list_info_->score = score; |
125 } | |
126 | |
9 | 127 void Anime::SetUserProgress(int progress) { |
264 | 128 assert(list_info_.has_value()); |
9 | 129 list_info_->progress = progress; |
130 } | |
131 | |
132 void Anime::SetUserDateStarted(Date const& started) { | |
264 | 133 assert(list_info_.has_value()); |
9 | 134 list_info_->started = started; |
135 } | |
136 | |
137 void Anime::SetUserDateCompleted(Date const& completed) { | |
264 | 138 assert(list_info_.has_value()); |
9 | 139 list_info_->completed = completed; |
140 } | |
141 | |
142 void Anime::SetUserIsPrivate(bool is_private) { | |
264 | 143 assert(list_info_.has_value()); |
9 | 144 list_info_->is_private = is_private; |
145 } | |
146 | |
147 void Anime::SetUserRewatchedTimes(int rewatched) { | |
264 | 148 assert(list_info_.has_value()); |
9 | 149 list_info_->rewatched_times = rewatched; |
150 } | |
151 | |
152 void Anime::SetUserIsRewatching(bool rewatching) { | |
264 | 153 assert(list_info_.has_value()); |
9 | 154 list_info_->rewatching = rewatching; |
155 } | |
156 | |
157 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
264 | 158 assert(list_info_.has_value()); |
9 | 159 list_info_->updated = updated; |
160 } | |
161 | |
162 void Anime::SetUserNotes(std::string const& notes) { | |
264 | 163 assert(list_info_.has_value()); |
9 | 164 list_info_->notes = notes; |
165 } | |
166 | |
167 /* Series data */ | |
168 int Anime::GetId() const { | |
169 return info_.id; | |
170 } | |
171 | |
172 std::string Anime::GetRomajiTitle() const { | |
173 return info_.title.romaji; | |
174 } | |
175 | |
176 std::string Anime::GetEnglishTitle() const { | |
177 return info_.title.english; | |
178 } | |
179 | |
180 std::string Anime::GetNativeTitle() const { | |
181 return info_.title.native; | |
182 } | |
183 | |
184 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
185 std::vector<std::string> result; | |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
186 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
187 auto add_to_synonyms = [this](std::vector<std::string>& vec, std::string key) { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
188 if (!key.empty() && !std::count(vec.begin(), vec.end(), key) && key != GetUserPreferredTitle()) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
189 vec.push_back(key); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
190 }; |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
191 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
192 add_to_synonyms(result, info_.title.english); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
193 add_to_synonyms(result, info_.title.romaji); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
194 add_to_synonyms(result, info_.title.native); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
195 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
196 for (auto& synonym : info_.synonyms) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
197 add_to_synonyms(result, synonym); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
198 |
9 | 199 return result; |
200 } | |
201 | |
202 int Anime::GetEpisodes() const { | |
203 return info_.episodes; | |
204 } | |
205 | |
206 SeriesStatus Anime::GetAiringStatus() const { | |
207 return info_.status; | |
208 } | |
209 | |
210 Date Anime::GetAirDate() const { | |
211 return info_.air_date; | |
212 } | |
213 | |
214 std::vector<std::string> Anime::GetGenres() const { | |
215 return info_.genres; | |
216 } | |
217 | |
218 std::vector<std::string> Anime::GetProducers() const { | |
219 return info_.producers; | |
220 } | |
221 | |
222 SeriesFormat Anime::GetFormat() const { | |
223 return info_.format; | |
224 } | |
225 | |
226 SeriesSeason Anime::GetSeason() const { | |
279 | 227 std::optional<Date::Month> month = info_.air_date.GetMonth(); |
228 return (month.has_value() ? GetSeasonForMonth(month.value()) : SeriesSeason::Unknown); | |
9 | 229 } |
230 | |
231 int Anime::GetAudienceScore() const { | |
232 return info_.audience_score; | |
233 } | |
234 | |
235 std::string Anime::GetSynopsis() const { | |
236 return info_.synopsis; | |
237 } | |
238 | |
239 int Anime::GetDuration() const { | |
240 return info_.duration; | |
241 } | |
242 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
243 std::string Anime::GetPosterUrl() const { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
244 return info_.poster_url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
245 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
246 |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
247 std::string Anime::GetServiceUrl() const { |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
248 /* todo: add support for other services... */ |
279 | 249 switch (session.config.service) { |
250 case Service::AniList: return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); | |
251 default: return ""; | |
252 } | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
253 } |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
254 |
9 | 255 void Anime::SetId(int id) { |
256 info_.id = id; | |
257 } | |
258 | |
259 void Anime::SetRomajiTitle(std::string const& title) { | |
260 info_.title.romaji = title; | |
261 } | |
262 | |
263 void Anime::SetEnglishTitle(std::string const& title) { | |
264 info_.title.english = title; | |
265 } | |
266 | |
267 void Anime::SetNativeTitle(std::string const& title) { | |
268 info_.title.native = title; | |
269 } | |
270 | |
271 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
272 info_.synonyms = synonyms; | |
273 } | |
274 | |
275 void Anime::AddTitleSynonym(std::string const& synonym) { | |
276 info_.synonyms.push_back(synonym); | |
277 } | |
278 | |
279 void Anime::SetEpisodes(int episodes) { | |
280 info_.episodes = episodes; | |
281 } | |
282 | |
283 void Anime::SetAiringStatus(SeriesStatus status) { | |
284 info_.status = status; | |
285 } | |
286 | |
287 void Anime::SetAirDate(Date const& date) { | |
288 info_.air_date = date; | |
289 } | |
290 | |
291 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
292 info_.genres = genres; | |
293 } | |
294 | |
295 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
296 info_.producers = producers; | |
297 } | |
298 | |
299 void Anime::SetFormat(SeriesFormat format) { | |
300 info_.format = format; | |
301 } | |
302 | |
303 void Anime::SetAudienceScore(int audience_score) { | |
304 info_.audience_score = audience_score; | |
305 } | |
306 | |
307 void Anime::SetSynopsis(std::string synopsis) { | |
308 info_.synopsis = synopsis; | |
309 } | |
310 | |
311 void Anime::SetDuration(int duration) { | |
312 info_.duration = duration; | |
313 } | |
314 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
315 void Anime::SetPosterUrl(std::string url) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
316 info_.poster_url = url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
317 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
318 |
9 | 319 std::string Anime::GetUserPreferredTitle() const { |
320 switch (session.config.anime_list.language) { | |
279 | 321 case TitleLanguage::Native: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); |
322 case TitleLanguage::Romaji: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
9 | 323 default: break; |
324 } | |
325 return GetRomajiTitle(); | |
326 } | |
327 | |
328 } // namespace Anime |