yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_rom_sync_panel.cc
Go to the documentation of this file.
2
3#include <string>
4
5#include "absl/strings/str_format.h"
6#include "absl/time/time.h"
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace editor {
13
15 const RomSyncCallbacks& callbacks,
16 ToastManager* toast_manager) {
17 auto& state = context->rom_sync_state();
18 auto& collab_state = context->collaboration_state();
19
20 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.18f, 0.14f, 0.12f, 1.0f));
21 ImGui::BeginChild("RomSync", ImVec2(0, 130), true);
22
23 ImGui::Text(ICON_MD_STORAGE " ROM State");
24 ImGui::Separator();
25
26 // Display current ROM hash
27 if (!state.current_rom_hash.empty()) {
28 ImGui::Text("Hash: %s",
29 state.current_rom_hash.substr(0, 16).c_str());
30 ImGui::SameLine();
31 if (ImGui::SmallButton(ICON_MD_CONTENT_COPY)) {
32 ImGui::SetClipboardText(state.current_rom_hash.c_str());
33 if (toast_manager) {
34 toast_manager->Show("ROM hash copied", ToastType::kInfo, 2.0f);
35 }
36 }
37 } else {
38 ImGui::TextDisabled("No ROM loaded");
39 }
40
41 if (state.last_sync_time != absl::InfinitePast()) {
42 ImGui::Text("Last Sync: %s",
43 absl::FormatTime("%H:%M:%S", state.last_sync_time,
44 absl::LocalTimeZone())
45 .c_str());
46 }
47
48 ImGui::Spacing();
49 ImGui::Checkbox("Auto-sync ROM changes", &state.auto_sync_enabled);
50
51 if (state.auto_sync_enabled) {
52 ImGui::SliderInt("Sync Interval (seconds)",
53 &state.sync_interval_seconds, 10, 120);
54 }
55
56 ImGui::Spacing();
57 ImGui::Separator();
58
59 bool can_sync = static_cast<bool>(callbacks.generate_rom_diff) &&
60 collab_state.active &&
61 collab_state.mode == CollaborationMode::kNetwork;
62
63 if (!can_sync)
64 ImGui::BeginDisabled();
65
66 if (ImGui::Button(ICON_MD_CLOUD_UPLOAD " Send ROM Sync", ImVec2(-1, 0))) {
67 if (callbacks.generate_rom_diff) {
68 auto diff_result = callbacks.generate_rom_diff();
69 if (diff_result.ok()) {
70 std::string hash = callbacks.get_rom_hash
71 ? callbacks.get_rom_hash()
72 : "";
73
74 state.current_rom_hash = hash;
75 state.last_sync_time = absl::Now();
76
77 // TODO: Send via network coordinator (handled by caller usually)
78 if (toast_manager) {
79 toast_manager->Show(ICON_MD_CLOUD_DONE
80 " ROM synced to collaborators",
82 }
83 } else if (toast_manager) {
84 toast_manager->Show(absl::StrFormat(ICON_MD_ERROR " Sync failed: %s",
85 diff_result.status().message()),
86 ToastType::kError, 5.0f);
87 }
88 }
89 }
90
91 if (!can_sync) {
92 ImGui::EndDisabled();
93 if (ImGui::IsItemHovered()) {
94 ImGui::SetTooltip("Connect to a network session to sync ROM");
95 }
96 }
97
98 // Show pending syncs
99 if (!state.pending_syncs.empty()) {
100 ImGui::Spacing();
101 ImGui::Text(ICON_MD_PENDING " Pending Syncs (%zu)",
102 state.pending_syncs.size());
103 ImGui::Separator();
104
105 ImGui::BeginChild("PendingSyncs", ImVec2(0, 80), true);
106 for (const auto& sync : state.pending_syncs) {
107 ImGui::BulletText("%s", sync.substr(0, 40).c_str());
108 }
109 ImGui::EndChild();
110 }
111
112 ImGui::EndChild();
113 ImGui::PopStyleColor();
114}
115
116} // namespace editor
117} // namespace yaze
void Draw(AgentUIContext *context, const RomSyncCallbacks &callbacks, ToastManager *toast_manager)
Unified context for agent UI components.
RomSyncState & rom_sync_state()
CollaborationState & collaboration_state()
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
#define ICON_MD_STORAGE
Definition icons.h:1865
#define ICON_MD_CLOUD_DONE
Definition icons.h:425
#define ICON_MD_ERROR
Definition icons.h:686
#define ICON_MD_PENDING
Definition icons.h:1398
#define ICON_MD_CONTENT_COPY
Definition icons.h:465
#define ICON_MD_CLOUD_UPLOAD
Definition icons.h:430
Callbacks for ROM sync operations.
std::function< std::string()> get_rom_hash
std::function< absl::StatusOr< std::string >()> generate_rom_diff