aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-08-28 22:29:52 -0300
committerflow <flowlnlnln@gmail.com>2022-09-03 13:37:21 -0300
commit050768c266833d8ad1c662f93f3c8dc044e57843 (patch)
treedcd280c07124205509d07b250358891fe3cb66e3 /launcher/minecraft/mod
parentcda2bfc24061870525fa6569f390141e5703a565 (diff)
downloadPrismLauncher-050768c266833d8ad1c662f93f3c8dc044e57843.tar.gz
PrismLauncher-050768c266833d8ad1c662f93f3c8dc044e57843.tar.bz2
PrismLauncher-050768c266833d8ad1c662f93f3c8dc044e57843.zip
feat: add more resource pack info
Adds pack format id and description to ResourcePack, that'll be parsed from pack.mcmeta. Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/minecraft/mod')
-rw-r--r--launcher/minecraft/mod/Resource.h1
-rw-r--r--launcher/minecraft/mod/ResourcePack.cpp48
-rw-r--r--launcher/minecraft/mod/ResourcePack.h37
3 files changed, 85 insertions, 1 deletions
diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h
index cee1f172..96ff9f4b 100644
--- a/launcher/minecraft/mod/Resource.h
+++ b/launcher/minecraft/mod/Resource.h
@@ -80,6 +80,7 @@ class Resource : public QObject {
[[nodiscard]] auto shouldResolve() const -> bool { return !m_is_resolving && !m_is_resolved; }
[[nodiscard]] auto isResolving() const -> bool { return m_is_resolving; }
+ [[nodiscard]] auto isResolved() const -> bool { return m_is_resolved; }
[[nodiscard]] auto resolutionTicket() const -> int { return m_resolution_ticket; }
void setResolving(bool resolving, int resolutionTicket)
diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp
new file mode 100644
index 00000000..68d86aed
--- /dev/null
+++ b/launcher/minecraft/mod/ResourcePack.cpp
@@ -0,0 +1,48 @@
+#include "ResourcePack.h"
+
+#include <QDebug>
+#include <QMap>
+
+#include "Version.h"
+
+// Values taken from:
+// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
+static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = {
+ { 1, { Version("1.6.1"), Version("1.8.9") } }, { 2, { Version("1.9"), Version("1.10.2") } },
+ { 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } },
+ { 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } },
+ { 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } },
+ { 9, { Version("1.19"), Version("1.19.2") } },
+};
+
+void ResourcePack::setPackFormat(int new_format_id)
+{
+ QMutexLocker locker(&m_data_lock);
+
+ if (!s_pack_format_versions.contains(new_format_id)) {
+ qCritical() << "Error: Pack format '%1' is not a recognized resource pack id.";
+ return;
+ }
+
+ m_pack_format = new_format_id;
+}
+
+void ResourcePack::setDescription(QString new_description)
+{
+ QMutexLocker locker(&m_data_lock);
+
+ m_description = new_description;
+}
+
+std::pair<Version, Version> ResourcePack::compatibleVersions() const
+{
+ if (!s_pack_format_versions.contains(m_pack_format)) {
+ // Not having a valid pack format is fine if we didn't yet parse the .mcmeta file,
+ // but if we did and we still don't have a valid pack format, that's a bit concerning.
+ Q_ASSERT(!isResolved());
+
+ return {{}, {}};
+ }
+
+ return s_pack_format_versions.constFind(m_pack_format).value();
+}
diff --git a/launcher/minecraft/mod/ResourcePack.h b/launcher/minecraft/mod/ResourcePack.h
index c2cc8690..ab84ad37 100644
--- a/launcher/minecraft/mod/ResourcePack.h
+++ b/launcher/minecraft/mod/ResourcePack.h
@@ -2,12 +2,47 @@
#include "Resource.h"
+#include <QMutex>
+
+class Version;
+
+/* TODO:
+ *
+ * Store pack.png
+ * Store localized descriptions
+ * */
+
class ResourcePack : public Resource {
Q_OBJECT
- public:
+ public:
using Ptr = shared_qobject_ptr<Resource>;
ResourcePack(QObject* parent = nullptr) : Resource(parent) {}
ResourcePack(QFileInfo file_info) : Resource(file_info) {}
+ /** Gets the numerical ID of the pack format. */
+ [[nodiscard]] int packFormat() const { return m_pack_format; }
+ /** Gets, respectively, the lower and upper versions supported by the set pack format. */
+ [[nodiscard]] std::pair<Version, Version> compatibleVersions() const;
+
+ /** Gets the description of the resource pack. */
+ [[nodiscard]] QString description() const { return m_description; }
+
+ /** Thread-safe. */
+ void setPackFormat(int new_format_id);
+
+ /** Thread-safe. */
+ void setDescription(QString new_description);
+
+ protected:
+ mutable QMutex m_data_lock;
+
+ /* The 'version' of a resource pack, as defined in the pack.mcmeta file.
+ * See https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
+ */
+ int m_pack_format = 0;
+
+ /** The resource pack's description, as defined in the pack.mcmeta file.
+ */
+ QString m_description;
};