Mercurial > minori
annotate src/anime.cpp @ 8:b1f73678ef61
update
text paragraphs are now their own objects, as they should be
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 26 Aug 2023 03:39:34 -0400 |
parents | 07a9095eaeed |
children |
rev | line source |
---|---|
7 | 1 /* |
2 * anime.cpp: defining of custom anime-related | |
3 * datatypes & variables | |
4 */ | |
2 | 5 #include <chrono> |
6 #include <string> | |
7 #include <vector> | |
8 #include <cmath> | |
7 | 9 #include <algorithm> |
2 | 10 #include "anilist.h" |
11 #include "anime.h" | |
12 #include "date.h" | |
7 | 13 #include "session.h" |
2 | 14 |
15 std::map<enum AnimeWatchingStatus, std::string> AnimeWatchingToStringMap = { | |
16 {CURRENT, "Watching"}, | |
17 {PLANNING, "Planning"}, | |
18 {COMPLETED, "Completed"}, | |
19 {DROPPED, "Dropped"}, | |
20 {PAUSED, "On hold"}, | |
21 {REPEATING, "Rewatching"} | |
22 }; | |
23 | |
24 std::map<enum AnimeAiringStatus, std::string> AnimeAiringToStringMap = { | |
25 {FINISHED, "Finished"}, | |
26 {RELEASING, "Airing"}, | |
27 {NOT_YET_RELEASED, "Not aired yet"}, | |
28 {CANCELLED, "Cancelled"}, | |
29 {HIATUS, "On hiatus"} | |
30 }; | |
31 | |
32 std::map<enum AnimeSeason, std::string> AnimeSeasonToStringMap = { | |
33 {UNKNOWN, "Unknown"}, | |
34 {WINTER, "Winter"}, | |
35 {SPRING, "Spring"}, | |
36 {SUMMER, "Summer"}, | |
37 {FALL, "Fall"} | |
38 }; | |
39 | |
40 std::map<enum AnimeFormat, std::string> AnimeFormatToStringMap = { | |
41 {TV, "TV"}, | |
42 {TV_SHORT, "TV short"}, | |
43 {MOVIE, "Movie"}, | |
44 {SPECIAL, "Special"}, | |
45 {OVA, "OVA"}, | |
46 {ONA, "ONA"}, | |
47 {MUSIC, "Music video"}, | |
48 /* these should NEVER be in the list. naybe we should | |
49 remove them? */ | |
50 {MANGA, "Manga"}, | |
51 {NOVEL, "Novel"}, | |
52 {ONE_SHOT, "One-shot"} | |
53 }; | |
54 | |
55 Anime::Anime() {} | |
56 Anime::Anime(const Anime& a) { | |
57 status = a.status; | |
58 progress = a.progress; | |
59 score = a.score; | |
60 started = a.started; | |
61 completed = a.completed; | |
62 updated = a.updated; | |
63 notes = a.notes; | |
64 id = a.id; | |
65 title = a.title; | |
66 episodes = a.episodes; | |
67 airing = a.airing; | |
68 air_date = a.air_date; | |
69 genres = a.genres; | |
70 producers = a.producers; | |
71 type = a.type; | |
72 season = a.season; | |
73 audience_score = a.audience_score; | |
74 synopsis = a.synopsis; | |
75 duration = a.duration; | |
76 } | |
77 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
3
diff
changeset
|
78 std::string Anime::GetUserPreferredTitle() { |
7 | 79 switch (session.config.anime_list.language) { |
80 case NATIVE: | |
81 return (title.native.empty()) ? title.romaji : title.native; | |
82 case ENGLISH: | |
83 return (title.english.empty()) ? title.romaji : title.english; | |
84 default: | |
85 return title.romaji; | |
86 } | |
87 } | |
88 | |
89 std::vector<std::string> Anime::GetTitleSynonyms() { | |
90 std::vector<std::string> result; | |
91 #define IN_VECTOR(v, k) \ | |
92 (std::count(v.begin(), v.end(), k)) | |
93 #define ADD_TO_SYNONYMS(v, k) \ | |
94 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) v.push_back(k) | |
95 ADD_TO_SYNONYMS(result, title.english); | |
96 ADD_TO_SYNONYMS(result, title.romaji); | |
97 ADD_TO_SYNONYMS(result, title.native); | |
98 for (auto& synonym : synonyms) { | |
99 ADD_TO_SYNONYMS(result, synonym); | |
100 } | |
101 #undef ADD_TO_SYNONYMS | |
102 #undef IN_VECTOR | |
103 return result; | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
3
diff
changeset
|
104 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
3
diff
changeset
|
105 |
2 | 106 void AnimeList::Add(Anime& anime) { |
107 if (anime_id_to_anime.contains(anime.id)) | |
108 return; | |
109 anime_list.push_back(anime); | |
110 anime_id_to_anime.emplace(anime.id, &anime); | |
111 } | |
112 | |
113 void AnimeList::Insert(size_t pos, Anime& anime) { | |
114 if (anime_id_to_anime.contains(anime.id)) | |
115 return; | |
116 anime_list.insert(anime_list.begin()+pos, anime); | |
117 anime_id_to_anime.emplace(anime.id, &anime); | |
118 } | |
119 | |
120 void AnimeList::Delete(size_t index) { | |
121 anime_list.erase(anime_list.begin()+index); | |
122 } | |
123 | |
124 void AnimeList::Clear() { | |
125 anime_list.clear(); | |
126 } | |
127 | |
128 size_t AnimeList::Size() const { | |
129 return anime_list.size(); | |
130 } | |
131 | |
132 std::vector<Anime>::iterator AnimeList::begin() noexcept { | |
133 return anime_list.begin(); | |
134 } | |
135 | |
136 std::vector<Anime>::iterator AnimeList::end() noexcept { | |
137 return anime_list.end(); | |
138 } | |
139 | |
140 std::vector<Anime>::const_iterator AnimeList::cbegin() noexcept { | |
141 return anime_list.cbegin(); | |
142 } | |
143 | |
144 std::vector<Anime>::const_iterator AnimeList::cend() noexcept { | |
145 return anime_list.cend(); | |
146 } | |
147 | |
148 AnimeList::AnimeList() {} | |
149 AnimeList::AnimeList(const AnimeList& l) { | |
3 | 150 for (unsigned long long i = 0; i < l.Size(); i++) { |
2 | 151 anime_list.push_back(Anime(l[i])); |
152 } | |
153 name = l.name; | |
154 } | |
155 | |
7 | 156 AnimeList& AnimeList::operator=(const AnimeList& l) { |
157 if (this != &l) { | |
158 for (unsigned long long i = 0; i < l.Size(); i++) { | |
159 this->anime_list.push_back(Anime(l[i])); | |
160 } | |
161 this->name = l.name; | |
162 } | |
163 return *this; | |
164 } | |
165 | |
2 | 166 AnimeList::~AnimeList() { |
167 anime_list.clear(); | |
168 anime_list.shrink_to_fit(); | |
169 } | |
170 | |
171 Anime* AnimeList::AnimeById(int id) { | |
172 return anime_id_to_anime.contains(id) ? anime_id_to_anime[id] : nullptr; | |
173 } | |
174 | |
175 bool AnimeList::AnimeInList(int id) { | |
176 return anime_id_to_anime.contains(id); | |
177 } | |
178 | |
179 int AnimeList::GetAnimeIndex(Anime& anime) const { | |
3 | 180 for (unsigned long long i = 0; i < Size(); i++) { |
2 | 181 if (&anime_list.at(i) == &anime) { // lazy |
182 return i; | |
183 } | |
184 } | |
185 return -1; | |
186 } | |
187 | |
188 Anime& AnimeList::operator[](std::size_t index) { | |
189 return anime_list.at(index); | |
190 } | |
191 | |
192 const Anime& AnimeList::operator[](std::size_t index) const { | |
193 return anime_list.at(index); | |
194 } |