aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-08-10 14:48:34 -0300
committerflow <flowlnlnln@gmail.com>2022-08-20 10:47:58 -0300
commit97a74d5c1f00a11d331a41b16690f7202fe102a3 (patch)
treee49ff4b05f4ac241a2df4920f3c6b4832bc0d252 /launcher/minecraft/mod
parent256f8094f5fed85ff9136e8d0b9c9677d7b9e9db (diff)
downloadPrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.tar.gz
PrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.tar.bz2
PrismLauncher-97a74d5c1f00a11d331a41b16690f7202fe102a3.zip
refactor: adapt rest of the codebase to the new resource model
In order to access the ModFolderModel from the ModFolderPage, i created a new m_model for the correct type, shadowing the m_model of type ResourceFolderModel. This creates two shared_ptr references to the same object, but since they will have the same lifetime, it doesn't generate a memory leak. Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/minecraft/mod')
-rw-r--r--launcher/minecraft/mod/Mod.h3
-rw-r--r--launcher/minecraft/mod/ModFolderModel.cpp2
-rw-r--r--launcher/minecraft/mod/Resource.h2
-rw-r--r--launcher/minecraft/mod/ResourceFolderModel.h3
-rw-r--r--launcher/minecraft/mod/ResourcePack.h13
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.cpp3
-rw-r--r--launcher/minecraft/mod/ResourcePackFolderModel.h4
-rw-r--r--launcher/minecraft/mod/ShaderPackFolderModel.h10
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.cpp22
-rw-r--r--launcher/minecraft/mod/TexturePackFolderModel.h6
10 files changed, 39 insertions, 29 deletions
diff --git a/launcher/minecraft/mod/Mod.h b/launcher/minecraft/mod/Mod.h
index 25ac88c9..0835e3b1 100644
--- a/launcher/minecraft/mod/Mod.h
+++ b/launcher/minecraft/mod/Mod.h
@@ -50,7 +50,8 @@ public:
Mod() = default;
Mod(const QFileInfo &file);
- explicit Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
+ Mod(const QDir& mods_dir, const Metadata::ModStruct& metadata);
+ Mod(QString file_path) : Mod(QFileInfo(file_path)) {}
auto enabled() const -> bool { return m_enabled; }
diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp
index 9b8c58bc..c316e710 100644
--- a/launcher/minecraft/mod/ModFolderModel.cpp
+++ b/launcher/minecraft/mod/ModFolderModel.cpp
@@ -49,7 +49,7 @@
#include "minecraft/mod/tasks/LocalModParseTask.h"
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
-ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(dir), m_is_indexed(is_indexed)
+ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : ResourceFolderModel(QDir(dir)), m_is_indexed(is_indexed)
{
FS::ensureFolderPathExists(m_dir.absolutePath());
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE };
diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h
index 68663ab0..bec7490f 100644
--- a/launcher/minecraft/mod/Resource.h
+++ b/launcher/minecraft/mod/Resource.h
@@ -34,6 +34,8 @@ class Resource : public QObject {
Resource(QObject* parent = nullptr);
Resource(QFileInfo file_info);
+ Resource(QString file_path) : Resource(QFileInfo(file_path)) {}
+
~Resource() override = default;
void setFile(QFileInfo file_info);
diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h
index 2ccf14f0..986d9885 100644
--- a/launcher/minecraft/mod/ResourceFolderModel.h
+++ b/launcher/minecraft/mod/ResourceFolderModel.h
@@ -261,6 +261,9 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
std::sort(removed_rows.begin(), removed_rows.end());
+ for (int i = 0; i < removed_rows.size(); i++)
+ removed_rows[i] -= i;
+
for (auto& removed_index : removed_rows) {
beginRemoveRows(QModelIndex(), removed_index, removed_index);
diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h
new file mode 100644
index 00000000..c2cc8690
--- /dev/null
+++ b/launcher/minecraft/mod/ResourcePack.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "Resource.h"
+
+class ResourcePack : public Resource {
+ Q_OBJECT
+ public:
+ using Ptr = shared_qobject_ptr<Resource>;
+
+ ResourcePack(QObject* parent = nullptr) : Resource(parent) {}
+ ResourcePack(QFileInfo file_info) : Resource(file_info) {}
+
+};
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
index 64a04469..e92be894 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp
@@ -35,5 +35,4 @@
#include "ResourcePackFolderModel.h"
-ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(dir) {
-}
+ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}
diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.h b/launcher/minecraft/mod/ResourcePackFolderModel.h
index d2a5bf18..1fe82867 100644
--- a/launcher/minecraft/mod/ResourcePackFolderModel.h
+++ b/launcher/minecraft/mod/ResourcePackFolderModel.h
@@ -2,9 +2,13 @@
#include "ResourceFolderModel.h"
+#include "ResourcePack.h"
+
class ResourcePackFolderModel : public ResourceFolderModel
{
Q_OBJECT
public:
explicit ResourcePackFolderModel(const QString &dir);
+
+ RESOURCE_HELPERS(ResourcePack)
};
diff --git a/launcher/minecraft/mod/ShaderPackFolderModel.h b/launcher/minecraft/mod/ShaderPackFolderModel.h
new file mode 100644
index 00000000..a3aa958f
--- /dev/null
+++ b/launcher/minecraft/mod/ShaderPackFolderModel.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "ResourceFolderModel.h"
+
+class ShaderPackFolderModel : public ResourceFolderModel {
+ Q_OBJECT
+
+ public:
+ explicit ShaderPackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir)) {}
+};
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp
index e3a22219..2c7c945b 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.cpp
+++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp
@@ -35,24 +35,4 @@
#include "TexturePackFolderModel.h"
-TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ModFolderModel(dir) {
-}
-
-QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (role == Qt::ToolTipRole) {
- switch (section) {
- case ActiveColumn:
- return tr("Is the texture pack enabled?");
- case NameColumn:
- return tr("The name of the texture pack.");
- case VersionColumn:
- return tr("The version of the texture pack.");
- case DateColumn:
- return tr("The date and time this texture pack was last changed (or added).");
- default:
- return QVariant();
- }
- }
-
- return ModFolderModel::headerData(section, orientation, role);
-}
+TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ResourceFolderModel(QDir(dir)) {}
diff --git a/launcher/minecraft/mod/TexturePackFolderModel.h b/launcher/minecraft/mod/TexturePackFolderModel.h
index a59d5119..69e98661 100644
--- a/launcher/minecraft/mod/TexturePackFolderModel.h
+++ b/launcher/minecraft/mod/TexturePackFolderModel.h
@@ -1,13 +1,11 @@
#pragma once
-#include "ModFolderModel.h"
+#include "ResourceFolderModel.h"
-class TexturePackFolderModel : public ModFolderModel
+class TexturePackFolderModel : public ResourceFolderModel
{
Q_OBJECT
public:
explicit TexturePackFolderModel(const QString &dir);
-
- QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
};