Mercurial > minori
annotate src/core/anime.cc @ 167:31735c8592bc
dep/animia: make x11 window walking actually work
this is HORRIBLY slow, and I'm not *entirely* sure why...
| author | paper@DavesDouble.local |
|---|---|
| date | Sun, 19 Nov 2023 05:32:06 -0500 |
| parents | 9b2b41f83a5e |
| children | bc8d2ccff09c |
| rev | line source |
|---|---|
| 9 | 1 /* |
| 2 * anime.cpp: defining of custom anime-related | |
| 3 * datatypes & variables | |
| 4 */ | |
| 5 #include "core/anime.h" | |
| 6 #include "core/date.h" | |
| 7 #include "core/session.h" | |
| 8 #include <algorithm> | |
| 9 #include <chrono> | |
| 10 #include <cmath> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 namespace Anime { | |
| 15 | |
| 16 /* User list data */ | |
| 17 bool Anime::IsInUserList() const { | |
| 18 if (list_info_.get()) | |
| 19 return true; | |
| 20 return false; | |
| 21 } | |
| 22 | |
| 23 void Anime::AddToUserList() { | |
| 24 list_info_.reset(new ListInformation); | |
| 25 } | |
| 26 | |
| 27 void Anime::RemoveFromUserList() { | |
| 28 list_info_.reset(); | |
| 29 } | |
| 30 | |
| 31 ListStatus Anime::GetUserStatus() const { | |
| 32 assert(list_info_.get()); | |
| 33 return list_info_->status; | |
| 34 } | |
| 35 | |
| 36 int Anime::GetUserProgress() const { | |
| 37 assert(list_info_.get()); | |
| 38 return list_info_->progress; | |
| 39 } | |
| 40 | |
| 41 int Anime::GetUserScore() const { | |
| 42 assert(list_info_.get()); | |
| 43 return list_info_->score; | |
| 44 } | |
| 45 | |
| 46 Date Anime::GetUserDateStarted() const { | |
| 47 assert(list_info_.get()); | |
| 48 return list_info_->started; | |
| 49 } | |
| 50 | |
| 51 Date Anime::GetUserDateCompleted() const { | |
| 52 assert(list_info_.get()); | |
| 53 return list_info_->completed; | |
| 54 } | |
| 55 | |
| 56 bool Anime::GetUserIsPrivate() const { | |
| 57 assert(list_info_.get()); | |
| 58 return list_info_->is_private; | |
| 59 } | |
| 60 | |
| 61 unsigned int Anime::GetUserRewatchedTimes() const { | |
| 62 assert(list_info_.get()); | |
| 63 return list_info_->rewatched_times; | |
| 64 } | |
| 65 | |
| 66 bool Anime::GetUserIsRewatching() const { | |
| 67 assert(list_info_.get()); | |
| 68 return list_info_->rewatching; | |
| 69 } | |
| 70 | |
| 71 uint64_t Anime::GetUserTimeUpdated() const { | |
| 72 assert(list_info_.get()); | |
| 73 return list_info_->updated; | |
| 74 } | |
| 75 | |
| 76 std::string Anime::GetUserNotes() const { | |
| 77 assert(list_info_.get()); | |
| 78 return list_info_->notes; | |
| 79 } | |
| 80 | |
| 81 void Anime::SetUserStatus(ListStatus status) { | |
| 82 assert(list_info_.get()); | |
| 83 list_info_->status = status; | |
| 84 } | |
| 85 | |
| 10 | 86 void Anime::SetUserScore(int score) { |
| 87 assert(list_info_.get()); | |
| 88 list_info_->score = score; | |
| 89 } | |
| 90 | |
| 9 | 91 void Anime::SetUserProgress(int progress) { |
| 92 assert(list_info_.get()); | |
| 93 list_info_->progress = progress; | |
| 94 } | |
| 95 | |
| 96 void Anime::SetUserDateStarted(Date const& started) { | |
| 97 assert(list_info_.get()); | |
| 98 list_info_->started = started; | |
| 99 } | |
| 100 | |
| 101 void Anime::SetUserDateCompleted(Date const& completed) { | |
| 102 assert(list_info_.get()); | |
| 103 list_info_->completed = completed; | |
| 104 } | |
| 105 | |
| 106 void Anime::SetUserIsPrivate(bool is_private) { | |
| 107 assert(list_info_.get()); | |
| 108 list_info_->is_private = is_private; | |
| 109 } | |
| 110 | |
| 111 void Anime::SetUserRewatchedTimes(int rewatched) { | |
| 112 assert(list_info_.get()); | |
| 113 list_info_->rewatched_times = rewatched; | |
| 114 } | |
| 115 | |
| 116 void Anime::SetUserIsRewatching(bool rewatching) { | |
| 117 assert(list_info_.get()); | |
| 118 list_info_->rewatching = rewatching; | |
| 119 } | |
| 120 | |
| 121 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
| 122 assert(list_info_.get()); | |
| 123 list_info_->updated = updated; | |
| 124 } | |
| 125 | |
| 126 void Anime::SetUserNotes(std::string const& notes) { | |
| 127 assert(list_info_.get()); | |
| 128 list_info_->notes = notes; | |
| 129 } | |
| 130 | |
| 131 /* Series data */ | |
| 132 int Anime::GetId() const { | |
| 133 return info_.id; | |
| 134 } | |
| 135 | |
| 136 std::string Anime::GetRomajiTitle() const { | |
| 137 return info_.title.romaji; | |
| 138 } | |
| 139 | |
| 140 std::string Anime::GetEnglishTitle() const { | |
| 141 return info_.title.english; | |
| 142 } | |
| 143 | |
| 144 std::string Anime::GetNativeTitle() const { | |
| 145 return info_.title.native; | |
| 146 } | |
| 147 | |
| 148 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
| 149 std::vector<std::string> result; | |
| 150 #define IN_VECTOR(v, k) (std::count(v.begin(), v.end(), k)) | |
| 36 | 151 #define ADD_TO_SYNONYMS(v, k) \ |
| 152 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \ | |
| 9 | 153 v.push_back(k) |
| 154 ADD_TO_SYNONYMS(result, info_.title.english); | |
| 155 ADD_TO_SYNONYMS(result, info_.title.romaji); | |
| 156 ADD_TO_SYNONYMS(result, info_.title.native); | |
| 157 for (auto& synonym : info_.synonyms) { | |
| 158 ADD_TO_SYNONYMS(result, synonym); | |
| 159 } | |
| 160 #undef ADD_TO_SYNONYMS | |
| 161 #undef IN_VECTOR | |
| 162 return result; | |
| 163 } | |
| 164 | |
| 165 int Anime::GetEpisodes() const { | |
| 166 return info_.episodes; | |
| 167 } | |
| 168 | |
| 169 SeriesStatus Anime::GetAiringStatus() const { | |
| 170 return info_.status; | |
| 171 } | |
| 172 | |
| 173 Date Anime::GetAirDate() const { | |
| 174 return info_.air_date; | |
| 175 } | |
| 176 | |
| 177 std::vector<std::string> Anime::GetGenres() const { | |
| 178 return info_.genres; | |
| 179 } | |
| 180 | |
| 181 std::vector<std::string> Anime::GetProducers() const { | |
| 182 return info_.producers; | |
| 183 } | |
| 184 | |
| 185 SeriesFormat Anime::GetFormat() const { | |
| 186 return info_.format; | |
| 187 } | |
| 188 | |
| 189 SeriesSeason Anime::GetSeason() const { | |
| 190 return info_.season; | |
| 191 } | |
| 192 | |
| 193 int Anime::GetAudienceScore() const { | |
| 194 return info_.audience_score; | |
| 195 } | |
| 196 | |
| 197 std::string Anime::GetSynopsis() const { | |
| 198 return info_.synopsis; | |
| 199 } | |
| 200 | |
| 201 int Anime::GetDuration() const { | |
| 202 return info_.duration; | |
| 203 } | |
| 204 | |
|
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
205 std::string Anime::GetPosterUrl() const { |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
206 return info_.poster_url; |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
207 } |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
208 |
|
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
209 std::string Anime::GetServiceUrl() const { |
|
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
210 return "https://anilist.co/anime/" + std::to_string(GetId()); |
|
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
211 } |
|
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
212 |
| 9 | 213 void Anime::SetId(int id) { |
| 214 info_.id = id; | |
| 215 } | |
| 216 | |
| 217 void Anime::SetRomajiTitle(std::string const& title) { | |
| 218 info_.title.romaji = title; | |
| 219 } | |
| 220 | |
| 221 void Anime::SetEnglishTitle(std::string const& title) { | |
| 222 info_.title.english = title; | |
| 223 } | |
| 224 | |
| 225 void Anime::SetNativeTitle(std::string const& title) { | |
| 226 info_.title.native = title; | |
| 227 } | |
| 228 | |
| 229 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
| 230 info_.synonyms = synonyms; | |
| 231 } | |
| 232 | |
| 233 void Anime::AddTitleSynonym(std::string const& synonym) { | |
| 234 info_.synonyms.push_back(synonym); | |
| 235 } | |
| 236 | |
| 237 void Anime::SetEpisodes(int episodes) { | |
| 238 info_.episodes = episodes; | |
| 239 } | |
| 240 | |
| 241 void Anime::SetAiringStatus(SeriesStatus status) { | |
| 242 info_.status = status; | |
| 243 } | |
| 244 | |
| 245 void Anime::SetAirDate(Date const& date) { | |
| 246 info_.air_date = date; | |
| 247 } | |
| 248 | |
| 249 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
| 250 info_.genres = genres; | |
| 251 } | |
| 252 | |
| 253 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
| 254 info_.producers = producers; | |
| 255 } | |
| 256 | |
| 257 void Anime::SetFormat(SeriesFormat format) { | |
| 258 info_.format = format; | |
| 259 } | |
| 260 | |
| 261 void Anime::SetSeason(SeriesSeason season) { | |
| 262 info_.season = season; | |
| 263 } | |
| 264 | |
| 265 void Anime::SetAudienceScore(int audience_score) { | |
| 266 info_.audience_score = audience_score; | |
| 267 } | |
| 268 | |
| 269 void Anime::SetSynopsis(std::string synopsis) { | |
| 270 info_.synopsis = synopsis; | |
| 271 } | |
| 272 | |
| 273 void Anime::SetDuration(int duration) { | |
| 274 info_.duration = duration; | |
| 275 } | |
| 276 | |
|
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
277 void Anime::SetPosterUrl(std::string url) { |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
278 info_.poster_url = url; |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
279 } |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
280 |
| 9 | 281 std::string Anime::GetUserPreferredTitle() const { |
| 282 switch (session.config.anime_list.language) { | |
| 283 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | |
| 284 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
| 285 default: break; | |
| 286 } | |
| 287 return GetRomajiTitle(); | |
| 288 } | |
| 289 | |
| 290 } // namespace Anime |
