2022-08-16 04:04:30 +00:00
|
|
|
using System;
|
|
|
|
using static PKHeX.Core.RibbonParseFlags;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2022-08-16 04:04:30 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
public readonly record struct RibbonResult
|
2017-09-04 02:51:29 +00:00
|
|
|
{
|
2022-08-16 04:04:30 +00:00
|
|
|
private readonly byte Value;
|
|
|
|
private readonly RibbonParseFlags Flags;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// True: ribbon is missing -- should have the ribbon.
|
|
|
|
/// False: ribbon is invalid -- should not have the ribbon.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsMissing => (Flags & Missing) != 0;
|
|
|
|
|
|
|
|
private RibbonParseFlags Type => Flags & ~Missing;
|
2017-09-04 02:51:29 +00:00
|
|
|
|
2022-08-16 04:04:30 +00:00
|
|
|
public RibbonResult(RibbonIndex index, bool missing = false) { Value = (byte)index; Flags = missing ? MissingM : Mainline; }
|
|
|
|
public RibbonResult(RibbonIndex3 index, bool missing = false) { Value = (byte)index; Flags = missing ? Missing3 : Index3; }
|
|
|
|
public RibbonResult(RibbonIndex4 index, bool missing = false) { Value = (byte)index; Flags = missing ? Missing4 : Index4; }
|
|
|
|
public bool Equals(RibbonIndex index) => Type == Mainline && Value == (byte)index;
|
|
|
|
public bool Equals(RibbonIndex3 index) => Type == Index3 && Value == (byte)index;
|
|
|
|
public bool Equals(RibbonIndex4 index) => Type == Index4 && Value == (byte)index;
|
2017-09-04 02:51:29 +00:00
|
|
|
|
2022-08-16 04:04:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Property Name that the ribbon can be get/set with, or looked up for localization.
|
|
|
|
/// </summary>
|
|
|
|
public string PropertyName => Type switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-16 04:04:30 +00:00
|
|
|
Mainline => ((RibbonIndex)Value).GetPropertyName(),
|
|
|
|
Index3 => ((RibbonIndex3)Value).GetPropertyName(),
|
|
|
|
Index4 => ((RibbonIndex4)Value).GetPropertyName(),
|
|
|
|
_ => throw new ArgumentOutOfRangeException(),
|
|
|
|
};
|
2017-09-04 02:51:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
2022-08-16 04:04:30 +00:00
|
|
|
/// Updates the ribbon state depending on the <see cref="args"/> and <see cref="IsMissing"/> state.
|
2022-06-18 18:04:24 +00:00
|
|
|
/// </summary>
|
2022-08-16 04:04:30 +00:00
|
|
|
public void Fix(RibbonVerifierArguments args)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2022-08-16 04:04:30 +00:00
|
|
|
switch (Type)
|
|
|
|
{
|
|
|
|
case Mainline: ((RibbonIndex)Value).Fix(args, IsMissing); break;
|
|
|
|
case Index3: ((RibbonIndex3)Value).Fix(args, IsMissing); break;
|
|
|
|
case Index4: ((RibbonIndex4)Value).Fix(args, IsMissing); break;
|
|
|
|
default: throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
2017-09-04 02:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 04:04:30 +00:00
|
|
|
|
|
|
|
[Flags]
|
|
|
|
public enum RibbonParseFlags : byte
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Mainline,
|
|
|
|
Index3,
|
|
|
|
Index4,
|
|
|
|
|
|
|
|
Missing = 0x80,
|
|
|
|
MissingM = Missing | Mainline,
|
|
|
|
Missing3 = Missing | Index3,
|
|
|
|
Missing4 = Missing | Index4,
|
|
|
|
}
|