VideoCommon: add graphics mod editor helper utilities for interacting with objects in the scene

This commit is contained in:
iwubcode 2025-03-14 22:43:43 -05:00
commit a727f8908c
2 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,35 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "VideoCommon/GraphicsModEditor/SceneUtils.h"
#include <fmt/format.h>
#include "Common/EnumUtils.h"
namespace GraphicsModEditor
{
std::string GetDrawCallName(const EditorState& editor_state,
GraphicsModSystem::DrawCallID draw_call)
{
if (draw_call == GraphicsModSystem::DrawCallID::INVALID)
return "";
std::string draw_call_name = std::to_string(Common::ToUnderlying(draw_call));
auto& draw_call_to_user_data = editor_state.m_user_data.m_draw_call_id_to_user_data;
if (const auto user_data_iter = draw_call_to_user_data.find(draw_call);
user_data_iter != draw_call_to_user_data.end())
{
if (!user_data_iter->second.m_friendly_name.empty())
draw_call_name = user_data_iter->second.m_friendly_name;
}
return draw_call_name;
}
std::string GetActionName(GraphicsModAction* action)
{
if (!action) [[unlikely]]
return "";
return fmt::format("{}-{}", action->GetFactoryName(), action->GetID());
}
} // namespace GraphicsModEditor

View file

@ -0,0 +1,36 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <concepts>
#include <string>
#include <vector>
#include "VideoCommon/GraphicsModEditor/EditorState.h"
#include "VideoCommon/GraphicsModSystem/Types.h"
namespace GraphicsModEditor
{
std::string GetDrawCallName(const EditorState& editor_state,
GraphicsModSystem::DrawCallID draw_call);
std::string GetActionName(GraphicsModAction* action);
template <std::derived_from<GraphicsModAction> ActionType>
std::vector<ActionType*> GetActionsForDrawCall(const EditorState& editor_state,
GraphicsModSystem::DrawCallID draw_call)
{
std::vector<ActionType*> result;
auto& draw_call_id_to_actions = editor_state.m_user_data.m_draw_call_id_to_actions;
if (const auto actions_iter = draw_call_id_to_actions.find(draw_call);
actions_iter != draw_call_id_to_actions.end())
{
for (GraphicsModAction* action : actions_iter->second)
{
if (action->GetFactoryName() == ActionType::factory_name)
result.push_back(static_cast<ActionType*>(action));
}
}
return result;
}
} // namespace GraphicsModEditor