Mercurial > minori
comparison src/core/anime.cpp @ 9:5c0397762b53
INCOMPLETE: megacommit :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 10 Sep 2023 03:59:16 -0400 |
| parents | |
| children | 4b198a111713 |
comparison
equal
deleted
inserted
replaced
| 8:b1f73678ef61 | 9:5c0397762b53 |
|---|---|
| 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 if (!list_info_.get()) | |
| 25 return; | |
| 26 list_info_.reset(new ListInformation); | |
| 27 } | |
| 28 | |
| 29 void Anime::RemoveFromUserList() { | |
| 30 if (list_info_.get()) | |
| 31 return; | |
| 32 list_info_.reset(); | |
| 33 } | |
| 34 | |
| 35 ListStatus Anime::GetUserStatus() const { | |
| 36 assert(list_info_.get()); | |
| 37 return list_info_->status; | |
| 38 } | |
| 39 | |
| 40 int Anime::GetUserProgress() const { | |
| 41 assert(list_info_.get()); | |
| 42 return list_info_->progress; | |
| 43 } | |
| 44 | |
| 45 int Anime::GetUserScore() const { | |
| 46 assert(list_info_.get()); | |
| 47 return list_info_->score; | |
| 48 } | |
| 49 | |
| 50 Date Anime::GetUserDateStarted() const { | |
| 51 assert(list_info_.get()); | |
| 52 return list_info_->started; | |
| 53 } | |
| 54 | |
| 55 Date Anime::GetUserDateCompleted() const { | |
| 56 assert(list_info_.get()); | |
| 57 return list_info_->completed; | |
| 58 } | |
| 59 | |
| 60 bool Anime::GetUserIsPrivate() const { | |
| 61 assert(list_info_.get()); | |
| 62 return list_info_->is_private; | |
| 63 } | |
| 64 | |
| 65 unsigned int Anime::GetUserRewatchedTimes() const { | |
| 66 assert(list_info_.get()); | |
| 67 return list_info_->rewatched_times; | |
| 68 } | |
| 69 | |
| 70 bool Anime::GetUserIsRewatching() const { | |
| 71 assert(list_info_.get()); | |
| 72 return list_info_->rewatching; | |
| 73 } | |
| 74 | |
| 75 uint64_t Anime::GetUserTimeUpdated() const { | |
| 76 assert(list_info_.get()); | |
| 77 return list_info_->updated; | |
| 78 } | |
| 79 | |
| 80 std::string Anime::GetUserNotes() const { | |
| 81 assert(list_info_.get()); | |
| 82 return list_info_->notes; | |
| 83 } | |
| 84 | |
| 85 void Anime::SetUserStatus(ListStatus status) { | |
| 86 assert(list_info_.get()); | |
| 87 list_info_->status = status; | |
| 88 } | |
| 89 | |
| 90 void Anime::SetUserProgress(int progress) { | |
| 91 assert(list_info_.get()); | |
| 92 list_info_->progress = progress; | |
| 93 } | |
| 94 | |
| 95 void Anime::SetUserDateStarted(Date const& started) { | |
| 96 assert(list_info_.get()); | |
| 97 list_info_->started = started; | |
| 98 } | |
| 99 | |
| 100 void Anime::SetUserDateCompleted(Date const& completed) { | |
| 101 assert(list_info_.get()); | |
| 102 list_info_->completed = completed; | |
| 103 } | |
| 104 | |
| 105 void Anime::SetUserIsPrivate(bool is_private) { | |
| 106 assert(list_info_.get()); | |
| 107 list_info_->is_private = is_private; | |
| 108 } | |
| 109 | |
| 110 void Anime::SetUserRewatchedTimes(int rewatched) { | |
| 111 assert(list_info_.get()); | |
| 112 list_info_->rewatched_times = rewatched; | |
| 113 } | |
| 114 | |
| 115 void Anime::SetUserIsRewatching(bool rewatching) { | |
| 116 assert(list_info_.get()); | |
| 117 list_info_->rewatching = rewatching; | |
| 118 } | |
| 119 | |
| 120 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
| 121 assert(list_info_.get()); | |
| 122 list_info_->updated = updated; | |
| 123 } | |
| 124 | |
| 125 void Anime::SetUserNotes(std::string const& notes) { | |
| 126 assert(list_info_.get()); | |
| 127 list_info_->notes = notes; | |
| 128 } | |
| 129 | |
| 130 /* Series data */ | |
| 131 int Anime::GetId() const { | |
| 132 return info_.id; | |
| 133 } | |
| 134 | |
| 135 std::string Anime::GetRomajiTitle() const { | |
| 136 return info_.title.romaji; | |
| 137 } | |
| 138 | |
| 139 std::string Anime::GetEnglishTitle() const { | |
| 140 return info_.title.english; | |
| 141 } | |
| 142 | |
| 143 std::string Anime::GetNativeTitle() const { | |
| 144 return info_.title.native; | |
| 145 } | |
| 146 | |
| 147 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
| 148 std::vector<std::string> result; | |
| 149 #define IN_VECTOR(v, k) (std::count(v.begin(), v.end(), k)) | |
| 150 #define ADD_TO_SYNONYMS(v, k) \ | |
| 151 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \ | |
| 152 v.push_back(k) | |
| 153 ADD_TO_SYNONYMS(result, info_.title.english); | |
| 154 ADD_TO_SYNONYMS(result, info_.title.romaji); | |
| 155 ADD_TO_SYNONYMS(result, info_.title.native); | |
| 156 for (auto& synonym : info_.synonyms) { | |
| 157 ADD_TO_SYNONYMS(result, synonym); | |
| 158 } | |
| 159 #undef ADD_TO_SYNONYMS | |
| 160 #undef IN_VECTOR | |
| 161 return result; | |
| 162 } | |
| 163 | |
| 164 int Anime::GetEpisodes() const { | |
| 165 return info_.episodes; | |
| 166 } | |
| 167 | |
| 168 SeriesStatus Anime::GetAiringStatus() const { | |
| 169 return info_.status; | |
| 170 } | |
| 171 | |
| 172 Date Anime::GetAirDate() const { | |
| 173 return info_.air_date; | |
| 174 } | |
| 175 | |
| 176 std::vector<std::string> Anime::GetGenres() const { | |
| 177 return info_.genres; | |
| 178 } | |
| 179 | |
| 180 std::vector<std::string> Anime::GetProducers() const { | |
| 181 return info_.producers; | |
| 182 } | |
| 183 | |
| 184 SeriesFormat Anime::GetFormat() const { | |
| 185 return info_.format; | |
| 186 } | |
| 187 | |
| 188 SeriesSeason Anime::GetSeason() const { | |
| 189 return info_.season; | |
| 190 } | |
| 191 | |
| 192 int Anime::GetAudienceScore() const { | |
| 193 return info_.audience_score; | |
| 194 } | |
| 195 | |
| 196 std::string Anime::GetSynopsis() const { | |
| 197 return info_.synopsis; | |
| 198 } | |
| 199 | |
| 200 int Anime::GetDuration() const { | |
| 201 return info_.duration; | |
| 202 } | |
| 203 | |
| 204 void Anime::SetId(int id) { | |
| 205 info_.id = id; | |
| 206 } | |
| 207 | |
| 208 void Anime::SetRomajiTitle(std::string const& title) { | |
| 209 info_.title.romaji = title; | |
| 210 } | |
| 211 | |
| 212 void Anime::SetEnglishTitle(std::string const& title) { | |
| 213 info_.title.english = title; | |
| 214 } | |
| 215 | |
| 216 void Anime::SetNativeTitle(std::string const& title) { | |
| 217 info_.title.native = title; | |
| 218 } | |
| 219 | |
| 220 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
| 221 info_.synonyms = synonyms; | |
| 222 } | |
| 223 | |
| 224 void Anime::AddTitleSynonym(std::string const& synonym) { | |
| 225 info_.synonyms.push_back(synonym); | |
| 226 } | |
| 227 | |
| 228 void Anime::SetEpisodes(int episodes) { | |
| 229 info_.episodes = episodes; | |
| 230 } | |
| 231 | |
| 232 void Anime::SetAiringStatus(SeriesStatus status) { | |
| 233 info_.status = status; | |
| 234 } | |
| 235 | |
| 236 void Anime::SetAirDate(Date const& date) { | |
| 237 info_.air_date = date; | |
| 238 } | |
| 239 | |
| 240 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
| 241 info_.genres = genres; | |
| 242 } | |
| 243 | |
| 244 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
| 245 info_.producers = producers; | |
| 246 } | |
| 247 | |
| 248 void Anime::SetFormat(SeriesFormat format) { | |
| 249 info_.format = format; | |
| 250 } | |
| 251 | |
| 252 void Anime::SetSeason(SeriesSeason season) { | |
| 253 info_.season = season; | |
| 254 } | |
| 255 | |
| 256 void Anime::SetAudienceScore(int audience_score) { | |
| 257 info_.audience_score = audience_score; | |
| 258 } | |
| 259 | |
| 260 void Anime::SetSynopsis(std::string synopsis) { | |
| 261 info_.synopsis = synopsis; | |
| 262 } | |
| 263 | |
| 264 void Anime::SetDuration(int duration) { | |
| 265 info_.duration = duration; | |
| 266 } | |
| 267 | |
| 268 std::string Anime::GetUserPreferredTitle() const { | |
| 269 switch (session.config.anime_list.language) { | |
| 270 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | |
| 271 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
| 272 default: break; | |
| 273 } | |
| 274 return GetRomajiTitle(); | |
| 275 } | |
| 276 | |
| 277 } // namespace Anime |
