Skip to content

Commit

Permalink
Merge pull request #10 from PoESkillTree/passive-skill-tree
Browse files Browse the repository at this point in the history
Passive Skill Tree Support
  • Loading branch information
brather1ng authored Mar 16, 2020
2 parents c2f1708 + 61b002f commit 822e067
Show file tree
Hide file tree
Showing 35 changed files with 1,690 additions and 29 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using PoESkillTree.Engine.GameModel.PassiveTree.Base;

namespace PoESkillTree.Engine.GameModel.PassiveTree
{
[TestFixture]
public class PassiveTreeDeserializationTest
{
[TestCase("skilltree_3.10.0.new.min.json")]
[TestCase("skilltree_3.10.0.old.min.json")]
[TestCase("skilltree_3.8.0.min.json")]
public void JsonPassiveTree_Deserialization_Serialization_Deserialization(string fileName)
{
var orignalJson = TestUtils.ReadDataFile(fileName);
Assert.IsNotEmpty(orignalJson);

var deserialized1 = JsonConvert.DeserializeObject<JsonPassiveTree>(orignalJson);
var serialized1 = JsonConvert.SerializeObject(deserialized1);
Assert.IsNotEmpty(serialized1);

var deserialized2 = JsonConvert.DeserializeObject<JsonPassiveTree>(serialized1);
var serialized2 = JsonConvert.SerializeObject(deserialized2);
Assert.IsNotEmpty(serialized2);

serialized1.Should().BeEquivalentTo(serialized2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>PoESkillTree.Engine.GameModel</RootNamespace>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8</LangVersion>
<AssemblyTitle>PoESkillTree.Engine.GameModel.IntegrationTests</AssemblyTitle>
<Product>PoESkillTree.Engine.GameModel.IntegrationTests</Product>
<Copyright>Copyright © 2018</Copyright>
<IsPackable>False</IsPackable>
<Nullable>enable</Nullable>
<WarningsAsErrors>8600;8601;8602;8603;8604;8619;8620</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="morelinq" Version="3.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup>
<ItemGroup>
<None Include="Data\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PoESkillTree.Engine.GameModel\PoESkillTree.Engine.GameModel.csproj" />
<ProjectReference Include="..\PoESkillTree.Engine.Utils\PoESkillTree.Engine.Utils.csproj" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions PoESkillTree.Engine.GameModel.IntegrationTests/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.IO;
using NUnit.Framework;

namespace PoESkillTree.Engine.GameModel
{
public static class TestUtils
{
public static string ReadDataFile(string fileName)
=> File.ReadAllText(GetDataFilePath(fileName));

public static string GetDataFilePath(string filename)
=> TestContext.CurrentContext.TestDirectory + "/Data/" + filename;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;

namespace PoESkillTree.Engine.GameModel.PassiveTree.Base
{
public class JsonPassiveNodeGroupTest
{
[TestCase(0, 0, 0.3835f)]
[TestCase(0, 1, 0.3835f)]
[TestCase(1, 0, 0.3835f)]
[TestCase(1, 1, 0.3835f)]
public void JsonPassiveNodeGroup_Position(float x, float y, float zoomLevel)
{
var group = new JsonPassiveNodeGroup()
{
OriginalX = x,
OriginalY = y,
ZoomLevel = zoomLevel,
};

Assert.AreEqual(x * zoomLevel, group.Position.X);
Assert.AreEqual(y * zoomLevel, group.Position.Y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using NUnit.Framework;
using System;

namespace PoESkillTree.Engine.GameModel.PassiveTree.Base
{
public class JsonPassiveNodeTest
{
[TestCase(CharacterClass.Scion)]
[TestCase(CharacterClass.Marauder)]
[TestCase(CharacterClass.Ranger)]
[TestCase(CharacterClass.Witch)]
[TestCase(CharacterClass.Duelist)]
[TestCase(CharacterClass.Templar)]
[TestCase(CharacterClass.Shadow)]
[TestCase(null)]
public void JsonPassiveNode_StartingCharacterClass(CharacterClass? characterClass)
{
var node = new JsonPassiveNode()
{
StartingCharacterClass = characterClass
};

Assert.AreEqual(characterClass.HasValue, node.IsRootNode);
Assert.AreEqual(characterClass, node.StartingCharacterClass);
}

[TestCase("", ExpectedResult = false)]
[TestCase("testing", ExpectedResult = true)]
public bool JsonPassiveNode_IsAscendancyNode(string ascendancyName)
{
var node = new JsonPassiveNode
{
AscendancyName = ascendancyName
};

return node.IsAscendancyNode;
}

[TestCase(PassiveNodeType.Keystone, ExpectedResult = PassiveNodeType.Keystone)]
[TestCase(PassiveNodeType.Mastery, ExpectedResult = PassiveNodeType.Mastery)]
[TestCase(PassiveNodeType.Notable, ExpectedResult = PassiveNodeType.Notable)]
[TestCase(PassiveNodeType.JewelSocket, ExpectedResult = PassiveNodeType.JewelSocket)]
[TestCase(PassiveNodeType.Small, ExpectedResult = PassiveNodeType.Small)]
[TestCase(PassiveNodeType.Keystone | PassiveNodeType.Mastery | PassiveNodeType.Notable | PassiveNodeType.JewelSocket | PassiveNodeType.Small, ExpectedResult = PassiveNodeType.Small)]
[TestCase(42, ExpectedResult = PassiveNodeType.Small)]
public PassiveNodeType JsonPassiveNode_PassiveNodeType(PassiveNodeType passiveNodeType)
{
var node = new JsonPassiveNode
{
IsKeystone = passiveNodeType == PassiveNodeType.Keystone,
IsMastery = passiveNodeType == PassiveNodeType.Mastery,
IsNotable = passiveNodeType == PassiveNodeType.Notable,
IsJewelSocket = passiveNodeType == PassiveNodeType.JewelSocket,
};

return node.PassiveNodeType;
}

[TestCase(0, new[] { 1f })]
[TestCase(1, new[] { 1f, 2f })]
public void JsonPassiveNode_Arc(int skillsPerOrbitIndex, float[] skillsPerOrbit)
{
var node = new JsonPassiveNode
{
SkillsPerOrbitIndex = skillsPerOrbitIndex,
SkillsPerOrbit = skillsPerOrbit,
};

Assert.AreEqual(2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex], node.Arc);
}

[TestCase(0, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(0, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(500, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(500, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 0, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
public void JsonPassiveNode_Position(float x, float y, float zoomLevel, int orbitRadiiIndex, float[] orbitRadii, int skillsPerOrbitIndex, float[] skillsPerOrbit)
{
var group = new JsonPassiveNodeGroup
{
OriginalX = x,
OriginalY = y,
ZoomLevel = zoomLevel,
};

var node = new JsonPassiveNode
{
PassiveNodeGroup = group,
OrbitRadiiIndex = orbitRadiiIndex,
OrbitRadii = orbitRadii,
SkillsPerOrbitIndex = skillsPerOrbitIndex,
SkillsPerOrbit = skillsPerOrbit,
ZoomLevel = zoomLevel,
};

Assert.AreEqual(group.Position.X - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Sin(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.X);
Assert.AreEqual(group.Position.Y - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Cos(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.Y);
}

[TestCase(0, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(0, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(500, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(500, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 0, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
public void JsonPassiveNode_Convert(float _x, float _y, float zoomLevel, int orbitRadiiIndex, float[] orbitRadii, int skillsPerOrbitIndex, float[] skillsPerOrbit)
{
var group = new JsonPassiveNodeGroup
{
OriginalX = _x,
OriginalY = _y,
ZoomLevel = zoomLevel,
};

var node = new JsonPassiveNode
{
PassiveNodeGroup = group,
OrbitRadiiIndex = orbitRadiiIndex,
OrbitRadii = orbitRadii,
SkillsPerOrbitIndex = skillsPerOrbitIndex,
SkillsPerOrbit = skillsPerOrbit,
ZoomLevel = zoomLevel,
};

var nodeDefinition = PassiveNodeDefinition.Convert(node);
var nodePosition = node.PositionAtZoomLevel(1f);
Assert.AreEqual(nodePosition.X, nodeDefinition.Position.X);
Assert.AreEqual(nodePosition.Y, nodeDefinition.Position.Y);
}

[TestCase(0, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(0, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 0, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(1, 1, 0.3835f, 0, new[] { 0f }, 0, new[] { 1f })]
[TestCase(500, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(500, 500, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 1, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
[TestCase(250, 250, 0.3835f, 0, new[] { 0f, 82f }, 1, new[] { 1f, 2f })]
public void JsonPassiveNode_ClearPosition(float x, float y, float zoomLevel, int orbitRadiiIndex, float[] orbitRadii, int skillsPerOrbitIndex, float[] skillsPerOrbit)
{
var group = new JsonPassiveNodeGroup
{
OriginalX = x,
OriginalY = y,
ZoomLevel = zoomLevel,
};

var node = new JsonPassiveNode
{
PassiveNodeGroup = group,
OrbitRadiiIndex = orbitRadiiIndex,
OrbitRadii = orbitRadii,
SkillsPerOrbitIndex = skillsPerOrbitIndex,
SkillsPerOrbit = skillsPerOrbit,
ZoomLevel = zoomLevel,
};

Assert.AreEqual(group.Position.X - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Sin(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.X);
Assert.AreEqual(group.Position.Y - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Cos(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.Y);

var newGroup = new JsonPassiveNodeGroup
{
OriginalX = x * 10,
OriginalY = y * 10,
ZoomLevel = zoomLevel,
};

node.PassiveNodeGroup = newGroup;
node.ClearPositionCache();

Assert.AreEqual(newGroup.Position.X - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Sin(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.X);
Assert.AreEqual(newGroup.Position.Y - orbitRadii[orbitRadiiIndex] * zoomLevel * (float)Math.Cos(-2 * Math.PI * skillsPerOrbitIndex / skillsPerOrbit[skillsPerOrbitIndex]), node.Position.Y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Newtonsoft.Json;
using NUnit.Framework;
using System.Drawing;

namespace PoESkillTree.Engine.GameModel.PassiveTree.Base
{
public class JsonPassiveTreeAscendancyClassTest
{
[TestCase(25f, 25f, 50f, 50f)]
[TestCase(0.25f, 0.50f, 150f, 50f)]
[TestCase(0.50f, 0.25f, 100f, 50f)]
public void JsonAscendancyClassOption_FlavourTextBounds(float x, float y, float width, float height)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextRect\": {{ \"x\": {x},\"y\": {y},\"width\": {width},\"height\": {height} }}}}");

Assert.AreEqual(x, ascendancy.FlavourTextBounds.X);
Assert.AreEqual(y, ascendancy.FlavourTextBounds.Y);
Assert.AreEqual(width, ascendancy.FlavourTextBounds.Width);
Assert.AreEqual(height, ascendancy.FlavourTextBounds.Height);
}

[TestCase(25f, 25f, 50f, 50f)]
[TestCase(0.25f, 0.50f, 150f, 50f)]
[TestCase(0.50f, 0.25f, 100f, 50f)]
public void JsonAscendancyClassOption_FlavourTextBounds_Old(float x, float y, float width, float height)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextRect\": \"{x},{y},{width},{height}\" }}");

Assert.AreEqual(x, ascendancy.FlavourTextBounds.X);
Assert.AreEqual(y, ascendancy.FlavourTextBounds.Y);
Assert.AreEqual(width, ascendancy.FlavourTextBounds.Width);
Assert.AreEqual(height, ascendancy.FlavourTextBounds.Height);
}

[Test]
public void JsonAscendancyClassOption_FlavourTextBounds_Empty()
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{ \"flavourTextRect\": {{ }} }}");

Assert.AreEqual(RectangleF.Empty, ascendancy.FlavourTextBounds);
}

[TestCase("50,50,50,50,50")]
[TestCase("50,50,50")]
[TestCase("50,50")]
[TestCase("50")]
[TestCase("")]
public void JsonAscendancyClassOption_FlavourTextBounds_Empty_Old(string boundsString)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextRect\": \"{boundsString}\" }}");

Assert.AreEqual(RectangleF.Empty, ascendancy.FlavourTextBounds);
}

[TestCase("128,128,128")]
[TestCase("128128")]
[TestCase("128")]
public void JsonAscendancyClassOption_FlavourTextColour_IsNotEmpty(string colourString)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextColour\": \"{colourString}\" }}");

Assert.AreNotEqual(Color.Empty, ascendancy.FlavourTextColour);
}

[TestCase(128, 128, 128)]
[TestCase(128, 128, 128)]
[TestCase(128, 128, 128)]
public void JsonAscendancyClassOption_FlavourTextColour_Old(byte red, byte green, byte blue)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextColour\": \"{red},{green},{blue}\" }}");

Assert.IsNotNull(ascendancy.FlavourTextColour);
Assert.AreEqual(red, ascendancy.FlavourTextColour.R);
Assert.AreEqual(green, ascendancy.FlavourTextColour.G);
Assert.AreEqual(blue, ascendancy.FlavourTextColour.B);
}

[TestCase("128,128,128,128")]
[TestCase("128,128")]
[TestCase("")]
public void JsonAscendancyClassOption_FlavourTextColour_IsEmpty(string colourString)
{
var ascendancy = JsonConvert.DeserializeObject<JsonPassiveTreeAscendancyClass>($"{{\"flavourTextColour\": \"{colourString}\" }}");

Assert.AreEqual(Color.Empty, ascendancy.FlavourTextColour);
}
}
}
Loading

0 comments on commit 822e067

Please sign in to comment.