-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from Ryex/identify-zip-packs
fix #349
- Loading branch information
Showing
48 changed files
with
1,857 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "DataPack.h" | ||
|
||
#include <QDebug> | ||
#include <QMap> | ||
#include <QRegularExpression> | ||
|
||
#include "Version.h" | ||
|
||
// Values taken from: | ||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_data_pack#%22pack_format%22 | ||
static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = { | ||
{ 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.1") } }, { 9, { Version("1.18.2"), Version("1.18.2") } }, | ||
{ 10, { Version("1.19"), Version("1.19.3") } }, | ||
}; | ||
|
||
void DataPack::setPackFormat(int new_format_id) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
if (!s_pack_format_versions.contains(new_format_id)) { | ||
qWarning() << "Pack format '" << new_format_id << "' is not a recognized data pack id!"; | ||
} | ||
|
||
m_pack_format = new_format_id; | ||
} | ||
|
||
void DataPack::setDescription(QString new_description) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
m_description = new_description; | ||
} | ||
|
||
std::pair<Version, Version> DataPack::compatibleVersions() const | ||
{ | ||
if (!s_pack_format_versions.contains(m_pack_format)) { | ||
return { {}, {} }; | ||
} | ||
|
||
return s_pack_format_versions.constFind(m_pack_format).value(); | ||
} | ||
|
||
std::pair<int, bool> DataPack::compare(const Resource& other, SortType type) const | ||
{ | ||
auto const& cast_other = static_cast<DataPack 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 }; | ||
} | ||
|
||
bool DataPack::applyFilter(QRegularExpression filter) const | ||
{ | ||
if (filter.match(description()).hasMatch()) | ||
return true; | ||
|
||
if (filter.match(QString::number(packFormat())).hasMatch()) | ||
return true; | ||
|
||
if (filter.match(compatibleVersions().first.toString()).hasMatch()) | ||
return true; | ||
if (filter.match(compatibleVersions().second.toString()).hasMatch()) | ||
return true; | ||
|
||
return Resource::applyFilter(filter); | ||
} | ||
|
||
bool DataPack::valid() const | ||
{ | ||
return m_pack_format != 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Resource.h" | ||
|
||
#include <QMutex> | ||
|
||
class Version; | ||
|
||
/* TODO: | ||
* | ||
* Store localized descriptions | ||
* */ | ||
|
||
class DataPack : public Resource { | ||
Q_OBJECT | ||
public: | ||
using Ptr = shared_qobject_ptr<Resource>; | ||
|
||
DataPack(QObject* parent = nullptr) : Resource(parent) {} | ||
DataPack(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 data pack. */ | ||
[[nodiscard]] QString description() const { return m_description; } | ||
|
||
/** Thread-safe. */ | ||
void setPackFormat(int new_format_id); | ||
|
||
/** Thread-safe. */ | ||
void setDescription(QString new_description); | ||
|
||
bool valid() const override; | ||
|
||
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override; | ||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override; | ||
|
||
protected: | ||
mutable QMutex m_data_lock; | ||
|
||
/* The 'version' of a data pack, as defined in the pack.mcmeta file. | ||
* See https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta | ||
*/ | ||
int m_pack_format = 0; | ||
|
||
/** The data pack's description, as defined in the pack.mcmeta file. | ||
*/ | ||
QString m_description; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
/* | ||
* Prism Launcher - Minecraft Launcher | ||
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "ShaderPack.h" | ||
|
||
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h" | ||
|
||
void ShaderPack::setPackFormat(ShaderPackFormat new_format) | ||
{ | ||
QMutexLocker locker(&m_data_lock); | ||
|
||
m_pack_format = new_format; | ||
} | ||
|
||
bool ShaderPack::valid() const | ||
{ | ||
return m_pack_format != ShaderPackFormat::INVALID; | ||
} |
Oops, something went wrong.