174 bool verbose = parser.
HasFlag(
"verbose");
175 bool all_rooms = parser.
HasFlag(
"all");
176 bool deep_scan = parser.
HasFlag(
"deep");
177 auto room_id_arg = parser.
GetInt(
"room");
178 bool is_json = formatter.
IsJson();
183 OutputTextBanner(is_json);
185 std::vector<RoomDiagnostic> diagnostics;
186 int total_objects = 0;
187 int total_sprites = 0;
189 int warning_rooms = 0;
192 if (room_id_arg.ok()) {
194 int room_id = room_id_arg.value();
195 if (room_id < 0 || room_id >= kNumRooms) {
196 return absl::InvalidArgumentError(
197 absl::StrFormat(
"Room ID must be between 0 and %d", kNumRooms - 1));
200 auto diag = DiagnoseRoom(rom, room_id);
201 diagnostics.push_back(diag);
202 total_objects = diag.object_count;
203 total_sprites = diag.sprite_count;
205 if (diag.IsValid() && diag.findings.empty()) {
208 bool has_errors =
false;
209 bool has_warnings =
false;
210 for (
const auto& finding : diag.findings) {
220 else if (has_warnings)
226 }
else if (all_rooms) {
229 std::cout <<
"\nAnalyzing all " << kNumRooms <<
" rooms...\n";
232 for (
int room_id = 0; room_id < kNumRooms; ++room_id) {
233 auto diag = DiagnoseRoom(rom, room_id);
234 diagnostics.push_back(diag);
235 total_objects += diag.object_count;
236 total_sprites += diag.sprite_count;
238 bool has_errors =
false;
239 bool has_warnings =
false;
240 for (
const auto& finding : diag.findings) {
251 }
else if (has_warnings) {
259 std::vector<int> sample_rooms = {0, 1, 2, 3,
266 std::cout <<
"\nAnalyzing " << sample_rooms.size()
267 <<
" sample rooms...\n";
268 std::cout <<
"(Use --all to analyze all " << kNumRooms <<
" rooms)\n";
271 for (
int room_id : sample_rooms) {
272 if (room_id >= kNumRooms)
274 auto diag = DiagnoseRoom(rom, room_id);
275 diagnostics.push_back(diag);
276 total_objects += diag.object_count;
277 total_sprites += diag.sprite_count;
279 bool has_errors =
false;
280 bool has_warnings =
false;
281 for (
const auto& finding : diag.findings) {
292 }
else if (has_warnings) {
301 std::vector<DiagnosticFinding> deep_findings;
303 CheckUnusedRooms(diagnostics, deep_findings);
307 formatter.
AddField(
"total_rooms",
static_cast<int>(diagnostics.size()));
308 formatter.
AddField(
"valid_rooms", valid_rooms);
309 formatter.
AddField(
"warning_rooms", warning_rooms);
310 formatter.
AddField(
"error_rooms", error_rooms);
311 formatter.
AddField(
"total_objects", total_objects);
312 formatter.
AddField(
"total_sprites", total_sprites);
315 for (
const auto& diag : diagnostics) {
318 }
else if (verbose || !diag.findings.empty()) {
321 diag.IsValid() && diag.findings.empty() ?
"OK" :
"ISSUES";
323 "Room 0x%02X: %s (objects=%d, sprites=%d, chests=%d)", diag.room_id,
324 status, diag.object_count, diag.sprite_count, diag.chest_count));
330 std::vector<DiagnosticFinding> all_findings;
331 for (
const auto& diag : diagnostics) {
332 for (
const auto& finding : diag.findings) {
333 all_findings.push_back(finding);
337 for (
const auto& finding : deep_findings) {
338 all_findings.push_back(finding);
342 for (
const auto& finding : all_findings) {
349 OutputTextSummary(
static_cast<int>(diagnostics.size()), valid_rooms,
350 warning_rooms, error_rooms, total_objects, total_sprites);
352 if (!all_findings.empty()) {
353 std::cout <<
"\n=== Issues Found ===\n";
354 for (
const auto& finding : all_findings) {
355 std::cout <<
" " << finding.FormatText() <<
"\n";
360 return absl::OkStatus();