yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
wasm_session_bridge.h
Go to the documentation of this file.
1#ifndef YAZE_APP_PLATFORM_WASM_SESSION_BRIDGE_H_
2#define YAZE_APP_PLATFORM_WASM_SESSION_BRIDGE_H_
3
4#ifdef __EMSCRIPTEN__
5
6#include <functional>
7#include <mutex>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "core/features.h"
13
14namespace yaze {
15
16// Forward declarations
17class Rom;
18
19namespace editor {
20class EditorManager;
21} // namespace editor
22
23namespace app {
24namespace platform {
25
32struct SharedSessionState {
33 // ROM state
34 bool rom_loaded = false;
35 std::string rom_filename;
36 std::string rom_title;
37 size_t rom_size = 0;
38 bool rom_dirty = false;
39
40 // Editor state
41 std::string current_editor;
42 int current_editor_type = 0;
43 std::vector<std::string> visible_cards;
44
45 // Session info
46 size_t session_id = 0;
47 size_t session_count = 1;
48 std::string session_name;
49
50 // Feature flags (serializable subset)
51 bool flag_save_all_palettes = false;
52 bool flag_save_gfx_groups = false;
53 bool flag_save_overworld_maps = true;
54 bool flag_load_custom_overworld = false;
55 bool flag_apply_zscustom_asm = false;
56
57 // Project info
58 std::string project_name;
59 std::string project_path;
60 bool has_project = false;
61
62 // Z3ed integration
63 std::string last_z3ed_command;
64 std::string last_z3ed_result;
65 bool z3ed_command_pending = false;
66
67 // Serialize to JSON string
68 std::string ToJson() const;
69
70 // Deserialize from JSON string
71 static SharedSessionState FromJson(const std::string& json);
72
73 // Update from current EditorManager state
74 void UpdateFromEditor(editor::EditorManager* manager);
75
76 // Apply changes to EditorManager
77 absl::Status ApplyToEditor(editor::EditorManager* manager);
78};
79
89class WasmSessionBridge {
90 public:
91 // Callback types
92 using StateChangeCallback = std::function<void(const SharedSessionState&)>;
93 using CommandCallback = std::function<std::string(const std::string&)>;
94
99 static void Initialize(editor::EditorManager* editor_manager);
100
104 static bool IsReady();
105
109 static void SetupJavaScriptBindings();
110
114 static std::string GetState();
115
119 static std::string SetState(const std::string& state_json);
120
124 static std::string GetProperty(const std::string& property_name);
125
129 static std::string SetProperty(const std::string& property_name,
130 const std::string& value);
131
132 // ============================================================================
133 // Feature Flags
134 // ============================================================================
135
139 static std::string GetFeatureFlags();
140
144 static std::string SetFeatureFlag(const std::string& flag_name, bool value);
145
149 static std::string GetAvailableFlags();
150
151 // ============================================================================
152 // Z3ed Command Integration
153 // ============================================================================
154
160 static std::string ExecuteZ3edCommand(const std::string& command);
161
165 static std::string GetPendingCommand();
166
170 static std::string SetCommandResult(const std::string& result);
171
175 static void SetCommandHandler(CommandCallback handler);
176
177 // ============================================================================
178 // Event System
179 // ============================================================================
180
184 static void OnStateChange(StateChangeCallback callback);
185
189 static void NotifyStateChange();
190
194 static std::string RefreshState();
195
196 private:
197 static editor::EditorManager* editor_manager_;
198 static bool initialized_;
199 static SharedSessionState current_state_;
200 static std::mutex state_mutex_;
201 static std::vector<StateChangeCallback> state_callbacks_;
202 static CommandCallback command_handler_;
203
204 // Pending z3ed command queue
205 static std::string pending_command_;
206 static std::string pending_result_;
207 static bool command_pending_;
208};
209
210} // namespace platform
211} // namespace app
212} // namespace yaze
213
214#else // !__EMSCRIPTEN__
215
216// Stub for non-WASM builds
217#include <string>
218#include <functional>
219
220namespace yaze {
221namespace editor {
222class EditorManager;
223}
224
225namespace app {
226namespace platform {
227
229 bool rom_loaded = false;
230 std::string rom_filename;
231 std::string ToJson() const { return "{}"; }
232 static SharedSessionState FromJson(const std::string&) { return {}; }
234};
235
237 public:
238 using StateChangeCallback = std::function<void(const SharedSessionState&)>;
239 using CommandCallback = std::function<std::string(const std::string&)>;
240
242 static bool IsReady() { return false; }
243 static void SetupJavaScriptBindings() {}
244 static std::string GetState() { return "{}"; }
245 static std::string SetState(const std::string&) { return "{}"; }
246 static std::string GetProperty(const std::string&) { return "{}"; }
247 static std::string SetProperty(const std::string&, const std::string&) { return "{}"; }
248 static std::string GetFeatureFlags() { return "{}"; }
249 static std::string SetFeatureFlag(const std::string&, bool) { return "{}"; }
250 static std::string GetAvailableFlags() { return "[]"; }
251 static std::string ExecuteZ3edCommand(const std::string&) { return "{}"; }
252 static std::string GetPendingCommand() { return "{}"; }
253 static std::string SetCommandResult(const std::string&) { return "{}"; }
256 static void NotifyStateChange() {}
257 static std::string RefreshState() { return "{}"; }
258};
259
260} // namespace platform
261} // namespace app
262} // namespace yaze
263
264#endif // __EMSCRIPTEN__
265
266#endif // YAZE_APP_PLATFORM_WASM_SESSION_BRIDGE_H_
267
static void OnStateChange(StateChangeCallback)
static void SetCommandHandler(CommandCallback)
static std::string SetFeatureFlag(const std::string &, bool)
static std::string GetProperty(const std::string &)
std::function< void(const SharedSessionState &)> StateChangeCallback
static std::string SetCommandResult(const std::string &)
static std::string ExecuteZ3edCommand(const std::string &)
static std::string SetProperty(const std::string &, const std::string &)
std::function< std::string(const std::string &)> CommandCallback
static void Initialize(editor::EditorManager *)
static std::string SetState(const std::string &)
The EditorManager controls the main editor window and manages the various editor classes.
void UpdateFromEditor(editor::EditorManager *)
static SharedSessionState FromJson(const std::string &)