Mercurial > minori
annotate src/core/anime.cc @ 178:bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 11:51:30 -0500 |
parents | 9b2b41f83a5e |
children | 01d259b9c89f |
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" | |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
8 |
9 | 9 #include <algorithm> |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 namespace Anime { | |
14 | |
15 /* User list data */ | |
16 bool Anime::IsInUserList() const { | |
17 if (list_info_.get()) | |
18 return true; | |
19 return false; | |
20 } | |
21 | |
22 void Anime::AddToUserList() { | |
23 list_info_.reset(new ListInformation); | |
24 } | |
25 | |
26 void Anime::RemoveFromUserList() { | |
27 list_info_.reset(); | |
28 } | |
29 | |
30 ListStatus Anime::GetUserStatus() const { | |
31 assert(list_info_.get()); | |
32 return list_info_->status; | |
33 } | |
34 | |
35 int Anime::GetUserProgress() const { | |
36 assert(list_info_.get()); | |
37 return list_info_->progress; | |
38 } | |
39 | |
40 int Anime::GetUserScore() const { | |
41 assert(list_info_.get()); | |
42 return list_info_->score; | |
43 } | |
44 | |
45 Date Anime::GetUserDateStarted() const { | |
46 assert(list_info_.get()); | |
47 return list_info_->started; | |
48 } | |
49 | |
50 Date Anime::GetUserDateCompleted() const { | |
51 assert(list_info_.get()); | |
52 return list_info_->completed; | |
53 } | |
54 | |
55 bool Anime::GetUserIsPrivate() const { | |
56 assert(list_info_.get()); | |
57 return list_info_->is_private; | |
58 } | |
59 | |
60 unsigned int Anime::GetUserRewatchedTimes() const { | |
61 assert(list_info_.get()); | |
62 return list_info_->rewatched_times; | |
63 } | |
64 | |
65 bool Anime::GetUserIsRewatching() const { | |
66 assert(list_info_.get()); | |
67 return list_info_->rewatching; | |
68 } | |
69 | |
70 uint64_t Anime::GetUserTimeUpdated() const { | |
71 assert(list_info_.get()); | |
72 return list_info_->updated; | |
73 } | |
74 | |
75 std::string Anime::GetUserNotes() const { | |
76 assert(list_info_.get()); | |
77 return list_info_->notes; | |
78 } | |
79 | |
80 void Anime::SetUserStatus(ListStatus status) { | |
81 assert(list_info_.get()); | |
82 list_info_->status = status; | |
83 } | |
84 | |
10 | 85 void Anime::SetUserScore(int score) { |
86 assert(list_info_.get()); | |
87 list_info_->score = score; | |
88 } | |
89 | |
9 | 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)) | |
36 | 150 #define ADD_TO_SYNONYMS(v, k) \ |
151 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \ | |
9 | 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 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
204 std::string Anime::GetPosterUrl() const { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
205 return info_.poster_url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
206 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
207 |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
208 std::string Anime::GetServiceUrl() const { |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
209 return "https://anilist.co/anime/" + std::to_string(GetId()); |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
210 } |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
211 |
9 | 212 void Anime::SetId(int id) { |
213 info_.id = id; | |
214 } | |
215 | |
216 void Anime::SetRomajiTitle(std::string const& title) { | |
217 info_.title.romaji = title; | |
218 } | |
219 | |
220 void Anime::SetEnglishTitle(std::string const& title) { | |
221 info_.title.english = title; | |
222 } | |
223 | |
224 void Anime::SetNativeTitle(std::string const& title) { | |
225 info_.title.native = title; | |
226 } | |
227 | |
228 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
229 info_.synonyms = synonyms; | |
230 } | |
231 | |
232 void Anime::AddTitleSynonym(std::string const& synonym) { | |
233 info_.synonyms.push_back(synonym); | |
234 } | |
235 | |
236 void Anime::SetEpisodes(int episodes) { | |
237 info_.episodes = episodes; | |
238 } | |
239 | |
240 void Anime::SetAiringStatus(SeriesStatus status) { | |
241 info_.status = status; | |
242 } | |
243 | |
244 void Anime::SetAirDate(Date const& date) { | |
245 info_.air_date = date; | |
246 } | |
247 | |
248 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
249 info_.genres = genres; | |
250 } | |
251 | |
252 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
253 info_.producers = producers; | |
254 } | |
255 | |
256 void Anime::SetFormat(SeriesFormat format) { | |
257 info_.format = format; | |
258 } | |
259 | |
260 void Anime::SetSeason(SeriesSeason season) { | |
261 info_.season = season; | |
262 } | |
263 | |
264 void Anime::SetAudienceScore(int audience_score) { | |
265 info_.audience_score = audience_score; | |
266 } | |
267 | |
268 void Anime::SetSynopsis(std::string synopsis) { | |
269 info_.synopsis = synopsis; | |
270 } | |
271 | |
272 void Anime::SetDuration(int duration) { | |
273 info_.duration = duration; | |
274 } | |
275 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
276 void Anime::SetPosterUrl(std::string url) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
277 info_.poster_url = url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
278 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
279 |
9 | 280 std::string Anime::GetUserPreferredTitle() const { |
281 switch (session.config.anime_list.language) { | |
282 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | |
283 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
284 default: break; | |
285 } | |
286 return GetRomajiTitle(); | |
287 } | |
288 | |
289 } // namespace Anime |