Rework constructors to remove the Create pattern.

This commit is contained in:
Deukhoofd 2020-08-08 13:57:54 +02:00
parent 1b025ea3cf
commit e0f4a38309
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
22 changed files with 148 additions and 147 deletions

View File

@ -11,11 +11,11 @@ namespace PkmnLibSharp.Battling
public LearnedMove(){}
internal LearnedMove(IntPtr ptr) : base(ptr){}
public static LearnedMove Create(MoveData move, byte maxUses, MoveLearnMethod learnMethod)
public LearnedMove(MoveData move, byte maxUses, MoveLearnMethod learnMethod)
{
var ptr = IntPtr.Zero;
LearnedAttack.Construct(ref ptr, move.Ptr, maxUses, (AttackLearnMethod) learnMethod).Assert();
return new LearnedMove(ptr);
Initialize(ptr);
}
public MoveData Move

View File

@ -81,14 +81,14 @@ namespace PkmnLibSharp.Battling
{
}
public static BattleLibrary Create(PokemonLibrary staticLibrary, StatCalculator statCalculator,
public BattleLibrary(PokemonLibrary staticLibrary, StatCalculator statCalculator,
DamageLibrary damageLibrary, ExperienceLibrary experienceLibrary, ScriptResolver scriptResolver,
MiscLibrary miscLibrary)
{
var ptr = IntPtr.Zero;
Pkmnlib.Generated.BattleLibrary.Construct(ref ptr, staticLibrary.Ptr, statCalculator.Ptr, damageLibrary.Ptr,
experienceLibrary.Ptr, scriptResolver.Ptr, miscLibrary.Ptr).Assert();
return new BattleLibrary(ptr);
Initialize(ptr);
}
protected override void DeletePtr()

View File

@ -143,7 +143,7 @@ namespace PkmnLibSharp.Battling
throw new Exception($"Move '{LearnedMoves[i].moveName}' was not found.");
}
moves[i] = LearnedMove.Create(move, move.BaseUsages, LearnedMoves[i].learnMethod);
moves[i] = new LearnedMove(move, move.BaseUsages, LearnedMoves[i].learnMethod);
}
if (string.IsNullOrEmpty(Nature))

View File

@ -112,7 +112,7 @@ namespace PkmnLibSharp.Library
return Types[index];
}
public static Forme Create(string name, float height, float weight, uint baseExperience, byte[] types,
public Forme(string name, float height, float weight, uint baseExperience, byte[] types,
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities,
LearnableMoves moves)
@ -130,7 +130,7 @@ namespace PkmnLibSharp.Library
Marshal.FreeHGlobal(intPtr);
foreach (var intPtr in hiddenAbilitiesConverted)
Marshal.FreeHGlobal(intPtr);
return f;
Initialize(ptr);
}
public byte GetRandomAbility(Random rand)

View File

@ -13,7 +13,7 @@ namespace PkmnLibSharp.Library.GrowthRates
{
}
public static ExternGrowthRate Create(CalculateLevelDelegate levelFunc,
public ExternGrowthRate(CalculateLevelDelegate levelFunc,
CalculateExperienceDelegate experienceFunc)
{
var ptr = IntPtr.Zero;
@ -21,7 +21,7 @@ namespace PkmnLibSharp.Library.GrowthRates
Marshal.GetFunctionPointerForDelegate(levelFunc),
Marshal.GetFunctionPointerForDelegate(experienceFunc)
);
return new ExternGrowthRate(ptr);
Initialize(ptr);
}
protected override void DeletePtr()

View File

@ -8,6 +8,8 @@ namespace PkmnLibSharp.Library.GrowthRates
internal GrowthRate(IntPtr ptr) : base(ptr)
{
}
protected GrowthRate(){}
public byte CalculateLevel(uint experience)
{

View File

@ -26,14 +26,14 @@ namespace PkmnLibSharp.Library.Items
return Creaturelib.Generated.Item.HasFlag(Ptr, s.ToPtr()) == MarshalHelper.True;
}
public static Item Create(string name, ItemCategory category, BattleItemCategory battleCategory,
public Item (string name, ItemCategory category, BattleItemCategory battleCategory,
int price,
string[] flags, byte flingPower)
{
var convertedFlags = flags.Select(x => x.ToPtr()).ToArray().ArrayPtr();
var p = Pkmnlib.Generated.Item.Construct(name.ToPtr(), (Pkmnlib.ItemCategory) category,
(Pkmnlib.BattleItemCategory) battleCategory, price, convertedFlags, (ulong) flags.Length, flingPower);
return new Item(p);
Initialize(p);
}
protected override void DeletePtr()

View File

@ -11,11 +11,11 @@ namespace PkmnLibSharp.Library
{
}
public static LearnableMoves Create(byte maxLevel)
public LearnableMoves(byte maxLevel)
{
var ptr = IntPtr.Zero;
LearnableAttacks.Construct(ref ptr, maxLevel);
return new LearnableMoves(ptr);
Initialize(ptr);
}
public void AddLevelAttack(byte level, MoveData move)

View File

@ -34,7 +34,7 @@ namespace PkmnLibSharp.Library.Moves
return AttackData.HasFlag(Ptr, s.ToPtr()) == 1;
}
public static MoveData Create(string name, byte type, MoveCategory category, byte power, byte accuracy,
public MoveData(string name, byte type, MoveCategory category, byte power, byte accuracy,
byte baseUsage, MoveTarget target, sbyte priority, float effectChance, string effectName,
EffectParameter[] parameters, string[] flags)
{
@ -45,7 +45,7 @@ namespace PkmnLibSharp.Library.Moves
AttackData.Construct(ref ptr, name.ToPtr(), type, (AttackCategory) category, power, accuracy, baseUsage,
(AttackTarget) target, priority, effectChance, effectName.ToPtr(), pars,
(ulong) parameters.Length, f, (ulong) flags.Length).Assert();
return new MoveData(ptr);
Initialize(ptr);
}
protected override void DeletePtr()

View File

@ -63,11 +63,11 @@ namespace PkmnLibSharp.Library.Moves
return move;
}
public static MoveLibrary Create(ulong defaultCapacity)
public MoveLibrary(ulong defaultCapacity)
{
var ptr = IntPtr.Zero;
AttackLibrary.Construct(ref ptr, defaultCapacity).Assert();
return new MoveLibrary(ptr);
Initialize(ptr);
}
protected internal override void MarkAsDeleted()

View File

@ -119,14 +119,14 @@ namespace PkmnLibSharp.Library
{
}
public static PokemonLibrary Create(LibrarySettings settings, SpeciesLibrary species, MoveLibrary moves,
public PokemonLibrary(LibrarySettings settings, SpeciesLibrary species, MoveLibrary moves,
ItemLibrary items,
GrowthRateLibrary growthRates, TypeLibrary types, NatureLibrary natures)
{
var ptr = IntPtr.Zero;
Pkmnlib.Generated.PokemonLibrary.Construct(ref ptr, settings.Ptr, species.Ptr, moves.Ptr, items.Ptr,
growthRates.Ptr, types.Ptr, natures.Ptr).Assert();
return new PokemonLibrary(ptr);
Initialize(ptr);
}
protected override void DeletePtr()

View File

@ -81,15 +81,14 @@ namespace PkmnLibSharp.Library
{
}
public static Species Create(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate,
public Species(ushort id, string name, Forme defaultForme, float genderRatio, string growthRate,
byte captureRate, byte baseHappiness)
{
var ptr = IntPtr.Zero;
PokemonSpecies.Construct(ref ptr, id, name.ToPtr(), defaultForme.Ptr, genderRatio,
growthRate.ToPtr(), captureRate, baseHappiness).Assert();
var s = new Species(ptr);
s._formes.Add("default", defaultForme);
return s;
_formes.Add("default", defaultForme);
Initialize(ptr);
}
protected internal override void MarkAsDeleted()

View File

@ -16,7 +16,7 @@ namespace PkmnLibSharpTests.Battling
{
if (_cache != null) return _cache;
_cache = BattleLibrary.Create(BuildStatic(), new StatCalculator(), new DamageLibrary(),
_cache = new BattleLibrary(BuildStatic(), new StatCalculator(), new DamageLibrary(),
new ExperienceLibrary(),
new AngelScriptResolver(), new MiscLibrary());
return _cache;
@ -26,22 +26,22 @@ namespace PkmnLibSharpTests.Battling
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
species.Insert("testSpecies", Species.Create(1, "testSpecies",
Forme.Create("default", 10f, 10f, 100, new byte[] {0, 1}, 100,
species.Insert("testSpecies", new Species(1, "testSpecies",
new Forme("default", 10f, 10f, 100, new byte[] {0, 1}, 100,
100, 100, 100, 100, 100, new[] {"testAbility", "testAbility2"},
new[] {"testHiddenAbility"}, LearnableMoves.Create(100)), 0.5f, "growthRate",
new[] {"testHiddenAbility"}, new LearnableMoves(100)), 0.5f, "growthRate",
20, 100));
var moves = MoveLibrary.Create(10);
moves.Insert("testMove", MoveData.Create("testMove", 0, MoveCategory.Physical, 100,
var moves = new MoveLibrary(10);
moves.Insert("testMove", new MoveData("testMove", 0, MoveCategory.Physical, 100,
100, 20, MoveTarget.Any, 0, 0f, "",
new EffectParameter[0], new string[0]));
moves.Insert("testMove2", MoveData.Create("testMove2", 0, MoveCategory.Physical, 100,
moves.Insert("testMove2", new MoveData("testMove2", 0, MoveCategory.Physical, 100,
100, 20, MoveTarget.Any, 0, 0f, "",
new EffectParameter[0], new string[0]));
var items = new ItemLibrary(10);
items.Insert("testItem", Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.None,
items.Insert("testItem", new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.None,
500, new string[] { }, 20));
var gr = new GrowthRateLibrary(10);
gr.AddGrowthRate("growthRate",
@ -52,7 +52,7 @@ namespace PkmnLibSharpTests.Battling
types.RegisterType("fighting");
var natures = new NatureLibrary(10);
natures.LoadNature("testNature", new Nature());
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
return lib;
}
}

View File

@ -8,16 +8,16 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ConstructDestruct()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
forme.Dispose();
}
[Test]
public void GetName()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual("foo", forme.Name);
forme.Dispose();
}
@ -25,8 +25,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetHeight()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(1f, forme.Height);
forme.Dispose();
}
@ -34,8 +34,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetWeight()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(2f, forme.Weight);
forme.Dispose();
}
@ -43,8 +43,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetBaseExperience()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(100, forme.BaseExperience);
forme.Dispose();
}
@ -52,13 +52,13 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetTypes()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(0, forme.GetPkmnType(0));
forme.Dispose();
forme = Forme.Create("foo", 1, 2, 100, new byte[] {0, 1}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
forme = new Forme("foo", 1, 2, 100, new byte[] {0, 1}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(0, forme.GetPkmnType(0));
Assert.AreEqual(1, forme.GetPkmnType(1));
forme.Dispose();
@ -67,8 +67,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetStats()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 20, 30, 40, 50, 60, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 20, 30, 40, 50, 60, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual(10, forme.BaseHealth);
Assert.AreEqual(20, forme.BaseAttack);
Assert.AreEqual(30, forme.BaseDefense);
@ -81,8 +81,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetAbilities()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual("foo", forme.Abilities[0]);
forme.Dispose();
}
@ -90,8 +90,8 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetHiddenAbilities()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
Assert.AreEqual("bar", forme.HiddenAbilities[0]);
forme.Dispose();
}

View File

@ -17,7 +17,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ExternGrowthRate()
{
var gr = PkmnLibSharp.Library.GrowthRates.ExternGrowthRate.Create(experience => (byte) (experience / 100),
var gr = new ExternGrowthRate(experience => (byte) (experience / 100),
level => (uint) (level * 100));
Assert.AreEqual(500, gr.CalculateExperience(5));
Assert.AreEqual(7, gr.CalculateLevel(750));

View File

@ -17,7 +17,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Insert()
{
var item = Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
var library = new ItemLibrary(100);
library.Insert("foobar", item);
@ -28,7 +28,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Delete()
{
var item = Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
var library = new ItemLibrary(100);
library.Insert("foobar", item);
@ -41,7 +41,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Get()
{
var item = Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
var library = new ItemLibrary(100);
library.Insert("foobar", item);
@ -58,7 +58,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void TryGet()
{
var item = Item.Create("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("testItem", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
var library = new ItemLibrary(100);
library.Insert("foobar", item);

View File

@ -9,14 +9,14 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ConstructDestruct()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
item.Dispose();
}
[Test]
public void GetName()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.AreEqual("foobar", item.Name);
item.Dispose();
@ -24,7 +24,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetCategory()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.AreEqual(ItemCategory.MiscItem, item.Category);
item.Dispose();
@ -32,7 +32,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetBattleCategory()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.AreEqual(BattleItemCategory.Healing, item.BattleCategory);
item.Dispose();
@ -40,7 +40,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetPrice()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.AreEqual(1000, item.Price);
item.Dispose();
@ -48,7 +48,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void HasFlag()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.True(item.HasFlag("testFlag"));
Assert.False(item.HasFlag("non-existing"));
@ -57,7 +57,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetFlingPower()
{
var item = Item.Create("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
var item = new Item("foobar", ItemCategory.MiscItem, BattleItemCategory.Healing, 1000,
new[] {"testFlag"}, 50);
Assert.AreEqual(50, item.FlingPower);
item.Dispose();

View File

@ -9,7 +9,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ConstructDestruct()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
move.Dispose();
}
@ -17,7 +17,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetName()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual("foobar", move.Name);
move.Dispose();
@ -26,7 +26,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetTypeProp()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(0, move.Type);
move.Dispose();
@ -35,7 +35,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetCategory()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(MoveCategory.Physical, move.Category);
move.Dispose();
@ -44,7 +44,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetBasePower()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(60, move.BasePower);
move.Dispose();
@ -53,7 +53,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetAccuracy()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(100, move.Accuracy);
move.Dispose();
@ -62,7 +62,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetBaseUsages()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(20, move.BaseUsages);
move.Dispose();
@ -71,7 +71,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetTarget()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(MoveTarget.Adjacent, move.Target);
move.Dispose();
@ -80,7 +80,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetPriority()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(1, move.Priority);
move.Dispose();
@ -89,7 +89,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetEffectChance()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "", new EffectParameter[0], new string[0]);
Assert.AreEqual(0.5f, move.SecondaryEffectChance);
move.Dispose();
@ -98,7 +98,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetEffectChanceName()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
Assert.AreEqual("test", move.SecondaryEffectName);
move.Dispose();
@ -107,11 +107,11 @@ namespace PkmnLibSharpTests.Library
[Test]
public void HasSecondaryEffect()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
Assert.True(move.HasSecondaryEffect);
move.Dispose();
move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "", new EffectParameter[0], new string[0]);
Assert.False(move.HasSecondaryEffect);
move.Dispose();
@ -121,7 +121,7 @@ namespace PkmnLibSharpTests.Library
[Test]
public void HasFlag()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new []{"flag1"});
Assert.True(move.HasFlag("flag1"));
Assert.False(move.HasFlag("flag2"));

View File

@ -10,16 +10,16 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ConstructDestruct()
{
var item = MoveLibrary.Create(100);
var item = new MoveLibrary(100);
item.Dispose();
}
[Test]
public void Insert()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
var library = MoveLibrary.Create(100);
var library = new MoveLibrary(100);
library.Insert("foobar", move);
Assert.AreEqual(1, library.Count);
library.Dispose();
@ -28,9 +28,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Delete()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
var library = MoveLibrary.Create(100);
var library = new MoveLibrary(100);
library.Insert("foobar", move);
Assert.AreEqual(1, library.Count);
library.Delete("foobar");
@ -41,9 +41,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Get()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
var library = MoveLibrary.Create(100);
var library = new MoveLibrary(100);
library.Insert("foobar", move);
Assert.AreEqual(1, library.Count);
var m = library.Get("foobar");
@ -58,9 +58,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void TryGet()
{
var move = MoveData.Create("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
var move = new MoveData("foobar", 0, MoveCategory.Physical, 60, 100, 20, MoveTarget.Adjacent, 1,
0.5f, "test", new EffectParameter[0], new string[0]);
var library = MoveLibrary.Create(100);
var library = new MoveLibrary(100);
library.Insert("foobar", move);
Assert.AreEqual(1, library.Count);
Assert.True(library.TryGet("foobar", out move));

View File

@ -13,13 +13,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
lib.Dispose();
}
@ -28,13 +28,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var s = lib.SpeciesLibrary;
Assert.AreEqual(species, s);
lib.Dispose();
@ -45,13 +45,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var s = lib.Settings;
Assert.AreEqual(settings, s);
lib.Dispose();
@ -62,13 +62,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var m = lib.MoveLibrary;
Assert.AreEqual(moves, m);
lib.Dispose();
@ -79,13 +79,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var i = lib.ItemLibrary;
Assert.AreEqual(items, i);
lib.Dispose();
@ -96,13 +96,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var g = lib.GrowthRateLibrary;
Assert.AreEqual(gr, g);
lib.Dispose();
@ -113,13 +113,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var t = lib.TypeLibrary;
Assert.AreEqual(types, t);
lib.Dispose();
@ -130,13 +130,13 @@ namespace PkmnLibSharpTests.Library
{
var settings = new LibrarySettings(100, 4, 4096);
var species = new SpeciesLibrary(10);
var moves = MoveLibrary.Create(10);
var moves = new MoveLibrary(10);
var items = new ItemLibrary(10);
var gr = new GrowthRateLibrary(10);
var types = new TypeLibrary(10);
var natures = new NatureLibrary(10);
var lib = PokemonLibrary.Create(settings, species, moves, items, gr, types, natures);
var lib = new PokemonLibrary(settings, species, moves, items, gr, types, natures);
var n = lib.NatureLibrary;
Assert.AreEqual(natures, n);
lib.Dispose();

View File

@ -16,9 +16,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Insert()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var library = new SpeciesLibrary(100);
library.Insert("foobar", species);
Assert.AreEqual(1, library.Count);
@ -28,9 +28,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Delete()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var library = new SpeciesLibrary(100);
library.Insert("foobar", species);
Assert.AreEqual(1, library.Count);
@ -42,9 +42,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void Get()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var library = new SpeciesLibrary(100);
library.Insert("foobar", species);
Assert.AreEqual(1, library.Count);
@ -60,9 +60,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void TryGet()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var library = new SpeciesLibrary(100);
library.Insert("foobar", species);
Assert.AreEqual(1, library.Count);

View File

@ -9,75 +9,75 @@ namespace PkmnLibSharpTests.Library
[Test]
public void ConstructDestruct()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(0, "testSpecies", forme, 0.5f, "exponential", 100, 80);
species.Dispose();
}
[Test]
public void GetId()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.AreEqual(10, species.Id);
species.Dispose();
}
[Test]
public void GetGenderRate()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.AreEqual(0.5f, species.GenderRate);
species.Dispose();
}
[Test]
public void GetCaptureRate()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.AreEqual(100, species.CaptureRate);
species.Dispose();
}
[Test]
public void GetName()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.AreEqual("testSpecies", species.Name);
species.Dispose();
}
[Test]
public void GetGrowthRate()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.AreEqual("exponential", species.GrowthRate);
species.Dispose();
}
[Test]
public void HasForme()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.True(species.HasForme("default"));
species.Dispose();
}
[Test]
public void SetForme()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.True(species.HasForme("default"));
forme = Forme.Create("bar", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
forme = new Forme("bar", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
species.SetForme("bar", forme);
Assert.True(species.HasForme("bar"));
species.Dispose();
@ -85,9 +85,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void GetForme()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var f = species.GetForme("default");
Assert.AreEqual(forme, f);
Assert.Throws<NativeException>(() =>
@ -99,9 +99,9 @@ namespace PkmnLibSharpTests.Library
[Test]
public void TrGetForme()
{
var forme = Forme.Create("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, LearnableMoves.Create(100));
var species = Species.Create(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
var forme = new Forme("foo", 1, 2, 100, new byte[] {0}, 10, 10, 10, 10, 10, 10, new[] {"foo"},
new[] {"bar"}, new LearnableMoves(100));
var species = new Species(10, "testSpecies", forme, 0.5f, "exponential", 100, 80);
Assert.True(species.TryGetForme("default", out var f));
Assert.AreEqual(forme, f);
Assert.False(species.TryGetForme("non-existing", out f));