2018-10-09 09:17:44 +00:00
|
|
|
#include "material.h"
|
|
|
|
#include "imageforever.h"
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "util.h"
|
2018-10-09 09:17:44 +00:00
|
|
|
|
2019-11-03 00:15:20 +00:00
|
|
|
void initializeMaterialTexturesFromSnapshot(const Snapshot &snapshot,
|
|
|
|
const QUuid &materialId,
|
|
|
|
MaterialTextures &materialTextures,
|
|
|
|
float &tileScale)
|
2018-10-09 09:17:44 +00:00
|
|
|
{
|
|
|
|
QString materialIdString = materialId.toString();
|
|
|
|
for (const auto &materialItem: snapshot.materials) {
|
|
|
|
if (materialIdString != valueOfKeyInMapOrEmpty(materialItem.first, "id"))
|
|
|
|
continue;
|
|
|
|
for (const auto &layer: materialItem.second) {
|
|
|
|
//FIXME: Only support one layer currently
|
2019-11-03 00:15:20 +00:00
|
|
|
auto findTileScale = layer.first.find("tileScale");
|
|
|
|
if (findTileScale != layer.first.end())
|
|
|
|
tileScale = findTileScale->second.toFloat();
|
2018-10-09 09:17:44 +00:00
|
|
|
for (const auto &mapItem: layer.second) {
|
|
|
|
auto textureType = TextureTypeFromString(valueOfKeyInMapOrEmpty(mapItem, "for").toUtf8().constData());
|
|
|
|
if (textureType != TextureType::None) {
|
|
|
|
int index = (int)textureType - 1;
|
|
|
|
if (index >= 0 && index < (int)TextureType::Count - 1) {
|
|
|
|
if ("imageId" == valueOfKeyInMapOrEmpty(mapItem, "linkDataType")) {
|
|
|
|
auto imageIdString = valueOfKeyInMapOrEmpty(mapItem, "linkData");
|
|
|
|
materialTextures.textureImages[index] = ImageForever::get(QUuid(imageIdString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|