summaryrefslogtreecommitdiff
path: root/src/factories/BaseFactory.cpp
diff options
context:
space:
mode:
authorLywx <kiritodev01@gmail.com>2026-07-02 20:42:38 -0600
committerGitHub <noreply@github.com>2026-07-02 20:42:38 -0600
commit58527d7bf8778bc67179454a19ad8c84a74aff13 (patch)
tree37df9df3eb558977b84b5a33b8143f3859c5d057 /src/factories/BaseFactory.cpp
parentb42a4fa16f7a75e2a96a7c107e6359c80b685863 (diff)
Implemented UI Framework (#225)
* Implemented base renderer among main UI framework implementation * Implemented basic geo layout rendering * Implemented animation support among fixing lightning among other things * Implemented multiple ui factories for sm64 * Implemented first iteration of the custom sequence driver * Added export buttons on multiple factories * More sequence player fixes among f3dex2 working correctly * Implemented pm64 viewers * Implemented audio support for pm64 * Fully implemented pm64 factories * Implemented more sm64 factories * Added tons of missing sf64 factories * Implemented all assets among sf64 wrong padding * Run formatting * Fixed wrong spacing on gfx too * Fixed CI * Fixed bad pipeline
Diffstat (limited to 'src/factories/BaseFactory.cpp')
-rw-r--r--src/factories/BaseFactory.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/factories/BaseFactory.cpp b/src/factories/BaseFactory.cpp
index 62f46a9..acd3b34 100644
--- a/src/factories/BaseFactory.cpp
+++ b/src/factories/BaseFactory.cpp
@@ -1,5 +1,55 @@
#include "BaseFactory.h"
+#ifdef BUILD_UI
+#include <sstream>
+#include <unordered_map>
+#include "Companion.h"
+#include "ui/Widgets.h"
+
+float BaseFactoryUI::GetItemHeight(const ParseResultData&) {
+ return UI::AssetCardHeight();
+}
+
+void BaseFactoryUI::DrawUI(const ParseResultData& item) {
+ UI::AssetHeader(item.name, item.type);
+ UI::BeginAssetBody();
+
+ // Exporter output is stable per asset; cache it instead of re-exporting
+ // every frame.
+ static std::unordered_map<std::string, std::string> sPreviewCache;
+ auto cached = sPreviewCache.find(item.name);
+ if (cached == sPreviewCache.end()) {
+ std::string text;
+ const auto factory = Companion::Instance->GetFactory(item.type);
+ if (factory.has_value() && factory.value()->CanPreviewCode() && item.data.has_value()) {
+ if (const auto exporter = factory.value()->GetExporter(ExportType::Code); exporter.has_value()) {
+ try {
+ std::ostringstream out;
+ std::string entryName = item.name;
+ std::string replacement = item.name;
+ YAML::Node node = item.node;
+ exporter.value()->Export(out, item.data.value(), entryName, node, &replacement);
+ text = out.str();
+ } catch (const std::exception& e) {
+ text = std::string("// preview unavailable: ") + e.what();
+ } catch (...) { text = "// preview unavailable"; }
+ }
+ }
+
+ if (text.empty()) {
+ // No code preview: fall back to the asset's YAML config.
+ YAML::Node node = item.node;
+ text = YAML::Dump(node);
+ }
+ cached = sPreviewCache.emplace(item.name, std::move(text)).first;
+ }
+ const std::string& text = cached->second;
+
+ ImGui::TextUnformatted(text.c_str());
+ UI::EndAssetBody();
+}
+#endif
+
void BaseExporter::WriteHeader(LUS::BinaryWriter& writer, Torch::ResourceType resType, int32_t version) {
writer.Write((int8_t)(Torch::Endianness::Native)); // 0x00 - Endianness
writer.Write((int8_t)0); // 0x01 - Is Asset Custom