From 07dcefabcbe3436ae6de09bc8c99120ab3f0a745 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 4 Sep 2022 14:45:09 +0200 Subject: feat: add texture pack parsing Signed-off-by: Sefa Eyeoglu --- tests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1265d7a5..9c86c221 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,9 @@ ecm_add_test(ResourceFolderModel_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_V ecm_add_test(ResourcePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test TEST_NAME ResourcePackParse) +ecm_add_test(minecraft/mod/TexturePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test + TEST_NAME TexturePackParse) + ecm_add_test(ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test TEST_NAME ParseUtils) -- cgit From aad6f74db6a08ca23a9b4ee7f261a051d230bef7 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 4 Sep 2022 15:05:11 +0200 Subject: fix: tests Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/mod/TexturePackParse_test.cpp | 70 --------------------- .../testdata/another_test_texturefolder/pack.txt | 2 - .../mod/testdata/test_texture_pack_idk.zip | Bin 184 -> 0 bytes .../assets/minecraft/textures/blah.txt | 1 - .../mod/testdata/test_texturefolder/pack.txt | 1 - tests/CMakeLists.txt | 2 +- tests/ResourceFolderModel_test.cpp | 1 - tests/TexturePackParse_test.cpp | 70 +++++++++++++++++++++ .../another_test_texturefolder/pack.txt | 2 + .../TexturePackParse/test_texture_pack_idk.zip | Bin 0 -> 184 bytes .../assets/minecraft/textures/blah.txt | 1 + .../TexturePackParse/test_texturefolder/pack.txt | 1 + 12 files changed, 75 insertions(+), 76 deletions(-) delete mode 100644 launcher/minecraft/mod/TexturePackParse_test.cpp delete mode 100644 launcher/minecraft/mod/testdata/another_test_texturefolder/pack.txt delete mode 100644 launcher/minecraft/mod/testdata/test_texture_pack_idk.zip delete mode 100644 launcher/minecraft/mod/testdata/test_texturefolder/assets/minecraft/textures/blah.txt delete mode 100644 launcher/minecraft/mod/testdata/test_texturefolder/pack.txt create mode 100644 tests/TexturePackParse_test.cpp create mode 100644 tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt create mode 100644 tests/testdata/TexturePackParse/test_texture_pack_idk.zip create mode 100644 tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt create mode 100644 tests/testdata/TexturePackParse/test_texturefolder/pack.txt (limited to 'tests') diff --git a/launcher/minecraft/mod/TexturePackParse_test.cpp b/launcher/minecraft/mod/TexturePackParse_test.cpp deleted file mode 100644 index 207c2c87..00000000 --- a/launcher/minecraft/mod/TexturePackParse_test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/* - * PolyMC - Minecraft Launcher - * Copyright (c) 2022 flowln - * - * 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 . - */ - -#include -#include - -#include "FileSystem.h" - -#include "TexturePack.h" -#include "tasks/LocalTexturePackParseTask.h" - -class TexturePackParseTest : public QObject { - Q_OBJECT - - private slots: - void test_parseZIP() - { - QString source = QFINDTESTDATA("testdata"); - - QString zip_rp = FS::PathCombine(source, "test_texture_pack_idk.zip"); - TexturePack pack { QFileInfo(zip_rp) }; - - TexturePackUtils::processZIP(pack); - - QVERIFY(pack.description() == "joe biden, wake up"); - } - - void test_parseFolder() - { - QString source = QFINDTESTDATA("testdata"); - - QString folder_rp = FS::PathCombine(source, "test_texturefolder"); - TexturePack pack { QFileInfo(folder_rp) }; - - TexturePackUtils::processFolder(pack); - - QVERIFY(pack.description() == "Some texture pack surely"); - } - - void test_parseFolder2() - { - QString source = QFINDTESTDATA("testdata"); - - QString folder_rp = FS::PathCombine(source, "another_test_texturefolder"); - TexturePack pack { QFileInfo(folder_rp) }; - - TexturePackUtils::process(pack); - - QVERIFY(pack.description() == "quieres\nfor real"); - } -}; - -QTEST_GUILESS_MAIN(TexturePackParseTest) - -#include "TexturePackParse_test.moc" diff --git a/launcher/minecraft/mod/testdata/another_test_texturefolder/pack.txt b/launcher/minecraft/mod/testdata/another_test_texturefolder/pack.txt deleted file mode 100644 index bbc0d271..00000000 --- a/launcher/minecraft/mod/testdata/another_test_texturefolder/pack.txt +++ /dev/null @@ -1,2 +0,0 @@ -quieres -for real \ No newline at end of file diff --git a/launcher/minecraft/mod/testdata/test_texture_pack_idk.zip b/launcher/minecraft/mod/testdata/test_texture_pack_idk.zip deleted file mode 100644 index fb4d3370..00000000 Binary files a/launcher/minecraft/mod/testdata/test_texture_pack_idk.zip and /dev/null differ diff --git a/launcher/minecraft/mod/testdata/test_texturefolder/assets/minecraft/textures/blah.txt b/launcher/minecraft/mod/testdata/test_texturefolder/assets/minecraft/textures/blah.txt deleted file mode 100644 index 8d1c8b69..00000000 --- a/launcher/minecraft/mod/testdata/test_texturefolder/assets/minecraft/textures/blah.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/launcher/minecraft/mod/testdata/test_texturefolder/pack.txt b/launcher/minecraft/mod/testdata/test_texturefolder/pack.txt deleted file mode 100644 index f6260725..00000000 --- a/launcher/minecraft/mod/testdata/test_texturefolder/pack.txt +++ /dev/null @@ -1 +0,0 @@ -Some texture pack surely \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9c86c221..630f1200 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,7 +24,7 @@ ecm_add_test(ResourceFolderModel_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_V ecm_add_test(ResourcePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test TEST_NAME ResourcePackParse) -ecm_add_test(minecraft/mod/TexturePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test +ecm_add_test(TexturePackParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test TEST_NAME TexturePackParse) ecm_add_test(ParseUtils_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test diff --git a/tests/ResourceFolderModel_test.cpp b/tests/ResourceFolderModel_test.cpp index 3f0f3ba1..e38b8e93 100644 --- a/tests/ResourceFolderModel_test.cpp +++ b/tests/ResourceFolderModel_test.cpp @@ -146,7 +146,6 @@ slots: for (auto mod : model.allMods()) qDebug() << mod->name(); - // FIXME: It considers every file in the directory as a mod, but we should probably filter that out somehow. QCOMPARE(model.size(), 4); model.stopWatching(); diff --git a/tests/TexturePackParse_test.cpp b/tests/TexturePackParse_test.cpp new file mode 100644 index 00000000..3e9eaf23 --- /dev/null +++ b/tests/TexturePackParse_test.cpp @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 flowln + * + * 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 . + */ + +#include +#include + +#include "FileSystem.h" + +#include "minecraft/mod/TexturePack.h" +#include "minecraft/mod/tasks/LocalTexturePackParseTask.h" + +class TexturePackParseTest : public QObject { + Q_OBJECT + + private slots: + void test_parseZIP() + { + QString source = QFINDTESTDATA("testdata/TexturePackParse"); + + QString zip_rp = FS::PathCombine(source, "test_texture_pack_idk.zip"); + TexturePack pack { QFileInfo(zip_rp) }; + + TexturePackUtils::processZIP(pack); + + QVERIFY(pack.description() == "joe biden, wake up"); + } + + void test_parseFolder() + { + QString source = QFINDTESTDATA("testdata/TexturePackParse"); + + QString folder_rp = FS::PathCombine(source, "test_texturefolder"); + TexturePack pack { QFileInfo(folder_rp) }; + + TexturePackUtils::processFolder(pack); + + QVERIFY(pack.description() == "Some texture pack surely"); + } + + void test_parseFolder2() + { + QString source = QFINDTESTDATA("testdata/TexturePackParse"); + + QString folder_rp = FS::PathCombine(source, "another_test_texturefolder"); + TexturePack pack { QFileInfo(folder_rp) }; + + TexturePackUtils::process(pack); + + QVERIFY(pack.description() == "quieres\nfor real"); + } +}; + +QTEST_GUILESS_MAIN(TexturePackParseTest) + +#include "TexturePackParse_test.moc" diff --git a/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt b/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt new file mode 100644 index 00000000..bbc0d271 --- /dev/null +++ b/tests/testdata/TexturePackParse/another_test_texturefolder/pack.txt @@ -0,0 +1,2 @@ +quieres +for real \ No newline at end of file diff --git a/tests/testdata/TexturePackParse/test_texture_pack_idk.zip b/tests/testdata/TexturePackParse/test_texture_pack_idk.zip new file mode 100644 index 00000000..fb4d3370 Binary files /dev/null and b/tests/testdata/TexturePackParse/test_texture_pack_idk.zip differ diff --git a/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt b/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/tests/testdata/TexturePackParse/test_texturefolder/assets/minecraft/textures/blah.txt @@ -0,0 +1 @@ + diff --git a/tests/testdata/TexturePackParse/test_texturefolder/pack.txt b/tests/testdata/TexturePackParse/test_texturefolder/pack.txt new file mode 100644 index 00000000..f6260725 --- /dev/null +++ b/tests/testdata/TexturePackParse/test_texturefolder/pack.txt @@ -0,0 +1 @@ +Some texture pack surely \ No newline at end of file -- cgit From 23fc453fae7091d6ef8176b3ba265e9242ebd540 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 8 Sep 2022 09:43:55 +0200 Subject: fix: comments and naming of texture pack stuff Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/mod/TexturePack.cpp | 19 ++++++++++++ launcher/minecraft/mod/TexturePack.h | 28 ++++++++++++----- launcher/minecraft/mod/TexturePackFolderModel.h | 36 ++++++++++++++++++++++ .../mod/tasks/LocalTexturePackParseTask.cpp | 7 +++-- .../mod/tasks/LocalTexturePackParseTask.h | 3 +- tests/TexturePackParse_test.cpp | 1 + 6 files changed, 83 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/launcher/minecraft/mod/TexturePack.cpp b/launcher/minecraft/mod/TexturePack.cpp index 32f69fc7..796eb69d 100644 --- a/launcher/minecraft/mod/TexturePack.cpp +++ b/launcher/minecraft/mod/TexturePack.cpp @@ -1,3 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu + * + * 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 . + */ + #include "TexturePack.h" #include diff --git a/launcher/minecraft/mod/TexturePack.h b/launcher/minecraft/mod/TexturePack.h index cd5e4b67..6aa5e18e 100644 --- a/launcher/minecraft/mod/TexturePack.h +++ b/launcher/minecraft/mod/TexturePack.h @@ -1,3 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu + * + * 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 . + */ + #pragma once #include "Resource.h" @@ -9,11 +28,6 @@ class Version; -/* TODO: - * - * Store localized descriptions - * */ - class TexturePack : public Resource { Q_OBJECT public: @@ -22,10 +36,10 @@ class TexturePack : public Resource { TexturePack(QObject* parent = nullptr) : Resource(parent) {} TexturePack(QFileInfo file_info) : Resource(file_info) {} - /** Gets the description of the resource pack. */ + /** Gets the description of the texture pack. */ [[nodiscard]] QString description() const { return m_description; } - /** Gets the image of the resource pack, converted to a QPixmap for drawing, and scaled to size. */ + /** Gets the image of the texture pack, converted to a QPixmap for drawing, and scaled to size. */ [[nodiscard]] QPixmap image(QSize size); /** Thread-safe. */ diff --git a/launcher/minecraft/mod/TexturePackFolderModel.h b/launcher/minecraft/mod/TexturePackFolderModel.h index f9a95466..261f83b4 100644 --- a/launcher/minecraft/mod/TexturePackFolderModel.h +++ b/launcher/minecraft/mod/TexturePackFolderModel.h @@ -1,3 +1,39 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu + * + * 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 . + * + * 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. + */ + #pragma once #include "ResourceFolderModel.h" diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp index 2d5a557e..bf1e308f 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp @@ -2,6 +2,7 @@ /* * PolyMC - Minecraft Launcher * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu * * 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 @@ -131,7 +132,7 @@ void processPackPNG(TexturePack& pack, QByteArray&& raw_data) } // namespace TexturePackUtils LocalTexturePackParseTask::LocalTexturePackParseTask(int token, TexturePack& rp) - : Task(nullptr, false), m_token(token), m_resource_pack(rp) + : Task(nullptr, false), m_token(token), m_texture_pack(rp) {} bool LocalTexturePackParseTask::abort() @@ -142,9 +143,9 @@ bool LocalTexturePackParseTask::abort() void LocalTexturePackParseTask::executeTask() { - Q_ASSERT(m_resource_pack.valid()); + Q_ASSERT(m_texture_pack.valid()); - if (!TexturePackUtils::process(m_resource_pack)) + if (!TexturePackUtils::process(m_texture_pack)) return; if (m_aborted) diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h index 239e1197..cb0e404a 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.h @@ -2,6 +2,7 @@ /* * PolyMC - Minecraft Launcher * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu * * 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 @@ -50,7 +51,7 @@ class LocalTexturePackParseTask : public Task { private: int m_token; - TexturePack& m_resource_pack; + TexturePack& m_texture_pack; bool m_aborted = false; }; diff --git a/tests/TexturePackParse_test.cpp b/tests/TexturePackParse_test.cpp index 3e9eaf23..0771f79f 100644 --- a/tests/TexturePackParse_test.cpp +++ b/tests/TexturePackParse_test.cpp @@ -2,6 +2,7 @@ /* * PolyMC - Minecraft Launcher * Copyright (c) 2022 flowln + * Copyright (C) 2022 Sefa Eyeoglu * * 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 -- cgit