Add some xmldoc, file scoped namespaces

Not much of a git diff history for these files so I don't mind them being reformatted.
This commit is contained in:
Kurt 2021-12-09 18:58:30 -08:00
parent 18469a78aa
commit d7e1f65faa
12 changed files with 215 additions and 172 deletions

View file

@ -4,17 +4,20 @@ using PKHeX.Core.Searching;
namespace PKHeX.Core
{
/// <summary>
/// Base class for defining a manipulation of box data.
/// </summary>
public abstract class BoxManipBase : IBoxManip
{
public BoxManipType Type { get; }
public Func<SaveFile, bool> Usable { get; }
protected BoxManipBase(BoxManipType type, Func<SaveFile, bool> usable)
{
Type = type;
Usable = usable;
}
public BoxManipType Type { get; }
public Func<SaveFile, bool> Usable { get; }
public abstract string GetPrompt(bool all);
public abstract string GetFail(bool all);
public abstract string GetSuccess(bool all);

View file

@ -1,21 +1,24 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Clears contents of boxes by deleting all that satisfy a <see cref="Criteria"/>.
/// </summary>
public sealed class BoxManipClear : BoxManipBase
{
public sealed class BoxManipClear : BoxManipBase
private readonly Func<PKM, bool> Criteria;
public BoxManipClear(BoxManipType type, Func<PKM, bool> criteria) : this(type, criteria, _ => true) { }
public BoxManipClear(BoxManipType type, Func<PKM, bool> criteria, Func<SaveFile, bool> usable) : base(type, usable) => Criteria = criteria;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Func<PKM, bool> Criteria;
public BoxManipClear(BoxManipType type, Func<PKM, bool> criteria) : this(type, criteria, _ => true) { }
public BoxManipClear(BoxManipType type, Func<PKM, bool> criteria, Func<SaveFile, bool> usable) : base(type, usable) => Criteria = criteria;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
bool Method(PKM p) => param.Reverse ^ Criteria(p);
return sav.ClearBoxes(param.Start, param.Stop, Method);
}
var (start, stop, reverse) = param;
bool Method(PKM p) => reverse ^ Criteria(p);
return sav.ClearBoxes(start, stop, Method);
}
}
}

View file

@ -1,21 +1,24 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Clears contents of boxes by deleting all that satisfy a <see cref="Criteria"/> based on a <see cref="SaveFile"/>.
/// </summary>
public sealed class BoxManipClearComplex : BoxManipBase
{
public sealed class BoxManipClearComplex : BoxManipBase
private readonly Func<PKM, SaveFile, bool> Criteria;
public BoxManipClearComplex(BoxManipType type, Func<PKM, SaveFile, bool> criteria) : this(type, criteria, _ => true) { }
public BoxManipClearComplex(BoxManipType type, Func<PKM, SaveFile, bool> criteria, Func<SaveFile, bool> usable) : base(type, usable) => Criteria = criteria;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Func<PKM, SaveFile, bool> Criteria;
public BoxManipClearComplex(BoxManipType type, Func<PKM, SaveFile, bool> criteria) : this(type, criteria, _ => true) { }
public BoxManipClearComplex(BoxManipType type, Func<PKM, SaveFile, bool> criteria, Func<SaveFile, bool> usable) : base(type, usable) => Criteria = criteria;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
bool Method(PKM p) => param.Reverse ^ Criteria(p, sav);
return sav.ClearBoxes(param.Start, param.Stop, Method);
}
var (start, stop, reverse) = param;
bool Method(PKM p) => reverse ^ Criteria(p, sav);
return sav.ClearBoxes(start, stop, Method);
}
}
}

View file

@ -1,35 +1,38 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Clears contents of boxes by deleting all but the first duplicate detected.
/// </summary>
/// <typeparam name="T">Base type of the "is duplicate" hash for the duplicate detection.</typeparam>
public sealed class BoxManipClearDuplicate<T> : BoxManipBase
{
public sealed class BoxManipClearDuplicate<T> : BoxManipBase
private readonly HashSet<T> HashSet = new();
private readonly Func<PKM, bool> Criteria;
public BoxManipClearDuplicate(BoxManipType type, Func<PKM, T> criteria) : this(type, criteria, _ => true) { }
public BoxManipClearDuplicate(BoxManipType type, Func<PKM, T> criteria, Func<SaveFile, bool> usable) : base(type, usable)
{
private readonly HashSet<T> HashSet = new();
private readonly Func<PKM, bool> Criteria;
public BoxManipClearDuplicate(BoxManipType type, Func<PKM, T> criteria) : this(type, criteria, _ => true) { }
public BoxManipClearDuplicate(BoxManipType type, Func<PKM, T> criteria, Func<SaveFile, bool> usable) : base(type, usable)
Criteria = pk =>
{
Criteria = pk =>
{
var result = criteria(pk);
if (HashSet.Contains(result))
return true;
HashSet.Add(result);
return false;
};
}
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
HashSet.Clear();
bool Method(PKM p) => param.Reverse ^ Criteria(p);
return sav.ClearBoxes(param.Start, param.Stop, Method);
}
var result = criteria(pk);
if (HashSet.Contains(result))
return true;
HashSet.Add(result);
return false;
};
}
}
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
HashSet.Clear();
bool Method(PKM p) => param.Reverse ^ Criteria(p);
return sav.ClearBoxes(param.Start, param.Stop, Method);
}
}

View file

@ -1,17 +1,23 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Modifies contents of boxes by using an <see cref="Action"/> to change data.
/// </summary>
public sealed class BoxManipModify : BoxManipBase
{
public sealed class BoxManipModify : BoxManipBase
private readonly Action<PKM> Action;
public BoxManipModify(BoxManipType type, Action<PKM> action) : this(type, action, _ => true) { }
public BoxManipModify(BoxManipType type, Action<PKM> action, Func<SaveFile, bool> usable) : base(type, usable) => Action = action;
public override string GetPrompt(bool all) => string.Empty;
public override string GetFail(bool all) => string.Empty;
public override string GetSuccess(bool all) => string.Empty;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Action<PKM> Action;
public BoxManipModify(BoxManipType type, Action<PKM> action) : this(type, action, _ => true) { }
public BoxManipModify(BoxManipType type, Action<PKM> action, Func<SaveFile, bool> usable) : base(type, usable) => Action = action;
public override string GetPrompt(bool all) => string.Empty;
public override string GetFail(bool all) => string.Empty;
public override string GetSuccess(bool all) => string.Empty;
public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(Action, param.Start, param.Stop);
var (start, stop, _) = param;
return sav.ModifyBoxes(Action, start, stop);
}
}

View file

@ -1,17 +1,23 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Modifies contents of boxes by using an <see cref="Action"/> (referencing a Save File) to change data.
/// </summary>
public sealed class BoxManipModifyComplex : BoxManipBase
{
public sealed class BoxManipModifyComplex : BoxManipBase
private readonly Action<PKM, SaveFile> Action;
public BoxManipModifyComplex(BoxManipType type, Action<PKM, SaveFile> action) : this(type, action, _ => true) { }
public BoxManipModifyComplex(BoxManipType type, Action<PKM, SaveFile> action, Func<SaveFile, bool> usable) : base(type, usable) => Action = action;
public override string GetPrompt(bool all) => string.Empty;
public override string GetFail(bool all) => string.Empty;
public override string GetSuccess(bool all) => string.Empty;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Action<PKM, SaveFile> Action;
public BoxManipModifyComplex(BoxManipType type, Action<PKM, SaveFile> action) : this(type, action, _ => true) { }
public BoxManipModifyComplex(BoxManipType type, Action<PKM, SaveFile> action, Func<SaveFile, bool> usable) : base(type, usable) => Action = action;
public override string GetPrompt(bool all) => string.Empty;
public override string GetFail(bool all) => string.Empty;
public override string GetSuccess(bool all) => string.Empty;
public override int Execute(SaveFile sav, BoxManipParam param) => sav.ModifyBoxes(pk => Action(pk, sav), param.Start, param.Stop);
var (start, stop, _) = param;
return sav.ModifyBoxes(pk => Action(pk, sav), start, stop);
}
}
}

View file

@ -1,3 +1,9 @@
namespace PKHeX.Core;
/// <summary>
/// Criteria for manipulating box data.
/// </summary>
/// <param name="Start">Box to start at (inclusive)</param>
/// <param name="Stop">Box to stop at (exclusive)</param>
/// <param name="Reverse">Iterate in reverse</param>
public readonly record struct BoxManipParam(int Start, int Stop, bool Reverse = false);

View file

@ -1,22 +1,25 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Sorts contents of boxes by using a <see cref="Sorter"/> to determine the order.
/// </summary>
public sealed class BoxManipSort : BoxManipBase
{
public sealed class BoxManipSort : BoxManipBase
private readonly Func<IEnumerable<PKM>, IEnumerable<PKM>> Sorter;
public BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = sorter;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxSortAll : MessageStrings.MsgSaveBoxSortCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle: MessageStrings.MsgSaveBoxSortCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Func<IEnumerable<PKM>, IEnumerable<PKM>> Sorter;
public BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = sorter;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxSortAll : MessageStrings.MsgSaveBoxSortCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle: MessageStrings.MsgSaveBoxSortCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
IEnumerable<PKM> Method(IEnumerable<PKM> p, int index) => Sorter(p);
return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
}
IEnumerable<PKM> Method(IEnumerable<PKM> p, int index) => Sorter(p);
var (start, stop, reverse) = param;
return sav.SortBoxes(start, stop, Method, reverse);
}
}
}

View file

@ -1,25 +1,28 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Sorts contents of boxes by using a <see cref="Sorter"/> (referencing a Save File) to determine the order.
/// </summary>
public sealed class BoxManipSortComplex : BoxManipBase
{
public sealed class BoxManipSortComplex : BoxManipBase
private readonly Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> Sorter;
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = (pkms, file, _) => sorter(pkms, file);
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = sorter;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxSortAll : MessageStrings.MsgSaveBoxSortCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle : MessageStrings.MsgSaveBoxSortCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
private readonly Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> Sorter;
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = (pkms, file, _) => sorter(pkms, file);
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> sorter) : this(type, sorter, _ => true) { }
public BoxManipSortComplex(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, int, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable) : base(type, usable) => Sorter = sorter;
public override string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxSortAll : MessageStrings.MsgSaveBoxSortCurrent;
public override string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle : MessageStrings.MsgSaveBoxSortCurrentFailBattle;
public override string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
public override int Execute(SaveFile sav, BoxManipParam param)
{
IEnumerable<PKM> Method(IEnumerable<PKM> p, int index) => Sorter(p, sav, index);
return sav.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
}
IEnumerable<PKM> Method(IEnumerable<PKM> p, int index) => Sorter(p, sav, index);
var (start, stop, reverse) = param;
return sav.SortBoxes(start, stop, Method, reverse);
}
}

View file

@ -1,46 +1,48 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Action to perform when manipulating boxes.
/// </summary>
public enum BoxManipType
{
public enum BoxManipType
{
DeleteAll,
DeleteEggs,
DeletePastGen,
DeleteForeign,
DeleteUntrained,
DeleteItemless,
DeleteIllegal,
DeleteClones,
DeleteAll,
DeleteEggs,
DeletePastGen,
DeleteForeign,
DeleteUntrained,
DeleteItemless,
DeleteIllegal,
DeleteClones,
SortSpecies,
SortSpeciesReverse,
SortLevel,
SortLevelReverse,
SortDate,
SortName,
SortFavorite,
SortParty,
SortShiny,
SortRandom,
SortSpecies,
SortSpeciesReverse,
SortLevel,
SortLevelReverse,
SortDate,
SortName,
SortFavorite,
SortParty,
SortShiny,
SortRandom,
SortUsage,
SortPotential,
SortTraining,
SortOwner,
SortType,
SortVersion,
SortBST,
SortCP,
SortLegal,
SortEncounterType,
SortUsage,
SortPotential,
SortTraining,
SortOwner,
SortType,
SortVersion,
SortBST,
SortCP,
SortLegal,
SortEncounterType,
ModifyHatchEggs,
ModifyMaxFriendship,
ModifyMaxLevel,
ModifyResetMoves,
ModifyRandomMoves,
ModifyHyperTrain,
ModifyRemoveNicknames,
ModifyRemoveItem,
ModifyHeal,
}
ModifyHatchEggs,
ModifyMaxFriendship,
ModifyMaxLevel,
ModifyResetMoves,
ModifyRandomMoves,
ModifyHyperTrain,
ModifyRemoveNicknames,
ModifyRemoveItem,
ModifyHeal,
}

View file

@ -1,5 +1,8 @@
namespace PKHeX.Core
{
/// <summary>
/// Manipulates boxes of a <see cref="SaveFile"/>.
/// </summary>
public abstract class BoxManipulator
{
protected abstract SaveFile SAV { get; }

View file

@ -1,16 +1,18 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Base interface for all box manipulation actions.
/// </summary>
public interface IBoxManip
{
public interface IBoxManip
{
BoxManipType Type { get; }
Func<SaveFile, bool> Usable { get; }
BoxManipType Type { get; }
Func<SaveFile, bool> Usable { get; }
string GetPrompt(bool all);
string GetFail(bool all);
string GetSuccess(bool all);
string GetPrompt(bool all);
string GetFail(bool all);
string GetSuccess(bool all);
int Execute(SaveFile sav, BoxManipParam param);
}
}
int Execute(SaveFile sav, BoxManipParam param);
}