PkmnLibRSharp/PkmnLibRSharp/StaticData/Libraries/LibrarySettings.cs

56 lines
2.0 KiB
C#

using System.Diagnostics;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.LibrarySettings;
namespace PkmnLibSharp.StaticData.Libraries
{
/// <summary>
/// This library holds several misc settings for the library.
/// </summary>
public class LibrarySettings : ExternPointer<LibrarySettings.CacheData>
{
public class CacheData
{
public LevelInt? MaxLevel { get; internal set; }
public uint? ShinyRate { get; internal set; }
}
/// <inheritdoc cref="LibrarySettings"/>
/// <param name="maxLevel">The highest level a Pokemon can be.</param>
/// <param name="shinyRate">
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
/// </param>
public LibrarySettings(LevelInt maxLevel, uint shinyRate)
{
Debug.Assert(maxLevel >= 1);
Debug.Assert(shinyRate >= 1);
InitializePointer(Interface.library_settings_new(maxLevel, shinyRate), true);
}
internal LibrarySettings(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{
}
/// <summary>
/// The highest level a Pokemon can be.
/// </summary>
public LevelInt MaxLevel => Cache.MaxLevel ??= Interface.library_settings_maximum_level(Ptr);
/// <summary>
/// The chance of a Pokemon being shiny, as the denominator of a fraction, where the nominator
/// is 1. For example, if this is 1000, then the chance of a Pokemon being shiny is 1/1000.
/// </summary>
public uint ShinyRate => Cache.ShinyRate ??= Interface.library_settings_shiny_rate(Ptr);
protected override CacheData CreateCache() => new();
protected override void Destructor() => Interface.library_settings_drop(Ptr);
~LibrarySettings()
{
Dispose();
}
}
}