Extract legality report (invalids) methods

This commit is contained in:
Kurt 2021-08-06 16:12:11 -07:00
parent b8e203bdef
commit 89372145b7
2 changed files with 23 additions and 40 deletions

View file

@ -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<string> 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<string> 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<string> GetVerboseLegalityReportLines(LegalityAnalysis l)
{
var lines = l.Valid ? new List<string> {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);

View file

@ -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<CheckResult> results, List<string> lines)
public static void AddSecondaryChecksValid(IEnumerable<CheckResult> results, List<string> 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<string> lines)
public static void AddSecondaryChecksInvalid(IReadOnlyList<CheckResult> results, List<string> 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(chk.Format(L_F0_1));
}
}
public static void AddRelearn(CheckResult[] relearn, List<string> 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 AddValidMoves(LegalInfo info, List<string> lines, in int currentFormat)
public static void AddMoves(CheckMoveResult[] moves, List<string> 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;