7#include <unordered_map>
35 Rom* current_rom =
nullptr;
52 std::vector<std::unique_ptr<WindowContent>>
panels;
53 std::vector<ContentRegistry::Panels::PanelFactory>
factories;
55 std::vector<ContentRegistry::Shortcuts::ShortcutDef>
shortcuts;
57 std::vector<ContentRegistry::Settings::SettingDef>
settings;
71namespace ContentRegistry {
76 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
77 RegistryState::Get().global_context = ctx;
81 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
82 auto& state = RegistryState::Get();
83 if (state.global_context)
84 return state.global_context->GetCurrentRom();
85 return state.current_rom;
89 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
90 auto& state = RegistryState::Get();
91 if (state.global_context) {
92 state.global_context->SetCurrentRom(
rom);
94 state.current_rom =
rom;
98 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
99 auto& state = RegistryState::Get();
100 if (state.global_context)
101 return &state.global_context->GetEventBus();
102 return state.event_bus;
106 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
107 auto& state = RegistryState::Get();
110 state.event_bus = bus;
114 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
115 auto& state = RegistryState::Get();
116 if (state.global_context)
117 return state.global_context->GetCurrentEditor();
118 return state.current_editor;
122 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
123 auto& state = RegistryState::Get();
124 if (state.global_context) {
125 state.global_context->SetCurrentEditor(editor);
127 state.current_editor = editor;
131 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
132 auto& state = RegistryState::Get();
133 auto it = state.current_window_editors.find(category);
134 return it != state.current_window_editors.end() ? it->second :
nullptr;
138 if (category.empty()) {
141 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
142 RegistryState::Get().current_window_editors[category] = editor;
146 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
147 auto& state = RegistryState::Get();
148 if (state.global_context)
149 return state.global_context->GetGameData();
150 return state.game_data;
154 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
155 auto& state = RegistryState::Get();
156 if (state.global_context) {
157 state.global_context->SetGameData(data);
159 state.game_data = data;
163 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
164 auto& state = RegistryState::Get();
165 if (state.global_context)
166 return state.global_context->GetCurrentProject();
167 return state.current_project;
171 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
172 auto& state = RegistryState::Get();
173 if (state.global_context) {
174 state.global_context->SetCurrentProject(project);
176 state.current_project = project;
180 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
181 return RegistryState::Get().user_settings;
185 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
186 RegistryState::Get().user_settings = settings;
190 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
191 return RegistryState::Get().layout_manager;
195 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
196 RegistryState::Get().layout_manager = manager;
200 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
201 return RegistryState::Get().hack_workflow_backend;
205 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
207 RegistryState::Get().hack_workflow_backend);
211 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
213 RegistryState::Get().hack_workflow_backend);
217 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
219 RegistryState::Get().hack_workflow_backend);
223 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
224 RegistryState::Get().hack_workflow_backend = backend;
228 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
229 return RegistryState::Get().build_workflow_status;
233 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
234 RegistryState::Get().build_workflow_status = status;
238 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
239 return RegistryState::Get().run_workflow_status;
243 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
244 RegistryState::Get().run_workflow_status = status;
248 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
249 return RegistryState::Get().build_workflow_log;
253 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
254 RegistryState::Get().build_workflow_log = output;
258 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
259 return RegistryState::Get().workflow_history;
263 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
264 auto& history = RegistryState::Get().workflow_history;
265 history.insert(history.begin(), entry);
266 constexpr size_t kMaxEntries = 20;
267 if (history.size() > kMaxEntries) {
268 history.resize(kMaxEntries);
273 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
274 RegistryState::Get().workflow_history.clear();
278 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
279 return RegistryState::Get().start_build_workflow_callback;
283 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
284 RegistryState::Get().start_build_workflow_callback = std::move(callback);
288 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
289 return RegistryState::Get().run_project_workflow_callback;
293 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
294 RegistryState::Get().run_project_workflow_callback = std::move(callback);
298 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
299 return RegistryState::Get().show_workflow_output_callback;
303 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
304 RegistryState::Get().show_workflow_output_callback = std::move(callback);
308 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
309 return RegistryState::Get().cancel_build_workflow_callback;
313 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
314 RegistryState::Get().cancel_build_workflow_callback = std::move(callback);
318 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
319 auto& state = RegistryState::Get();
320 if (state.global_context) {
321 state.global_context->Clear();
323 state.current_rom =
nullptr;
324 state.event_bus =
nullptr;
325 state.current_editor =
nullptr;
326 state.game_data =
nullptr;
327 state.current_project =
nullptr;
328 state.hack_workflow_backend =
nullptr;
329 state.user_settings =
nullptr;
330 state.layout_manager =
nullptr;
331 state.current_window_editors.clear();
334 state.build_workflow_log.clear();
335 state.workflow_history.clear();
336 state.start_build_workflow_callback =
nullptr;
337 state.run_project_workflow_callback =
nullptr;
338 state.show_workflow_output_callback =
nullptr;
339 state.cancel_build_workflow_callback =
nullptr;
351 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
352 RegistryState::Get().factories.push_back(std::move(factory));
355std::vector<std::unique_ptr<WindowContent>>
CreateAll() {
356 std::vector<PanelFactory> factories;
358 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
359 factories = RegistryState::Get().factories;
362 std::vector<std::unique_ptr<WindowContent>> result;
363 result.reserve(factories.size());
365 for (
const auto& factory : factories) {
366 if (
auto panel = factory()) {
367 result.push_back(std::move(panel));
373void Register(std::unique_ptr<WindowContent> panel) {
377 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
378 RegistryState::Get().panels.push_back(std::move(panel));
382 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
384 std::vector<WindowContent*> result;
385 result.reserve(RegistryState::Get().panels.size());
387 for (
const auto& panel : RegistryState::Get().panels) {
388 result.push_back(panel.get());
395 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
397 for (
const auto& panel : RegistryState::Get().panels) {
398 if (panel->GetId() == id) {
407 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
408 RegistryState::Get().panels.clear();
420 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
421 RegistryState::Get().editor_factories.push_back(std::move(factory));
425 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
426 std::vector<std::unique_ptr<Editor>> result;
427 result.reserve(RegistryState::Get().editor_factories.size());
429 for (
const auto& factory : RegistryState::Get().editor_factories) {
430 if (
auto editor = factory(deps)) {
431 result.push_back(std::move(editor));
446 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
447 RegistryState::Get().shortcuts.push_back(shortcut);
450void add(
const std::string&
id,
const std::string& key,
451 const std::string& desc) {
456 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
457 return RegistryState::Get().shortcuts;
466namespace WorkflowActions {
469 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
470 auto& actions = RegistryState::Get().workflow_actions;
471 auto it = std::find_if(
472 actions.begin(), actions.end(),
473 [&](
const ActionDef& existing) { return existing.id == action.id; });
474 if (it != actions.end()) {
478 actions.push_back(action);
482 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
483 return RegistryState::Get().workflow_actions;
487 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
488 RegistryState::Get().workflow_actions.clear();
500 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
501 RegistryState::Get().settings.push_back(setting);
504void add(
const std::string& section,
const std::string& key,
505 const std::string& default_val,
const std::string& desc) {
506 Register({key, section, default_val, desc});
510 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
511 return RegistryState::Get().settings;
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Interface for editor classes.
Instance-based runtime context replacing ContentRegistry::Context.
Manages ImGui DockBuilder layouts for each editor type.
Manages user preferences and settings persistence.
Base interface for all logical window content components.
std::vector< ProjectWorkflowHistoryEntry > workflow_history()
std::string build_workflow_log()
void ClearWorkflowHistory()
void SetGlobalContext(GlobalEditorContext *ctx)
void SetShowWorkflowOutputCallback(std::function< void()> callback)
void SetEditorWindowContext(const std::string &category, Editor *editor)
Rom * rom()
Get the current ROM instance.
void SetEventBus(::yaze::EventBus *bus)
Set the current EventBus instance.
::yaze::EventBus * event_bus()
Get the current EventBus instance.
void SetRom(Rom *rom)
Set the current ROM instance.
void SetGameData(::yaze::zelda3::GameData *data)
Set the current game data instance.
void AppendWorkflowHistory(const ProjectWorkflowHistoryEntry &entry)
UserSettings * user_settings()
Get the current UserSettings instance.
Editor * current_editor()
Get the currently active editor.
void SetRunProjectWorkflowCallback(std::function< void()> callback)
LayoutManager * layout_manager()
Get the shared LayoutManager instance.
void SetBuildWorkflowStatus(const ProjectWorkflowStatus &status)
void SetCancelBuildWorkflowCallback(std::function< void()> callback)
std::function< void()> cancel_build_workflow_callback()
void SetCurrentEditor(Editor *editor)
Set the currently active editor.
::yaze::zelda3::GameData * game_data()
Get the current game data instance.
void SetLayoutManager(LayoutManager *manager)
ProjectWorkflowStatus build_workflow_status()
workflow::PlanningCapability * hack_planning_backend()
::yaze::project::YazeProject * current_project()
Get the current project instance.
void SetBuildWorkflowLog(const std::string &output)
void SetStartBuildWorkflowCallback(std::function< void()> callback)
void SetRunWorkflowStatus(const ProjectWorkflowStatus &status)
workflow::ValidationCapability * hack_validation_backend()
std::function< void()> run_project_workflow_callback()
void SetHackWorkflowBackend(workflow::HackWorkflowBackend *backend)
void SetUserSettings(UserSettings *settings)
void Clear()
Clear all context state.
workflow::HackWorkflowBackend * hack_workflow_backend()
std::function< void()> show_workflow_output_callback()
std::function< void()> start_build_workflow_callback()
Editor * editor_window_context(const std::string &category)
ProjectWorkflowStatus run_workflow_status()
workflow::ProgressionCapability * hack_progression_backend()
void SetCurrentProject(::yaze::project::YazeProject *project)
Set the current project instance.
void RegisterFactory(EditorFactory factory)
std::function< std::unique_ptr< Editor >(const EditorDependencies &)> EditorFactory
std::vector< std::unique_ptr< Editor > > CreateAll(const EditorDependencies &deps)
void Clear()
Clear all registered panels.
void Register(std::unique_ptr< WindowContent > panel)
Register a panel instance (Legacy/Global).
std::vector< WindowContent * > GetAll()
Get all registered panels.
WindowContent * Get(const std::string &id)
Get a specific panel by its ID.
std::function< std::unique_ptr< WindowContent >()> PanelFactory
void RegisterFactory(PanelFactory factory)
Register a panel factory.
std::vector< std::unique_ptr< WindowContent > > CreateAll()
Create new instances of all registered panels.
void Register(const SettingDef &setting)
std::vector< SettingDef > GetAll()
void add(const std::string §ion, const std::string &key, const std::string &default_val, const std::string &desc)
std::vector< ShortcutDef > GetAll()
void add(const std::string &id, const std::string &key, const std::string &desc)
void Register(const ShortcutDef &shortcut)
std::vector< ActionDef > GetAll()
void Register(const ActionDef &action)
Editors are the view controllers for the application.
Unified dependency container for all editor types.
std::function< void()> start_build_workflow_callback
std::unordered_map< std::string, Editor * > current_window_editors
std::vector< ContentRegistry::Shortcuts::ShortcutDef > shortcuts
std::function< void()> show_workflow_output_callback
std::vector< std::unique_ptr< WindowContent > > panels
std::function< void()> run_project_workflow_callback
std::vector< ProjectWorkflowHistoryEntry > workflow_history
ProjectWorkflowStatus build_workflow_status
std::vector< ContentRegistry::Panels::PanelFactory > factories
std::vector< ContentRegistry::WorkflowActions::ActionDef > workflow_actions
std::string build_workflow_log
std::function< void()> cancel_build_workflow_callback
static RegistryState & Get()
ProjectWorkflowStatus run_workflow_status
std::vector< ContentRegistry::Editors::EditorFactory > editor_factories
std::vector< ContentRegistry::Settings::SettingDef > settings
Modern project structure with comprehensive settings consolidation.