[studio] Cleanup useless complexity
All checks were successful
Build / build (push) Successful in 1m16s

This commit is contained in:
2026-02-06 21:28:46 -06:00
parent f204d01a3d
commit c9cb186462
2 changed files with 56 additions and 69 deletions

View File

@@ -13,13 +13,14 @@ FileInfo::FileInfo(Context &sctx) noexcept:
ox::Error FileInfo::open(ox::StringParam filePath) noexcept { ox::Error FileInfo::open(ox::StringParam filePath) noexcept {
m_filePath = std::move(filePath); m_filePath = std::move(filePath);
auto &fs = m_sctx.project->romFs(); auto &fs = m_sctx.project->romFs();
auto const fileBuff = fs.read(m_filePath).or_value({}); OX_REQUIRE(fileBuff, fs.read(m_filePath));
auto hdr = keel::readAssetHeader(fileBuff).or_value({}); auto [hdr, err] = keel::readAssetHeader(fileBuff);
m_fileInfo = {}; if (!err) {
m_fileInfo.assetId.emplace(hdr.uuid.toString()); m_fileInfo.emplace(Info{
m_fileInfo.typeName.emplace(std::move(hdr.clawHdr.typeName)); .assetId = hdr.uuid.toString(),
m_fileInfo.typeVersion.emplace(hdr.clawHdr.typeVersion); .typeName = std::move(hdr.clawHdr.typeName),
m_fileInfo.format.emplace([&hdr] { .typeVersion = hdr.clawHdr.typeVersion,
.format = [&hdr] {
switch (hdr.clawHdr.fmt) { switch (hdr.clawHdr.fmt) {
case ox::ClawFormat::Metal: case ox::ClawFormat::Metal:
return ox::StringLiteral{"Metal Claw"}; return ox::StringLiteral{"Metal Claw"};
@@ -28,8 +29,10 @@ ox::Error FileInfo::open(ox::StringParam filePath) noexcept {
default: default:
return ox::StringLiteral{"Other"}; return ox::StringLiteral{"Other"};
} }
}()); }(),
m_fileInfo.dataSize.emplace(hdr.clawHdr.dataSize); .dataSize = hdr.clawHdr.dataSize,
});
}
Popup::open(); Popup::open();
return {}; return {};
} }
@@ -76,63 +79,46 @@ void FileInfo::draw(Context &sctx) noexcept {
void FileInfo::drawTable() const noexcept { void FileInfo::drawTable() const noexcept {
ig::IDStackItem const idStackItem{"FileInfo"}; ig::IDStackItem const idStackItem{"FileInfo"};
ImGui::Text("%s", m_filePath.c_str()); ImGui::Text("%s", m_filePath.c_str());
if (ImGui::BeginTable( if (m_fileInfo && ImGui::BeginTable(
"Table", 2, "Table", 2,
ImGuiTableFlags_Borders | ImGuiTableFlags_Borders |
ImGuiTableFlags_RowBg)) { ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70); ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70);
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide); ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide);
bool somethingDrew = false;
// asset id // asset id
if (m_fileInfo.assetId) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("Asset ID:"); ImGui::Text("Asset ID:");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::Text("%s", m_fileInfo.assetId->c_str()); ImGui::Text("%s", m_fileInfo->assetId.c_str());
somethingDrew = true;
}
// typeName // typeName
if (m_fileInfo.typeName) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("Type Name:"); ImGui::Text("Type Name:");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::Text("%s", m_fileInfo.typeName->c_str()); ImGui::Text("%s", m_fileInfo->typeName.c_str());
somethingDrew = true;
}
// typeVersion // typeVersion
if (m_fileInfo.typeVersion) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("Type Version:"); ImGui::Text("Type Version:");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::Text("%d", *m_fileInfo.typeVersion); ImGui::Text("%d", m_fileInfo->typeVersion);
somethingDrew = true;
}
// format // format
if (m_fileInfo.format) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("Format:"); ImGui::Text("Format:");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::Text("%s", m_fileInfo.format->c_str()); ImGui::Text("%s", m_fileInfo->format.c_str());
somethingDrew = true;
}
// size // size
if (m_fileInfo.dataSize) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
ImGui::Text("Data Size:"); ImGui::Text("Data Size:");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::Text("%lluB", *m_fileInfo.dataSize); ImGui::Text("%lluB", m_fileInfo->dataSize);
somethingDrew = true;
}
ImGui::EndTable(); ImGui::EndTable();
if (!somethingDrew) { } else {
ImGui::Text("No information available"); ImGui::Text("No information available");
} }
}
} }
} }

View File

@@ -15,14 +15,15 @@ class FileInfo: public ig::Popup {
private: private:
Context &m_sctx; Context &m_sctx;
ox::String m_filePath; ox::String m_filePath;
struct { struct Info {
ox::Optional<ox::UUIDStr> assetId; ox::UUIDStr assetId;
ox::Optional<ox::String> typeName; ox::String typeName;
ox::Optional<int> typeVersion{}; int typeVersion{};
ox::Optional<ox::StringLiteral> format; ox::StringLiteral format;
// use manual sizing to work with %ull // use manual sizing to work with %ull
ox::Optional<unsigned long long> dataSize{}; unsigned long long dataSize{};
} m_fileInfo; };
ox::Optional<Info> m_fileInfo;
public: public:
explicit FileInfo(Context &sctx) noexcept; explicit FileInfo(Context &sctx) noexcept;