82 lines
3.5 KiB
C#
82 lines
3.5 KiB
C#
using JetBrains.Annotations;
|
|
using PkmnLibSharp.FFI;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.StaticData;
|
|
|
|
namespace PkmnLibSharp.StaticData.Libraries
|
|
{
|
|
public class StaticData : ExternPointer<StaticData.CacheData>
|
|
{
|
|
public class CacheData
|
|
{
|
|
public LibrarySettings? Settings { get; internal set; }
|
|
public SpeciesLibrary? SpeciesLibrary { get; internal set; }
|
|
public MoveLibrary? MoveLibrary { get; internal set; }
|
|
public ItemLibrary? ItemLibrary { get; internal set; }
|
|
public GrowthRateLibrary? GrowthRateLibrary { get; internal set; }
|
|
public TypeLibrary? TypeLibrary { get; internal set; }
|
|
public NatureLibrary? NatureLibrary { get; internal set; }
|
|
public AbilityLibrary? AbilityLibrary { get; internal set; }
|
|
}
|
|
|
|
internal StaticData(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner){}
|
|
|
|
public StaticData(LibrarySettings settings, SpeciesLibrary speciesLibrary, MoveLibrary moveLibrary,
|
|
ItemLibrary itemLibrary, GrowthRateLibrary growthRateLibrary, TypeLibrary typeLibrary,
|
|
NatureLibrary natureLibrary, AbilityLibrary abilityLibrary) : base(
|
|
Interface.static_data_new(settings.TakeOwnershipAndInvalidate(),
|
|
speciesLibrary.TakeOwnershipAndInvalidate(), moveLibrary.TakeOwnershipAndInvalidate(),
|
|
itemLibrary.TakeOwnershipAndInvalidate(), growthRateLibrary.TakeOwnershipAndInvalidate(),
|
|
typeLibrary.TakeOwnershipAndInvalidate(), natureLibrary.TakeOwnershipAndInvalidate(),
|
|
abilityLibrary.TakeOwnershipAndInvalidate()), true)
|
|
{
|
|
}
|
|
|
|
public LibrarySettings LibrarySettings =>
|
|
Cache.Settings ??= new LibrarySettings(Interface.static_data_settings(Ptr), false);
|
|
|
|
public SpeciesLibrary SpeciesLibrary =>
|
|
Cache.SpeciesLibrary ??= new SpeciesLibrary(Interface.static_data_species(Ptr), false);
|
|
|
|
public MoveLibrary MoveLibrary =>
|
|
Cache.MoveLibrary ??= new MoveLibrary(Interface.static_data_moves(Ptr), false);
|
|
|
|
public ItemLibrary ItemLibrary =>
|
|
Cache.ItemLibrary ??= new ItemLibrary(Interface.static_data_items(Ptr), false);
|
|
|
|
public GrowthRateLibrary GrowthRateLibrary =>
|
|
Cache.GrowthRateLibrary ??= new GrowthRateLibrary(Interface.static_data_growth_rates(Ptr), false);
|
|
|
|
public TypeLibrary TypeLibrary =>
|
|
Cache.TypeLibrary ??= new TypeLibrary(Interface.static_data_types(Ptr), false);
|
|
|
|
public NatureLibrary NatureLibrary =>
|
|
Cache.NatureLibrary ??= new NatureLibrary(Interface.static_data_natures(Ptr), false);
|
|
|
|
public AbilityLibrary AbilityLibrary =>
|
|
Cache.AbilityLibrary ??= new AbilityLibrary(Interface.static_data_abilities(Ptr), false);
|
|
|
|
protected override CacheData CreateCache() => new();
|
|
|
|
protected override void Destructor() => Interface.static_data_drop(Ptr);
|
|
|
|
public override void InvalidateChildren()
|
|
{
|
|
if (!HasCache)
|
|
return;
|
|
Cache.Settings?.Invalidate();
|
|
Cache.SpeciesLibrary?.Invalidate();
|
|
Cache.MoveLibrary?.Invalidate();
|
|
Cache.ItemLibrary?.Invalidate();
|
|
Cache.GrowthRateLibrary?.Invalidate();
|
|
Cache.TypeLibrary?.Invalidate();
|
|
Cache.NatureLibrary?.Invalidate();
|
|
Cache.AbilityLibrary?.Invalidate();
|
|
}
|
|
|
|
~StaticData()
|
|
{
|
|
Dispose();
|
|
}
|
|
}
|
|
} |