refactor: move general code from mod model to its own model
This aims to continue decoupling other types of resources (e.g. resource
packs, shader packs, etc) from mods, so that we don't have to
continuously watch our backs for changes to one of them affecting the
others.
To do so, this creates a more general list model for resources, based on
the mods one, that allows you to extend it with functionality for other
resources.
I had to do some template and preprocessor stuff to get around the
QObject limitation of not allowing templated classes, so that's sadge :c
On the other hand, I tried cleaning up most general-purpose code in the
mod model, and added some documentation, because it looks nice :D
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-09 10:28:22 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "minecraft/mod/Resource.h"
|
|
|
|
|
|
|
|
#include "tasks/Task.h"
|
|
|
|
|
|
|
|
/** Very simple task that just loads a folder's contents directly.
|
|
|
|
*/
|
|
|
|
class BasicFolderLoadTask : public Task
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
struct Result {
|
2022-08-13 01:39:56 +05:30
|
|
|
QMap<QString, Resource::Ptr> resources;
|
refactor: move general code from mod model to its own model
This aims to continue decoupling other types of resources (e.g. resource
packs, shader packs, etc) from mods, so that we don't have to
continuously watch our backs for changes to one of them affecting the
others.
To do so, this creates a more general list model for resources, based on
the mods one, that allows you to extend it with functionality for other
resources.
I had to do some template and preprocessor stuff to get around the
QObject limitation of not allowing templated classes, so that's sadge :c
On the other hand, I tried cleaning up most general-purpose code in the
mod model, and added some documentation, because it looks nice :D
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-09 10:28:22 +05:30
|
|
|
};
|
|
|
|
using ResultPtr = std::shared_ptr<Result>;
|
|
|
|
|
|
|
|
[[nodiscard]] ResultPtr result() const {
|
|
|
|
return m_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
BasicFolderLoadTask(QDir dir) : Task(nullptr, false), m_dir(dir), m_result(new Result) {}
|
2022-08-13 01:39:56 +05:30
|
|
|
|
|
|
|
[[nodiscard]] bool canAbort() const override { return true; }
|
|
|
|
bool abort() override { m_aborted = true; return true; }
|
|
|
|
|
refactor: move general code from mod model to its own model
This aims to continue decoupling other types of resources (e.g. resource
packs, shader packs, etc) from mods, so that we don't have to
continuously watch our backs for changes to one of them affecting the
others.
To do so, this creates a more general list model for resources, based on
the mods one, that allows you to extend it with functionality for other
resources.
I had to do some template and preprocessor stuff to get around the
QObject limitation of not allowing templated classes, so that's sadge :c
On the other hand, I tried cleaning up most general-purpose code in the
mod model, and added some documentation, because it looks nice :D
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-09 10:28:22 +05:30
|
|
|
void executeTask() override
|
|
|
|
{
|
|
|
|
m_dir.refresh();
|
|
|
|
for (auto entry : m_dir.entryInfoList()) {
|
|
|
|
auto resource = new Resource(entry);
|
|
|
|
m_result->resources.insert(resource->internal_id(), resource);
|
|
|
|
}
|
|
|
|
|
2022-08-13 01:39:56 +05:30
|
|
|
if (m_aborted)
|
|
|
|
emitAborted();
|
|
|
|
else
|
|
|
|
emitSucceeded();
|
refactor: move general code from mod model to its own model
This aims to continue decoupling other types of resources (e.g. resource
packs, shader packs, etc) from mods, so that we don't have to
continuously watch our backs for changes to one of them affecting the
others.
To do so, this creates a more general list model for resources, based on
the mods one, that allows you to extend it with functionality for other
resources.
I had to do some template and preprocessor stuff to get around the
QObject limitation of not allowing templated classes, so that's sadge :c
On the other hand, I tried cleaning up most general-purpose code in the
mod model, and added some documentation, because it looks nice :D
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-09 10:28:22 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QDir m_dir;
|
|
|
|
ResultPtr m_result;
|
2022-08-13 01:39:56 +05:30
|
|
|
|
|
|
|
bool m_aborted = false;
|
refactor: move general code from mod model to its own model
This aims to continue decoupling other types of resources (e.g. resource
packs, shader packs, etc) from mods, so that we don't have to
continuously watch our backs for changes to one of them affecting the
others.
To do so, this creates a more general list model for resources, based on
the mods one, that allows you to extend it with functionality for other
resources.
I had to do some template and preprocessor stuff to get around the
QObject limitation of not allowing templated classes, so that's sadge :c
On the other hand, I tried cleaning up most general-purpose code in the
mod model, and added some documentation, because it looks nice :D
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-09 10:28:22 +05:30
|
|
|
};
|