171 bool verbose = parser.
HasFlag(
"verbose");
172 bool all_rooms = parser.
HasFlag(
"all");
173 bool deep_scan = parser.
HasFlag(
"deep");
174 auto room_id_arg = parser.
GetInt(
"room");
175 bool is_json = formatter.
IsJson();
180 OutputTextBanner(is_json);
182 std::vector<RoomDiagnostic> diagnostics;
183 int total_objects = 0;
184 int total_sprites = 0;
186 int warning_rooms = 0;
189 if (room_id_arg.ok()) {
191 int room_id = room_id_arg.value();
192 if (room_id < 0 || room_id >= kNumRooms) {
193 return absl::InvalidArgumentError(
194 absl::StrFormat(
"Room ID must be between 0 and %d", kNumRooms - 1));
197 auto diag = DiagnoseRoom(rom, room_id);
198 diagnostics.push_back(diag);
199 total_objects = diag.object_count;
200 total_sprites = diag.sprite_count;
202 if (diag.IsValid() && diag.findings.empty()) {
205 bool has_errors =
false;
206 bool has_warnings =
false;
207 for (
const auto& finding : diag.findings) {
217 else if (has_warnings)
223 }
else if (all_rooms) {
226 std::cout <<
"\nAnalyzing all " << kNumRooms <<
" rooms...\n";
229 for (
int room_id = 0; room_id < kNumRooms; ++room_id) {
230 auto diag = DiagnoseRoom(rom, room_id);
231 diagnostics.push_back(diag);
232 total_objects += diag.object_count;
233 total_sprites += diag.sprite_count;
235 bool has_errors =
false;
236 bool has_warnings =
false;
237 for (
const auto& finding : diag.findings) {
248 }
else if (has_warnings) {
256 std::vector<int> sample_rooms = {0, 1, 2, 3,
263 std::cout <<
"\nAnalyzing " << sample_rooms.size()
264 <<
" sample rooms...\n";
265 std::cout <<
"(Use --all to analyze all " << kNumRooms <<
" rooms)\n";
268 for (
int room_id : sample_rooms) {
269 if (room_id >= kNumRooms)
271 auto diag = DiagnoseRoom(rom, room_id);
272 diagnostics.push_back(diag);
273 total_objects += diag.object_count;
274 total_sprites += diag.sprite_count;
276 bool has_errors =
false;
277 bool has_warnings =
false;
278 for (
const auto& finding : diag.findings) {
289 }
else if (has_warnings) {
298 std::vector<DiagnosticFinding> deep_findings;
300 CheckUnusedRooms(diagnostics, deep_findings);
304 formatter.
AddField(
"total_rooms",
static_cast<int>(diagnostics.size()));
305 formatter.
AddField(
"valid_rooms", valid_rooms);
306 formatter.
AddField(
"warning_rooms", warning_rooms);
307 formatter.
AddField(
"error_rooms", error_rooms);
308 formatter.
AddField(
"total_objects", total_objects);
309 formatter.
AddField(
"total_sprites", total_sprites);
312 for (
const auto& diag : diagnostics) {
315 }
else if (verbose || !diag.findings.empty()) {
318 diag.IsValid() && diag.findings.empty() ?
"OK" :
"ISSUES";
320 "Room 0x%02X: %s (objects=%d, sprites=%d, chests=%d)", diag.room_id,
321 status, diag.object_count, diag.sprite_count, diag.chest_count));
327 std::vector<DiagnosticFinding> all_findings;
328 for (
const auto& diag : diagnostics) {
329 for (
const auto& finding : diag.findings) {
330 all_findings.push_back(finding);
334 for (
const auto& finding : deep_findings) {
335 all_findings.push_back(finding);
339 for (
const auto& finding : all_findings) {
346 OutputTextSummary(
static_cast<int>(diagnostics.size()), valid_rooms,
347 warning_rooms, error_rooms, total_objects, total_sprites);
349 if (!all_findings.empty()) {
350 std::cout <<
"\n=== Issues Found ===\n";
351 for (
const auto& finding : all_findings) {
352 std::cout <<
" " << finding.FormatText() <<
"\n";
357 return absl::OkStatus();