Mercurial > minori
comparison src/core/anime.cc @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:16:02 -0400 |
parents | b5d6c27c308f |
children |
comparison
equal
deleted
inserted
replaced
368:6d37a998cf91 | 369:47c9f8502269 |
---|---|
7 #include "core/date.h" | 7 #include "core/date.h" |
8 #include "core/session.h" | 8 #include "core/session.h" |
9 #include "core/strings.h" | 9 #include "core/strings.h" |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <cassert> | |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 #include <cassert> | |
15 | 15 |
16 #include <iostream> | 16 #include <iostream> |
17 | 17 |
18 namespace Anime { | 18 namespace Anime { |
19 | 19 |
20 /* User list data */ | 20 /* User list data */ |
21 bool Anime::IsInUserList() const { | 21 bool Anime::IsInUserList() const |
22 { | |
22 if (list_info_.has_value()) | 23 if (list_info_.has_value()) |
23 return true; | 24 return true; |
24 return false; | 25 return false; |
25 } | 26 } |
26 | 27 |
27 void Anime::AddToUserList() { | 28 void Anime::AddToUserList() |
29 { | |
28 ListInformation list; | 30 ListInformation list; |
29 list_info_.emplace(list); | 31 list_info_.emplace(list); |
30 } | 32 } |
31 | 33 |
32 void Anime::RemoveFromUserList() { | 34 void Anime::RemoveFromUserList() |
35 { | |
33 list_info_.reset(); | 36 list_info_.reset(); |
34 } | 37 } |
35 | 38 |
36 std::string Anime::GetUserId() const { | 39 std::string Anime::GetUserId() const |
40 { | |
37 assert(list_info_.has_value()); | 41 assert(list_info_.has_value()); |
38 return list_info_->id; | 42 return list_info_->id; |
39 } | 43 } |
40 | 44 |
41 ListStatus Anime::GetUserStatus() const { | 45 ListStatus Anime::GetUserStatus() const |
46 { | |
42 assert(list_info_.has_value()); | 47 assert(list_info_.has_value()); |
43 return list_info_->status; | 48 return list_info_->status; |
44 } | 49 } |
45 | 50 |
46 int Anime::GetUserProgress() const { | 51 int Anime::GetUserProgress() const |
52 { | |
47 assert(list_info_.has_value()); | 53 assert(list_info_.has_value()); |
48 return list_info_->progress; | 54 return list_info_->progress; |
49 } | 55 } |
50 | 56 |
51 int Anime::GetUserScore() const { | 57 int Anime::GetUserScore() const |
58 { | |
52 assert(list_info_.has_value()); | 59 assert(list_info_.has_value()); |
53 return list_info_->score; | 60 return list_info_->score; |
54 } | 61 } |
55 | 62 |
56 std::string Anime::GetUserPresentableScore() const { | 63 std::string Anime::GetUserPresentableScore() const |
64 { | |
57 assert(list_info_.has_value()); | 65 assert(list_info_.has_value()); |
58 | 66 |
59 const int score = list_info_->score; | 67 const int score = list_info_->score; |
60 if (score == 0) | 68 if (score == 0) |
61 return ""; | 69 return ""; |
85 default: | 93 default: |
86 case ScoreFormat::Point100: return Strings::ToUtf8String(score); | 94 case ScoreFormat::Point100: return Strings::ToUtf8String(score); |
87 } | 95 } |
88 } | 96 } |
89 | 97 |
90 Date Anime::GetUserDateStarted() const { | 98 Date Anime::GetUserDateStarted() const |
99 { | |
91 assert(list_info_.has_value()); | 100 assert(list_info_.has_value()); |
92 return list_info_->started; | 101 return list_info_->started; |
93 } | 102 } |
94 | 103 |
95 Date Anime::GetUserDateCompleted() const { | 104 Date Anime::GetUserDateCompleted() const |
105 { | |
96 assert(list_info_.has_value()); | 106 assert(list_info_.has_value()); |
97 return list_info_->completed; | 107 return list_info_->completed; |
98 } | 108 } |
99 | 109 |
100 bool Anime::GetUserIsPrivate() const { | 110 bool Anime::GetUserIsPrivate() const |
111 { | |
101 assert(list_info_.has_value()); | 112 assert(list_info_.has_value()); |
102 return list_info_->is_private; | 113 return list_info_->is_private; |
103 } | 114 } |
104 | 115 |
105 unsigned int Anime::GetUserRewatchedTimes() const { | 116 unsigned int Anime::GetUserRewatchedTimes() const |
117 { | |
106 assert(list_info_.has_value()); | 118 assert(list_info_.has_value()); |
107 return list_info_->rewatched_times; | 119 return list_info_->rewatched_times; |
108 } | 120 } |
109 | 121 |
110 bool Anime::GetUserIsRewatching() const { | 122 bool Anime::GetUserIsRewatching() const |
123 { | |
111 assert(list_info_.has_value()); | 124 assert(list_info_.has_value()); |
112 return list_info_->rewatching; | 125 return list_info_->rewatching; |
113 } | 126 } |
114 | 127 |
115 uint64_t Anime::GetUserTimeUpdated() const { | 128 uint64_t Anime::GetUserTimeUpdated() const |
129 { | |
116 assert(list_info_.has_value()); | 130 assert(list_info_.has_value()); |
117 return list_info_->updated; | 131 return list_info_->updated; |
118 } | 132 } |
119 | 133 |
120 std::string Anime::GetUserNotes() const { | 134 std::string Anime::GetUserNotes() const |
135 { | |
121 assert(list_info_.has_value()); | 136 assert(list_info_.has_value()); |
122 return list_info_->notes; | 137 return list_info_->notes; |
123 } | 138 } |
124 | 139 |
125 void Anime::SetUserId(const std::string& id) { | 140 void Anime::SetUserId(const std::string &id) |
141 { | |
126 assert(list_info_.has_value()); | 142 assert(list_info_.has_value()); |
127 list_info_->id = id; | 143 list_info_->id = id; |
128 } | 144 } |
129 | 145 |
130 void Anime::SetUserStatus(ListStatus status) { | 146 void Anime::SetUserStatus(ListStatus status) |
147 { | |
131 assert(list_info_.has_value()); | 148 assert(list_info_.has_value()); |
132 list_info_->status = status; | 149 list_info_->status = status; |
133 } | 150 } |
134 | 151 |
135 void Anime::SetUserScore(int score) { | 152 void Anime::SetUserScore(int score) |
153 { | |
136 assert(list_info_.has_value()); | 154 assert(list_info_.has_value()); |
137 list_info_->score = score; | 155 list_info_->score = score; |
138 } | 156 } |
139 | 157 |
140 void Anime::SetUserProgress(int progress) { | 158 void Anime::SetUserProgress(int progress) |
159 { | |
141 assert(list_info_.has_value()); | 160 assert(list_info_.has_value()); |
142 list_info_->progress = progress; | 161 list_info_->progress = progress; |
143 } | 162 } |
144 | 163 |
145 void Anime::SetUserDateStarted(const Date& started) { | 164 void Anime::SetUserDateStarted(const Date &started) |
165 { | |
146 assert(list_info_.has_value()); | 166 assert(list_info_.has_value()); |
147 list_info_->started = started; | 167 list_info_->started = started; |
148 } | 168 } |
149 | 169 |
150 void Anime::SetUserDateCompleted(const Date& completed) { | 170 void Anime::SetUserDateCompleted(const Date &completed) |
171 { | |
151 assert(list_info_.has_value()); | 172 assert(list_info_.has_value()); |
152 list_info_->completed = completed; | 173 list_info_->completed = completed; |
153 } | 174 } |
154 | 175 |
155 void Anime::SetUserIsPrivate(bool is_private) { | 176 void Anime::SetUserIsPrivate(bool is_private) |
177 { | |
156 assert(list_info_.has_value()); | 178 assert(list_info_.has_value()); |
157 list_info_->is_private = is_private; | 179 list_info_->is_private = is_private; |
158 } | 180 } |
159 | 181 |
160 void Anime::SetUserRewatchedTimes(int rewatched) { | 182 void Anime::SetUserRewatchedTimes(int rewatched) |
183 { | |
161 assert(list_info_.has_value()); | 184 assert(list_info_.has_value()); |
162 list_info_->rewatched_times = rewatched; | 185 list_info_->rewatched_times = rewatched; |
163 } | 186 } |
164 | 187 |
165 void Anime::SetUserIsRewatching(bool rewatching) { | 188 void Anime::SetUserIsRewatching(bool rewatching) |
189 { | |
166 assert(list_info_.has_value()); | 190 assert(list_info_.has_value()); |
167 list_info_->rewatching = rewatching; | 191 list_info_->rewatching = rewatching; |
168 } | 192 } |
169 | 193 |
170 void Anime::SetUserTimeUpdated(uint64_t updated) { | 194 void Anime::SetUserTimeUpdated(uint64_t updated) |
195 { | |
171 assert(list_info_.has_value()); | 196 assert(list_info_.has_value()); |
172 list_info_->updated = updated; | 197 list_info_->updated = updated; |
173 } | 198 } |
174 | 199 |
175 void Anime::SetUserNotes(const std::string& notes) { | 200 void Anime::SetUserNotes(const std::string ¬es) |
201 { | |
176 assert(list_info_.has_value()); | 202 assert(list_info_.has_value()); |
177 list_info_->notes = notes; | 203 list_info_->notes = notes; |
178 } | 204 } |
179 | 205 |
180 /* Series data */ | 206 /* Series data */ |
181 int Anime::GetId() const { | 207 int Anime::GetId() const |
208 { | |
182 return info_.id; | 209 return info_.id; |
183 } | 210 } |
184 | 211 |
185 std::optional<std::string> Anime::GetServiceId(Service service) const { | 212 std::optional<std::string> Anime::GetServiceId(Service service) const |
213 { | |
186 if (info_.ids.find(service) == info_.ids.end()) | 214 if (info_.ids.find(service) == info_.ids.end()) |
187 return std::nullopt; | 215 return std::nullopt; |
188 | 216 |
189 return info_.ids.at(service); | 217 return info_.ids.at(service); |
190 } | 218 } |
191 | 219 |
192 /* note: this should use std::optional */ | 220 /* note: this should use std::optional */ |
193 std::optional<std::string> Anime::GetTitle(TitleLanguage language) const { | 221 std::optional<std::string> Anime::GetTitle(TitleLanguage language) const |
222 { | |
194 if (info_.titles.find(language) == info_.titles.end()) | 223 if (info_.titles.find(language) == info_.titles.end()) |
195 return std::nullopt; | 224 return std::nullopt; |
196 | 225 |
197 return info_.titles.at(language); | 226 return info_.titles.at(language); |
198 } | 227 } |
199 | 228 |
200 std::vector<std::string> Anime::GetTitleSynonyms() const { | 229 std::vector<std::string> Anime::GetTitleSynonyms() const |
230 { | |
201 /* mainly for the GUI */ | 231 /* mainly for the GUI */ |
202 std::vector<std::string> result; | 232 std::vector<std::string> result; |
203 | 233 |
204 auto add_to_synonyms = [this](std::vector<std::string>& vec, std::string key) { | 234 auto add_to_synonyms = [this](std::vector<std::string> &vec, std::string key) { |
205 if (!key.empty() && !std::count(vec.begin(), vec.end(), key) && key != GetUserPreferredTitle()) | 235 if (!key.empty() && !std::count(vec.begin(), vec.end(), key) && key != GetUserPreferredTitle()) |
206 vec.push_back(key); | 236 vec.push_back(key); |
207 }; | 237 }; |
208 | 238 |
209 for (const auto& lang : TitleLanguages) | 239 for (const auto &lang : TitleLanguages) |
210 if (info_.titles.find(lang) != info_.titles.end()) | 240 if (info_.titles.find(lang) != info_.titles.end()) |
211 add_to_synonyms(result, info_.titles.at(lang)); | 241 add_to_synonyms(result, info_.titles.at(lang)); |
212 | 242 |
213 for (auto& synonym : info_.synonyms) | 243 for (auto &synonym : info_.synonyms) |
214 add_to_synonyms(result, synonym); | 244 add_to_synonyms(result, synonym); |
215 | 245 |
216 return result; | 246 return result; |
217 } | 247 } |
218 | 248 |
219 int Anime::GetEpisodes() const { | 249 int Anime::GetEpisodes() const |
250 { | |
220 return info_.episodes; | 251 return info_.episodes; |
221 } | 252 } |
222 | 253 |
223 SeriesStatus Anime::GetAiringStatus() const { | 254 SeriesStatus Anime::GetAiringStatus() const |
255 { | |
224 return info_.status; | 256 return info_.status; |
225 } | 257 } |
226 | 258 |
227 Date Anime::GetStartedDate() const { | 259 Date Anime::GetStartedDate() const |
260 { | |
228 return info_.started; | 261 return info_.started; |
229 } | 262 } |
230 | 263 |
231 Date Anime::GetCompletedDate() const { | 264 Date Anime::GetCompletedDate() const |
265 { | |
232 return info_.completed; | 266 return info_.completed; |
233 } | 267 } |
234 | 268 |
235 std::vector<std::string> Anime::GetGenres() const { | 269 std::vector<std::string> Anime::GetGenres() const |
270 { | |
236 return info_.genres; | 271 return info_.genres; |
237 } | 272 } |
238 | 273 |
239 std::vector<std::string> Anime::GetProducers() const { | 274 std::vector<std::string> Anime::GetProducers() const |
275 { | |
240 return info_.producers; | 276 return info_.producers; |
241 } | 277 } |
242 | 278 |
243 SeriesFormat Anime::GetFormat() const { | 279 SeriesFormat Anime::GetFormat() const |
280 { | |
244 return info_.format; | 281 return info_.format; |
245 } | 282 } |
246 | 283 |
247 Season Anime::GetSeason() const { | 284 Season Anime::GetSeason() const |
285 { | |
248 return Season(info_.started); | 286 return Season(info_.started); |
249 } | 287 } |
250 | 288 |
251 double Anime::GetAudienceScore() const { | 289 double Anime::GetAudienceScore() const |
290 { | |
252 return info_.audience_score; | 291 return info_.audience_score; |
253 } | 292 } |
254 | 293 |
255 std::string Anime::GetSynopsis() const { | 294 std::string Anime::GetSynopsis() const |
295 { | |
256 return info_.synopsis; | 296 return info_.synopsis; |
257 } | 297 } |
258 | 298 |
259 int Anime::GetDuration() const { | 299 int Anime::GetDuration() const |
300 { | |
260 return info_.duration; | 301 return info_.duration; |
261 } | 302 } |
262 | 303 |
263 std::string Anime::GetPosterUrl() const { | 304 std::string Anime::GetPosterUrl() const |
305 { | |
264 /* this isn't really service-specific. this could use | 306 /* this isn't really service-specific. this could use |
265 * kitsu, MAL, or anilist, and would achieve basically | 307 * kitsu, MAL, or anilist, and would achieve basically |
266 * the same effect. */ | 308 * the same effect. */ |
267 return info_.poster_url; | 309 return info_.poster_url; |
268 } | 310 } |
269 | 311 |
270 std::optional<std::string> Anime::GetServiceUrl(Service service) const { | 312 std::optional<std::string> Anime::GetServiceUrl(Service service) const |
313 { | |
271 /* todo: add support for other services... */ | 314 /* todo: add support for other services... */ |
272 std::optional<std::string> id = GetServiceId(service); | 315 std::optional<std::string> id = GetServiceId(service); |
273 if (!id.has_value()) | 316 if (!id.has_value()) |
274 return std::nullopt; | 317 return std::nullopt; |
275 | 318 |
276 switch (service) { | 319 switch (service) { |
277 case Service::AniList: | 320 case Service::AniList: return "https://anilist.co/anime/" + id.value(); |
278 return "https://anilist.co/anime/" + id.value(); | |
279 default: return ""; | 321 default: return ""; |
280 } | 322 } |
281 } | 323 } |
282 | 324 |
283 void Anime::SetId(int id) { | 325 void Anime::SetId(int id) |
326 { | |
284 info_.id = id; | 327 info_.id = id; |
285 } | 328 } |
286 | 329 |
287 void Anime::SetServiceId(Service service, const std::string& id) { | 330 void Anime::SetServiceId(Service service, const std::string &id) |
331 { | |
288 info_.ids[service] = id; | 332 info_.ids[service] = id; |
289 } | 333 } |
290 | 334 |
291 void Anime::SetTitle(TitleLanguage language, const std::string& title) { | 335 void Anime::SetTitle(TitleLanguage language, const std::string &title) |
336 { | |
292 info_.titles[language] = title; | 337 info_.titles[language] = title; |
293 } | 338 } |
294 | 339 |
295 void Anime::SetTitleSynonyms(const std::vector<std::string>& synonyms) { | 340 void Anime::SetTitleSynonyms(const std::vector<std::string> &synonyms) |
341 { | |
296 info_.synonyms = synonyms; | 342 info_.synonyms = synonyms; |
297 } | 343 } |
298 | 344 |
299 void Anime::AddTitleSynonym(const std::string& synonym) { | 345 void Anime::AddTitleSynonym(const std::string &synonym) |
346 { | |
300 info_.synonyms.push_back(synonym); | 347 info_.synonyms.push_back(synonym); |
301 } | 348 } |
302 | 349 |
303 void Anime::SetEpisodes(int episodes) { | 350 void Anime::SetEpisodes(int episodes) |
351 { | |
304 info_.episodes = episodes; | 352 info_.episodes = episodes; |
305 } | 353 } |
306 | 354 |
307 void Anime::SetAiringStatus(SeriesStatus status) { | 355 void Anime::SetAiringStatus(SeriesStatus status) |
356 { | |
308 info_.status = status; | 357 info_.status = status; |
309 } | 358 } |
310 | 359 |
311 void Anime::SetStartedDate(const Date& date) { | 360 void Anime::SetStartedDate(const Date &date) |
361 { | |
312 info_.started = date; | 362 info_.started = date; |
313 } | 363 } |
314 | 364 |
315 void Anime::SetCompletedDate(const Date& date) { | 365 void Anime::SetCompletedDate(const Date &date) |
366 { | |
316 info_.completed = date; | 367 info_.completed = date; |
317 } | 368 } |
318 | 369 |
319 void Anime::SetGenres(const std::vector<std::string>& genres) { | 370 void Anime::SetGenres(const std::vector<std::string> &genres) |
371 { | |
320 info_.genres = genres; | 372 info_.genres = genres; |
321 } | 373 } |
322 | 374 |
323 void Anime::SetProducers(const std::vector<std::string>& producers) { | 375 void Anime::SetProducers(const std::vector<std::string> &producers) |
376 { | |
324 info_.producers = producers; | 377 info_.producers = producers; |
325 } | 378 } |
326 | 379 |
327 void Anime::SetFormat(SeriesFormat format) { | 380 void Anime::SetFormat(SeriesFormat format) |
381 { | |
328 info_.format = format; | 382 info_.format = format; |
329 } | 383 } |
330 | 384 |
331 void Anime::SetAudienceScore(double audience_score) { | 385 void Anime::SetAudienceScore(double audience_score) |
386 { | |
332 info_.audience_score = audience_score; | 387 info_.audience_score = audience_score; |
333 } | 388 } |
334 | 389 |
335 void Anime::SetSynopsis(std::string synopsis) { | 390 void Anime::SetSynopsis(std::string synopsis) |
391 { | |
336 info_.synopsis = synopsis; | 392 info_.synopsis = synopsis; |
337 } | 393 } |
338 | 394 |
339 void Anime::SetDuration(int duration) { | 395 void Anime::SetDuration(int duration) |
396 { | |
340 info_.duration = duration; | 397 info_.duration = duration; |
341 } | 398 } |
342 | 399 |
343 void Anime::SetPosterUrl(std::string url) { | 400 void Anime::SetPosterUrl(std::string url) |
401 { | |
344 info_.poster_url = url; | 402 info_.poster_url = url; |
345 } | 403 } |
346 | 404 |
347 std::string Anime::GetUserPreferredTitle() const { | 405 std::string Anime::GetUserPreferredTitle() const |
406 { | |
348 std::optional<std::string> title = GetTitle(session.config.anime_list.language); | 407 std::optional<std::string> title = GetTitle(session.config.anime_list.language); |
349 if (title.has_value()) | 408 if (title.has_value()) |
350 return title.value(); | 409 return title.value(); |
351 | 410 |
352 title = GetTitle(TitleLanguage::Romaji); | 411 title = GetTitle(TitleLanguage::Romaji); |