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

View File

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