-
Notifications
You must be signed in to change notification settings - Fork 5
/
texturesplitter.cpp
60 lines (48 loc) · 1.7 KB
/
texturesplitter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "texturesplitter.h"
#include <QImage>
#include <QThread>
namespace ProjectZomboidPackManager
{
TextureSplitter::TextureSplitter(QObject *parent)
: ThreadableTask(parent)
{
}
TextureSplitter::~TextureSplitter()
{
}
void TextureSplitter::DoTask()
{
emit SendMessage("Splitting Textures!");
QStringList filters;
filters << "*.png";
QFileInfoList files = _folder.entryInfoList(
filters,
QDir::Files | QDir::NoDotAndDotDot,
QDir::Name);
for (QFileInfo next : files)
{
emit SendMessage("Splitting " + next.fileName() + "...");
for (PackFilePageMetaData data : _fileData->Pages())
{
if (data.Name() == next.baseName())
{
QImage image(next.absoluteFilePath());
QDir folderToSaveTo = _folder;
folderToSaveTo.mkdir(next.baseName());
folderToSaveTo.cd(next.baseName());
for (PackEntryMetaData entry : data.Entries())
{
QRect rect(entry.XPos(),
entry.YPos(),
entry.Width(), entry.Height());
QImage texture = image.copy(rect);
texture.save(folderToSaveTo.absolutePath() + "/" + entry.Name() + ".png");
}
break;
}
}
QThread::msleep(0);
}
emit SendMessage("Finished Splitting Textures");
}
}