# HG changeset patch # User Paper # Date 1718253720 14400 # Node ID 10096c5489e3aeed57de4db2bb21979c530c0aee # Parent 78929794e7d8a961f8b5eb95f6017f7163b05032 anime/db: refactor anime_season_db out diff -r 78929794e7d8 -r 10096c5489e3 Makefile.am --- a/Makefile.am Thu Jun 13 00:36:41 2024 -0400 +++ b/Makefile.am Thu Jun 13 00:42:00 2024 -0400 @@ -158,7 +158,6 @@ include/core/anime_db.h \ include/core/anime.h \ include/core/anime_season.h \ - include/core/anime_season_db.h \ include/core/config.h \ include/core/date.h \ include/core/filesystem.h \ @@ -213,7 +212,6 @@ src/core/anime_db.cc \ src/core/anime.cc \ src/core/anime_season.cc \ - src/core/anime_season_db.cc \ src/core/config.cc \ src/core/date.cc \ src/core/filesystem.cc \ diff -r 78929794e7d8 -r 10096c5489e3 include/core/anime_db.h --- a/include/core/anime_db.h Thu Jun 13 00:36:41 2024 -0400 +++ b/include/core/anime_db.h Thu Jun 13 00:42:00 2024 -0400 @@ -34,6 +34,8 @@ /* when syncing we don't want to keep deleted anime */ void RemoveAllUserData(); + + std::vector GetAllAnimeForSeason(SeriesSeason season, Date::Year year); }; extern Database db; diff -r 78929794e7d8 -r 10096c5489e3 include/core/anime_season.h --- a/include/core/anime_season.h Thu Jun 13 00:36:41 2024 -0400 +++ b/include/core/anime_season.h Thu Jun 13 00:42:00 2024 -0400 @@ -1,7 +1,7 @@ #ifndef MINORI_CORE_ANIME_SEASON_H_ #define MINORI_CORE_ANIME_SEASON_H_ -#include "core/anime.h" /* SeriesSeason */ +#include "core/anime.h" /* Anime::SeriesSeason */ #include "core/date.h" /* Date::Month */ namespace Anime { diff -r 78929794e7d8 -r 10096c5489e3 include/core/anime_season_db.h --- a/include/core/anime_season_db.h Thu Jun 13 00:36:41 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#ifndef MINORI_CORE_ANIME_SEASON_DB_H_ -#define MINORI_CORE_ANIME_SEASON_DB_H_ - -#include "core/anime.h" -#include "core/date.h" - -namespace Anime::Season { - -std::vector GetAllAnimeForSeason(SeriesSeason season, Date::Year year); - -} - -#endif // MINORI_CORE_ANIME_SEASON_DB_H_ diff -r 78929794e7d8 -r 10096c5489e3 src/core/anime_db.cc --- a/src/core/anime_db.cc Thu Jun 13 00:36:41 2024 -0400 +++ b/src/core/anime_db.cc Thu Jun 13 00:42:00 2024 -0400 @@ -347,6 +347,17 @@ } } +std::vector Database::GetAllAnimeForSeason(SeriesSeason season, Date::Year year) { + std::vector res; + + for (const auto& [id, anime] : items) { + if (anime.GetSeason() == season && anime.GetStartedDate().GetYear() == year) + res.push_back(id); + } + + return res; +} + Database db; } // namespace Anime diff -r 78929794e7d8 -r 10096c5489e3 src/core/anime_season.cc --- a/src/core/anime_season.cc Thu Jun 13 00:36:41 2024 -0400 +++ b/src/core/anime_season.cc Thu Jun 13 00:42:00 2024 -0400 @@ -2,8 +2,6 @@ namespace Anime { -/* MAL has a different idea of seasons than Kitsu/AniList - * prepare ahead of time for this discrepancy. */ SeriesSeason GetSeasonForMonth(Date::Month month) { switch (month) { case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: diff -r 78929794e7d8 -r 10096c5489e3 src/core/anime_season_db.cc --- a/src/core/anime_season_db.cc Thu Jun 13 00:36:41 2024 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -#include "core/anime_season_db.h" -#include "core/anime.h" -#include "core/anime_db.h" -#include "core/date.h" - -namespace Anime::Season { - -std::vector GetAllAnimeForSeason(SeriesSeason season, Date::Year year) { - std::vector ret; - - for (const auto& [id, anime] : db.items) { - std::optional anime_year = anime.GetStartedDate().GetYear(); - if (anime.GetSeason() == season && anime_year && anime_year.value() == year) - ret.push_back(id); - } - - return ret; -} - -} diff -r 78929794e7d8 -r 10096c5489e3 src/gui/pages/seasons.cc --- a/src/gui/pages/seasons.cc Thu Jun 13 00:36:41 2024 -0400 +++ b/src/gui/pages/seasons.cc Thu Jun 13 00:42:00 2024 -0400 @@ -1,7 +1,6 @@ #include "gui/pages/seasons.h" #include "core/anime_db.h" -#include "core/anime_season_db.h" #include "core/strings.h" #include "gui/widgets/anime_button.h" #include "gui/translate/anime.h" @@ -62,7 +61,7 @@ buttons->clear(); - for (const auto& id : Anime::Season::GetAllAnimeForSeason(season_, year_)) { + for (const auto& id : Anime::db.GetAllAnimeForSeason(season_, year_)) { QListWidgetItem* item = new QListWidgetItem; AnimeButton* button = new AnimeButton(this); button->SetAnime(Anime::db.items[id]);