Move constructing from pointer to Constructor class to easily handle inheritance.
This commit is contained in:
@@ -8,7 +8,7 @@ using PkmnLibSharp.Utilities;
|
||||
|
||||
namespace PkmnLibSharp.Library.Evolution
|
||||
{
|
||||
public class EvolutionData : PointerWrapper
|
||||
public sealed class EvolutionData : PointerWrapper
|
||||
{
|
||||
private EvolutionData(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
@@ -89,7 +89,7 @@ namespace PkmnLibSharp.Library.Evolution
|
||||
var ptr = Pkmnlib.Generated.EvolutionData.GetNewSpecies(Ptr);
|
||||
if (TryResolvePointer(ptr, out _species))
|
||||
return _species!;
|
||||
_species = new Species(ptr);
|
||||
_species = Constructor.Active.ConstructSpecies(ptr)!;
|
||||
return _species;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,7 @@ namespace PkmnLibSharp.Library
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
Initialize(ptr);
|
||||
}
|
||||
|
||||
internal Forme(IntPtr parent) : base(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString()!;
|
||||
public float Height => SpeciesVariant.GetHeight(Ptr);
|
||||
public float Weight => SpeciesVariant.GetWeight(Ptr);
|
||||
@@ -126,7 +122,7 @@ namespace PkmnLibSharp.Library
|
||||
if (_moves != null) return _moves;
|
||||
var movesPtr = SpeciesVariant.GetLearnableAttacks(Ptr);
|
||||
if (!TryResolvePointer(movesPtr, out _moves))
|
||||
_moves = new LearnableMoves(movesPtr);
|
||||
_moves = Constructor.Active.ConstructLearnableMoves(movesPtr);
|
||||
|
||||
return _moves!;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,6 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
public class Species : PointerWrapper
|
||||
{
|
||||
internal Species(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
public Species(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate,
|
||||
byte captureRate, byte baseHappiness, IReadOnlyCollection<string> eggGroups, IReadOnlyCollection<string> tags)
|
||||
{
|
||||
@@ -95,7 +91,7 @@ namespace PkmnLibSharp.Library
|
||||
return true;
|
||||
}
|
||||
|
||||
forme = new Forme(ptr);
|
||||
forme = Constructor.Active.ConstructForme(ptr)!;
|
||||
_formeCache.Add(s, forme);
|
||||
return true;
|
||||
}
|
||||
@@ -114,7 +110,7 @@ namespace PkmnLibSharp.Library
|
||||
_formeCache.Add(s, f!);
|
||||
return f!;
|
||||
}
|
||||
forme = new Forme(ptr);
|
||||
forme = Constructor.Active.ConstructForme(ptr)!;
|
||||
_formeCache.Add(s, forme);
|
||||
return forme;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace PkmnLibSharp.Library
|
||||
_cache.Add(key, species!);
|
||||
return true;
|
||||
}
|
||||
species = new Species(ptr);
|
||||
species = Constructor.Active.ConstructSpecies(ptr)!;
|
||||
_cache.Add(key, species);
|
||||
return true;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace PkmnLibSharp.Library
|
||||
_cache.Add(key, s!);
|
||||
return s!;
|
||||
}
|
||||
species = new Species(ptr);
|
||||
species = Constructor.Active.ConstructSpecies(ptr)!;
|
||||
_cache.Add(key, species);
|
||||
return species;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
return s!;
|
||||
}
|
||||
s = new Species(ptr);
|
||||
s = Constructor.Active.ConstructSpecies(ptr)!;
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,9 @@ namespace PkmnLibSharp.Library
|
||||
{
|
||||
var ptr = Pkmnlib.Generated.SpeciesLibrary.FindPreEvolution(Ptr, species.Ptr);
|
||||
if (ptr == IntPtr.Zero) return null;
|
||||
return TryResolvePointer(ptr, out Species? prevoSpecies) ? prevoSpecies : new Species(ptr);
|
||||
return TryResolvePointer(ptr, out Species? prevoSpecies)
|
||||
? prevoSpecies
|
||||
: Constructor.Active.ConstructSpecies(ptr);
|
||||
}
|
||||
|
||||
public IEnumerable<Species> GetEnumerator()
|
||||
@@ -81,7 +83,7 @@ namespace PkmnLibSharp.Library
|
||||
Creaturelib.Generated.SpeciesLibrary.GetAtIndex(Ptr, i, ref ptr).Assert();
|
||||
if (TryResolvePointer(ptr, out Species? species))
|
||||
yield return species!;
|
||||
yield return new Species(ptr);
|
||||
yield return Constructor.Active.ConstructSpecies(ptr)!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user