From 89372145b79cd0ed6c98deaa4e110666b7d72b7f Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 6 Aug 2021 16:12:11 -0700 Subject: [PATCH] Extract legality report (invalids) methods --- .../Formatting/BaseLegalityFormatter.cs | 36 ++++--------------- .../Legality/Formatting/LegalityFormatting.cs | 27 ++++++++------ 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/PKHeX.Core/Legality/Formatting/BaseLegalityFormatter.cs b/PKHeX.Core/Legality/Formatting/BaseLegalityFormatter.cs index 1f35f314d..ccc5b9a35 100644 --- a/PKHeX.Core/Legality/Formatting/BaseLegalityFormatter.cs +++ b/PKHeX.Core/Legality/Formatting/BaseLegalityFormatter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using static PKHeX.Core.LegalityCheckStrings; namespace PKHeX.Core @@ -36,36 +35,13 @@ namespace PKHeX.Core var info = l.Info; var pkm = l.pkm; - AddMoves(info.Moves, lines); + LegalityFormatting.AddMoves(info.Moves, lines, pkm.Format, false); if (pkm.Format >= 6) - AddRelearn(info.Relearn, lines); - - // Build result string... - var outputLines = l.Results.Where(chk => !chk.Valid); - lines.AddRange(outputLines.Select(chk => chk.Format(L_F0_1))); + LegalityFormatting.AddRelearn(info.Relearn, lines, false); + LegalityFormatting.AddSecondaryChecksInvalid(l.Results, lines); return lines; } - private static void AddMoves(CheckMoveResult[] moves, List lines) - { - for (int i = 0; i < moves.Length; i++) - { - var move = moves[i]; - if (!move.Valid) - lines.Add(move.Format(L_F0_M_1_2, i + 1)); - } - } - - private static void AddRelearn(CheckResult[] relearn, List lines) - { - for (int i = 0; i < relearn.Length; i++) - { - var move = relearn[i]; - if (!move.Valid) - lines.Add(move.Format(L_F0_RM_1_2, i + 1)); - } - } - private static IReadOnlyList GetVerboseLegalityReportLines(LegalityAnalysis l) { var lines = l.Valid ? new List {L_ALegal} : GetLegalityReportLines(l); @@ -77,15 +53,15 @@ namespace PKHeX.Core int initialCount = lines.Count; var format = pkm.Format; - LegalityFormatting.AddValidMoves(info, lines, format); + LegalityFormatting.AddMoves(info.Moves, lines, format, true); if (format >= 6) - LegalityFormatting.AddValidMovesRelearn(info, lines); + LegalityFormatting.AddRelearn(info.Relearn, lines, true); if (lines.Count != initialCount) // move info added, break for next section lines.Add(string.Empty); - LegalityFormatting.AddValidSecondaryChecks(l.Results, lines); + LegalityFormatting.AddSecondaryChecksValid(l.Results, lines); lines.Add(separator); lines.Add(string.Empty); diff --git a/PKHeX.Core/Legality/Formatting/LegalityFormatting.cs b/PKHeX.Core/Legality/Formatting/LegalityFormatting.cs index a45ce1326..5f4e688c8 100644 --- a/PKHeX.Core/Legality/Formatting/LegalityFormatting.cs +++ b/PKHeX.Core/Legality/Formatting/LegalityFormatting.cs @@ -22,7 +22,7 @@ namespace PKHeX.Core public static string GetLegalityReport(LegalityAnalysis la) => Formatter.GetReport(la); public static string GetVerboseLegalityReport(LegalityAnalysis la) => Formatter.GetReportVerbose(la); - public static void AddValidSecondaryChecks(IEnumerable results, List lines) + public static void AddSecondaryChecksValid(IEnumerable results, List lines) { var outputLines = results .Where(chk => chk.Valid && chk.Comment != L_AValid) @@ -31,25 +31,32 @@ namespace PKHeX.Core lines.AddRange(outputLines); } - public static void AddValidMovesRelearn(LegalInfo info, List lines) + public static void AddSecondaryChecksInvalid(IReadOnlyList results, List lines) { - var moves = info.Relearn; - for (int i = 0; i < moves.Length; i++) + foreach (var chk in results) { - var move = moves[i]; - if (!move.Valid) + if (chk.Valid) continue; - lines.Add(move.Format(L_F0_RM_1_2, i + 1)); + lines.Add(chk.Format(L_F0_1)); } } - public static void AddValidMoves(LegalInfo info, List lines, in int currentFormat) + public static void AddRelearn(CheckResult[] relearn, List lines, bool state) + { + for (int i = 0; i < relearn.Length; i++) + { + var move = relearn[i]; + if (move.Valid == state) + lines.Add(move.Format(L_F0_RM_1_2, i + 1)); + } + } + + public static void AddMoves(CheckMoveResult[] moves, List lines, in int currentFormat, bool state) { - var moves = info.Moves; for (int i = 0; i < moves.Length; i++) { var move = moves[i]; - if (!move.Valid) + if (move.Valid != state) continue; var msg = move.Format(L_F0_M_1_2, i + 1); var gen = move.Generation;