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"
23#include "app/gui/core/icons.h"
25#ifdef YAZE_WITH_GRPC
27#endif
28#include "imgui/imgui.h"
29#include "util/macro.h"
30#include "util/platform_paths.h"
31#include "util/rom_hash.h"
39
40namespace yaze::editor {
41
42namespace {
43
44constexpr float kIssueReportDialogWidth = 620.0f;
45constexpr float kIssueReportNotesHeight = 120.0f;
46constexpr float kIssueReportDiagnosticsHeight = 180.0f;
47constexpr char kIssueReportSummaryHint[] = "What looks wrong?";
48constexpr char kIssueReportPopupIdDiagnostics[] = "##DungeonIssueDiagnostics";
49constexpr char kIssueReportSectionPaths[] = "Paths";
50constexpr char kIssueReportSectionDiagnostics[] = "Diagnostics";
52 "Captured room screenshot to %s";
53constexpr char kIssueReportStatusSavedLog[] = "Saved issue report to %s";
54constexpr char kIssueReportStatusStartedLog[] = "Started issue report in %s";
56 "Copied report to clipboard and saved issue report to %s";
58 "Copied diagnostics and saved issue report to %s";
60 ICON_MD_ADD_A_PHOTO " Capture Screenshot";
62 ICON_MD_PHOTO_CAMERA " Re-capture Screenshot";
63
64const char* GetStoredPlacementLabel(const zelda3::RoomObject& object) {
65 const int layer_value = object.GetLayerValue();
66 if (!zelda3::UsesRoomObjectStream(object)) {
67 if (layer_value == 0) {
68 return "Upper layer (BG1)";
69 }
70 return layer_value == 1 ? "Lower layer (BG2)" : "Invalid selector";
71 }
72 switch (layer_value) {
73 case 0:
74 return "Primary";
75 case 1:
76 return "BG2 overlay";
77 case 2:
78 return "BG1 overlay";
79 default:
80 return "Unknown";
81 }
82}
83
84const char* GetBlocksetGroupName(uint8_t blockset) {
85 static const char* kGroupNames[] = {
86 "HC/Sewers", "Eastern", "Desert", "Hera", "A-Tower", "PoD", "Swamp",
87 "Skull", "Thieves", "Ice", "Misery", "Turtle", "GT",
88 };
89 constexpr size_t kCount = sizeof(kGroupNames) / sizeof(kGroupNames[0]);
90 return blockset < kCount ? kGroupNames[blockset] : "Custom";
91}
92
94 return absl::FormatTime("%Y%m%d-%H%M%S", absl::Now(), absl::LocalTimeZone());
95}
96
98 return absl::FormatTime("%Y-%m-%d %H:%M:%S %Z", absl::Now(),
99 absl::LocalTimeZone());
100}
101
103 const auto blocks = room.blocks();
104 if (blocks.size() < 8) {
105 return "BG sheets: unavailable";
106 }
107 return absl::StrFormat(
108 "BG sheets: [%02X %02X %02X %02X %02X %02X %02X %02X]",
109 static_cast<int>(blocks[0]), static_cast<int>(blocks[1]),
110 static_cast<int>(blocks[2]), static_cast<int>(blocks[3]),
111 static_cast<int>(blocks[4]), static_cast<int>(blocks[5]),
112 static_cast<int>(blocks[6]), static_cast<int>(blocks[7]));
113}
114
116 const auto semantics = zelda3::GetObjectLayerSemantics(obj);
118 return absl::StrFormat(
119 "storage=special-table selector=%d (%s) routine=%d both_bgs=%s",
120 obj.GetLayerValue(), GetStoredPlacementLabel(obj), semantics.routine_id,
121 semantics.draws_to_both_bgs ? "yes" : "no");
122 }
123 return absl::StrFormat(
124 "stream=%s draw_layer=%d effective_bg=%s routine=%d both_bgs=%s",
126 static_cast<int>(
128 zelda3::EffectiveBgLayerLabel(semantics.effective_bg_layer),
129 semantics.routine_id, semantics.draws_to_both_bgs ? "yes" : "no");
130}
131
132const char* TraceLayerLabel(uint8_t layer) {
133 switch (static_cast<zelda3::RoomObject::LayerType>(layer)) {
135 return "BG1";
137 return "BG2";
139 return "BG3";
140 }
141 return "BG?";
142}
143
144std::string FormatObjectTileSample(std::span<const gfx::TileInfo> tiles,
145 size_t max_count, std::string_view prefix) {
146 std::string out = absl::StrFormat("%s count=%zu", std::string(prefix).c_str(),
147 tiles.size());
148 const size_t preview_count = std::min<size_t>(tiles.size(), max_count);
149 for (size_t i = 0; i < preview_count; ++i) {
150 const auto& tile = tiles[i];
151 out += absl::StrFormat(" [%zu]=0x%03X/p%d/pr%d/h%d/v%d", i, tile.id_,
152 static_cast<int>(tile.palette_), tile.over_ ? 1 : 0,
153 tile.horizontal_mirror_ ? 1 : 0,
154 tile.vertical_mirror_ ? 1 : 0);
155 }
156 if (tiles.size() > preview_count) {
157 out += absl::StrFormat(" ... %zu more", tiles.size() - preview_count);
158 }
159 return out;
160}
161
163 std::string summary;
164 std::vector<zelda3::ObjectDrawer::TileTrace> writes;
165};
166
168 Rom* rom, int room_id, const zelda3::RoomObject& obj,
169 const gfx::PaletteGroup& palette_group) {
170 if (rom == nullptr || !rom->is_loaded()) {
171 return {.summary = "\nDrawer trace: unavailable (ROM not loaded)"};
172 }
173
174 zelda3::ObjectDrawer drawer(rom, room_id, /*room_gfx_buffer=*/nullptr);
175 gfx::BackgroundBuffer bg1(512, 512);
176 gfx::BackgroundBuffer bg2(512, 512);
177 std::vector<zelda3::ObjectDrawer::TileTrace> trace;
178 drawer.SetTraceCollector(&trace, /*trace_only=*/true);
179 const auto status = drawer.DrawObject(obj, bg1, bg2, palette_group);
180 drawer.ClearTraceCollector();
181 if (!status.ok()) {
182 return {.summary = absl::StrFormat("\nDrawer trace: unavailable (%s)",
183 std::string(status.message()).c_str())};
184 }
185
186 if (trace.empty()) {
187 return {.summary = "\nDrawer trace: status=ok writes=0"};
188 }
189
190 int min_x = std::numeric_limits<int>::max();
191 int min_y = std::numeric_limits<int>::max();
192 int max_x = std::numeric_limits<int>::min();
193 int max_y = std::numeric_limits<int>::min();
194 std::array<int, 3> layer_counts = {0, 0, 0};
195 std::set<std::tuple<int, int, uint8_t>> unique_cells;
196 for (const auto& write : trace) {
197 min_x = std::min<int>(min_x, write.x_tile);
198 min_y = std::min<int>(min_y, write.y_tile);
199 max_x = std::max<int>(max_x, write.x_tile);
200 max_y = std::max<int>(max_y, write.y_tile);
201 if (write.layer < layer_counts.size()) {
202 ++layer_counts[write.layer];
203 }
204 unique_cells.insert({write.x_tile, write.y_tile, write.layer});
205 }
206
207 std::string out = absl::StrFormat(
208 "\nDrawer trace: status=ok writes=%zu unique_cells=%zu "
209 "bounds_tiles=(%d,%d)..(%d,%d) layer_counts BG1=%d BG2=%d BG3=%d",
210 trace.size(), unique_cells.size(), min_x, min_y, max_x, max_y,
214
215 const size_t preview_count = std::min<size_t>(trace.size(), 12);
216 for (size_t i = 0; i < preview_count; ++i) {
217 const auto& write = trace[i];
218 const int palette = (write.flags >> 3) & 0x7;
219 out += absl::StrFormat(
220 "\n write[%zu] %s tile=(%d,%d) id=0x%03X pal=%d pri=%d h=%d v=%d", i,
221 TraceLayerLabel(write.layer), write.x_tile, write.y_tile, write.tile_id,
222 palette, (write.flags & 0x4) ? 1 : 0, (write.flags & 0x1) ? 1 : 0,
223 (write.flags & 0x2) ? 1 : 0);
224 }
225 if (trace.size() > preview_count) {
226 out += absl::StrFormat("\n ... %zu more write(s)",
227 trace.size() - preview_count);
228 }
229 return {.summary = std::move(out), .writes = std::move(trace)};
230}
231
233 std::string label;
234 int x = 0;
235 int y = 0;
236};
237
238bool PaletteIndexMatchesTracePalette(uint8_t palette_index,
239 uint8_t trace_flags) {
240 if ((palette_index & 0x0F) == 0) {
241 return false;
242 }
243 const uint8_t trace_palette = static_cast<uint8_t>((trace_flags >> 3) & 0x7);
244 return static_cast<uint8_t>((palette_index >> 4) & 0x7) == trace_palette;
245}
246
247std::optional<PaletteSamplePoint> ChooseObjectTracePaletteSample(
248 std::span<const zelda3::ObjectDrawer::TileTrace> trace,
249 const zelda3::PaletteDebugger& palette_debugger) {
250 constexpr std::array<std::pair<int, int>, 6> kPreferredOffsets = {
251 std::pair{4, 4}, std::pair{3, 3}, std::pair{0, 0},
252 std::pair{7, 7}, std::pair{0, 7}, std::pair{7, 0},
253 };
254
255 for (size_t i = 0; i < trace.size(); ++i) {
256 const auto& write = trace[i];
257 const int tile_origin_x = write.x_tile * 8;
258 const int tile_origin_y = write.y_tile * 8;
259 const auto label = absl::StrFormat(
260 "object-trace[%zu] tile=(%d,%d) pal=%d", i, write.x_tile, write.y_tile,
261 static_cast<int>((write.flags >> 3) & 0x7));
262
263 for (const auto& [dx, dy] : kPreferredOffsets) {
264 const int sample_x = tile_origin_x + dx;
265 const int sample_y = tile_origin_y + dy;
266 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
267 if (PaletteIndexMatchesTracePalette(comp.palette_index, write.flags)) {
268 return PaletteSamplePoint{.label = label, .x = sample_x, .y = sample_y};
269 }
270 }
271
272 for (int dy = 0; dy < 8; ++dy) {
273 for (int dx = 0; dx < 8; ++dx) {
274 const int sample_x = tile_origin_x + dx;
275 const int sample_y = tile_origin_y + dy;
276 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
277 if (PaletteIndexMatchesTracePalette(comp.palette_index, write.flags)) {
278 return PaletteSamplePoint{
279 .label = label, .x = sample_x, .y = sample_y};
280 }
281 }
282 }
283 }
284
285 if (!trace.empty()) {
286 const auto& write = trace.front();
287 return PaletteSamplePoint{
288 .label = absl::StrFormat("object-trace[0] tile=(%d,%d) pal=%d fallback",
289 write.x_tile, write.y_tile,
290 static_cast<int>((write.flags >> 3) & 0x7)),
291 .x = write.x_tile * 8 + 4,
292 .y = write.y_tile * 8 + 4};
293 }
294
295 return std::nullopt;
296}
297
299 std::span<const zelda3::ObjectDrawer::TileTrace> trace, int selection_x_px,
300 int selection_y_px, int selection_w_px, int selection_h_px) {
301 if (trace.empty()) {
302 return "trace: writes=0";
303 }
304
305 int min_x = std::numeric_limits<int>::max();
306 int min_y = std::numeric_limits<int>::max();
307 int max_x = std::numeric_limits<int>::min();
308 int max_y = std::numeric_limits<int>::min();
309 std::set<std::tuple<int, int, uint8_t>> unique_cells;
310 for (const auto& write : trace) {
311 min_x = std::min<int>(min_x, write.x_tile);
312 min_y = std::min<int>(min_y, write.y_tile);
313 max_x = std::max<int>(max_x, write.x_tile);
314 max_y = std::max<int>(max_y, write.y_tile);
315 unique_cells.insert({write.x_tile, write.y_tile, write.layer});
316 }
317
318 const int trace_x_px = min_x * 8;
319 const int trace_y_px = min_y * 8;
320 const int trace_w_px = (max_x - min_x + 1) * 8;
321 const int trace_h_px = (max_y - min_y + 1) * 8;
322 return absl::StrFormat(
323 "trace: writes=%zu unique_cells=%zu bounds_px=(%d,%d,%d,%d) "
324 "delta_vs_selection_px=(%+d,%+d,%+d,%+d)",
325 trace.size(), unique_cells.size(), trace_x_px, trace_y_px, trace_w_px,
326 trace_h_px, trace_x_px - selection_x_px, trace_y_px - selection_y_px,
327 trace_w_px - selection_w_px, trace_h_px - selection_h_px);
328}
329
330std::string BuildDoorIssueSummary(const zelda3::Room::Door& door, size_t index,
331 std::string_view label) {
332 const auto [tile_x, tile_y] = door.GetTileCoords();
333 const auto [pixel_x, pixel_y] = door.GetPixelCoords();
334 const auto dims = door.GetDimensions();
335 const auto editor_dims = door.GetEditorDimensions();
336 const auto [bounds_x, bounds_y, bounds_w, bounds_h] = door.GetBounds();
337 const auto [editor_x, editor_y, editor_w, editor_h] = door.GetEditorBounds();
338 const auto [encoded_b1, encoded_b2] = door.EncodeBytes();
339
340 return absl::StrFormat(
341 "\n%s[%zu]:\n"
342 "- type=%s (0x%02X)\n"
343 "- direction=%s (%d)\n"
344 "- position=%d\n"
345 "- tile_coords=(%d,%d) pixel_coords=(%d,%d)\n"
346 "- dims_tiles=(%d,%d) editor_dims_tiles=(%d,%d)\n"
347 "- bounds_px=(%d,%d,%d,%d) editor_bounds_px=(%d,%d,%d,%d)\n"
348 "- encoded=(0x%02X,0x%02X) original=(0x%02X,0x%02X)",
349 std::string(label).c_str(), index,
350 std::string(zelda3::GetDoorTypeName(door.type)).c_str(),
351 static_cast<int>(door.type),
352 std::string(zelda3::GetDoorDirectionName(door.direction)).c_str(),
353 static_cast<int>(door.direction), static_cast<int>(door.position), tile_x,
354 tile_y, pixel_x, pixel_y, dims.width_tiles, dims.height_tiles,
355 editor_dims.width_tiles, editor_dims.height_tiles, bounds_x, bounds_y,
356 bounds_w, bounds_h, editor_x, editor_y, editor_w, editor_h, encoded_b1,
357 encoded_b2, door.byte1, door.byte2);
358}
359
360std::string BuildRomDisplayName(const Rom& rom) {
361 if (!rom.short_name().empty()) {
362 return rom.short_name();
363 }
364 if (!rom.filename().empty()) {
365 return std::filesystem::path(rom.filename()).filename().string();
366 }
367 const std::string title = rom.title();
368 return title.empty() ? "in-memory ROM" : title;
369}
370
371std::string BuildReportSessionSummary(const Rom* rom,
372 const project::YazeProject* project) {
373 std::string summary;
374 if (rom && rom->is_loaded()) {
375 const std::string rom_path =
376 rom->filename().empty()
377 ? std::string("in-memory")
379 summary += absl::StrFormat(
380 "ROM: %s | CRC32:%s | Path:%s", BuildRomDisplayName(*rom).c_str(),
381 util::ComputeRomHash(rom->data(), rom->size()).c_str(),
382 rom_path.c_str());
383 } else {
384 summary += "ROM: unavailable";
385 }
386
387 if (project && project->project_opened()) {
388 summary += absl::StrFormat(
389 "\nProject: %s | Path:%s", project->GetDisplayName().c_str(),
391 .c_str());
392 }
393
394 return summary;
395}
396
398 const zelda3::PaletteDebugEvent& event) {
399 if (event.palette_id >= 0 && event.color_count > 0) {
400 return absl::StrFormat("- [%s] palette=%d colors=%d %s",
401 event.location.c_str(), event.palette_id,
402 event.color_count, event.message.c_str());
403 }
404 if (event.palette_id >= 0) {
405 return absl::StrFormat("- [%s] palette=%d %s", event.location.c_str(),
406 event.palette_id, event.message.c_str());
407 }
408 if (event.color_count > 0) {
409 return absl::StrFormat("- [%s] colors=%d %s", event.location.c_str(),
410 event.color_count, event.message.c_str());
411 }
412 return absl::StrFormat("- [%s] %s", event.location.c_str(),
413 event.message.c_str());
414}
415
417
418} // namespace
419
421 const zelda3::Room& room, int room_id) const {
422 const int resolved_palette_id = room.ResolveDungeonPaletteId();
423 const uint8_t entrance_blockset = room.render_entrance_blockset();
424 std::string entrance_context = "Entrance:none";
425 if (current_entrance_id_ >= 0 || entrance_blockset != 0xFF) {
426 const std::string entrance_id_text =
428 ? absl::StrFormat("%02X", current_entrance_id_)
429 : std::string("--");
430 const std::string entrance_blockset_text =
431 entrance_blockset != 0xFF
432 ? absl::StrFormat("%02X", static_cast<int>(entrance_blockset))
433 : std::string("--");
434 entrance_context =
435 absl::StrFormat("Entrance:%s EB:%s", entrance_id_text.c_str(),
436 entrance_blockset_text.c_str());
437 }
438
439 std::string summary = absl::StrFormat(
440 "Room 0x%03X [%s] | B:%02X P:%02X->%02X L:%02X S:%02X | %s | Group:%s | "
441 "Floor:%d Effect:%d Tag1:%d Tag2:%d\n%s\n%s",
442 room_id, zelda3::GetRoomLabel(room_id).c_str(), room.blockset(),
443 room.palette(), resolved_palette_id, room.layout_id(), room.spriteset(),
444 entrance_context, GetBlocksetGroupName(room.blockset()), room.floor1(),
445 room.effect(), room.tag1(), room.tag2(),
446 BuildReportSessionSummary(rom_, project_).c_str(),
447 BuildEffectiveBlockListSummary(room).c_str());
448
449 // Connectivity diagnostics: enumerate doors/staircases/holewarp without
450 // reciprocity filtering so the report captures the room's actual link
451 // configuration. Staircase configuration issues (stale headers, missing
452 // destinations, extra placed objects beyond 4 slots) are listed
453 // separately so a reader can spot phantom or unreachable connections.
454 const auto link_diagnostics =
455 CollectDungeonConnectedRoomLinkDiagnostics(room_id, room, nullptr);
456 if (!link_diagnostics.links.empty() ||
457 !link_diagnostics.staircase_issues.empty()) {
458 summary += "\nConnectivity:";
459 for (const auto& link : link_diagnostics.links) {
460 summary += "\n ";
462 }
463 for (const auto& issue : link_diagnostics.staircase_issues) {
464 summary += "\n ";
466 }
467 }
468
469 return summary;
470}
471
473 int room_id) const {
474 std::string report = "Dungeon Draw Issue Report\n";
475 report += BuildRoomMetadataSummary(room, room_id);
476 report += absl::StrFormat(
477 "\nResolved palette group: 0x%02X\nInteraction mode: %s\nView: BG1=%s "
478 "BG2=%s Grid=%s Bounds=%s Sprites=%s Pots=%s Collision=%s Camera=%s",
481 IsBG1Visible(room_id) ? "on" : "off",
482 IsBG2Visible(room_id) ? "on" : "off", show_grid_ ? "on" : "off",
483 show_object_bounds_ ? "on" : "off",
484 entity_visibility_.show_sprites ? "on" : "off",
485 entity_visibility_.show_pot_items ? "on" : "off",
486 show_custom_collision_overlay_ ? "on" : "off",
487 show_camera_quadrant_overlay_ ? "on" : "off");
488
489 const auto selected = object_interaction_.GetSelectedObjectIndices();
490 if (!selected.empty()) {
491 report += absl::StrFormat("\nSelected objects: %zu", selected.size());
492 if (selected.size() == 1) {
493 const auto& objects = room.GetTileObjects();
494 const size_t index = selected.front();
495 if (index < objects.size()) {
496 const auto& obj = objects[index];
497 report += absl::StrFormat(
498 "\nObject: id=0x%03X name=%s pos=(%d,%d) size=0x%02X %s", obj.id_,
499 GetObjectName(obj.id_).c_str(), obj.x_, obj.y_, obj.size_,
500 BuildSelectedObjectSemanticsSummary(obj).c_str());
501 if (auto tiles = obj.GetTiles(); tiles.ok()) {
502 report += "\n";
503 report += FormatObjectTileSample(*tiles, 16, "Object tiles:");
504 }
505
506 auto [bounds_x, bounds_y, bounds_w, bounds_h] =
508 bounds_w = std::max(bounds_w, 8);
509 bounds_h = std::max(bounds_h, 8);
510 const int origin_x = obj.x_ * 8;
511 const int origin_y = obj.y_ * 8;
512 const int center_x = bounds_x + std::max(0, (bounds_w / 2) - 1);
513 const int center_y = bounds_y + std::max(0, (bounds_h / 2) - 1);
514 report += absl::StrFormat(
515 "\nObject geometry: selection_bounds_px=(%d,%d,%d,%d) "
516 "object_origin_px=(%d,%d) center_px=(%d,%d)",
517 bounds_x, bounds_y, bounds_w, bounds_h, origin_x, origin_y,
518 center_x, center_y);
519 const auto trace_report =
520 BuildObjectTraceReport(rom_, room_id, obj, current_palette_group_);
521 report += trace_report.summary;
522
523 auto& palette_debugger = zelda3::PaletteDebugger::Get();
524 auto append_sample = [&](std::string_view label, int sample_x,
525 int sample_y) {
526 const auto comp = palette_debugger.SamplePixelAt(sample_x, sample_y);
527 palette_debugger.AddComparison(comp);
528 const std::string label_text(label);
529 report += absl::StrFormat(
530 "\nPalette sample %s (%d,%d): idx=%d expected=(%d,%d,%d) "
531 "actual=(%d,%d,%d) match=%s",
532 label_text.c_str(), sample_x, sample_y,
533 static_cast<int>(comp.palette_index),
534 static_cast<int>(comp.expected_r),
535 static_cast<int>(comp.expected_g),
536 static_cast<int>(comp.expected_b),
537 static_cast<int>(comp.actual_r), static_cast<int>(comp.actual_g),
538 static_cast<int>(comp.actual_b), comp.matches ? "yes" : "no");
539 };
540
541 if (auto trace_sample = ChooseObjectTracePaletteSample(
542 trace_report.writes, palette_debugger)) {
543 append_sample(trace_sample->label, trace_sample->x, trace_sample->y);
544 } else {
545 append_sample("selection-origin", bounds_x, bounds_y);
546 if (center_x != bounds_x || center_y != bounds_y) {
547 append_sample("selection-center", center_x, center_y);
548 }
549 }
550 } else {
551 report += absl::StrFormat(
552 "\nSelected object index %zu is stale; room currently has %zu "
553 "object(s). Reselect the object and report again if this issue "
554 "still reproduces.",
555 index, objects.size());
556 }
557 }
558 }
559
561 const auto selected_entity = object_interaction_.GetSelectedEntity();
562 switch (selected_entity.type) {
563 case EntityType::Door: {
564 const auto& doors = room.GetDoors();
565 if (selected_entity.index < doors.size()) {
566 const auto& door = doors[selected_entity.index];
567 report += BuildDoorIssueSummary(door, selected_entity.index,
568 "Selected door");
569 }
570 break;
571 }
572 case EntityType::Sprite: {
573 const auto& sprites = room.GetSprites();
574 if (selected_entity.index < sprites.size()) {
575 const auto& sprite = sprites[selected_entity.index];
576 report += absl::StrFormat(
577 "\nSelected entity: sprite id=0x%02X name=%s pos=(%d,%d) "
578 "layer=%d",
579 sprite.id(), zelda3::ResolveSpriteName(sprite.id()), sprite.x(),
580 sprite.y(), sprite.layer());
581 }
582 break;
583 }
584 case EntityType::Item: {
585 const auto& items = room.GetPotItems();
586 if (selected_entity.index < items.size()) {
587 const auto& item = items[selected_entity.index];
588 report +=
589 absl::StrFormat("\nSelected entity: pot item=0x%02X pos=(%d,%d)",
590 item.item, item.GetPixelX(), item.GetPixelY());
591 }
592 break;
593 }
594 default:
595 break;
596 }
597 }
598
599 const auto& palette_events = zelda3::PaletteDebugger::Get().GetEvents();
600 if (!palette_events.empty()) {
601 report +=
602 absl::StrFormat("\nPalette debug events: %zu", palette_events.size());
603 const size_t preview_count = std::min<size_t>(palette_events.size(), 4);
604 const size_t start = palette_events.size() - preview_count;
605 for (size_t i = start; i < palette_events.size(); ++i) {
606 const auto& event = palette_events[i];
607 report += "\n";
608 report += FormatPaletteDebugEventForReport(event);
609 }
610 }
611
612 return report;
613}
614
616 const zelda3::Room& room, int room_id) const {
617 std::string report = "Dungeon Selection Issue Report\n";
618 report += BuildRoomMetadataSummary(room, room_id);
619 report +=
620 absl::StrFormat("\nInteraction mode: %s\nResolved palette group: 0x%02X",
623
624 const auto selected_objects = object_interaction_.GetSelectedObjectIndices();
625 if (!selected_objects.empty()) {
626 report +=
627 absl::StrFormat("\nSelected objects: %zu", selected_objects.size());
628 const auto& objects = room.GetTileObjects();
629 const size_t preview_count = std::min<size_t>(selected_objects.size(), 4);
630 for (size_t i = 0; i < preview_count; ++i) {
631 const size_t index = selected_objects[i];
632 if (index >= objects.size()) {
633 report += absl::StrFormat(
634 "\n- object[%zu] unavailable; room currently has %zu object(s) "
635 "(selection is stale)",
636 index, objects.size());
637 continue;
638 }
639 const auto& obj = objects[index];
640 report += absl::StrFormat(
641 "\n- object[%zu] id=0x%03X name=%s pos=(%d,%d) size=0x%02X %s", index,
642 obj.id_, GetObjectName(obj.id_).c_str(), obj.x_, obj.y_, obj.size_,
643 BuildSelectedObjectSemanticsSummary(obj).c_str());
644 auto [bounds_x, bounds_y, bounds_w, bounds_h] =
646 bounds_w = std::max(bounds_w, 8);
647 bounds_h = std::max(bounds_h, 8);
648 report += absl::StrFormat(
649 "\n geometry: selection_bounds_px=(%d,%d,%d,%d) "
650 "object_origin_px=(%d,%d)",
651 bounds_x, bounds_y, bounds_w, bounds_h, obj.x_ * 8, obj.y_ * 8);
652 if (auto tiles = obj.GetTiles(); tiles.ok() && !tiles->empty()) {
653 report += "\n ";
654 report += FormatObjectTileSample(*tiles, 10, "tiles:");
655 }
656 const auto trace_report =
657 BuildObjectTraceReport(rom_, room_id, obj, current_palette_group_);
658 report += "\n ";
659 report += BuildObjectTraceBoundsSummary(trace_report.writes, bounds_x,
660 bounds_y, bounds_w, bounds_h);
661 }
662 if (selected_objects.size() > preview_count) {
663 report += absl::StrFormat("\n- ... %zu more object(s)",
664 selected_objects.size() - preview_count);
665 }
666 return report;
667 }
668
670 const auto selected_entity = object_interaction_.GetSelectedEntity();
671 switch (selected_entity.type) {
672 case EntityType::Door: {
673 const auto& doors = room.GetDoors();
674 if (selected_entity.index < doors.size()) {
675 const auto& door = doors[selected_entity.index];
676 report += BuildDoorIssueSummary(door, selected_entity.index,
677 "Selected door");
678 return report;
679 }
680 break;
681 }
682 case EntityType::Sprite: {
683 const auto& sprites = room.GetSprites();
684 if (selected_entity.index < sprites.size()) {
685 const auto& sprite = sprites[selected_entity.index];
686 report += absl::StrFormat(
687 "\nSelected sprite[%zu]:\n"
688 "- id=0x%02X\n"
689 "- name=%s\n"
690 "- pos=(%d,%d)\n"
691 "- layer=%d",
692 selected_entity.index, sprite.id(),
693 zelda3::ResolveSpriteName(sprite.id()), sprite.x(), sprite.y(),
694 sprite.layer());
695 return report;
696 }
697 break;
698 }
699 case EntityType::Item: {
700 const auto& items = room.GetPotItems();
701 if (selected_entity.index < items.size()) {
702 const auto& item = items[selected_entity.index];
703 report += absl::StrFormat(
704 "\nSelected pot item[%zu]:\n"
705 "- item=0x%02X\n"
706 "- pixel_pos=(%d,%d)",
707 selected_entity.index, item.item, item.GetPixelX(),
708 item.GetPixelY());
709 return report;
710 }
711 break;
712 }
713 default:
714 break;
715 }
716 }
717
718 report += "\nNo active object or entity selection.";
719 return report;
720}
721
725
726 auto paths_or = ResolveDungeonIssueReportPaths();
727 if (!paths_or.ok()) {
728 SetIssueReportPopupStatus(std::string(paths_or.status().message()), true);
729 return;
730 }
731
735 util::PlatformPaths::NormalizePathForDisplay(paths_or->screenshots_dir);
736}
737
739 bool is_error) {
740 issue_report_popup_status_message_ = std::move(message);
742}
743
747
753 return;
754 }
755
756 gui::SeparatorText(kIssueReportSectionPaths);
758 ImGui::TextWrapped(tr("Log target: %s"),
760 }
763 ImGui::TextWrapped(tr("Screenshot dir: %s"),
765 }
767 ImGui::TextWrapped(tr("Screenshot: %s"),
769 }
771 ImGui::TextWrapped(tr("Issue log: %s"),
773 }
774}
775
778 return;
779 }
780
781 const ImVec4 color = issue_report_popup_status_is_error_
784 ImGui::TextColored(color, "%s", issue_report_popup_status_message_.c_str());
785}
786
788 const std::string& title, const std::string& summary,
789 const std::string& kind_label, const std::string& diagnostics, int room_id,
790 int default_category_index) {
792 issue_report_popup_kind_ = kind_label;
796 std::clamp(default_category_index, 0,
797 static_cast<int>(kDungeonIssueCategoryLabels.size()) - 1);
801 SetIssueReportPopupStatus("", false);
803 std::snprintf(issue_report_summary_, sizeof(issue_report_summary_), "%s",
804 summary.c_str());
805 issue_report_notes_[0] = '\0';
806 const auto initial_persist_status = EnsureIssueReportPersisted();
807 if (initial_persist_status.ok()) {
809 absl::StrFormat(kIssueReportStatusStartedLog,
811 false);
812 } else {
813 SetIssueReportPopupStatus(std::string(initial_persist_status.message()),
814 true);
815 }
816 return initial_persist_status;
817}
818
819void DungeonCanvasViewer::OpenIssueReportPopup(const std::string& title,
820 const std::string& summary,
821 const std::string& kind_label,
822 const std::string& diagnostics,
823 int room_id,
824 int default_category_index) {
825 (void)PrepareIssueReportPopup(title, summary, kind_label, diagnostics,
826 room_id, default_category_index);
828 if (ImGui::BeginPopupModal(issue_report_popup_id_.c_str(), nullptr,
829 ImGuiWindowFlags_AlwaysAutoResize)) {
830 if (!issue_report_popup_title_.empty()) {
831 ImGui::TextUnformatted(issue_report_popup_title_.c_str());
832 if (!issue_report_popup_kind_.empty()) {
833 ImGui::TextDisabled("%s", issue_report_popup_kind_.c_str());
834 }
835 ImGui::Separator();
836 }
837
838 const char* category_preview =
840 if (ImGui::BeginCombo(tr("Category"), category_preview)) {
841 for (size_t i = 0; i < kDungeonIssueCategoryLabels.size(); ++i) {
842 const bool selected =
843 issue_report_category_index_ == static_cast<int>(i);
844 if (ImGui::Selectable(kDungeonIssueCategoryLabels[i], selected)) {
845 issue_report_category_index_ = static_cast<int>(i);
847 }
848 if (selected) {
849 ImGui::SetItemDefaultFocus();
850 }
851 }
852 ImGui::EndCombo();
853 }
854
855 ImGui::SetNextItemWidth(kIssueReportDialogWidth);
856 if (ImGui::InputTextWithHint("Summary", kIssueReportSummaryHint,
858 sizeof(issue_report_summary_))) {
860 }
861 if (ImGui::InputTextMultiline(
862 tr("Observed issue"), issue_report_notes_,
863 sizeof(issue_report_notes_),
864 ImVec2(kIssueReportDialogWidth, kIssueReportNotesHeight))) {
866 }
867
870 ImGui::TextDisabled(
871 tr("Reports auto-save on open, screenshot capture, copy, or close."));
872
873 if (ImGui::CollapsingHeader(kIssueReportSectionDiagnostics,
874 ImGuiTreeNodeFlags_DefaultOpen)) {
875 ImGui::InputTextMultiline(
876 kIssueReportPopupIdDiagnostics,
879 ImVec2(kIssueReportDialogWidth, kIssueReportDiagnosticsHeight),
880 ImGuiInputTextFlags_ReadOnly);
881 }
882
883#ifdef YAZE_WITH_GRPC
884 const char* capture_label = issue_report_popup_screenshot_path_.empty()
885 ? kIssueReportCaptureButtonLabel
886 : kIssueReportRecaptureButtonLabel;
887 if (ImGui::Button(capture_label)) {
888 const auto status = CaptureIssueReportScreenshot();
889 if (status.ok()) {
891 const auto persist_status = EnsureIssueReportPersisted();
892 if (persist_status.ok()) {
894 absl::StrFormat(kIssueReportStatusSavedScreenshot,
896 false);
897 } else {
898 SetIssueReportPopupStatus(std::string(persist_status.message()),
899 true);
900 }
901 } else {
902 SetIssueReportPopupStatus(std::string(status.message()), true);
903 }
904 }
905 ImGui::SameLine();
906#endif
907 if (ImGui::Button(ICON_MD_SAVE_AS " Save to Issue Log")) {
908 const auto status = EnsureIssueReportPersisted();
909 if (status.ok()) {
911 absl::StrFormat(kIssueReportStatusSavedLog,
913 false);
914 } else {
915 SetIssueReportPopupStatus(std::string(status.message()), true);
916 }
917 }
918 ImGui::SameLine();
919 if (ImGui::Button(ICON_MD_CONTENT_COPY " Copy Report")) {
920 std::string report = BuildIssueReportClipboardText();
921 ImGui::SetClipboardText(report.c_str());
922 const auto status = EnsureIssueReportPersisted();
923 if (status.ok()) {
925 absl::StrFormat(kIssueReportStatusCopiedReport,
927 false);
928 } else {
929 SetIssueReportPopupStatus(std::string(status.message()), true);
930 }
931 }
932 ImGui::SameLine();
933 if (ImGui::Button(ICON_MD_ASSIGNMENT " Copy Diagnostics")) {
934 ImGui::SetClipboardText(issue_report_popup_diagnostics_.c_str());
935 const auto status = EnsureIssueReportPersisted();
936 if (status.ok()) {
938 absl::StrFormat(kIssueReportStatusCopiedDiagnostics,
940 false);
941 } else {
942 SetIssueReportPopupStatus(std::string(status.message()), true);
943 }
944 }
945 ImGui::SameLine();
946 if (ImGui::Button(ICON_MD_CLOSE " Close")) {
947 const auto status = EnsureIssueReportPersisted();
948 if (!status.ok()) {
949 SetIssueReportPopupStatus(std::string(status.message()), true);
950 ImGui::EndPopup();
951 return;
952 }
954 ImGui::CloseCurrentPopup();
955 }
956 ImGui::EndPopup();
957 return;
958 }
959
962 }
963 });
964}
965
967 std::string report;
968 if (!issue_report_popup_kind_.empty()) {
969 report += issue_report_popup_kind_ + "\n";
970 }
971 report += absl::StrFormat(
973 if (issue_report_summary_[0] != '\0') {
974 report += absl::StrFormat("Summary: %s\n", issue_report_summary_);
975 }
977 report += absl::StrFormat("Screenshot: %s\n",
979 }
980 if (issue_report_notes_[0] != '\0') {
981 report += absl::StrFormat("\nObserved issue:\n%s\n", issue_report_notes_);
982 }
983 report += "\nDiagnostics:\n";
985 return report;
986}
987
989#ifdef YAZE_WITH_GRPC
992 return absl::FailedPreconditionError(
993 "Room canvas region is not available for screenshot capture");
994 }
995
996 const std::string timestamp = BuildIssueTimestampSlug();
997 auto screenshot_path_or = BuildDungeonIssueScreenshotPath(
1000 if (!screenshot_path_or.ok()) {
1001 return screenshot_path_or.status();
1002 }
1003
1004 yaze::test::CaptureRegion region;
1005 region.x = canvas_capture_x_;
1006 region.y = canvas_capture_y_;
1007 region.width = canvas_capture_width_;
1008 region.height = canvas_capture_height_;
1009
1010 auto artifact_or = yaze::test::CaptureHarnessScreenshotRegion(
1011 std::optional<yaze::test::CaptureRegion>(region),
1012 screenshot_path_or->string(),
1013 /*reveal_to_user=*/false);
1014 if (!artifact_or.ok()) {
1015 return artifact_or.status();
1016 }
1017
1019 util::PlatformPaths::NormalizePathForDisplay(artifact_or->file_path);
1020 return absl::OkStatus();
1021#else
1022 return absl::UnimplementedError(
1023 "Screenshot capture is unavailable without YAZE_WITH_GRPC");
1024#endif
1025}
1026
1029 entry.timestamp_display = BuildIssueTimestampDisplay();
1038
1039 auto log_path_or = AppendDungeonIssueLogEntry(entry);
1040 if (!log_path_or.ok()) {
1041 return log_path_or.status();
1042 }
1043
1046 return absl::OkStatus();
1047}
1048
1052 return absl::OkStatus();
1053 }
1054
1057 return absl::OkStatus();
1058}
1059
1060} // 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:157
auto data() const
Definition rom.h:151
auto size() const
Definition rom.h:150
auto short_name() const
Definition rom.h:159
bool is_loaded() const
Definition rom.h:144
auto title() const
Definition rom.h:149
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_
std::string BuildDrawIssueReport(const zelda3::Room &room, int room_id) const
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
const char * GetModeName() const
Get mode name for debugging/UI.
void ClosePersistentPopup(const std::string &popup_id)
Definition canvas.cc:873
void OpenPersistentPopup(const std::string &popup_id, std::function< void()> render_callback)
Definition canvas.cc:867
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.
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)
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
uint8_t blockset() const
Definition room.h:902
const std::vector< Door > & GetDoors() const
Definition room.h:350
TagKey tag2() const
Definition room.h:889
uint8_t palette() const
Definition room.h:905
TagKey tag1() const
Definition room.h:888
uint8_t spriteset() const
Definition room.h:904
const std::vector< zelda3::Sprite > & GetSprites() const
Definition room.h:253
const std::vector< RoomObject > & GetTileObjects() const
Definition room.h:382
auto blocks() const
Definition room.h:956
EffectKey effect() const
Definition room.h:887
uint8_t floor1() const
Definition room.h:926
int ResolveDungeonPaletteId() const
Definition room.cc:724
uint8_t render_entrance_blockset() const
Definition room.h:903
uint8_t layout_id() const
Definition room.h:912
const std::vector< PotItem > & GetPotItems() const
Definition room.h:366
#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)
std::string FormatPaletteDebugEventForReport(const zelda3::PaletteDebugEvent &event)
std::string BuildReportSessionSummary(const Rom *rom, const project::YazeProject *project)
ObjectTraceReport BuildObjectTraceReport(Rom *rom, int room_id, const zelda3::RoomObject &obj, const gfx::PaletteGroup &palette_group)
std::string FormatObjectTileSample(std::span< const gfx::TileInfo > tiles, size_t max_count, std::string_view prefix)
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)
ImVec4 GetSuccessColor()
Definition ui_helpers.cc:49
void SeparatorText(const char *label)
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)
constexpr std::string_view GetDoorDirectionName(DoorDirection dir)
Get human-readable name for door direction.
Definition door_types.h:204
bool UsesRoomObjectStream(const RoomObject &object)
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
const char * EffectiveBgLayerLabel(EffectiveBgLayer layer)
const char * ResolveSpriteName(uint16_t id)
Definition sprite.cc:284
#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:1459
Represents a door in a dungeon room.
Definition room.h:276
std::tuple< int, int, int, int > GetEditorBounds() const
Get editor interaction bounds (x, y, width, height in pixels)
Definition room.h:310
std::tuple< int, int, int, int > GetBounds() const
Get bounding rectangle (x, y, width, height in pixels)
Definition room.h:305
uint8_t byte1
Original ROM byte 1 (position data)
Definition room.h:281
DoorDimensions GetDimensions() const
Get door dimensions in tiles.
Definition room.h:295
DoorType type
Door type (determines appearance/behavior)
Definition room.h:278
std::pair< uint8_t, uint8_t > EncodeBytes() const
Encode door data for ROM storage.
Definition room.h:326
DoorDirection direction
Which wall the door is on.
Definition room.h:279
DoorDimensions GetEditorDimensions() const
Get editor interaction dimensions in tiles.
Definition room.h:300
uint8_t position
Encoded position (5-bit, 0-31)
Definition room.h:277
std::pair< int, int > GetPixelCoords() const
Get pixel coordinates for this door.
Definition room.h:290
uint8_t byte2
Original ROM byte 2 (type + direction)
Definition room.h:282
std::pair< int, int > GetTileCoords() const
Get tile coordinates for this door.
Definition room.h:285