7#include <unordered_map>
33 Rom* current_rom =
nullptr;
48 std::vector<std::unique_ptr<WindowContent>>
panels;
49 std::vector<ContentRegistry::Panels::PanelFactory>
factories;
51 std::vector<ContentRegistry::Shortcuts::ShortcutDef>
shortcuts;
53 std::vector<ContentRegistry::Settings::SettingDef>
settings;
67namespace ContentRegistry {
72 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
73 RegistryState::Get().global_context = ctx;
77 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
78 auto& state = RegistryState::Get();
79 if (state.global_context)
return state.global_context->GetCurrentRom();
80 return state.current_rom;
84 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
85 auto& state = RegistryState::Get();
86 if (state.global_context) {
87 state.global_context->SetCurrentRom(
rom);
89 state.current_rom =
rom;
93 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
94 auto& state = RegistryState::Get();
95 if (state.global_context)
return &state.global_context->GetEventBus();
96 return state.event_bus;
100 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
101 auto& state = RegistryState::Get();
104 state.event_bus = bus;
108 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
109 auto& state = RegistryState::Get();
110 if (state.global_context)
return state.global_context->GetCurrentEditor();
111 return state.current_editor;
115 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
116 auto& state = RegistryState::Get();
117 if (state.global_context) {
118 state.global_context->SetCurrentEditor(editor);
120 state.current_editor = editor;
124 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
125 auto& state = RegistryState::Get();
126 auto it = state.current_window_editors.find(category);
127 return it != state.current_window_editors.end() ? it->second :
nullptr;
131 if (category.empty()) {
134 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
135 RegistryState::Get().current_window_editors[category] = editor;
139 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
140 auto& state = RegistryState::Get();
141 if (state.global_context)
return state.global_context->GetGameData();
142 return state.game_data;
146 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
147 auto& state = RegistryState::Get();
148 if (state.global_context) {
149 state.global_context->SetGameData(data);
151 state.game_data = data;
155 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
156 auto& state = RegistryState::Get();
157 if (state.global_context)
return state.global_context->GetCurrentProject();
158 return state.current_project;
162 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
163 auto& state = RegistryState::Get();
164 if (state.global_context) {
165 state.global_context->SetCurrentProject(project);
167 state.current_project = project;
171 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
172 return RegistryState::Get().hack_workflow_backend;
176 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
178 RegistryState::Get().hack_workflow_backend);
182 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
184 RegistryState::Get().hack_workflow_backend);
188 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
190 RegistryState::Get().hack_workflow_backend);
194 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
195 RegistryState::Get().hack_workflow_backend = backend;
199 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
200 return RegistryState::Get().build_workflow_status;
204 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
205 RegistryState::Get().build_workflow_status = status;
209 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
210 return RegistryState::Get().run_workflow_status;
214 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
215 RegistryState::Get().run_workflow_status = status;
219 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
220 return RegistryState::Get().build_workflow_log;
224 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
225 RegistryState::Get().build_workflow_log = output;
229 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
230 return RegistryState::Get().workflow_history;
234 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
235 auto& history = RegistryState::Get().workflow_history;
236 history.insert(history.begin(), entry);
237 constexpr size_t kMaxEntries = 20;
238 if (history.size() > kMaxEntries) {
239 history.resize(kMaxEntries);
244 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
245 RegistryState::Get().workflow_history.clear();
249 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
250 return RegistryState::Get().start_build_workflow_callback;
254 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
255 RegistryState::Get().start_build_workflow_callback = std::move(callback);
259 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
260 return RegistryState::Get().run_project_workflow_callback;
264 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
265 RegistryState::Get().run_project_workflow_callback = std::move(callback);
269 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
270 return RegistryState::Get().show_workflow_output_callback;
274 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
275 RegistryState::Get().show_workflow_output_callback = std::move(callback);
279 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
280 return RegistryState::Get().cancel_build_workflow_callback;
284 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
285 RegistryState::Get().cancel_build_workflow_callback = std::move(callback);
289 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
290 auto& state = RegistryState::Get();
291 if (state.global_context) {
292 state.global_context->Clear();
294 state.current_rom =
nullptr;
295 state.event_bus =
nullptr;
296 state.current_editor =
nullptr;
297 state.game_data =
nullptr;
298 state.current_project =
nullptr;
299 state.hack_workflow_backend =
nullptr;
300 state.current_window_editors.clear();
303 state.build_workflow_log.clear();
304 state.workflow_history.clear();
305 state.start_build_workflow_callback =
nullptr;
306 state.run_project_workflow_callback =
nullptr;
307 state.show_workflow_output_callback =
nullptr;
308 state.cancel_build_workflow_callback =
nullptr;
320 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
321 RegistryState::Get().factories.push_back(std::move(factory));
324std::vector<std::unique_ptr<WindowContent>>
CreateAll() {
325 std::vector<PanelFactory> factories;
327 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
328 factories = RegistryState::Get().factories;
331 std::vector<std::unique_ptr<WindowContent>> result;
332 result.reserve(factories.size());
334 for (
const auto& factory : factories) {
335 if (
auto panel = factory()) {
336 result.push_back(std::move(panel));
342void Register(std::unique_ptr<WindowContent> panel) {
345 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
346 RegistryState::Get().panels.push_back(std::move(panel));
350 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
352 std::vector<WindowContent*> result;
353 result.reserve(RegistryState::Get().panels.size());
355 for (
const auto& panel : RegistryState::Get().panels) {
356 result.push_back(panel.get());
363 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
365 for (
const auto& panel : RegistryState::Get().panels) {
366 if (panel->GetId() == id) {
375 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
376 RegistryState::Get().panels.clear();
388 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
389 RegistryState::Get().editor_factories.push_back(std::move(factory));
393 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
394 std::vector<std::unique_ptr<Editor>> result;
395 result.reserve(RegistryState::Get().editor_factories.size());
397 for (
const auto& factory : RegistryState::Get().editor_factories) {
398 if (
auto editor = factory(deps)) {
399 result.push_back(std::move(editor));
414 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
415 RegistryState::Get().shortcuts.push_back(shortcut);
418void add(
const std::string&
id,
const std::string& key,
const std::string& desc) {
423 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
424 return RegistryState::Get().shortcuts;
433namespace WorkflowActions {
436 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
437 auto& actions = RegistryState::Get().workflow_actions;
438 auto it = std::find_if(actions.begin(), actions.end(),
440 return existing.id == action.id;
442 if (it != actions.end()) {
446 actions.push_back(action);
450 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
451 return RegistryState::Get().workflow_actions;
455 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
456 RegistryState::Get().workflow_actions.clear();
468 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
469 RegistryState::Get().settings.push_back(setting);
472void add(
const std::string& section,
const std::string& key,
const std::string& default_val,
const std::string& desc) {
473 Register({key, section, default_val, desc});
477 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
478 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.
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)
Editor * current_editor()
Get the currently active editor.
void SetRunProjectWorkflowCallback(std::function< void()> callback)
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.
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 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::vector< ContentRegistry::Editors::EditorFactory > editor_factories
std::vector< ProjectWorkflowHistoryEntry > workflow_history
std::function< void()> cancel_build_workflow_callback
std::vector< std::unique_ptr< WindowContent > > panels
std::vector< ContentRegistry::Panels::PanelFactory > factories
std::function< void()> run_project_workflow_callback
std::unordered_map< std::string, Editor * > current_window_editors
std::vector< ContentRegistry::Settings::SettingDef > settings
std::vector< ContentRegistry::WorkflowActions::ActionDef > workflow_actions
ProjectWorkflowStatus build_workflow_status
std::vector< ContentRegistry::Shortcuts::ShortcutDef > shortcuts
std::function< void()> start_build_workflow_callback
std::function< void()> show_workflow_output_callback
std::string build_workflow_log
static RegistryState & Get()
ProjectWorkflowStatus run_workflow_status
Modern project structure with comprehensive settings consolidation.