Removed extra code
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
f738d7566e
commit
248920a221
@ -95,7 +95,6 @@ struct IndexedPack {
|
|||||||
|
|
||||||
bool versionsLoaded = false;
|
bool versionsLoaded = false;
|
||||||
QVector<IndexedVersion> versions;
|
QVector<IndexedVersion> versions;
|
||||||
QVariant loadedFileId; // to check for already downloaded mods
|
|
||||||
|
|
||||||
// Don't load by default, since some modplatform don't have that info
|
// Don't load by default, since some modplatform don't have that info
|
||||||
bool extraDataLoaded = true;
|
bool extraDataLoaded = true;
|
||||||
@ -111,8 +110,6 @@ struct IndexedPack {
|
|||||||
}
|
}
|
||||||
[[nodiscard]] bool isAnyVersionSelected() const
|
[[nodiscard]] bool isAnyVersionSelected() const
|
||||||
{
|
{
|
||||||
if (loadedFileId.isValid())
|
|
||||||
return true;
|
|
||||||
if (!versionsLoaded)
|
if (!versionsLoaded)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -161,8 +161,8 @@ void ResourceDownloadDialog::addResource(ModPlatform::IndexedPack& pack, ModPlat
|
|||||||
|
|
||||||
void ResourceDownloadDialog::removeResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver)
|
void ResourceDownloadDialog::removeResource(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& ver)
|
||||||
{
|
{
|
||||||
dynamic_cast<ResourcePage*>(m_container->getPage(Modrinth::id()))->removeResourceFromPage(pack.name);
|
for (auto page : m_container->getPages())
|
||||||
dynamic_cast<ResourcePage*>(m_container->getPage(Flame::id()))->removeResourceFromPage(pack.name);
|
static_cast<ResourcePage*>(page)->removeResourceFromPage(pack.name);
|
||||||
|
|
||||||
// Deselect the new version too, since all versions of that pack got removed.
|
// Deselect the new version too, since all versions of that pack got removed.
|
||||||
ver.is_currently_selected = false;
|
ver.is_currently_selected = false;
|
||||||
|
@ -13,16 +13,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst)
|
ModModel::ModModel(BaseInstance const& base_inst, ResourceAPI* api) : ResourceModel(api), m_base_instance(base_inst) {}
|
||||||
{
|
|
||||||
auto folder = static_cast<MinecraftInstance const&>(m_base_instance).loaderModList();
|
|
||||||
for (auto mod : folder->allMods()) {
|
|
||||||
auto meta = mod->metadata();
|
|
||||||
ModPlatform::IndexedPack pack{ meta->project_id, meta->provider, meta->name, meta->slug };
|
|
||||||
pack.loadedFileId = meta->file_id;
|
|
||||||
addPack(pack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******** Make data requests ********/
|
/******** Make data requests ********/
|
||||||
|
|
||||||
|
@ -148,8 +148,8 @@ void ModPage::updateVersionList()
|
|||||||
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
void ModPage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||||
{
|
{
|
||||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||||
m_model->addPack(pack);
|
|
||||||
m_parent_dialog->addResource(pack, version, is_indexed);
|
m_parent_dialog->addResource(pack, version, is_indexed);
|
||||||
|
m_model->addPack(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -343,7 +343,6 @@ void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
|
|||||||
sel != m_selected.end()) {
|
sel != m_selected.end()) {
|
||||||
pack.versionsLoaded = sel->versionsLoaded;
|
pack.versionsLoaded = sel->versionsLoaded;
|
||||||
pack.versions = sel->versions;
|
pack.versions = sel->versions;
|
||||||
pack.loadedFileId = sel->loadedFileId;
|
|
||||||
}
|
}
|
||||||
newList.append(pack);
|
newList.append(pack);
|
||||||
} catch (const JSONValidationError& e) {
|
} catch (const JSONValidationError& e) {
|
||||||
@ -408,12 +407,6 @@ void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::Ind
|
|||||||
try {
|
try {
|
||||||
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
|
auto arr = doc.isObject() ? Json::ensureArray(doc.object(), "data") : doc.array();
|
||||||
loadIndexedPackVersions(current_pack, arr);
|
loadIndexedPackVersions(current_pack, arr);
|
||||||
if (current_pack.loadedFileId.isValid())
|
|
||||||
if (auto ver =
|
|
||||||
std::find_if(current_pack.versions.begin(), current_pack.versions.end(),
|
|
||||||
[¤t_pack](const ModPlatform::IndexedVersion& v) { return v.fileId == current_pack.loadedFileId; });
|
|
||||||
ver != current_pack.versions.end())
|
|
||||||
ver->is_currently_selected = true;
|
|
||||||
} catch (const JSONValidationError& e) {
|
} catch (const JSONValidationError& e) {
|
||||||
qDebug() << doc;
|
qDebug() << doc;
|
||||||
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
|
qWarning() << "Error while reading " << debugName() << " resource version: " << e.cause();
|
||||||
@ -463,41 +456,19 @@ void ResourceModel::removePack(QString& rem)
|
|||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
|
||||||
m_selected.removeIf(pred);
|
m_selected.removeIf(pred);
|
||||||
#else
|
#else
|
||||||
{ // well partial implementation of remove_if in case the QT Version is not high enough
|
{
|
||||||
const auto cbegin = m_selected.cbegin();
|
for (auto it = m_selected.begin(); it != m_selected.end();)
|
||||||
const auto cend = m_selected.cend();
|
if (pred(*it))
|
||||||
const auto t_it = std::find_if(cbegin, cend, pred);
|
it = m_selected.erase(it);
|
||||||
auto result = std::distance(cbegin, t_it);
|
else
|
||||||
if (result != m_selected.size()) {
|
++it;
|
||||||
// now detach:
|
|
||||||
const auto e = m_selected.end();
|
|
||||||
|
|
||||||
auto it = std::next(m_selected.begin(), result);
|
|
||||||
auto dest = it;
|
|
||||||
|
|
||||||
// Loop Invariants:
|
|
||||||
// - it != e
|
|
||||||
// - [next(it), e[ still to be checked
|
|
||||||
// - [c.begin(), dest[ are result
|
|
||||||
while (++it != e) {
|
|
||||||
if (!pred(*it)) {
|
|
||||||
*dest = std::move(*it);
|
|
||||||
++dest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = std::distance(dest, e);
|
|
||||||
m_selected.erase(dest, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// m_selected.removeAt(qsizetype i)
|
|
||||||
auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](const ModPlatform::IndexedPack& i) { return rem == i.name; });
|
auto pack = std::find_if(m_packs.begin(), m_packs.end(), [&rem](const ModPlatform::IndexedPack& i) { return rem == i.name; });
|
||||||
if (pack == m_packs.end()) { // ignore it if is not in the current search
|
if (pack == m_packs.end()) { // ignore it if is not in the current search
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pack->versionsLoaded) {
|
if (!pack->versionsLoaded) {
|
||||||
pack->loadedFileId = {};
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto& ver : pack->versions)
|
for (auto& ver : pack->versions)
|
||||||
|
@ -308,8 +308,8 @@ void ResourcePage::onVersionSelectionChanged(QString data)
|
|||||||
|
|
||||||
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
void ResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||||
{
|
{
|
||||||
m_model->addPack(pack);
|
|
||||||
m_parent_dialog->addResource(pack, version);
|
m_parent_dialog->addResource(pack, version);
|
||||||
|
m_model->addPack(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::removeResourceFromDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
void ResourcePage::removeResourceFromDialog(ModPlatform::IndexedPack& pack, ModPlatform::IndexedVersion& version)
|
||||||
|
@ -47,8 +47,8 @@ void ShaderPackResourcePage::addResourceToDialog(ModPlatform::IndexedPack& pack,
|
|||||||
{
|
{
|
||||||
if (version.loaders.contains(QStringLiteral("canvas")))
|
if (version.loaders.contains(QStringLiteral("canvas")))
|
||||||
version.custom_target_folder = QStringLiteral("resourcepacks");
|
version.custom_target_folder = QStringLiteral("resourcepacks");
|
||||||
m_model->addPack(pack);
|
|
||||||
m_parent_dialog->addResource(pack, version);
|
m_parent_dialog->addResource(pack, version);
|
||||||
|
m_model->addPack(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -135,6 +135,11 @@ BasePage* PageContainer::getPage(QString pageId)
|
|||||||
return m_model->findPageEntryById(pageId);
|
return m_model->findPageEntryById(pageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<BasePage*> PageContainer::getPages() const
|
||||||
|
{
|
||||||
|
return m_model->pages();
|
||||||
|
}
|
||||||
|
|
||||||
void PageContainer::refreshContainer()
|
void PageContainer::refreshContainer()
|
||||||
{
|
{
|
||||||
m_proxyModel->invalidate();
|
m_proxyModel->invalidate();
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
|
|
||||||
virtual bool selectPage(QString pageId) override;
|
virtual bool selectPage(QString pageId) override;
|
||||||
BasePage* getPage(QString pageId) override;
|
BasePage* getPage(QString pageId) override;
|
||||||
|
const QList<BasePage*> getPages() const;
|
||||||
|
|
||||||
void refreshContainer() override;
|
void refreshContainer() override;
|
||||||
virtual void setParentContainer(BasePageContainer * container)
|
virtual void setParentContainer(BasePageContainer * container)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user