mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Setup script model status
This commit is contained in:
parent
859ec57ded
commit
28c9aa031c
6 changed files with 45 additions and 20 deletions
|
@ -21,19 +21,6 @@
|
|||
#include <NetworkLogging.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
void AssetMappingModel::clear() {
|
||||
// make sure we are on the same thread before we touch the hash
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this, "clear");
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Clearing loaded asset mappings for Asset Browser";
|
||||
|
||||
_pathToItemMap.clear();
|
||||
QStandardItemModel::clear();
|
||||
}
|
||||
|
||||
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
|
||||
_proxyModel.setSourceModel(&_assetMappingModel);
|
||||
_proxyModel.setSortRole(Qt::DisplayRole);
|
||||
|
@ -154,7 +141,7 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) {
|
|||
auto map = callback.engine()->newObject();
|
||||
|
||||
for (auto& kv : mappings ) {
|
||||
map.setProperty(kv.first, kv.second);
|
||||
map.setProperty(kv.first, kv.second.hash);
|
||||
}
|
||||
|
||||
if (callback.isCallable()) {
|
||||
|
@ -184,6 +171,10 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new
|
|||
request->start();
|
||||
}
|
||||
|
||||
AssetMappingModel::AssetMappingModel() {
|
||||
setupHeaders();
|
||||
}
|
||||
|
||||
bool AssetMappingModel::isKnownFolder(QString path) const {
|
||||
if (!path.endsWith("/")) {
|
||||
return false;
|
||||
|
@ -228,17 +219,19 @@ void AssetMappingModel::refresh() {
|
|||
if (it == _pathToItemMap.end()) {
|
||||
auto item = new QStandardItem(parts[i]);
|
||||
bool isFolder = i < length - 1;
|
||||
auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
|
||||
item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
|
||||
item->setData(isFolder, Qt::UserRole + 1);
|
||||
item->setData(parts[i], Qt::UserRole + 2);
|
||||
item->setData("atp:" + fullPath, Qt::UserRole + 3);
|
||||
item->setData(fullPath, Qt::UserRole + 4);
|
||||
item->setData(statusString, Qt::UserRole + 5);
|
||||
|
||||
if (lastItem) {
|
||||
lastItem->setChild(lastItem->rowCount(), 0, item);
|
||||
lastItem->appendRow(item);
|
||||
} else {
|
||||
appendRow(item);
|
||||
}
|
||||
|
||||
lastItem = item;
|
||||
_pathToItemMap[fullPath] = lastItem;
|
||||
} else {
|
||||
|
@ -300,3 +293,25 @@ void AssetMappingModel::refresh() {
|
|||
|
||||
request->start();
|
||||
}
|
||||
|
||||
void AssetMappingModel::clear() {
|
||||
// make sure we are on the same thread before we touch the hash
|
||||
if (thread() != QThread::currentThread()) {
|
||||
QMetaObject::invokeMethod(this, "clear");
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Clearing loaded asset mappings for Asset Browser";
|
||||
|
||||
_pathToItemMap.clear();
|
||||
QStandardItemModel::clear();
|
||||
setupHeaders(); // restore headers
|
||||
}
|
||||
|
||||
void AssetMappingModel::setupHeaders() {
|
||||
setHorizontalHeaderLabels(QStringList() << "Name" << "Use Baked?");
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames[Qt::DisplayRole] = "name";
|
||||
roleNames[Qt::UserRole + 5] = "baked";
|
||||
setItemRoleNames(roleNames);
|
||||
}
|
|
@ -26,6 +26,8 @@
|
|||
class AssetMappingModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssetMappingModel();
|
||||
|
||||
Q_INVOKABLE void refresh();
|
||||
|
||||
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); }
|
||||
|
@ -38,6 +40,8 @@ signals:
|
|||
void errorGettingMappings(QString errorString);
|
||||
|
||||
private:
|
||||
void setupHeaders();
|
||||
|
||||
QHash<QString, QStandardItem*> _pathToItemMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ using DataOffset = int64_t;
|
|||
|
||||
using AssetPath = QString;
|
||||
using AssetHash = QString;
|
||||
using AssetMapping = std::map<AssetPath, AssetHash>;
|
||||
using AssetPathList = QStringList;
|
||||
|
||||
const size_t SHA256_HASH_LENGTH = 32;
|
||||
|
@ -59,6 +58,13 @@ enum BakingStatus {
|
|||
Baked
|
||||
};
|
||||
|
||||
struct MappingInfo {
|
||||
AssetHash hash;
|
||||
BakingStatus status;
|
||||
};
|
||||
|
||||
using AssetMapping = std::map<AssetPath, MappingInfo>;
|
||||
|
||||
QUrl getATPUrl(const QString& hash);
|
||||
|
||||
QByteArray hashData(const QByteArray& data);
|
||||
|
|
|
@ -138,7 +138,7 @@ void GetAllMappingsRequest::doStart() {
|
|||
auto hash = message->read(SHA256_HASH_LENGTH).toHex();
|
||||
BakingStatus status;
|
||||
message->readPrimitive(&status);
|
||||
_mappings[path] = hash;
|
||||
_mappings[path] = { hash, status };
|
||||
}
|
||||
}
|
||||
emit finished(this);
|
||||
|
|
|
@ -130,7 +130,7 @@ signals:
|
|||
private:
|
||||
virtual void doStart() override;
|
||||
|
||||
std::map<AssetPath, AssetHash> _mappings;
|
||||
AssetMapping _mappings;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -332,7 +332,7 @@ void ATPClientApp::listAssets() {
|
|||
} else if (result == GetAllMappingsRequest::NoError) {
|
||||
auto mappings = request->getMappings();
|
||||
for (auto& kv : mappings ) {
|
||||
qDebug() << kv.first << kv.second;
|
||||
qDebug() << kv.first << kv.second.hash;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "error -- " << request->getError() << " -- " << request->getErrorString();
|
||||
|
|
Loading…
Reference in a new issue