Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Add search to object inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed May 20, 2024
1 parent 06acb98 commit 2a8daed
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
27 changes: 19 additions & 8 deletions Bouny/ui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ void ui_manager::draw()
CRoom* room = nullptr;
g_module_interface->GetCurrentRoomData(room);

CInstance* global = nullptr;
g_module_interface->GetGlobalInstance(&global);
if (global != nullptr)
{
if (ImGui::Begin("Global"))
{
auto value = RValue(global);
std::map<std::string, std::string> results;
utils::enumerate_members(value, results, true);
static std::string search_query;
utils::draw_search(results, search_query);
}
ImGui::End();
}

if (room != nullptr)
{
Expand Down Expand Up @@ -214,14 +228,11 @@ void ui_manager::draw()
if (element->m_Type == 2)
{
auto instance = static_cast<CLayerInstanceElement*>(element);
g_module_interface->EnumInstanceMembers(instance->m_Instance,
[](const char* name, RValue* value) -> bool
{
ImGui::Text(
"%s: %s", name,
utils::rvalue_to_string(value).c_str());
return false;
});
auto value = RValue(instance->m_Instance);
std::map<std::string, std::string> results;
utils::enumerate_members(value, results);
static std::string search_query;
utils::draw_search(results, search_query);
}
}

Expand Down
41 changes: 36 additions & 5 deletions Bouny/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "utils.h"

#include "globals.h"
#include "utils.h"
#include <imgui_stdlib.h>
#include <numeric>

#include "globals.h"

std::map<RValueType, std::string> names = {
{VALUE_REAL, "real"},
{VALUE_STRING, "string"},
Expand Down Expand Up @@ -42,7 +41,7 @@ void utils::log_hook(std::string name, YYTK::RValue& return_value, int num_args,
std::string args_str = std::accumulate(args, args + num_args, std::string{},
[](std::string acc, YYTK::RValue* arg)
{
auto arg_str = rvalue_to_string(arg);
auto arg_str = utils::rvalue_to_string(arg);
auto type_str = names.contains(arg->m_Kind)
? names[arg->m_Kind]
: "unknown";
Expand All @@ -69,3 +68,35 @@ int utils::hook_and_log(std::string name)
log_hook(name, return_value, num_args, args);
});
}

void utils::draw_search(std::map<std::string, std::string>& search_results, std::string& search_query)
{
ImGui::InputText("Search", &search_query);
ImGui::Separator();
if (ImGui::BeginChild("##search_results", ImGui::GetContentRegionAvail()))
{
for (auto& [key, value] : search_results)
{
auto key_lower = key;
std::ranges::transform(key_lower, key_lower.begin(), ::tolower);
auto search_query_lower = search_query;
std::ranges::transform(search_query_lower, search_query_lower.begin(), ::tolower);
if (search_query_lower.empty() || key_lower.contains(search_query_lower))
{
ImGui::Text("%s: %s", key.c_str(), value.c_str());
}
}
}
ImGui::EndChild();
}

void utils::enumerate_members(YYTK::RValue rvalue, std::map<std::string, std::string>& results, bool ignore_functions)
{
g_module_interface->EnumInstanceMembers(rvalue, [&results, ignore_functions](const char* name, YYTK::RValue* value)
{
auto str = utils::rvalue_to_string(value);
if (ignore_functions && str == "function") return false;
results[std::string(name)] = str;
return false;
});
}
3 changes: 3 additions & 0 deletions Bouny/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ class utils
static std::string rvalue_to_string(YYTK::RValue* rvalue);
static void log_hook(std::string name, YYTK::RValue& return_value, int num_args, YYTK::RValue** args);
static int hook_and_log(std::string name);

static void draw_search(std::map<std::string, std::string>& search_results, std::string& search_query);
static void enumerate_members(YYTK::RValue rvalue, std::map<std::string, std::string>& results, bool ignore_functions = false);
};

0 comments on commit 2a8daed

Please sign in to comment.