forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UX] Pasting into X textbox will split coords into textboxes
- Loading branch information
Showing
13 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using NUnit.Framework; | ||
using WDE.Common.Utils; | ||
|
||
namespace WDE.Common.Test.Utils | ||
{ | ||
public class CoordsParserTests | ||
{ | ||
private static float? O => null; | ||
|
||
[Test] | ||
public void TestSpaceXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1 2 3")); | ||
Assert.AreEqual((1.5f, 2.5f, 3.5f, O), CoordsParser.ExtractCoords("1.5 2.5 3.5")); | ||
Assert.AreEqual((-1.5f, -2.5f, -3.5f, O), CoordsParser.ExtractCoords("-1.5 -2.5 -3.5")); | ||
} | ||
|
||
[Test] | ||
public void TestCommaXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1, 2, 3")); | ||
} | ||
|
||
[Test] | ||
public void TestSemicolonXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("1; 2; 3")); | ||
} | ||
|
||
[Test] | ||
public void TestLettersXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("X 1 Y 2 Z 3")); | ||
} | ||
|
||
[Test] | ||
public void TestLettersXyzo() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("X 1 Y 2 Z 3 O 4")); | ||
} | ||
|
||
[Test] | ||
public void TestLettersColonXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, O), CoordsParser.ExtractCoords("X: 1 Y: 2 Z: 3")); | ||
} | ||
|
||
[Test] | ||
public void TestLettersColonXyzo() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("X: 1 Y: 2 Z: 3 O: 4")); | ||
} | ||
|
||
[Test] | ||
public void TestMixedXyz() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("1 2, 3; 4")); | ||
} | ||
|
||
[Test] | ||
public void TestRandomPrefix() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("[1] position: 1, 2, 3, 4")); | ||
} | ||
|
||
[Test] | ||
public void TestRandomSuffix() | ||
{ | ||
Assert.AreEqual((1f, 2f, 3f, 4f), CoordsParser.ExtractCoords("1, 2, 3, 4[random]")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<Configurations>Debug;Release</Configurations> | ||
<Platforms>AnyCPU</Platforms> | ||
<Nullable>enable</Nullable> | ||
<WarningsAsErrors>nullable</WarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NSubstitute" Version="4.2.2" /> | ||
<PackageReference Include="NUnit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\WoWDatabaseEditor.Common\WDE.Common\WDE.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace WDE.Common.Utils | ||
{ | ||
public class CoordsParser | ||
{ | ||
private static Regex waypointRegex = new Regex(@"(-?\d+(?:\.\d+)?)[ ,;Yy:]{1,5}(-?\d+(?:\.\d+)?)[ ,;Zz:]{1,5}(-?\d+(?:\.\d+)?)(?:[ ,;Oo:]{1,5}(-?\d+(?:\.\d+)?))?"); | ||
|
||
public static (float x, float y, float z, float? o)? ExtractCoords(string line) | ||
{ | ||
var match = waypointRegex.Match(line); | ||
if (match.Success && | ||
float.TryParse(match.Groups[1].Value, out var x) && | ||
float.TryParse(match.Groups[2].Value, out var y) && | ||
float.TryParse(match.Groups[3].Value, out var z)) | ||
{ | ||
float? o = null; | ||
if (match.Groups.Count == 5 && | ||
float.TryParse(match.Groups[4].Value, out var o_)) | ||
o = o_; | ||
return (x, y, z, o); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters