mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-22 12:07:45 +00:00
Cache EXDs in exdpart
This commit is contained in:
parent
9663164e76
commit
1e35855496
2 changed files with 131 additions and 36 deletions
|
@ -4,8 +4,12 @@
|
|||
#include "exdpart.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <physis.hpp>
|
||||
|
||||
EXDPart::EXDPart(GameData* data) : data(data) {
|
||||
|
@ -21,80 +25,164 @@ void EXDPart::loadSheet(const QString& name) {
|
|||
|
||||
pageTabWidget->clear();
|
||||
|
||||
QFile definitionFile("Achievement.json");
|
||||
definitionFile.open(QIODevice::ReadOnly);
|
||||
|
||||
auto document = QJsonDocument::fromJson(definitionFile.readAll());
|
||||
auto definitionList = document.object()["definitions"].toArray();
|
||||
|
||||
for (auto definition : definitionList) {
|
||||
if (definition.toObject().contains("converter") && definition.toObject()["converter"].toObject()["type"].toString() == "link") {
|
||||
auto linkName = definition.toObject()["converter"].toObject()["target"].toString();
|
||||
|
||||
auto linkExh = physis_gamedata_read_excel_sheet_header(data, linkName.toStdString().c_str());
|
||||
auto linkExd = physis_gamedata_read_excel_sheet(data, linkName.toStdString().c_str(), linkExh, getSuitableLanguage(linkExh), 0);
|
||||
|
||||
if (linkExd.p_ptr != nullptr) {
|
||||
cachedExcelSheets[linkName] = CachedExcel{linkExh, linkExd};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto exh = physis_gamedata_read_excel_sheet_header(data, name.toStdString().c_str());
|
||||
|
||||
for(int i = 0; i < exh->page_count; i++) {
|
||||
QTableWidget* tableWidget = new QTableWidget();
|
||||
auto tableWidget = new QTableWidget();
|
||||
|
||||
tableWidget->setColumnCount(exh->column_count);
|
||||
|
||||
auto exd = physis_gamedata_read_excel_sheet(data, name.toStdString().c_str(), exh, exh->languages[0], i);
|
||||
auto exd = physis_gamedata_read_excel_sheet(data, name.toStdString().c_str(), exh, getSuitableLanguage(exh), i);
|
||||
|
||||
tableWidget->setRowCount(exd.row_count);
|
||||
|
||||
for(int z = 0; z < exd.column_count; z++) {
|
||||
auto columnData = exd.row_data[0].column_data[z];
|
||||
|
||||
QString columnType;
|
||||
switch (columnData.tag) {
|
||||
case physis_ColumnData::Tag::String:
|
||||
columnType = "String";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Bool:
|
||||
columnType = "Bool";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int8:
|
||||
columnType = "Int8";
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt8:
|
||||
columnType = "UInt8";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int16:
|
||||
columnType = "Int16";
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt16:
|
||||
columnType = "UInt16";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int32:
|
||||
columnType = "Int32";
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt32:
|
||||
columnType = "UInt32";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Float32:
|
||||
columnType = "Float32";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int64:
|
||||
columnType = "Int64";
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt64:
|
||||
columnType = "UInt64";
|
||||
break;
|
||||
}
|
||||
|
||||
columnType = definitionList[z].toObject()["name"].toString();
|
||||
|
||||
auto headerItem = new QTableWidgetItem();
|
||||
headerItem->setText(columnType);
|
||||
|
||||
tableWidget->setHorizontalHeaderItem(z, headerItem);
|
||||
}
|
||||
|
||||
for (int j = 0; j < exd.row_count; j++) {
|
||||
for(int z = 0; z < exd.column_count; z++) {
|
||||
auto data = exd.row_data[j].column_data[z];
|
||||
auto columnData = exd.row_data[j].column_data[z];
|
||||
|
||||
QString columnString;
|
||||
QString columnType;
|
||||
switch (data.tag) {
|
||||
int columnRow;
|
||||
switch (columnData.tag) {
|
||||
case physis_ColumnData::Tag::String:
|
||||
columnString = QString(data.string._0);
|
||||
columnType = "String";
|
||||
columnString = QString(columnData.string._0);
|
||||
break;
|
||||
case physis_ColumnData::Tag::Bool:
|
||||
columnString = data.bool_._0 ? "True" : "False";
|
||||
columnType = "Bool";
|
||||
columnString = columnData.bool_._0 ? "True" : "False";
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int8:
|
||||
columnString = QString::number(data.int8._0);
|
||||
columnType = "Int8";
|
||||
columnString = QString::number(columnData.int8._0);
|
||||
columnRow = columnData.int8._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt8:
|
||||
columnString = QString::number(data.u_int8._0);
|
||||
columnType = "UInt8";
|
||||
columnString = QString::number(columnData.u_int8._0);
|
||||
columnRow = columnData.u_int8._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int16:
|
||||
columnString = QString::number(data.int16._0);
|
||||
columnType = "Int16";
|
||||
columnString = QString::number(columnData.int16._0);
|
||||
columnRow = columnData.int16._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt16:
|
||||
columnString = QString::number(data.u_int16._0);
|
||||
columnType = "UInt16";
|
||||
columnString = QString::number(columnData.u_int16._0);
|
||||
columnRow = columnData.u_int16._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int32:
|
||||
columnString = QString::number(data.int32._0);
|
||||
columnType = "Int32";
|
||||
columnString = QString::number(columnData.int32._0);
|
||||
columnRow = columnData.int32._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt32:
|
||||
columnString = QString::number(data.u_int32._0);
|
||||
columnType = "UInt32";
|
||||
columnString = QString::number(columnData.u_int32._0);
|
||||
columnRow = columnData.u_int32._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::Float32:
|
||||
columnString = QString::number(data.float32._0);
|
||||
columnType = "Float32";
|
||||
columnString = QString::number(columnData.float32._0);
|
||||
break;
|
||||
case physis_ColumnData::Tag::Int64:
|
||||
columnString = QString::number(data.int64._0);
|
||||
columnType = "Int64";
|
||||
columnString = QString::number(columnData.int64._0);
|
||||
columnRow = columnData.int64._0;
|
||||
break;
|
||||
case physis_ColumnData::Tag::UInt64:
|
||||
columnString = QString::number(data.u_int64._0);
|
||||
columnType = "UInt64";
|
||||
columnString = QString::number(columnData.u_int64._0);
|
||||
columnRow = columnData.u_int64._0;
|
||||
break;
|
||||
}
|
||||
|
||||
auto definition = definitionList[z].toObject();
|
||||
if (definition.contains("converter") && definition["converter"].toObject()["type"].toString() == "link") {
|
||||
auto linkName = definition["converter"].toObject()["target"].toString();
|
||||
|
||||
if (cachedExcelSheets.contains(linkName)) {
|
||||
auto cachedExcel = cachedExcelSheets[linkName];
|
||||
if (columnRow < cachedExcel.exd.row_count) {
|
||||
columnString = cachedExcel.exd.row_data[columnRow].column_data->string._0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto newItem = new QTableWidgetItem(columnString);
|
||||
|
||||
tableWidget->setItem(i, j, newItem);
|
||||
|
||||
QTableWidgetItem* headerItem = new QTableWidgetItem();
|
||||
headerItem->setText(columnType);
|
||||
tableWidget->setHorizontalHeaderItem(j, headerItem);
|
||||
tableWidget->setItem(j, z, newItem);
|
||||
}
|
||||
}
|
||||
|
||||
tableWidget->resizeColumnsToContents();
|
||||
|
||||
pageTabWidget->addTab(tableWidget, QString("Page %1").arg(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Language EXDPart::getSuitableLanguage(physis_EXH* pExh) {
|
||||
for (int i = 0; i < pExh->language_count; i++) {
|
||||
if (pExh->languages[i] == Language::English) {
|
||||
return Language::English;
|
||||
}
|
||||
}
|
||||
|
||||
return Language::None;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
|
||||
struct GameData;
|
||||
#include <QTabWidget>
|
||||
#include <QMap>
|
||||
#include <physis.hpp>
|
||||
|
||||
class EXDPart : public QWidget {
|
||||
public:
|
||||
|
@ -18,4 +18,11 @@ private:
|
|||
GameData* data = nullptr;
|
||||
|
||||
QTabWidget* pageTabWidget = nullptr;
|
||||
|
||||
struct CachedExcel {
|
||||
physis_EXH* exh = nullptr;
|
||||
physis_EXD exd;
|
||||
};
|
||||
QMap<QString, CachedExcel> cachedExcelSheets;
|
||||
Language getSuitableLanguage(physis_EXH* pExh);
|
||||
};
|
Loading…
Add table
Reference in a new issue