7#include <unordered_map>
31 GlobalEditorContext* global_context =
nullptr;
33 Rom* current_rom =
nullptr;
36 std::unordered_map<std::string, Editor*> current_window_editors;
48 std::vector<std::unique_ptr<WindowContent>> panels;
49 std::vector<ContentRegistry::Panels::PanelFactory> factories;
50 std::vector<ContentRegistry::Editors::EditorFactory> editor_factories;
51 std::vector<ContentRegistry::Shortcuts::ShortcutDef> shortcuts;
52 std::vector<ContentRegistry::WorkflowActions::ActionDef> workflow_actions;
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)
80 return state.global_context->GetCurrentRom();
81 return state.current_rom;
85 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
86 auto& state = RegistryState::Get();
87 if (state.global_context) {
88 state.global_context->SetCurrentRom(
rom);
90 state.current_rom =
rom;
94 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
95 auto& state = RegistryState::Get();
96 if (state.global_context)
97 return &state.global_context->GetEventBus();
98 return state.event_bus;
102 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
103 auto& state = RegistryState::Get();
106 state.event_bus = bus;
110 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
111 auto& state = RegistryState::Get();
112 if (state.global_context)
113 return state.global_context->GetCurrentEditor();
114 return state.current_editor;
118 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
119 auto& state = RegistryState::Get();
120 if (state.global_context) {
121 state.global_context->SetCurrentEditor(editor);
123 state.current_editor = editor;
127 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
128 auto& state = RegistryState::Get();
129 auto it = state.current_window_editors.find(category);
130 return it != state.current_window_editors.end() ? it->second :
nullptr;
137 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
138 RegistryState::Get().current_window_editors[
category] = editor;
142 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
143 auto& state = RegistryState::Get();
144 if (state.global_context)
145 return state.global_context->GetGameData();
146 return state.game_data;
150 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
151 auto& state = RegistryState::Get();
152 if (state.global_context) {
153 state.global_context->SetGameData(data);
155 state.game_data = data;
159 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
160 auto& state = RegistryState::Get();
161 if (state.global_context)
162 return state.global_context->GetCurrentProject();
163 return state.current_project;
167 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
168 auto& state = RegistryState::Get();
169 if (state.global_context) {
170 state.global_context->SetCurrentProject(project);
172 state.current_project = project;
176 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
177 return RegistryState::Get().hack_workflow_backend;
181 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
182 return dynamic_cast<workflow::ValidationCapability*
>(
183 RegistryState::Get().hack_workflow_backend);
187 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
188 return dynamic_cast<workflow::ProgressionCapability*
>(
189 RegistryState::Get().hack_workflow_backend);
193 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
194 return dynamic_cast<workflow::PlanningCapability*
>(
195 RegistryState::Get().hack_workflow_backend);
199 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
200 RegistryState::Get().hack_workflow_backend = backend;
204 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
205 return RegistryState::Get().build_workflow_status;
209 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
210 RegistryState::Get().build_workflow_status = status;
214 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
215 return RegistryState::Get().run_workflow_status;
219 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
220 RegistryState::Get().run_workflow_status = status;
224 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
225 return RegistryState::Get().build_workflow_log;
229 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
230 RegistryState::Get().build_workflow_log = output;
234 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
235 return RegistryState::Get().workflow_history;
239 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
240 auto& history = RegistryState::Get().workflow_history;
241 history.insert(history.begin(), entry);
242 constexpr size_t kMaxEntries = 20;
243 if (history.size() > kMaxEntries) {
244 history.resize(kMaxEntries);
249 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
250 RegistryState::Get().workflow_history.clear();
254 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
255 return RegistryState::Get().start_build_workflow_callback;
259 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
260 RegistryState::Get().start_build_workflow_callback = std::move(callback);
264 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
265 return RegistryState::Get().run_project_workflow_callback;
269 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
270 RegistryState::Get().run_project_workflow_callback = std::move(callback);
274 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
275 return RegistryState::Get().show_workflow_output_callback;
279 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
280 RegistryState::Get().show_workflow_output_callback = std::move(callback);
284 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
285 return RegistryState::Get().cancel_build_workflow_callback;
289 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
290 RegistryState::Get().cancel_build_workflow_callback = std::move(callback);
294 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
295 auto& state = RegistryState::Get();
296 if (state.global_context) {
297 state.global_context->Clear();
299 state.current_rom =
nullptr;
300 state.event_bus =
nullptr;
301 state.current_editor =
nullptr;
302 state.game_data =
nullptr;
303 state.current_project =
nullptr;
304 state.hack_workflow_backend =
nullptr;
305 state.current_window_editors.clear();
306 state.build_workflow_status = ProjectWorkflowStatus{};
307 state.run_workflow_status = ProjectWorkflowStatus{};
308 state.build_workflow_log.clear();
309 state.workflow_history.clear();
310 state.start_build_workflow_callback =
nullptr;
311 state.run_project_workflow_callback =
nullptr;
312 state.show_workflow_output_callback =
nullptr;
313 state.cancel_build_workflow_callback =
nullptr;
325 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
326 RegistryState::Get().factories.push_back(std::move(factory));
329std::vector<std::unique_ptr<WindowContent>>
CreateAll() {
330 std::vector<PanelFactory> factories;
332 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
333 factories = RegistryState::Get().factories;
336 std::vector<std::unique_ptr<WindowContent>> result;
337 result.reserve(factories.size());
339 for (
const auto& factory : factories) {
340 if (
auto panel = factory()) {
341 result.push_back(std::move(panel));
347void Register(std::unique_ptr<WindowContent> panel) {
351 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
352 RegistryState::Get().panels.push_back(std::move(panel));
355std::vector<WindowContent*>
GetAll() {
356 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
358 std::vector<WindowContent*> result;
359 result.reserve(RegistryState::Get().panels.size());
361 for (
const auto& panel : RegistryState::
Get().panels) {
362 result.push_back(panel.get());
368WindowContent*
Get(
const std::string&
id) {
369 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
371 for (
const auto& panel : RegistryState::
Get().panels) {
372 if (panel->GetId() ==
id) {
381 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
382 RegistryState::Get().panels.clear();
394 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
395 RegistryState::Get().editor_factories.push_back(std::move(factory));
398std::vector<std::unique_ptr<Editor>>
CreateAll(
const EditorDependencies& deps) {
399 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
400 std::vector<std::unique_ptr<Editor>> result;
401 result.reserve(RegistryState::Get().editor_factories.size());
403 for (
const auto& factory : RegistryState::
Get().editor_factories) {
404 if (
auto editor = factory(deps)) {
405 result.push_back(std::move(editor));
419void Register(
const ShortcutDef& shortcut) {
420 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
421 RegistryState::Get().shortcuts.push_back(shortcut);
424void add(
const std::string&
id,
const std::string& key,
425 const std::string& desc) {
429std::vector<ShortcutDef>
GetAll() {
430 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
431 return RegistryState::Get().shortcuts;
440namespace WorkflowActions {
442void Register(
const ActionDef& action) {
443 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
444 auto& actions = RegistryState::Get().workflow_actions;
445 auto it = std::find_if(
446 actions.begin(), actions.end(),
447 [&](
const ActionDef& existing) { return existing.id == action.id; });
448 if (it != actions.end()) {
452 actions.push_back(action);
455std::vector<ActionDef>
GetAll() {
456 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
457 return RegistryState::Get().workflow_actions;
461 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
462 RegistryState::Get().workflow_actions.clear();
473void Register(
const SettingDef& setting) {
474 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
475 RegistryState::Get().settings.push_back(setting);
478void add(
const std::string& section,
const std::string& key,
479 const std::string& default_val,
const std::string& desc) {
483std::vector<SettingDef>
GetAll() {
484 std::lock_guard<std::mutex> lock(RegistryState::Get().mutex);
485 return RegistryState::Get().settings;
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.
static RegistryState & Get()
Modern project structure with comprehensive settings consolidation.