feat(RD): add texture pack downloader
This extends the resource pack downloader, with the custom behavior of filtering the versions that shows up, to those <= 1.6. As always, Flame is funky and requires a bit more workarounds than average. This will also get a nice improvement when the Version parsing and comparison PR gets merged! :D Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
80
launcher/ui/pages/modplatform/TexturePackModel.cpp
Normal file
80
launcher/ui/pages/modplatform/TexturePackModel.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "TexturePackModel.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
#include "meta/Index.h"
|
||||
#include "meta/Version.h"
|
||||
|
||||
static std::list<Version> s_availableVersions = {};
|
||||
|
||||
namespace ResourceDownload {
|
||||
TexturePackResourceModel::TexturePackResourceModel(BaseInstance const& inst, ResourceAPI* api)
|
||||
: ResourcePackResourceModel(inst, api), m_version_list(APPLICATION->metadataIndex()->get("net.minecraft"))
|
||||
{
|
||||
if (!m_version_list->isLoaded()) {
|
||||
qDebug() << "Loading version list...";
|
||||
auto task = m_version_list->getLoadTask();
|
||||
if (!task->isRunning())
|
||||
task->start();
|
||||
}
|
||||
}
|
||||
|
||||
void waitOnVersionListLoad(Meta::VersionList::Ptr version_list)
|
||||
{
|
||||
QEventLoop load_version_list_loop;
|
||||
|
||||
QTimer time_limit_for_list_load;
|
||||
time_limit_for_list_load.setTimerType(Qt::TimerType::CoarseTimer);
|
||||
time_limit_for_list_load.setSingleShot(true);
|
||||
time_limit_for_list_load.callOnTimeout(&load_version_list_loop, &QEventLoop::quit);
|
||||
time_limit_for_list_load.start(4000);
|
||||
|
||||
auto task = version_list->getLoadTask();
|
||||
QObject::connect(task.get(), &Task::finished, &load_version_list_loop, &QEventLoop::quit);
|
||||
|
||||
load_version_list_loop.exec();
|
||||
if (time_limit_for_list_load.isActive())
|
||||
time_limit_for_list_load.stop();
|
||||
}
|
||||
|
||||
ResourceAPI::SearchArgs TexturePackResourceModel::createSearchArguments()
|
||||
{
|
||||
if (s_availableVersions.empty())
|
||||
waitOnVersionListLoad(m_version_list);
|
||||
|
||||
auto args = ResourcePackResourceModel::createSearchArguments();
|
||||
|
||||
if (!m_version_list->isLoaded()) {
|
||||
qCritical() << "The version list could not be loaded. Falling back to showing all entries.";
|
||||
return args;
|
||||
}
|
||||
|
||||
if (s_availableVersions.empty()) {
|
||||
for (auto&& version : m_version_list->versions()) {
|
||||
// FIXME: This duplicates the logic in meta for the 'texturepacks' trait. However, we don't have access to that
|
||||
// information from the index file alone. Also, downloading every version's file isn't a very good idea.
|
||||
if (auto ver = version->toComparableVersion(); ver <= maximumTexturePackVersion())
|
||||
s_availableVersions.push_back(ver);
|
||||
}
|
||||
}
|
||||
|
||||
Q_ASSERT(!s_availableVersions.empty());
|
||||
|
||||
args.versions = s_availableVersions;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
ResourceAPI::VersionSearchArgs TexturePackResourceModel::createVersionsArguments(QModelIndex& entry)
|
||||
{
|
||||
auto args = ResourcePackResourceModel::createVersionsArguments(entry);
|
||||
if (!m_version_list->isLoaded()) {
|
||||
qCritical() << "The version list could not be loaded. Falling back to showing all entries.";
|
||||
return args;
|
||||
}
|
||||
|
||||
args.mcVersions = s_availableVersions;
|
||||
return args;
|
||||
}
|
||||
|
||||
} // namespace ResourceDownload
|
Reference in New Issue
Block a user