mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-25 17:07:58 -05:00
add option for single-page local mods list
This commit is contained in:
parent
a3b306a4e0
commit
efb1fbf729
6 changed files with 38 additions and 13 deletions
|
@ -85,6 +85,12 @@
|
|||
"name": "Enable Geode-Themed Colors",
|
||||
"description": "When enabled, the Geode menu has a <ca>Geode-themed color scheme</c>. <cy>This does not affect any other menus!</c>"
|
||||
},
|
||||
"infinite-local-mods-list": {
|
||||
"type": "bool",
|
||||
"default": false,
|
||||
"name": "Expand Installed Mods List",
|
||||
"description": "Make the installed mods list a single infinite scrollable list instead of having pages"
|
||||
},
|
||||
"developer-title": {
|
||||
"type": "title",
|
||||
"name": "Developer Settings"
|
||||
|
|
|
@ -68,9 +68,15 @@ void InstalledModListSource::resetQuery() {
|
|||
};
|
||||
}
|
||||
|
||||
InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) {
|
||||
InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, bool forceUpdate) {
|
||||
m_query.page = page;
|
||||
m_query.pageSize = pageSize;
|
||||
m_query.pageSize = m_pageSize;
|
||||
|
||||
// Infinite mods list option
|
||||
if (Mod::get()->template getSettingValue<bool>("infinite-local-mods-list")) {
|
||||
m_query.page = 0;
|
||||
m_query.pageSize = Loader::get()->getAllMods().size();
|
||||
}
|
||||
|
||||
auto content = ModListSource::ProvidedMods();
|
||||
for (auto& mod : Loader::get()->getAllMods()) {
|
||||
|
@ -122,3 +128,12 @@ InvalidateQueryAfter<InstalledModsQuery> InstalledModListSource::getQueryMut() {
|
|||
bool InstalledModListSource::isDefaultQuery() const {
|
||||
return m_query.isDefault();
|
||||
}
|
||||
|
||||
$execute {
|
||||
listenForSettingChanges("infinite-local-mods-list", [](bool value) {
|
||||
auto size = value ? std::numeric_limits<size_t>::max() : 10;
|
||||
InstalledModListSource::get(InstalledModListType::All)->setPageSize(size);
|
||||
InstalledModListSource::get(InstalledModListType::OnlyErrors)->setPageSize(size);
|
||||
// Updates is technically a server mod list :-) So I left it out here
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#define FTS_FUZZY_MATCH_IMPLEMENTATION
|
||||
#include <Geode/external/fts/fts_fuzzy_match.h>
|
||||
|
||||
static constexpr size_t PER_PAGE = 10;
|
||||
static std::vector<ModListSource*> ALL_EXTANT_SOURCES {};
|
||||
|
||||
static size_t ceildiv(size_t a, size_t b) {
|
||||
|
@ -33,7 +32,7 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f
|
|||
return PageLoadTask::immediate(Ok(m_cachedPages.at(page)));
|
||||
}
|
||||
m_cachedPages.erase(page);
|
||||
return this->fetchPage(page, PER_PAGE, forceUpdate).map(
|
||||
return this->fetchPage(page, forceUpdate).map(
|
||||
[this, page](Result<ProvidedMods, LoadPageError>* result) -> Result<Page, LoadPageError> {
|
||||
if (result->isOk()) {
|
||||
auto data = result->unwrap();
|
||||
|
@ -56,12 +55,15 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f
|
|||
}
|
||||
|
||||
std::optional<size_t> ModListSource::getPageCount() const {
|
||||
return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), PER_PAGE)) : std::nullopt;
|
||||
return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), m_pageSize)) : std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<size_t> ModListSource::getItemCount() const {
|
||||
return m_cachedItemCount;
|
||||
}
|
||||
void ModListSource::setPageSize(size_t size) {
|
||||
m_pageSize = size;
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void ModListSource::reset() {
|
||||
this->resetQuery();
|
||||
|
|
|
@ -51,9 +51,10 @@ public:
|
|||
protected:
|
||||
std::unordered_map<size_t, Page> m_cachedPages;
|
||||
std::optional<size_t> m_cachedItemCount;
|
||||
size_t m_pageSize = 10;
|
||||
|
||||
virtual void resetQuery() = 0;
|
||||
virtual ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) = 0;
|
||||
virtual ProviderTask fetchPage(size_t page, bool forceUpdate) = 0;
|
||||
virtual void setSearchQuery(std::string const& query) = 0;
|
||||
|
||||
ModListSource();
|
||||
|
@ -75,6 +76,7 @@ public:
|
|||
PageLoadTask loadPage(size_t page, bool forceUpdate = false);
|
||||
std::optional<size_t> getPageCount() const;
|
||||
std::optional<size_t> getItemCount() const;
|
||||
void setPageSize(size_t size);
|
||||
|
||||
static void clearAllCaches();
|
||||
static bool isRestartRequired();
|
||||
|
@ -123,7 +125,7 @@ protected:
|
|||
InstalledModsQuery m_query;
|
||||
|
||||
void resetQuery() override;
|
||||
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override;
|
||||
ProviderTask fetchPage(size_t page, bool forceUpdate) override;
|
||||
void setSearchQuery(std::string const& query) override;
|
||||
|
||||
InstalledModListSource(InstalledModListType type);
|
||||
|
@ -153,7 +155,7 @@ protected:
|
|||
server::ModsQuery m_query;
|
||||
|
||||
void resetQuery() override;
|
||||
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override;
|
||||
ProviderTask fetchPage(size_t page, bool forceUpdate) override;
|
||||
void setSearchQuery(std::string const& query) override;
|
||||
|
||||
ServerModListSource(ServerModListType type);
|
||||
|
@ -174,7 +176,7 @@ public:
|
|||
class ModPackListSource : public ModListSource {
|
||||
protected:
|
||||
void resetQuery() override;
|
||||
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override;
|
||||
ProviderTask fetchPage(size_t page, bool forceUpdate) override;
|
||||
void setSearchQuery(std::string const& query) override;
|
||||
|
||||
ModPackListSource();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "ModListSource.hpp"
|
||||
|
||||
void ModPackListSource::resetQuery() {}
|
||||
ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) {
|
||||
ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, bool forceUpdate) {
|
||||
return ProviderTask::immediate(Err(LoadPageError("Coming soon ;)")));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ void ServerModListSource::resetQuery() {
|
|||
m_query = this->createDefaultQuery();
|
||||
}
|
||||
|
||||
ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) {
|
||||
ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, bool forceUpdate) {
|
||||
m_query.page = page;
|
||||
m_query.pageSize = pageSize;
|
||||
m_query.pageSize = m_pageSize;
|
||||
return server::getMods(m_query, !forceUpdate).map(
|
||||
[](Result<server::ServerModsList, server::ServerError>* result) -> ProviderTask::Value {
|
||||
if (result->isOk()) {
|
||||
|
|
Loading…
Reference in a new issue