yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_canvas_issue_report.cc
Go to the documentation of this file.
2#include "util/i18n/tr.h"
3
4#include <algorithm>
5#include <array>
6#include <cstdio>
7#include <filesystem>
8#include <limits>
9#include <optional>
10#include <set>
11#include <span>
12#include <string>
13#include <string_view>
14#include <tuple>
15#include <vector>
16
17#include "absl/status/status.h"
18#include "absl/strings/str_cat.h"
19#include "absl/strings/str_format.h"
20#include "absl/time/clock.h"
21#include "absl/time/time.h"
24#include "app/gui/core/icons.h"
27#ifdef YAZE_WITH_GRPC
29#endif
30#include "imgui/imgui.h"
31#include "imgui/imgui_internal.h"
32#include "util/macro.h"
33#include "util/platform_paths.h"
34#include "util/rom_hash.h"
42
43namespace yaze::editor {
44
45namespace {
46
47constexpr float kIssueReportDialogWidth = 640.0f;
48constexpr float kIssueReportDialogHeight = 620.0f;
49constexpr float kIssueReportDialogMinWidth = 360.0f;
50constexpr float kIssueReportDialogMinHeight = 340.0f;
51constexpr float kIssueReportDialogViewportMargin = 16.0f;
52constexpr float kIssueReportNotesHeight = 116.0f;
53constexpr float kIssueReportDiagnosticsHeight = 168.0f;
54constexpr char kIssueReportSummaryHint[] = "What looks wrong?";
55constexpr char kIssueReportPopupIdDiagnostics[] = "##DungeonIssueDiagnostics";
56constexpr char kIssueReportSectionPaths[] = "Local files";
57constexpr char kIssueReportSectionDiagnostics[] = "Diagnostics";
58constexpr char kIssueReportStatusIdle[] =
59 "Local draft. Nothing is uploaded or submitted.";
61 "Screenshot captured. Open Local files for its path.";
62constexpr char kIssueReportStatusSavedLog[] = "Saved to the local issue log.";
64 "Copied report to clipboard. Nothing was submitted.";
66 "Copied diagnostics to clipboard. Nothing was submitted.";
68 ICON_MD_ADD_A_PHOTO " Capture Screenshot";
70 ICON_MD_PHOTO_CAMERA " Re-capture Screenshot";
72 ICON_MD_SAVE_AS " Save to Issue Log";
74 ICON_MD_CONTENT_COPY " Copy Report";
75constexpr char kIssueReportCloseButtonLabel[] = ICON_MD_CLOSE " Close";
76
78 ImVec2 center;
80 ImVec2 min_size;
81 ImVec2 max_size;
82};
83
85 const ImGuiViewport* viewport = ImGui::GetMainViewport();
86 const ImVec2 work_size =
87 viewport != nullptr ? viewport->WorkSize : ImGui::GetIO().DisplaySize;
88 const ImVec2 center = viewport != nullptr
89 ? viewport->GetWorkCenter()
90 : ImVec2(work_size.x * 0.5f, work_size.y * 0.5f);
91 const ImVec2 max_size(
92 std::max(1.0f, work_size.x - kIssueReportDialogViewportMargin * 2.0f),
93 std::max(1.0f, work_size.y - kIssueReportDialogViewportMargin * 2.0f));
94 const ImVec2 min_size(std::min(kIssueReportDialogMinWidth, max_size.x),
95 std::min(kIssueReportDialogMinHeight, max_size.y));
96 const ImVec2 initial_size(
97 std::clamp(kIssueReportDialogWidth, min_size.x, max_size.x),
98 std::clamp(kIssueReportDialogHeight, min_size.y, max_size.y));
99 return {center, initial_size, min_size, max_size};
100}
101
102float GetIssueActionButtonWidth(const char* label) {
103 float text_width = ImGui::CalcTextSize(label).x;
104 if (label == kIssueReportCaptureButtonLabel ||
106 text_width =
107 std::max(ImGui::CalcTextSize(kIssueReportCaptureButtonLabel).x,
108 ImGui::CalcTextSize(kIssueReportRecaptureButtonLabel).x);
109 }
110 return text_width + ImGui::GetStyle().FramePadding.x * 2.0f;
111}
112
113int CountWrappedIssueActionRows(std::span<const char* const> labels,
114 float available_width) {
115 const float spacing = ImGui::GetStyle().ItemSpacing.x;
116 float used_width = 0.0f;
117 int rows = labels.empty() ? 0 : 1;
118 for (const char* label : labels) {
119 const float button_width = GetIssueActionButtonWidth(label);
120 if (used_width > 0.0f &&
121 used_width + spacing + button_width > available_width) {
122 ++rows;
123 used_width = button_width;
124 } else {
125 used_width += (used_width > 0.0f ? spacing : 0.0f) + button_width;
126 }
127 }
128 return rows;
129}
130
131void PlaceNextIssueAction(const char* label, float available_width,
132 float* used_width) {
133 const float spacing = ImGui::GetStyle().ItemSpacing.x;
134 const float button_width = GetIssueActionButtonWidth(label);
135 if (*used_width > 0.0f &&
136 *used_width + spacing + button_width <= available_width) {
137 ImGui::SameLine();
138 *used_width += spacing + button_width;
139 return;
140 }
141 *used_width = button_width;
142}
143
144const char* GetStoredPlacementLabel(const zelda3::RoomObject& object) {
145 const int layer_value = object.GetLayerValue();
146 if (!zelda3::UsesRoomObjectStream(object)) {
147 if (layer_value == 0) {
148 return "Upper layer (BG1)";
149 }
150 return layer_value == 1 ? "Lower layer (BG2)" : "Invalid selector";
151 }
152 switch (layer_value) {
153 case 0:
154 return "Primary";
155 case 1:
156 return "BG2 overlay";
157 case 2:
158 return "BG1 overlay";
159 default:
160 return "Unknown";
161 }
162}
163
164const char* GetBlocksetGroupName(uint8_t blockset) {
165 static const char* kGroupNames[] = {
166 "HC/Sewers", "Eastern", "Desert", "Hera", "A-Tower", "PoD", "Swamp",
167 "Skull", "Thieves", "Ice", "Misery", "Turtle", "GT",
168 };
169 constexpr size_t kCount = sizeof(kGroupNames) / sizeof(kGroupNames[0]);
170 return blockset < kCount ? kGroupNames[blockset] : "Custom";
171}
172
174 return absl::FormatTime("%Y%m%d-%H%M%S", absl::Now(), absl::LocalTimeZone());
175}
176
178 return absl::FormatTime("%Y-%m-%d %H:%M:%S %Z", absl::Now(),
179 absl::LocalTimeZone());
180}
181
183 const auto blocks = room.blocks();
184 if (blocks.size() < 8) {
185 return "BG sheets: unavailable";
186 }
187 return absl::StrFormat(
188 "BG sheets: [%02X %02X %02X %02X %02X %02X %02X %02X]",
189 static_cast<int>(blocks[0]), static_cast<int>(blocks[1]),
190 static_cast<int>(blocks[2]), static_cast<int>(blocks[3]),
191 static_cast<int>(blocks[4]), static_cast<int>(blocks[5]),
192 static_cast<int>(blocks[6]), static_cast<int>(blocks[7]));
193}
194
196 const auto semantics = zelda3::GetObjectLayerSemantics(obj);
198 return absl::StrFormat(
199 "storage=special-table selector=%d (%s) routine=%d "
200 "legacy_both_bgs=%s "
201 "routing=%s",
202 obj.GetLayerValue(), GetStoredPlacementLabel(obj), semantics.routine_id,
203 semantics.draws_to_both_bgs ? "yes" : "no",
204 zelda3::ObjectRenderRoutingToken(semantics.render_routing));
205 }
206 return absl::StrFormat(
207 "stream=%s draw_layer=%d effective_bg=%s routine=%d "
208 "legacy_both_bgs=%s "
209 "routing=%s",
211 static_cast<int>(
213 zelda3::EffectiveBgLayerLabel(semantics.effective_bg_layer),
214 semantics.routine_id, semantics.draws_to_both_bgs ? "yes" : "no",
215 zelda3::ObjectRenderRoutingToken(semantics.render_routing));
216}
217
218const char* TraceLayerLabel(uint8_t layer) {
219 switch (static_cast<zelda3::RoomObject::LayerType>(layer)) {
221 return "BG1";
223 return "BG2";
225 return "BG3";
226 }
227 return "BG?";
228}
229
230std::string FormatObjectTileSample(std::span<const gfx::TileInfo> tiles,
231 size_t max_count, std::string_view prefix) {
232 std::string out = absl::StrFormat("%s count=%zu", std::string(prefix).c_str(),
233 tiles.size());
234 const size_t preview_count = std::min<size_t>(tiles.size(), max_count);
235 for (size_t i = 0; i < preview_count; ++i) {
236 const auto& tile = tiles[i];
237 out += absl::StrFormat(" [%zu]=0x%03X/p%d/pr%d/h%d/v%d", i, tile.id_,
238 static_cast<int>(tile.palette_), tile.over_ ? 1 : 0,
239 tile.horizontal_mirror_ ? 1 : 0,
240 tile.vertical_mirror_ ? 1 : 0);
241 }
242 if (tiles.size() > preview_count) {
243 out += absl::StrFormat(" ... %zu more", tiles.size() - preview_count);
244 }
245 return out;
246}
247
249 std::string summary;
250 std::vector<zelda3::ObjectDrawer::TileTrace> writes;
251};
252
254 std::array<gfx::Bitmap*, 2> bitmaps;
255
257 for (gfx::Bitmap* bitmap : bitmaps) {
258 if (bitmap != nullptr) {
259 gfx::Arena::Get().RetireBitmap(*bitmap);
260 }
261 }
262 }
263};
264
266 Rom* rom, const zelda3::Room& room, size_t selected_index,
267 const gfx::PaletteGroup& palette_group) {
268 if (rom == nullptr || !rom->is_loaded()) {
269 return {.summary = "\nDrawer trace: unavailable (ROM not loaded)"};
270 }
271
272 const auto& objects = room.GetTileObjects();
273 if (selected_index >= objects.size()) {
274 return {.summary = "\nDrawer trace: unavailable (stale selection)"};
275 }
276 if (!zelda3::UsesRoomObjectStream(objects[selected_index])) {
277 return {.summary =
278 "\nDrawer trace: unavailable (special-table object uses the "
279 "dedicated room pass)"};
280 }
281
282 // The report must follow the same primary -> BG2 overlay -> BG1 overlay
283 // order as Room::RenderObjectsToBackground. Earlier object writes can own a
284 // physical tilemap entry and therefore override the matching layout word
285 // used by conditional edge/cap routines.
286 zelda3::ObjectDrawer drawer(rom, room.id(), room.get_gfx_buffer().data());
287 drawer.SetRoomFloorGraphics(room.floor1(), room.floor2());
289 gfx::BackgroundBuffer bg1(512, 512);
290 gfx::BackgroundBuffer bg2(512, 512);
291 gfx::BackgroundBuffer layout_bg1(512, 512);
292 gfx::BackgroundBuffer layout_bg2(512, 512);
293 ScopedBitmapRetirement retire_trace_bitmaps{{&bg1.bitmap(), &bg2.bitmap()}};
294 for (auto* buffer : {&bg1, &bg2}) {
295 buffer->EnsureBitmapInitialized();
296 buffer->bitmap().Fill(255);
297 buffer->ClearBuffer();
298 }
299 layout_bg1.buffer() = room.bg1_buffer().buffer();
300 layout_bg2.buffer() = room.bg2_buffer().buffer();
301
302 std::vector<zelda3::ObjectDrawer::TileTrace> trace;
303 absl::Status status = absl::NotFoundError("selected object not replayed");
304 bool selected_was_replayed = false;
305 for (uint8_t pass = 0; pass < 3 && !selected_was_replayed; ++pass) {
306 for (size_t index = 0; index < objects.size(); ++index) {
307 const auto& stored_obj = objects[index];
308 if (!zelda3::UsesRoomObjectStream(stored_obj)) {
309 continue;
310 }
311 const uint8_t list_index =
312 std::min<uint8_t>(stored_obj.GetLayerValue(), 2);
313 if (list_index != pass) {
314 continue;
315 }
316
317 zelda3::RoomObject render_obj = stored_obj;
318 render_obj.layer_ = zelda3::MapRoomObjectListIndexToDrawLayer(list_index);
319 if (index == selected_index) {
320 drawer.SetTraceCollector(&trace, /*trace_only=*/false);
321 status =
322 drawer.DrawObject(render_obj, bg1, bg2, palette_group,
323 room.GetDungeonState(), &layout_bg1, &layout_bg2);
324 drawer.ClearTraceCollector();
325 selected_was_replayed = true;
326 break;
327 }
328
329 status =
330 drawer.DrawObject(render_obj, bg1, bg2, palette_group,
331 room.GetDungeonState(), &layout_bg1, &layout_bg2);
332 if (!status.ok()) {
333 break;
334 }
335 }
336 if (!status.ok() && !selected_was_replayed) {
337 break;
338 }
339 }
340 if (!status.ok()) {
341 return {.summary = absl::StrFormat("\nDrawer trace: unavailable (%s)",
342 std::string(status.message()).c_str())};
343 }
344
345 if (trace.empty()) {
346 return {.summary = "\nDrawer trace: status=ok writes=0"};
347 }
348
349 int min_x = std::numeric_limits<int>::max();
350 int min_y = std::numeric_limits<int>::max();
351 int max_x = std::numeric_limits<int>::min();
352 int max_y = std::numeric_limits<int>::min();
353 std::array<int, 3> layer_counts = {0, 0, 0};
354 std::set<std::tuple<int, int, uint8_t>> unique_cells;
355 for (const auto& write : trace) {
356 min_x = std::min<int>(min_x, write.x_tile);
357 min_y = std::min<int>(min_y, write.y_tile);
358 max_x = std::max<int>(max_x, write.x_tile);
359 max_y = std::max<int>(max_y, write.y_tile);
360 if (write.layer < layer_counts.size()) {
361 ++layer_counts[write.layer];
362 }
363 unique_cells.insert({write.x_tile, write.y_tile, write.layer});
364 }
365
366 std::string out = absl::StrFormat(
367 "\nDrawer trace: status=ok context=room-stream-prefix+layout-tilewords "
368 "writes=%zu unique_cells=%zu "
369 "bounds_tiles=(%d,%d)..(%d,%d) layer_counts BG1=%d BG2=%d BG3=%d",
370 trace.size(), unique_cells.size(), min_x, min_y, max_x, max_y,
374
375 const size_t preview_count = std::min<size_t>(trace.size(), 12);
376 for (size_t i = 0; i < preview_count; ++i) {
377 const auto& write = trace[i];
378 const int palette = (write.flags >> 3) & 0x7;
379 out += absl::StrFormat(
380 "\n write[%zu] %s tile=(%d,%d) id=0x%03X pal=%d pri=%d h=%d v=%d", i,
381 TraceLayerLabel(write.layer), write.x_tile, write.y_tile, write.tile_id,
382 palette, (write.flags & 0x4) ? 1 : 0, (write.flags & 0x1) ? 1 : 0,
383 (write.flags & 0x2) ? 1 : 0);
384 }
385 if (trace.size() > preview_count) {
386 out += absl::StrFormat("\n ... %zu more write(s)",
387 trace.size() - preview_count);
388 }
389 return {.summary = std::move(out), .writes = std::move(trace)};
390}
391
393 std::string label;
394 int x = 0;
395 int y = 0;
396};
397
398bool PaletteIndexMatchesTracePalette(uint8_t palette_index,
399 uint8_t trace_flags) {
400 if ((palette_index & 0x0F) == 0) {
401 return false;
402 }
403 const uint8_t trace_palette = static_cast<uint8_t>((trace_flags >> 3) & 0x7);
404 return static_cast<uint8_t>((palette_index >> 4) & 0x7) == trace_palette;
405}
406
407std::optional<PaletteSamplePoint> ChooseObjectTracePaletteSample(
408 std::span<const zelda3::ObjectDrawer::TileTrace> trace,
409 const zelda3::PaletteDebugger& palette_debugger) {
410 constexpr std::array<std::pair<int, int>, 6> kPreferredOffsets = {
411 std::pair{4, 4}, std::pair{3, 3}, std::pair{0, 0},
412 std::pair{7, 7}, std::pair{0, 7}, std::pair{7, 0},
413 };
414
415 for (size_t i = 0; i < trace.size(); ++i) {
416 const auto& write = trace[i];
417 const int tile_origin_x = write.x_tile * 8;
418 const int tile_origin_y = write.y_tile * 8;
419 const auto label = absl::StrFormat(
420 "object-trace[%zu] tile=(%d,%d) pal=%d", i, write.x_tile, write.y_tile,
421 static_cast<int>((write.flags >> 3) & 0x7));
422
423 for (const auto& [dx, dy] : kPreferredOffsets) {
424 const int sample_x = tile_origin_x + dx;
425 const int sample_y = tile_origin_y + dy;
426 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
427 if (PaletteIndexMatchesTracePalette(comp.palette_index, write.flags)) {
428 return PaletteSamplePoint{.label = label, .x = sample_x, .y = sample_y};
429 }
430 }
431
432 for (int dy = 0; dy < 8; ++dy) {
433 for (int dx = 0; dx < 8; ++dx) {
434 const int sample_x = tile_origin_x + dx;
435 const int sample_y = tile_origin_y + dy;
436 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
437 if (PaletteIndexMatchesTracePalette(comp.palette_index, write.flags)) {
438 return PaletteSamplePoint{
439 .label = label, .x = sample_x, .y = sample_y};
440 }
441 }
442 }
443 }
444
445 if (!trace.empty()) {
446 const auto& write = trace.front();
447 return PaletteSamplePoint{
448 .label = absl::StrFormat("object-trace[0] tile=(%d,%d) pal=%d fallback",
449 write.x_tile, write.y_tile,
450 static_cast<int>((write.flags >> 3) & 0x7)),
451 .x = write.x_tile * 8 + 4,
452 .y = write.y_tile * 8 + 4};
453 }
454
455 return std::nullopt;
456}
457
459 std::span<const zelda3::ObjectDrawer::TileTrace> trace, int selection_x_px,
460 int selection_y_px, int selection_w_px, int selection_h_px) {
461 if (trace.empty()) {
462 return "trace: writes=0";
463 }
464
465 int min_x = std::numeric_limits<int>::max();
466 int min_y = std::numeric_limits<int>::max();
467 int max_x = std::numeric_limits<int>::min();
468 int max_y = std::numeric_limits<int>::min();
469 std::set<std::tuple<int, int, uint8_t>> unique_cells;
470 for (const auto& write : trace) {
471 min_x = std::min<int>(min_x, write.x_tile);
472 min_y = std::min<int>(min_y, write.y_tile);
473 max_x = std::max<int>(max_x, write.x_tile);
474 max_y = std::max<int>(max_y, write.y_tile);
475 unique_cells.insert({write.x_tile, write.y_tile, write.layer});
476 }
477
478 const int trace_x_px = min_x * 8;
479 const int trace_y_px = min_y * 8;
480 const int trace_w_px = (max_x - min_x + 1) * 8;
481 const int trace_h_px = (max_y - min_y + 1) * 8;
482 return absl::StrFormat(
483 "trace: writes=%zu unique_cells=%zu bounds_px=(%d,%d,%d,%d) "
484 "delta_vs_selection_px=(%+d,%+d,%+d,%+d)",
485 trace.size(), unique_cells.size(), trace_x_px, trace_y_px, trace_w_px,
486 trace_h_px, trace_x_px - selection_x_px, trace_y_px - selection_y_px,
487 trace_w_px - selection_w_px, trace_h_px - selection_h_px);
488}
489
490std::string BuildDoorIssueSummary(const zelda3::Room::Door& door, size_t index,
491 std::string_view label) {
492 const auto [tile_x, tile_y] = door.GetTileCoords();
493 const auto [pixel_x, pixel_y] = door.GetPixelCoords();
494 const auto dims = door.GetDimensions();
495 const auto editor_dims = door.GetEditorDimensions();
496 const auto [bounds_x, bounds_y, bounds_w, bounds_h] = door.GetBounds();
497 const auto [editor_x, editor_y, editor_w, editor_h] = door.GetEditorBounds();
498 const auto [encoded_b1, encoded_b2] = door.EncodeBytes();
499
500 return absl::StrFormat(
501 "\n%s[%zu]:\n"
502 "- type=%s (0x%02X)\n"
503 "- direction=%s (%d)\n"
504 "- position=%d\n"
505 "- tile_coords=(%d,%d) pixel_coords=(%d,%d)\n"
506 "- dims_tiles=(%d,%d) editor_dims_tiles=(%d,%d)\n"
507 "- bounds_px=(%d,%d,%d,%d) editor_bounds_px=(%d,%d,%d,%d)\n"
508 "- encoded=(0x%02X,0x%02X) original=(0x%02X,0x%02X)",
509 std::string(label).c_str(), index,
510 std::string(zelda3::GetDoorTypeName(door.type)).c_str(),
511 static_cast<int>(door.type),
512 std::string(zelda3::GetDoorDirectionName(door.direction)).c_str(),
513 static_cast<int>(door.direction), static_cast<int>(door.position), tile_x,
514 tile_y, pixel_x, pixel_y, dims.width_tiles, dims.height_tiles,
515 editor_dims.width_tiles, editor_dims.height_tiles, bounds_x, bounds_y,
516 bounds_w, bounds_h, editor_x, editor_y, editor_w, editor_h, encoded_b1,
517 encoded_b2, door.byte1, door.byte2);
518}
519
520std::string BuildRomDisplayName(const Rom& rom) {
521 if (!rom.short_name().empty()) {
522 return rom.short_name();
523 }
524 if (!rom.filename().empty()) {
525 return std::filesystem::path(rom.filename()).filename().string();
526 }
527 const std::string title = rom.title();
528 return title.empty() ? "in-memory ROM" : title;
529}
530
531std::string BuildReportSessionSummary(const Rom* rom,
532 const project::YazeProject* project) {
533 std::string summary;
534 if (rom && rom->is_loaded()) {
535 const std::string rom_path =
536 rom->filename().empty()
537 ? std::string("in-memory")
539 summary += absl::StrFormat(
540 "ROM: %s | CRC32:%s | Path:%s", BuildRomDisplayName(*rom).c_str(),
541 util::ComputeRomHash(rom->data(), rom->size()).c_str(),
542 rom_path.c_str());
543 } else {
544 summary += "ROM: unavailable";
545 }
546
547 if (project && project->project_opened()) {
548 summary += absl::StrFormat(
549 "\nProject: %s | Path:%s", project->GetDisplayName().c_str(),
551 .c_str());
552 }
553
554 return summary;
555}
556
558 const zelda3::PaletteDebugEvent& event) {
559 if (event.palette_id >= 0 && event.color_count > 0) {
560 return absl::StrFormat("- [%s] palette=%d colors=%d %s",
561 event.location.c_str(), event.palette_id,
562 event.color_count, event.message.c_str());
563 }
564 if (event.palette_id >= 0) {
565 return absl::StrFormat("- [%s] palette=%d %s", event.location.c_str(),
566 event.palette_id, event.message.c_str());
567 }
568 if (event.color_count > 0) {
569 return absl::StrFormat("- [%s] colors=%d %s", event.location.c_str(),
570 event.color_count, event.message.c_str());
571 }
572 return absl::StrFormat("- [%s] %s", event.location.c_str(),
573 event.message.c_str());
574}
575
577
578} // namespace
579
581 const zelda3::Room& room, int room_id) const {
582 const int resolved_palette_id = room.ResolveDungeonPaletteId();
583 const uint8_t entrance_blockset = room.render_entrance_blockset();
584 std::string entrance_context = "Entrance:none";
585 if (current_entrance_id_ >= 0 || entrance_blockset != 0xFF) {
586 const std::string entrance_id_text =
588 ? absl::StrFormat("%02X", current_entrance_id_)
589 : std::string("--");
590 const std::string entrance_blockset_text =
591 entrance_blockset != 0xFF
592 ? absl::StrFormat("%02X", static_cast<int>(entrance_blockset))
593 : std::string("--");
594 entrance_context =
595 absl::StrFormat("Entrance:%s EB:%s", entrance_id_text.c_str(),
596 entrance_blockset_text.c_str());
597 }
598
599 std::string summary = absl::StrFormat(
600 "Room 0x%03X [%s] | B:%02X P:%02X->%02X L:%02X S:%02X | %s | Group:%s | "
601 "Floor1:%d Floor2:%d Effect:%d Tag1:%d Tag2:%d\n%s\n%s",
602 room_id, zelda3::GetRoomLabel(room_id).c_str(), room.blockset(),
603 room.palette(), resolved_palette_id, room.layout_id(), room.spriteset(),
604 entrance_context, GetBlocksetGroupName(room.blockset()), room.floor1(),
605 room.floor2(), room.effect(), room.tag1(), room.tag2(),
606 BuildReportSessionSummary(rom_, project_).c_str(),
607 BuildEffectiveBlockListSummary(room).c_str());
608
609 // Connectivity diagnostics: enumerate doors/staircases/holewarp without
610 // reciprocity filtering so the report captures the room's actual link
611 // configuration. Staircase configuration issues (stale headers, missing
612 // destinations, extra placed objects beyond 4 slots) are listed
613 // separately so a reader can spot phantom or unreachable connections.
614 const auto link_diagnostics =
615 CollectDungeonConnectedRoomLinkDiagnostics(room_id, room, nullptr);
616 if (!link_diagnostics.links.empty() ||
617 !link_diagnostics.staircase_issues.empty()) {
618 summary += "\nConnectivity:";
619 for (const auto& link : link_diagnostics.links) {
620 summary += "\n ";
622 }
623 for (const auto& issue : link_diagnostics.staircase_issues) {
624 summary += "\n ";
626 }
627 }
628
629 return summary;
630}
631
633 int room_id) {
634 // Context-menu actions run inside BeginCanvas, before the normal room draw
635 // pass. Rebind at the diagnostic boundary too, so palette sampling remains
636 // correct even if the surrounding canvas order changes in the future.
637 if (rooms_ != nullptr && room_id >= 0 && room_id < zelda3::kNumberOfRooms &&
638 rooms_->GetIfMaterialized(room_id) == &room) {
640 }
641
642 std::string report = "Dungeon Draw Issue Report\n";
643 report += BuildRoomMetadataSummary(room, room_id);
644 report += absl::StrFormat(
645 "\nResolved palette group: 0x%02X\nInteraction mode: %s\nView: BG1=%s "
646 "BG2=%s Grid=%s Bounds=%s Sprites=%s Pots=%s Collision=%s Camera=%s",
649 IsBG1Visible(room_id) ? "on" : "off",
650 IsBG2Visible(room_id) ? "on" : "off", show_grid_ ? "on" : "off",
651 show_object_bounds_ ? "on" : "off",
652 entity_visibility_.show_sprites ? "on" : "off",
653 entity_visibility_.show_pot_items ? "on" : "off",
654 show_custom_collision_overlay_ ? "on" : "off",
655 show_camera_quadrant_overlay_ ? "on" : "off");
656
657 const auto selected = object_interaction_.GetSelectedObjectIndices();
658 if (!selected.empty()) {
659 report += absl::StrFormat("\nSelected objects: %zu", selected.size());
660 if (selected.size() == 1) {
661 const auto& objects = room.GetTileObjects();
662 const size_t index = selected.front();
663 if (index < objects.size()) {
664 const auto& obj = objects[index];
665 report += absl::StrFormat(
666 "\nObject: id=0x%03X name=%s pos=(%d,%d) size=0x%02X %s", obj.id_,
667 GetObjectName(obj.id_).c_str(), obj.x_, obj.y_, obj.size_,
668 BuildSelectedObjectSemanticsSummary(obj).c_str());
669 if (auto tiles = obj.GetTiles(); tiles.ok()) {
670 report += "\n";
671 report += FormatObjectTileSample(*tiles, 16, "Descriptor tiles:");
672 }
673 if (obj.id_ == 0x00C4 || obj.id_ == 0x00DB) {
674 const bool uses_floor1 = obj.id_ == 0x00C4;
675 const uint8_t floor_pattern =
676 uses_floor1 ? room.floor1() : room.floor2();
677 report += absl::StrFormat(
678 "\nFloor copy source: Floor %d (room.floor%d) pattern=%d",
679 uses_floor1 ? 1 : 2, uses_floor1 ? 1 : 2,
680 static_cast<int>(floor_pattern));
681 if (rom_ != nullptr && rom_->is_loaded()) {
682 const auto effective_tiles = gfx::DecodeDungeonFloorTilePattern(
685 if (effective_tiles.has_value()) {
686 report += "\n";
687 report += FormatObjectTileSample(*effective_tiles,
688 effective_tiles->size(),
689 "Effective floor-copy tiles:");
690 } else {
691 report +=
692 "\nEffective floor-copy tiles: unavailable "
693 "(ROM tables out of range)";
694 }
695 } else {
696 report +=
697 "\nEffective floor-copy tiles: unavailable (ROM not loaded)";
698 }
699 }
700
701 auto [bounds_x, bounds_y, bounds_w, bounds_h] =
703 bounds_w = std::max(bounds_w, 8);
704 bounds_h = std::max(bounds_h, 8);
705 const int origin_x = obj.x_ * 8;
706 const int origin_y = obj.y_ * 8;
707 const int center_x = bounds_x + std::max(0, (bounds_w / 2) - 1);
708 const int center_y = bounds_y + std::max(0, (bounds_h / 2) - 1);
709 report += absl::StrFormat(
710 "\nObject geometry: selection_bounds_px=(%d,%d,%d,%d) "
711 "object_origin_px=(%d,%d) center_px=(%d,%d)",
712 bounds_x, bounds_y, bounds_w, bounds_h, origin_x, origin_y,
713 center_x, center_y);
714 const auto trace_report =
715 BuildObjectTraceReport(rom_, room, index, current_palette_group_);
716 report += trace_report.summary;
717
718 auto& palette_debugger = zelda3::PaletteDebugger::Get();
719 auto append_sample = [&](std::string_view label, int sample_x,
720 int sample_y) {
721 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
722 palette_debugger.AddComparison(comp);
723 const std::string label_text(label);
724 report += absl::StrFormat(
725 "\nPalette sample %s (%d,%d): idx=%d expected=(%d,%d,%d) "
726 "actual=(%d,%d,%d) match=%s",
727 label_text.c_str(), sample_x, sample_y,
728 static_cast<int>(comp.palette_index),
729 static_cast<int>(comp.expected_r),
730 static_cast<int>(comp.expected_g),
731 static_cast<int>(comp.expected_b),
732 static_cast<int>(comp.actual_r), static_cast<int>(comp.actual_g),
733 static_cast<int>(comp.actual_b), comp.matches ? "yes" : "no");
734 };
735
736 if (auto trace_sample = ChooseObjectTracePaletteSample(
737 trace_report.writes, palette_debugger)) {
738 append_sample(trace_sample->label, trace_sample->x, trace_sample->y);
739 } else {
740 append_sample("selection-origin", bounds_x, bounds_y);
741 if (center_x != bounds_x || center_y != bounds_y) {
742 append_sample("selection-center", center_x, center_y);
743 }
744 }
745 } else {
746 report += absl::StrFormat(
747 "\nSelected object index %zu is stale; room currently has %zu "
748 "object(s). Reselect the object and report again if this issue "
749 "still reproduces.",
750 index, objects.size());
751 }
752 }
753 }
754
756 const auto selected_entity = object_interaction_.GetSelectedEntity();
757 switch (selected_entity.type) {
758 case EntityType::Door: {
759 const auto& doors = room.GetDoors();
760 if (selected_entity.index < doors.size()) {
761 const auto& door = doors[selected_entity.index];
762 report += BuildDoorIssueSummary(door, selected_entity.index,
763 "Selected door");
764 }
765 break;
766 }
767 case EntityType::Sprite: {
768 const auto& sprites = room.GetSprites();
769 if (selected_entity.index < sprites.size()) {
770 const auto& sprite = sprites[selected_entity.index];
771 report += absl::StrFormat(
772 "\nSelected entity: sprite id=0x%02X name=%s pos=(%d,%d) "
773 "layer=%d",
774 sprite.id(), zelda3::ResolveSpriteName(sprite.id()), sprite.x(),
775 sprite.y(), sprite.layer());
776 }
777 break;
778 }
779 case EntityType::Item: {
780 const auto& items = room.GetPotItems();
781 if (selected_entity.index < items.size()) {
782 const auto& item = items[selected_entity.index];
783 report +=
784 absl::StrFormat("\nSelected entity: pot item=0x%02X pos=(%d,%d)",
785 item.item, item.GetPixelX(), item.GetPixelY());
786 }
787 break;
788 }
789 default:
790 break;
791 }
792 }
793
794 const auto& palette_events = zelda3::PaletteDebugger::Get().GetEvents();
795 if (!palette_events.empty()) {
796 report +=
797 absl::StrFormat("\nPalette debug events: %zu", palette_events.size());
798 const size_t preview_count = std::min<size_t>(palette_events.size(), 4);
799 const size_t start = palette_events.size() - preview_count;
800 for (size_t i = start; i < palette_events.size(); ++i) {
801 const auto& event = palette_events[i];
802 report += "\n";
803 report += FormatPaletteDebugEventForReport(event);
804 }
805 }
806
807 return report;
808}
809
811 const zelda3::Room& room, int room_id) const {
812 std::string report = "Dungeon Selection Issue Report\n";
813 report += BuildRoomMetadataSummary(room, room_id);
814 report +=
815 absl::StrFormat("\nInteraction mode: %s\nResolved palette group: 0x%02X",
818
819 const auto selected_objects = object_interaction_.GetSelectedObjectIndices();
820 if (!selected_objects.empty()) {
821 report +=
822 absl::StrFormat("\nSelected objects: %zu", selected_objects.size());
823 const auto& objects = room.GetTileObjects();
824 const size_t preview_count = std::min<size_t>(selected_objects.size(), 4);
825 for (size_t i = 0; i < preview_count; ++i) {
826 const size_t index = selected_objects[i];
827 if (index >= objects.size()) {
828 report += absl::StrFormat(
829 "\n- object[%zu] unavailable; room currently has %zu object(s) "
830 "(selection is stale)",
831 index, objects.size());
832 continue;
833 }
834 const auto& obj = objects[index];
835 report += absl::StrFormat(
836 "\n- object[%zu] id=0x%03X name=%s pos=(%d,%d) size=0x%02X %s", index,
837 obj.id_, GetObjectName(obj.id_).c_str(), obj.x_, obj.y_, obj.size_,
838 BuildSelectedObjectSemanticsSummary(obj).c_str());
839 auto [bounds_x, bounds_y, bounds_w, bounds_h] =
841 bounds_w = std::max(bounds_w, 8);
842 bounds_h = std::max(bounds_h, 8);
843 report += absl::StrFormat(
844 "\n geometry: selection_bounds_px=(%d,%d,%d,%d) "
845 "object_origin_px=(%d,%d)",
846 bounds_x, bounds_y, bounds_w, bounds_h, obj.x_ * 8, obj.y_ * 8);
847 if (auto tiles = obj.GetTiles(); tiles.ok() && !tiles->empty()) {
848 report += "\n ";
849 report += FormatObjectTileSample(*tiles, 10, "tiles:");
850 }
851 const auto trace_report =
852 BuildObjectTraceReport(rom_, room, index, current_palette_group_);
853 report += "\n ";
854 report += BuildObjectTraceBoundsSummary(trace_report.writes, bounds_x,
855 bounds_y, bounds_w, bounds_h);
856 }
857 if (selected_objects.size() > preview_count) {
858 report += absl::StrFormat("\n- ... %zu more object(s)",
859 selected_objects.size() - preview_count);
860 }
861 return report;
862 }
863
865 const auto selected_entity = object_interaction_.GetSelectedEntity();
866 switch (selected_entity.type) {
867 case EntityType::Door: {
868 const auto& doors = room.GetDoors();
869 if (selected_entity.index < doors.size()) {
870 const auto& door = doors[selected_entity.index];
871 report += BuildDoorIssueSummary(door, selected_entity.index,
872 "Selected door");
873 return report;
874 }
875 break;
876 }
877 case EntityType::Sprite: {
878 const auto& sprites = room.GetSprites();
879 if (selected_entity.index < sprites.size()) {
880 const auto& sprite = sprites[selected_entity.index];
881 report += absl::StrFormat(
882 "\nSelected sprite[%zu]:\n"
883 "- id=0x%02X\n"
884 "- name=%s\n"
885 "- pos=(%d,%d)\n"
886 "- layer=%d",
887 selected_entity.index, sprite.id(),
888 zelda3::ResolveSpriteName(sprite.id()), sprite.x(), sprite.y(),
889 sprite.layer());
890 return report;
891 }
892 break;
893 }
894 case EntityType::Item: {
895 const auto& items = room.GetPotItems();
896 if (selected_entity.index < items.size()) {
897 const auto& item = items[selected_entity.index];
898 report += absl::StrFormat(
899 "\nSelected pot item[%zu]:\n"
900 "- item=0x%02X\n"
901 "- pixel_pos=(%d,%d)",
902 selected_entity.index, item.item, item.GetPixelX(),
903 item.GetPixelY());
904 return report;
905 }
906 break;
907 }
908 default:
909 break;
910 }
911 }
912
913 report += "\nNo active object or entity selection.";
914 return report;
915}
916
920
921 auto paths_or = ResolveDungeonIssueReportPaths();
922 if (!paths_or.ok()) {
923 SetIssueReportPopupStatus(std::string(paths_or.status().message()), true);
924 return;
925 }
926
930 util::PlatformPaths::NormalizePathForDisplay(paths_or->screenshots_dir);
931}
932
934 bool is_error) {
935 issue_report_popup_status_message_ = std::move(message);
937}
938
942
948 return;
949 }
950
951 if (!ImGui::CollapsingHeader(kIssueReportSectionPaths)) {
952 return;
953 }
955 ImGui::TextWrapped(tr("Log target: %s"),
957 }
960 ImGui::TextWrapped(tr("Screenshot dir: %s"),
962 }
964 ImGui::TextWrapped(tr("Screenshot: %s"),
966 }
968 ImGui::TextWrapped(tr("Issue log: %s"),
970 }
971}
972
974 const bool idle = issue_report_popup_status_message_.empty();
975 const std::string_view message =
976 idle ? std::string_view(tr(kIssueReportStatusIdle))
977 : std::string_view(issue_report_popup_status_message_);
978 const size_t line_end = message.find_first_of("\r\n");
979 std::string visible_line(message.substr(0, line_end));
980 if (line_end != std::string_view::npos) {
981 visible_line += "...";
982 }
983 const ImVec4 color =
984 idle ? ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)
987 const ImVec2 start = ImGui::GetCursorScreenPos();
988 const ImVec2 size(std::max(ImGui::GetContentRegionAvail().x, 1.0f),
989 ImGui::GetTextLineHeight());
990 const ImVec2 end(start.x + size.x, start.y + size.y);
991 ImGui::PushStyleColor(ImGuiCol_Text, color);
992 ImGui::RenderTextEllipsis(ImGui::GetWindowDrawList(), start, end, end.x,
993 visible_line.c_str(), nullptr, nullptr);
994 ImGui::PopStyleColor();
995 ImGui::Dummy(size);
996 if (ImGui::IsItemHovered()) {
997 ImGui::BeginTooltip();
998 ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
999 ImGui::TextUnformatted(message.data(), message.data() + message.size());
1000 ImGui::PopTextWrapPos();
1001 ImGui::EndTooltip();
1002 }
1003}
1004
1006 const std::string& title, const std::string& summary,
1007 const std::string& kind_label, const std::string& diagnostics, int room_id,
1008 int default_category_index) {
1010 issue_report_popup_kind_ = kind_label;
1011 issue_report_popup_diagnostics_ = diagnostics;
1014 std::clamp(default_category_index, 0,
1015 static_cast<int>(kDungeonIssueCategoryLabels.size()) - 1);
1019 SetIssueReportPopupStatus("", false);
1021 std::snprintf(issue_report_summary_, sizeof(issue_report_summary_), "%s",
1022 summary.c_str());
1023 issue_report_notes_[0] = '\0';
1024 return absl::OkStatus();
1025}
1026
1027void DungeonCanvasViewer::OpenIssueReportPopup(const std::string& title,
1028 const std::string& summary,
1029 const std::string& kind_label,
1030 const std::string& diagnostics,
1031 int room_id,
1032 int default_category_index) {
1033 (void)PrepareIssueReportPopup(title, summary, kind_label, diagnostics,
1034 room_id, default_category_index);
1036 const IssueReportWindowLayout window_layout = GetIssueReportWindowLayout();
1037 ImGui::SetNextWindowPos(window_layout.center, ImGuiCond_Appearing,
1038 ImVec2(0.5f, 0.5f));
1039 ImGui::SetNextWindowSize(window_layout.initial_size, ImGuiCond_Appearing);
1040 ImGui::SetNextWindowSizeConstraints(window_layout.min_size,
1041 window_layout.max_size);
1042
1043 if (ImGui::BeginPopupModal(issue_report_popup_id_.c_str(), nullptr,
1044 ImGuiWindowFlags_NoSavedSettings)) {
1045#ifdef YAZE_WITH_GRPC
1046 const char* capture_label = issue_report_popup_screenshot_path_.empty()
1047 ? kIssueReportCaptureButtonLabel
1048 : kIssueReportRecaptureButtonLabel;
1049 const std::array<const char*, 4> action_labels = {
1050 kIssueReportSaveButtonLabel, capture_label,
1051 kIssueReportCopyButtonLabel, kIssueReportCloseButtonLabel};
1052#else
1053 const std::array<const char*, 3> action_labels = {
1054 kIssueReportSaveButtonLabel, kIssueReportCopyButtonLabel,
1055 kIssueReportCloseButtonLabel};
1056#endif
1057 const float footer_width =
1058 std::max(ImGui::GetContentRegionAvail().x, 1.0f);
1059 const int action_rows = CountWrappedIssueActionRows(
1060 std::span<const char* const>(action_labels), footer_width);
1061 const ImGuiStyle& style = ImGui::GetStyle();
1062 const float action_height =
1063 action_rows * ImGui::GetFrameHeight() +
1064 std::max(0, action_rows - 1) * style.ItemSpacing.y;
1065 const float footer_height = ImGui::GetTextLineHeightWithSpacing() +
1066 action_height + style.ItemSpacing.y * 2.0f +
1067 1.0f;
1068
1069 if (ImGui::BeginChild("##DungeonIssueReportBody",
1070 ImVec2(0.0f, -footer_height), false,
1071 ImGuiWindowFlags_None)) {
1072 if (!issue_report_popup_title_.empty()) {
1073 ImGui::TextUnformatted(issue_report_popup_title_.c_str());
1074 if (!issue_report_popup_kind_.empty()) {
1075 ImGui::TextDisabled("%s", issue_report_popup_kind_.c_str());
1076 }
1077 ImGui::Separator();
1078 }
1079
1080 ImGui::TextUnformatted(tr("Category"));
1081 ImGui::SetNextItemWidth(
1082 std::max(ImGui::GetContentRegionAvail().x, 1.0f));
1083 const char* category_preview =
1085 if (ImGui::BeginCombo("##DungeonIssueCategory", category_preview)) {
1086 for (size_t i = 0; i < kDungeonIssueCategoryLabels.size(); ++i) {
1087 const bool selected =
1088 issue_report_category_index_ == static_cast<int>(i);
1089 if (ImGui::Selectable(kDungeonIssueCategoryLabels[i], selected)) {
1090 issue_report_category_index_ = static_cast<int>(i);
1092 }
1093 if (selected) {
1094 ImGui::SetItemDefaultFocus();
1095 }
1096 }
1097 ImGui::EndCombo();
1098 }
1099
1100 ImGui::TextUnformatted(tr("Summary"));
1101 ImGui::SetNextItemWidth(
1102 std::max(ImGui::GetContentRegionAvail().x, 1.0f));
1103 if (ImGui::InputTextWithHint(
1104 "##DungeonIssueSummary", kIssueReportSummaryHint,
1107 }
1108
1109 ImGui::TextUnformatted(tr("Observed issue"));
1110 if (ImGui::InputTextMultiline("##DungeonIssueObserved",
1112 sizeof(issue_report_notes_),
1113 ImVec2(-1.0f, kIssueReportNotesHeight))) {
1115 }
1116
1118
1119 if (ImGui::CollapsingHeader(kIssueReportSectionDiagnostics)) {
1120 ImGui::InputTextMultiline(
1121 kIssueReportPopupIdDiagnostics,
1124 ImVec2(-1.0f, kIssueReportDiagnosticsHeight),
1125 ImGuiInputTextFlags_ReadOnly);
1126 if (ImGui::Button(ICON_MD_ASSIGNMENT " Copy Diagnostics")) {
1127 ImGui::SetClipboardText(issue_report_popup_diagnostics_.c_str());
1128 SetIssueReportPopupStatus(kIssueReportStatusCopiedDiagnostics,
1129 false);
1130 }
1131 }
1132 }
1133 ImGui::EndChild();
1134
1135 ImGui::Separator();
1137
1138 float used_action_width = 0.0f;
1139 PlaceNextIssueAction(kIssueReportSaveButtonLabel, footer_width,
1140 &used_action_width);
1141 if (gui::PrimaryButton(kIssueReportSaveButtonLabel)) {
1142 const auto status = EnsureIssueReportPersisted();
1143 if (status.ok()) {
1144 SetIssueReportPopupStatus(kIssueReportStatusSavedLog, false);
1145 } else {
1146 SetIssueReportPopupStatus(std::string(status.message()), true);
1147 }
1148 }
1149
1150#ifdef YAZE_WITH_GRPC
1151 PlaceNextIssueAction(capture_label, footer_width, &used_action_width);
1152 if (ImGui::Button(
1153 capture_label,
1154 ImVec2(GetIssueActionButtonWidth(capture_label), 0.0f))) {
1155 const auto status = CaptureIssueReportScreenshot();
1156 if (status.ok()) {
1158 SetIssueReportPopupStatus(kIssueReportStatusSavedScreenshot, false);
1159 } else {
1160 SetIssueReportPopupStatus(std::string(status.message()), true);
1161 }
1162 }
1163#endif
1164
1165 PlaceNextIssueAction(kIssueReportCopyButtonLabel, footer_width,
1166 &used_action_width);
1167 if (ImGui::Button(kIssueReportCopyButtonLabel)) {
1168 std::string report = BuildIssueReportClipboardText();
1169 ImGui::SetClipboardText(report.c_str());
1170 SetIssueReportPopupStatus(kIssueReportStatusCopiedReport, false);
1171 }
1172
1173 PlaceNextIssueAction(kIssueReportCloseButtonLabel, footer_width,
1174 &used_action_width);
1175 if (ImGui::Button(kIssueReportCloseButtonLabel)) {
1177 ImGui::CloseCurrentPopup();
1178 }
1179 ImGui::EndPopup();
1180 return;
1181 }
1182 });
1183}
1184
1186 std::string report;
1187 if (!issue_report_popup_kind_.empty()) {
1188 report += issue_report_popup_kind_ + "\n";
1189 }
1190 report += absl::StrFormat(
1192 if (issue_report_summary_[0] != '\0') {
1193 report += absl::StrFormat("Summary: %s\n", issue_report_summary_);
1194 }
1196 report += absl::StrFormat("Screenshot: %s\n",
1198 }
1199 if (issue_report_notes_[0] != '\0') {
1200 report += absl::StrFormat("\nObserved issue:\n%s\n", issue_report_notes_);
1201 }
1202 report += "\nDiagnostics:\n";
1204 return report;
1205}
1206
1208#ifdef YAZE_WITH_GRPC
1211 return absl::FailedPreconditionError(
1212 "Room canvas region is not available for screenshot capture");
1213 }
1214
1215 const std::string timestamp = BuildIssueTimestampSlug();
1216 auto screenshot_path_or = BuildDungeonIssueScreenshotPath(
1219 if (!screenshot_path_or.ok()) {
1220 return screenshot_path_or.status();
1221 }
1222
1223 yaze::test::CaptureRegion region;
1224 region.x = canvas_capture_x_;
1225 region.y = canvas_capture_y_;
1226 region.width = canvas_capture_width_;
1227 region.height = canvas_capture_height_;
1228
1229 auto artifact_or = yaze::test::CaptureHarnessScreenshotRegion(
1230 std::optional<yaze::test::CaptureRegion>(region),
1231 screenshot_path_or->string(),
1232 /*reveal_to_user=*/false);
1233 if (!artifact_or.ok()) {
1234 return artifact_or.status();
1235 }
1236
1238 util::PlatformPaths::NormalizePathForDisplay(artifact_or->file_path);
1239 return absl::OkStatus();
1240#else
1241 return absl::UnimplementedError(
1242 "Screenshot capture is unavailable without YAZE_WITH_GRPC");
1243#endif
1244}
1245
1248 entry.timestamp_display = BuildIssueTimestampDisplay();
1257
1258 auto log_path_or = AppendDungeonIssueLogEntry(entry);
1259 if (!log_path_or.ok()) {
1260 return log_path_or.status();
1261 }
1262
1265 return absl::OkStatus();
1266}
1267
1271 return absl::OkStatus();
1272 }
1273
1276 return absl::OkStatus();
1277}
1278
1279} // namespace yaze::editor
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
auto filename() const
Definition rom.h:175
const auto & vector() const
Definition rom.h:173
auto data() const
Definition rom.h:169
auto size() const
Definition rom.h:168
auto short_name() const
Definition rom.h:177
bool is_loaded() const
Definition rom.h:155
auto title() const
Definition rom.h:167
std::string BuildDrawIssueReport(const zelda3::Room &room, int room_id)
void SetIssueReportPopupStatus(std::string message, bool is_error)
DungeonObjectInteraction object_interaction_
void OpenIssueReportPopup(const std::string &title, const std::string &summary, const std::string &kind_label, const std::string &diagnostics, int room_id, int default_category_index)
std::string BuildRoomMetadataSummary(const zelda3::Room &room, int room_id) const
const project::YazeProject * project_
gfx::Bitmap * PrepareRoomCompositeBitmap(int room_id)
absl::Status PrepareIssueReportPopup(const std::string &title, const std::string &summary, const std::string &kind_label, const std::string &diagnostics, int room_id, int default_category_index)
std::string BuildSelectionIssueReport(const zelda3::Room &room, int room_id) const
std::vector< size_t > GetSelectedObjectIndices() const
zelda3::Room * GetIfMaterialized(int room_id)
const char * GetModeName() const
Get mode name for debugging/UI.
std::vector< uint16_t > & buffer()
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:69
void ClosePersistentPopup(const std::string &popup_id)
Definition canvas.cc:884
void OpenPersistentPopup(const std::string &popup_id, std::function< void()> render_callback)
Definition canvas.cc:878
static std::string NormalizePathForDisplay(const std::filesystem::path &path)
Normalize path separators for display.
static DimensionService & Get()
std::tuple< int, int, int, int > GetSelectionBoundsPixels(const RoomObject &obj) const
Draws dungeon objects to background buffers using game patterns.
void SetRoomFloorGraphics(uint8_t floor1, uint8_t floor2)
void SetBG1RevealMaskSource(gfx::BG1RevealMaskSource source)
absl::Status DrawObject(const RoomObject &object, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group, const DungeonState *state=nullptr, gfx::BackgroundBuffer *layout_bg1=nullptr, gfx::BackgroundBuffer *layout_bg2=nullptr)
Draw a room object to background buffers.
void SetTraceCollector(std::vector< TileTrace > *collector, bool trace_only=false)
static PaletteDebugger & Get()
const std::vector< PaletteDebugEvent > & GetEvents() const
ColorComparison SamplePixelAt(int x, int y) const
uint8_t GetLayerValue() const
const std::array< uint8_t, 0x10000 > & get_gfx_buffer() const
Definition room.h:1019
uint8_t blockset() const
Definition room.h:951
const std::vector< Door > & GetDoors() const
Definition room.h:373
TagKey tag2() const
Definition room.h:937
uint8_t floor2() const
Definition room.h:976
uint8_t palette() const
Definition room.h:954
TagKey tag1() const
Definition room.h:936
uint8_t spriteset() const
Definition room.h:953
const std::vector< zelda3::Sprite > & GetSprites() const
Definition room.h:276
auto & bg1_buffer()
Definition room.h:1039
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:405
DungeonState * GetDungeonState()
Definition room.h:1059
auto blocks() const
Definition room.h:1005
EffectKey effect() const
Definition room.h:935
uint8_t floor1() const
Definition room.h:975
int ResolveDungeonPaletteId() const
Definition room.cc:854
uint8_t render_entrance_blockset() const
Definition room.h:952
uint8_t layout_id() const
Definition room.h:961
const std::vector< PotItem > & GetPotItems() const
Definition room.h:389
auto & bg2_buffer()
Definition room.h:1040
int id() const
Definition room.h:948
#define ICON_MD_SAVE_AS
Definition icons.h:1646
#define ICON_MD_ADD_A_PHOTO
Definition icons.h:87
#define ICON_MD_ASSIGNMENT
Definition icons.h:194
#define ICON_MD_CONTENT_COPY
Definition icons.h:465
#define ICON_MD_CLOSE
Definition icons.h:418
#define ICON_MD_PHOTO_CAMERA
Definition icons.h:1453
std::string BuildDoorIssueSummary(const zelda3::Room::Door &door, size_t index, std::string_view label)
bool PaletteIndexMatchesTracePalette(uint8_t palette_index, uint8_t trace_flags)
std::string BuildObjectTraceBoundsSummary(std::span< const zelda3::ObjectDrawer::TileTrace > trace, int selection_x_px, int selection_y_px, int selection_w_px, int selection_h_px)
std::optional< PaletteSamplePoint > ChooseObjectTracePaletteSample(std::span< const zelda3::ObjectDrawer::TileTrace > trace, const zelda3::PaletteDebugger &palette_debugger)
ObjectTraceReport BuildObjectTraceReport(Rom *rom, const zelda3::Room &room, size_t selected_index, const gfx::PaletteGroup &palette_group)
void PlaceNextIssueAction(const char *label, float available_width, float *used_width)
std::string FormatPaletteDebugEventForReport(const zelda3::PaletteDebugEvent &event)
std::string BuildReportSessionSummary(const Rom *rom, const project::YazeProject *project)
std::string FormatObjectTileSample(std::span< const gfx::TileInfo > tiles, size_t max_count, std::string_view prefix)
int CountWrappedIssueActionRows(std::span< const char *const > labels, float available_width)
Editors are the view controllers for the application.
std::string FormatDungeonConnectedLinkDescription(const DungeonConnectedRoomLink &link)
DungeonConnectedRoomLinkDiagnostics CollectDungeonConnectedRoomLinkDiagnostics(int room_id, const zelda3::Room &room, const std::function< bool(int, zelda3::DoorDirection)> &has_reciprocal_door)
const char * GetIssueCategoryLabel(int index)
constexpr std::array< const char *, 6 > kDungeonIssueCategoryLabels
absl::StatusOr< std::filesystem::path > AppendDungeonIssueLogEntry(const DungeonIssueLogEntry &entry)
absl::StatusOr< std::filesystem::path > BuildDungeonIssueScreenshotPath(int room_id, const std::string &category_label, const std::string &timestamp_slug)
absl::StatusOr< DungeonIssueReportPaths > ResolveDungeonIssueReportPaths()
std::string FormatDungeonStaircaseIssueDescription(const DungeonStaircaseIssue &issue)
std::optional< std::array< TileInfo, 8 > > DecodeDungeonFloorTilePattern(const std::vector< uint8_t > &rom_data, int tile_address, int tile_address_floor, uint8_t floor_graphics)
bool PrimaryButton(const char *label, const ImVec2 &size, const char *panel_id, const char *anim_id)
Draw a primary action button (accented color).
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:49
ImVec4 GetErrorColor()
Definition ui_helpers.cc:59
std::string ComputeRomHash(const uint8_t *data, size_t size)
Definition rom_hash.cc:70
ObjectLayerSemantics GetObjectLayerSemantics(const RoomObject &object)
std::string GetRoomLabel(int id)
Convenience function to get a room label.
RoomObject::LayerType MapRoomObjectListIndexToDrawLayer(uint8_t list_index)
const char * ObjectRenderRoutingToken(ObjectRenderRouting routing)
constexpr std::string_view GetDoorDirectionName(DoorDirection dir)
Get human-readable name for door direction.
Definition door_types.h:204
bool UsesRoomObjectStream(const RoomObject &object)
constexpr int kRoomObjectTileAddress
Definition room_object.h:48
std::string GetObjectName(int object_id)
constexpr std::string_view GetDoorTypeName(DoorType type)
Get human-readable name for door type.
Definition door_types.h:110
constexpr int kNumberOfRooms
const char * EffectiveBgLayerLabel(EffectiveBgLayer layer)
constexpr int kRoomObjectTileAddressFloor
Definition room_object.h:49
const char * ResolveSpriteName(uint16_t id)
Definition sprite.cc:287
#define RETURN_IF_ERROR(expr)
Definition snes.cc:22
Represents a group of palettes.
Modern project structure with comprehensive settings consolidation.
Definition project.h:172
bool project_opened() const
Definition project.h:348
std::string GetDisplayName() const
Definition project.cc:1521
Represents a door in a dungeon room.
Definition room.h:299
std::tuple< int, int, int, int > GetEditorBounds() const
Get editor interaction bounds (x, y, width, height in pixels)
Definition room.h:333
std::tuple< int, int, int, int > GetBounds() const
Get bounding rectangle (x, y, width, height in pixels)
Definition room.h:328
uint8_t byte1
Original ROM byte 1 (position data)
Definition room.h:304
DoorDimensions GetDimensions() const
Get door dimensions in tiles.
Definition room.h:318
DoorType type
Door type (determines appearance/behavior)
Definition room.h:301
std::pair< uint8_t, uint8_t > EncodeBytes() const
Encode door data for ROM storage.
Definition room.h:349
DoorDirection direction
Which wall the door is on.
Definition room.h:302
DoorDimensions GetEditorDimensions() const
Get editor interaction dimensions in tiles.
Definition room.h:323
uint8_t position
Encoded position (5-bit, 0-31)
Definition room.h:300
std::pair< int, int > GetPixelCoords() const
Get pixel coordinates for this door.
Definition room.h:313
uint8_t byte2
Original ROM byte 2 (type + direction)
Definition room.h:305
std::pair< int, int > GetTileCoords() const
Get tile coordinates for this door.
Definition room.h:308