2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
#include "exdpart.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
2023-09-23 14:09:00 -04:00
|
|
|
#include <QFile>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <QTableWidget>
|
2023-04-09 15:28:00 -04:00
|
|
|
#include <QVBoxLayout>
|
2023-09-23 14:09:00 -04:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2023-08-06 08:48:11 -04:00
|
|
|
#include <physis.hpp>
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
EXDPart::EXDPart(GameData* data) : data(data) {
|
|
|
|
pageTabWidget = new QTabWidget();
|
|
|
|
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
layout->addWidget(pageTabWidget);
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXDPart::loadSheet(const QString& name) {
|
|
|
|
qDebug() << "Loading" << name;
|
|
|
|
|
|
|
|
pageTabWidget->clear();
|
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
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};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
auto exh = physis_gamedata_read_excel_sheet_header(data, name.toStdString().c_str());
|
|
|
|
|
2023-07-08 10:18:07 -04:00
|
|
|
for(int i = 0; i < exh->page_count; i++) {
|
2023-09-23 14:09:00 -04:00
|
|
|
auto tableWidget = new QTableWidget();
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-07-08 10:18:07 -04:00
|
|
|
tableWidget->setColumnCount(exh->column_count);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
auto exd = physis_gamedata_read_excel_sheet(data, name.toStdString().c_str(), exh, getSuitableLanguage(exh), i);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
tableWidget->setRowCount(exd.row_count);
|
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
for (int j = 0; j < exd.row_count; j++) {
|
|
|
|
for(int z = 0; z < exd.column_count; z++) {
|
2023-09-23 14:09:00 -04:00
|
|
|
auto columnData = exd.row_data[j].column_data[z];
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
QString columnString;
|
2023-09-23 14:09:00 -04:00
|
|
|
int columnRow;
|
|
|
|
switch (columnData.tag) {
|
2023-04-09 15:28:00 -04:00
|
|
|
case physis_ColumnData::Tag::String:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString(columnData.string._0);
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Bool:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = columnData.bool_._0 ? "True" : "False";
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Int8:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.int8._0);
|
|
|
|
columnRow = columnData.int8._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::UInt8:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.u_int8._0);
|
|
|
|
columnRow = columnData.u_int8._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Int16:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.int16._0);
|
|
|
|
columnRow = columnData.int16._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::UInt16:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.u_int16._0);
|
|
|
|
columnRow = columnData.u_int16._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Int32:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.int32._0);
|
|
|
|
columnRow = columnData.int32._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::UInt32:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.u_int32._0);
|
|
|
|
columnRow = columnData.u_int32._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Float32:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.float32._0);
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::Int64:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.int64._0);
|
|
|
|
columnRow = columnData.int64._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
case physis_ColumnData::Tag::UInt64:
|
2023-09-23 14:09:00 -04:00
|
|
|
columnString = QString::number(columnData.u_int64._0);
|
|
|
|
columnRow = columnData.u_int64._0;
|
2023-04-09 15:28:00 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
auto newItem = new QTableWidgetItem(columnString);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
tableWidget->setItem(j, z, newItem);
|
2023-04-09 15:28:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-23 14:09:00 -04:00
|
|
|
tableWidget->resizeColumnsToContents();
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
pageTabWidget->addTab(tableWidget, QString("Page %1").arg(i));
|
|
|
|
}
|
2023-09-23 14:09:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|