diff options
author | flow <flowlnlnln@gmail.com> | 2022-08-28 22:52:29 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-09-03 13:37:21 -0300 |
commit | 3ab17a97a8df6c7dd21ccbb1ea349cf3985fafaf (patch) | |
tree | b76a316f05001679bc9379b99ab6157c7d7049da /launcher/minecraft/mod | |
parent | f21ae66265d5e3251bd996df1fc7ed7f52ec95b0 (diff) | |
download | PrismLauncher-3ab17a97a8df6c7dd21ccbb1ea349cf3985fafaf.tar.gz PrismLauncher-3ab17a97a8df6c7dd21ccbb1ea349cf3985fafaf.tar.bz2 PrismLauncher-3ab17a97a8df6c7dd21ccbb1ea349cf3985fafaf.zip |
fix: sorting by pack format
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/minecraft/mod')
-rw-r--r-- | launcher/minecraft/mod/Resource.h | 1 | ||||
-rw-r--r-- | launcher/minecraft/mod/ResourcePack.cpp | 25 | ||||
-rw-r--r-- | launcher/minecraft/mod/ResourcePack.h | 2 | ||||
-rw-r--r-- | launcher/minecraft/mod/ResourcePackFolderModel.cpp | 2 |
4 files changed, 28 insertions, 2 deletions
diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h index 96ff9f4b..f9bd811e 100644 --- a/launcher/minecraft/mod/Resource.h +++ b/launcher/minecraft/mod/Resource.h @@ -20,6 +20,7 @@ enum class SortType { DATE, VERSION, ENABLED, + PACK_FORMAT }; enum class EnableAction { diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp index 68d86aed..cab20b50 100644 --- a/launcher/minecraft/mod/ResourcePack.cpp +++ b/launcher/minecraft/mod/ResourcePack.cpp @@ -41,8 +41,31 @@ std::pair<Version, Version> ResourcePack::compatibleVersions() const // but if we did and we still don't have a valid pack format, that's a bit concerning. Q_ASSERT(!isResolved()); - return {{}, {}}; + return { {}, {} }; } return s_pack_format_versions.constFind(m_pack_format).value(); } + +std::pair<int, bool> ResourcePack::compare(const Resource& other, SortType type) const +{ + auto const& cast_other = static_cast<ResourcePack const&>(other); + + switch (type) { + default: { + auto res = Resource::compare(other, type); + if (res.first != 0) + return res; + } + case SortType::PACK_FORMAT: { + auto this_ver = packFormat(); + auto other_ver = cast_other.packFormat(); + + if (this_ver > other_ver) + return { 1, type == SortType::PACK_FORMAT }; + if (this_ver < other_ver) + return { -1, type == SortType::PACK_FORMAT }; + } + } + return { 0, false }; +} diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h index ab84ad37..0bd9ebbd 100644 --- a/launcher/minecraft/mod/ResourcePack.h +++ b/launcher/minecraft/mod/ResourcePack.h @@ -34,6 +34,8 @@ class ResourcePack : public Resource { /** Thread-safe. */ void setDescription(QString new_description); + [[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override; + protected: mutable QMutex m_data_lock; diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp index b634130f..66b6cf5e 100644 --- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp +++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp @@ -43,7 +43,7 @@ ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir) : ResourceFolderModel(QDir(dir)) { - m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE }; + m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE }; } QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const |