PkmnLibRSharp/PkmnLibRSharp/StaticData/Libraries/MoveLibrary.cs

51 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using PkmnLibSharp.FFI;
using PkmnLibSharp.Utils;
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.MoveLibrary;
namespace PkmnLibSharp.StaticData.Libraries
{
public class MoveLibrary : DataLibrary<MoveData>
{
public MoveLibrary(ulong capacity) : base(Interface.move_library_new(capacity), true)
{
}
internal MoveLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
{
}
protected override void Destructor()
{
Interface.move_library_drop(Ptr);
}
public override void Add(string key, MoveData value) =>
Interface.move_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
public override int Count => (int)Interface.move_library_len(Ptr);
protected override MoveData? GetValueByKey(string key)
{
var ptr = Interface.move_library_get(Ptr, key.ToPtr());
return ptr.Ptr == IntPtr.Zero ? null : new MoveData(ptr, false);
}
public override string? GetKeyByIndex(ulong index) =>
Interface.move_library_get_key_by_index(Ptr, index).PtrString();
public override void InvalidateChildren()
{
foreach (var value in Cache.ValueCache.Values)
{
value.Invalidate();
}
}
~MoveLibrary()
{
Dispose();
}
}
}