PKHeX/PKHeX.Core/Ribbons/RibbonInfo.cs

74 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2018-07-29 23:39:15 +00:00
namespace PKHeX.Core;
/// <summary>
/// Provides information about the state of a given ribbon.
/// </summary>
public sealed class RibbonInfo
2018-07-29 23:39:15 +00:00
{
public const string PropertyPrefix = "Ribbon";
public readonly string Name;
public readonly RibbonValueType Type;
public bool HasRibbon { get; set; }
public byte RibbonCount { get; set; }
2018-07-29 23:39:15 +00:00
private RibbonInfo(string name, bool hasRibbon)
{
Name = name;
HasRibbon = hasRibbon;
Type = RibbonValueType.Boolean;
}
2018-07-29 23:39:15 +00:00
private RibbonInfo(string name, byte count)
{
Name = name;
Type = RibbonValueType.Byte;
RibbonCount = count;
}
2018-07-29 23:39:15 +00:00
public int MaxCount
{
get
2018-07-29 23:39:15 +00:00
{
if (Type is RibbonValueType.Boolean)
throw new ArgumentOutOfRangeException(nameof(Type));
return Name switch
2018-07-29 23:39:15 +00:00
{
nameof(IRibbonSetMemory6.RibbonCountMemoryContest) => 40,
nameof(IRibbonSetMemory6.RibbonCountMemoryBattle) => 8,
_ => 4, // Gen3/4 Contest Ribbons
};
2018-07-29 23:39:15 +00:00
}
}
2018-07-29 23:39:15 +00:00
public static List<RibbonInfo> GetRibbonInfo(PKM pk)
{
// Get a list of all Ribbon Attributes in the PKM
var riblist = new List<RibbonInfo>();
var names = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), PropertyPrefix);
foreach (var name in names)
2018-07-29 23:39:15 +00:00
{
object? RibbonValue = ReflectUtil.GetValue(pk, name);
if (RibbonValue is bool b)
riblist.Add(new RibbonInfo(name, b));
else if (RibbonValue is byte x)
riblist.Add(new RibbonInfo(name, x));
2018-07-29 23:39:15 +00:00
}
return riblist;
2018-07-29 23:39:15 +00:00
}
}
/// <summary>
/// Type of Ribbon Value
/// </summary>
public enum RibbonValueType
{
Boolean,
Byte,
}