Merge pull request #1617 from cullvox/components-resource-pack-fix

added functionality for components in resource pack descriptions.
This commit is contained in:
Alexandru Ionut Tripon 2024-06-09 16:03:19 +03:00 committed by GitHub
commit 55b6490530
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 297 additions and 6 deletions

View file

@ -57,5 +57,8 @@ ecm_add_test(Index_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}:
ecm_add_test(Version_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME Version)
ecm_add_test(MetaComponentParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME MetaComponentParse)
ecm_add_test(CatPack_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
TEST_NAME CatPack)

View file

@ -0,0 +1,87 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* 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/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QTest>
#include <QTimer>
#include <FileSystem.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
class MetaComponentParseTest : public QObject {
Q_OBJECT
void doTest(QString name)
{
QString source = QFINDTESTDATA("testdata/MetaComponentParse");
QString comp_rp = FS::PathCombine(source, name);
QFile file;
file.setFileName(comp_rp);
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
QString data = file.readAll();
file.close();
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
QJsonObject obj = doc.object();
QJsonValue description_json = obj.value("description");
QJsonValue expected_json = obj.value("expected_output");
QVERIFY(!description_json.isUndefined());
QVERIFY(expected_json.isString());
QString expected = expected_json.toString();
QString processed = ResourcePackUtils::processComponent(description_json);
QCOMPARE(processed, expected);
}
private slots:
void test_parseComponentBasic() { doTest("component_basic.json"); }
void test_parseComponentWithFormat() { doTest("component_with_format.json"); }
void test_parseComponentWithExtra() { doTest("component_with_extra.json"); }
void test_parseComponentWithLink() { doTest("component_with_link.json"); }
void test_parseComponentWithMixed() { doTest("component_with_mixed.json"); }
};
QTEST_GUILESS_MAIN(MetaComponentParseTest)
#include "MetaComponentParse_test.moc"

View file

@ -0,0 +1,8 @@
{
"description": [
{
"text": "Hello, Component!"
}
],
"expected_output": "Hello, Component!"
}

View file

@ -0,0 +1,21 @@
{
"description": [
{
"text": "Hello, ",
"color": "red",
"bold": true,
"italic": true,
"extra": [
{
"extra": [
"Component!"
],
"bold": false,
"italic": false
}
]
}
],
"expected_output":
"<span style=\"color: red; font-weight: bold; font-style: italic;\">Hello, <span style=\"font-weight: normal; font-style: normal;\">Component!</span></span>"
}

View file

@ -0,0 +1,13 @@
{
"description": [
{
"text": "Hello, Component!",
"color": "blue",
"bold": true,
"italic": true,
"underlined": true,
"strikethrough": true
}
],
"expected_output": "<span style=\"color: blue; font-weight: bold; font-style: italic;\"><s><u>Hello, Component!</u></s></span>"
}

View file

@ -0,0 +1,12 @@
{
"description": [
{
"text": "Hello, Component!",
"clickEvent": {
"action": "open_url",
"value": "https://google.com"
}
}
],
"expected_output": "<a href=\"https://google.com\">Hello, Component!</a>"
}

View file

@ -0,0 +1,45 @@
{
"description": [
{
"text": "The quick ",
"color": "blue",
"italic": true
},
{
"text": "brown fox ",
"color": "#873600",
"bold": true,
"underlined": true,
"extra": [
{
"text": "jumped over ",
"color": "blue",
"bold": false,
"underlined": false,
"italic": true,
"strikethrough": true
}
]
},
{
"text": "the lazy dog's back. ",
"color": "green",
"bold": true,
"italic": true,
"underlined": true,
"strikethrough": true,
"extra": [
{
"text": "1234567890 ",
"color": "black",
"strikethrough": false,
"extra": [
"How vexingly quick daft zebras jump!"
]
}
]
}
],
"expected_output":
"<span style=\"color: blue; font-style: italic;\">The quick </span><span style=\"color: #873600; font-weight: bold;\"><u>brown fox </u><span style=\"color: blue; font-weight: normal; font-style: italic;\"><s>jumped over </s></span></span><span style=\"color: green; font-weight: bold; font-style: italic;\"><s><u>the lazy dog's back. </u></s><span style=\"color: black;\"><u>1234567890 </u>How vexingly quick daft zebras jump!</span></span>"
}