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/clock.h"
7#include "absl/time/time.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13namespace editor {
14
16 const RomSyncCallbacks& callbacks,
17 ToastManager* toast_manager) {
18 auto& state = context->rom_sync_state();
19 auto& collab_state = context->collaboration_state();
20
21 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.18f, 0.14f, 0.12f, 1.0f));
22 ImGui::BeginChild("RomSync", ImVec2(0, 130), true);
23
24 ImGui::Text(ICON_MD_STORAGE " ROM State");
25 ImGui::Separator();
26
27 // Display current ROM hash
28 if (!state.current_rom_hash.empty()) {
29 ImGui::Text("Hash: %s", 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)", &state.sync_interval_seconds,
53 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 =
71 callbacks.get_rom_hash ? callbacks.get_rom_hash() : "";
72
73 state.current_rom_hash = hash;
74 state.last_sync_time = absl::Now();
75
76 // TODO: Send via network coordinator (handled by caller usually)
77 if (toast_manager) {
78 toast_manager->Show(ICON_MD_CLOUD_DONE " ROM synced to collaborators",
80 }
81 } else if (toast_manager) {
82 toast_manager->Show(absl::StrFormat(ICON_MD_ERROR " Sync failed: %s",
83 diff_result.status().message()),
84 ToastType::kError, 5.0f);
85 }
86 }
87 }
88
89 if (!can_sync) {
90 ImGui::EndDisabled();
91 if (ImGui::IsItemHovered()) {
92 ImGui::SetTooltip("Connect to a network session to sync ROM");
93 }
94 }
95
96 // Show pending syncs
97 if (!state.pending_syncs.empty()) {
98 ImGui::Spacing();
99 ImGui::Text(ICON_MD_PENDING " Pending Syncs (%zu)",
100 state.pending_syncs.size());
101 ImGui::Separator();
102
103 ImGui::BeginChild("PendingSyncs", ImVec2(0, 80), true);
104 for (const auto& sync : state.pending_syncs) {
105 ImGui::BulletText("%s", sync.substr(0, 40).c_str());
106 }
107 ImGui::EndChild();
108 }
109
110 ImGui::EndChild();
111 ImGui::PopStyleColor();
112}
113
114} // namespace editor
115} // 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