2023-01-23 14:03:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
#include "ModModel.h"
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
|
|
|
#include "minecraft/PackProfile.h"
|
2023-06-08 18:26:09 +01:00
|
|
|
#include "minecraft/mod/ModFolderModel.h"
|
2022-07-15 02:23:41 +01:00
|
|
|
|
2022-03-03 00:17:10 +00:00
|
|
|
#include <QMessageBox>
|
2023-06-08 18:26:09 +01:00
|
|
|
#include <algorithm>
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
namespace ResourceDownload {
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2023-06-10 20:04:08 +01:00
|
|
|
ModModel::ModModel(BaseInstance& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
2022-03-07 22:29:59 +00:00
|
|
|
|
|
|
|
/******** Make data requests ********/
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
2022-03-07 22:29:59 +00:00
|
|
|
{
|
2022-12-18 18:41:46 +00:00
|
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
|
|
|
|
Q_ASSERT(profile);
|
|
|
|
Q_ASSERT(m_filter);
|
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
std::optional<std::list<Version>> versions{};
|
|
|
|
|
2023-06-10 20:04:08 +01:00
|
|
|
{ // Version filter
|
2022-12-20 15:15:17 +00:00
|
|
|
if (!m_filter->versions.empty())
|
|
|
|
versions = m_filter->versions;
|
|
|
|
}
|
2022-12-18 18:41:46 +00:00
|
|
|
|
2022-12-23 20:28:42 +00:00
|
|
|
auto sort = getCurrentSortingMethodByIndex();
|
2022-12-20 15:15:17 +00:00
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
return { ModPlatform::ResourceType::MOD, m_next_search_offset, m_search_term, sort, profile->getSupportedModLoaders(), versions };
|
2022-03-07 22:29:59 +00:00
|
|
|
}
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
2022-07-18 23:17:44 +01:00
|
|
|
{
|
2023-05-27 03:21:07 +01:00
|
|
|
auto& pack = *m_packs[entry.row()];
|
2022-12-18 18:41:46 +00:00
|
|
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
|
|
|
|
|
|
|
Q_ASSERT(profile);
|
|
|
|
Q_ASSERT(m_filter);
|
2022-07-18 23:17:44 +01:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
std::optional<std::list<Version>> versions{};
|
|
|
|
if (!m_filter->versions.empty())
|
2022-12-18 18:41:46 +00:00
|
|
|
versions = m_filter->versions;
|
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
return { pack, versions, profile->getSupportedModLoaders() };
|
2022-07-18 23:17:44 +01:00
|
|
|
}
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
2022-05-24 13:38:48 +01:00
|
|
|
{
|
2023-05-27 03:21:07 +01:00
|
|
|
auto& pack = *m_packs[entry.row()];
|
2022-11-25 12:23:46 +00:00
|
|
|
return { pack };
|
2022-05-24 13:38:48 +01:00
|
|
|
}
|
2022-03-03 00:17:10 +00:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filter_changed)
|
2022-04-02 23:21:02 +01:00
|
|
|
{
|
2022-12-20 15:15:17 +00:00
|
|
|
if (m_search_term == term && m_search_term.isNull() == term.isNull() && m_current_sort_index == sort && !filter_changed) {
|
2022-05-08 08:22:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-04-14 14:27:03 +01:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
setSearchTerm(term);
|
2022-12-20 15:15:17 +00:00
|
|
|
m_current_sort_index = sort;
|
2022-04-02 23:21:02 +01:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2023-06-08 18:26:09 +01:00
|
|
|
bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const
|
|
|
|
{
|
2023-06-10 20:04:08 +01:00
|
|
|
auto allMods = static_cast<MinecraftInstance&>(m_base_instance).loaderModList()->allMods();
|
2023-06-08 18:26:09 +01:00
|
|
|
return std::any_of(allMods.cbegin(), allMods.cend(), [pack](Mod* mod) {
|
|
|
|
if (auto meta = mod->metadata(); meta)
|
|
|
|
return meta->provider == pack->provider && meta->project_id == pack->addonId;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
} // namespace ResourceDownload
|