Skip to content

Commit

Permalink
Merge pull request #85 from anno-mods/devel/mash
Browse files Browse the repository at this point in the history
merge 0.6 changes into main
  • Loading branch information
jakobharder authored Aug 27, 2023
2 parents a21d941 + 2cf86c1 commit 05b0ac5
Show file tree
Hide file tree
Showing 125 changed files with 3,930 additions and 2,630 deletions.
106 changes: 53 additions & 53 deletions AnnoMapEditor.Tests/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public static bool HasNoDuplicates<TSource, TResult>(this IEnumerable<TSource> t
}
}

public class PatchedAssetsFixture
{
public readonly Dictionary<MapType, XDocument> Data;
//public class PatchedAssetsFixture
//{
// public readonly Dictionary<MapType, XDocument> Data;

public PatchedAssetsFixture()
{
using Stream assetsXml = File.OpenRead("./TestData/assets.xml");
Data = new(MapType.All.Select(x =>
{
Stream patch = new MemoryStream(Encoding.Unicode.GetBytes(Mod.CreateAssetsModOps(Region.Moderate, MapType.Archipelago, "mods/[Map] test/test.a7t")));
return new KeyValuePair<MapType, XDocument>(x, XDocument.Load(XmlTest.Patch(assetsXml, patch)!));
}));
}
}
// public PatchedAssetsFixture()
// {
// using Stream assetsXml = File.OpenRead("./TestData/assets.xml");
// Data = new(MapType.All.Select(x =>
// {
// Stream patch = new MemoryStream(Encoding.Unicode.GetBytes(Mod.CreateAssetsModOps(Region.Moderate, MapType.Archipelago, "mods/[Map] test/test.a7t")));
// return new KeyValuePair<MapType, XDocument>(x, XDocument.Load(XmlTest.Patch(assetsXml, patch)!));
// }));
// }
//}

public class MapTypeData : IEnumerable<object[]>
{
Expand All @@ -43,51 +43,51 @@ public IEnumerator<object[]> GetEnumerator()
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
}

public class Assets : IClassFixture<PatchedAssetsFixture>
{
private readonly PatchedAssetsFixture _assetsFixture;
//public class Assets : IClassFixture<PatchedAssetsFixture>
//{
// private readonly PatchedAssetsFixture _assetsFixture;


public Assets(PatchedAssetsFixture fixture)
{
_assetsFixture = fixture;
}
// public Assets(PatchedAssetsFixture fixture)
// {
// _assetsFixture = fixture;
// }


[Theory]
[ClassData(typeof(MapTypeData))]
public void NotEmpty(MapType mapType)
{
var xml = _assetsFixture.Data[mapType];
var assets = xml.Descendants("Asset");
Assert.NotEmpty(assets);
}
// [Theory]
// [ClassData(typeof(MapTypeData))]
// public void NotEmpty(MapType mapType)
// {
// var xml = _assetsFixture.Data[mapType];
// var assets = xml.Descendants("Asset");
// Assert.NotEmpty(assets);
// }

[Theory]
[ClassData(typeof(MapTypeData))]
public void IsPatched(MapType mapType)
{
var xml = _assetsFixture.Data[mapType];
var assets = xml.Descendants("Asset");
Assert.NotEmpty(assets.Where(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename")?.StartsWith("mods/[Map]") ?? false));
}
// [Theory]
// [ClassData(typeof(MapTypeData))]
// public void IsPatched(MapType mapType)
// {
// var xml = _assetsFixture.Data[mapType];
// var assets = xml.Descendants("Asset");
// Assert.NotEmpty(assets.Where(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename")?.StartsWith("mods/[Map]") ?? false));
// }

[Theory]
[ClassData(typeof(MapTypeData))]
public void NoDuplicateName(MapType mapType)
{
var xml = _assetsFixture.Data[mapType];
var assets = xml.Descendants("Asset");
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/Standard/Name") ?? ""));
}
// [Theory]
// [ClassData(typeof(MapTypeData))]
// public void NoDuplicateName(MapType mapType)
// {
// var xml = _assetsFixture.Data[mapType];
// var assets = xml.Descendants("Asset");
// Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/Standard/Name") ?? ""));
// }

[Theory]
[ClassData(typeof(MapTypeData))]
public void NoDuplicateTemplateFilename(MapType mapType)
{
var xml = _assetsFixture.Data[mapType];
var assets = xml.Descendants("Asset");
Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename") ?? ""));
}
}
// [Theory]
// [ClassData(typeof(MapTypeData))]
// public void NoDuplicateTemplateFilename(MapType mapType)
// {
// var xml = _assetsFixture.Data[mapType];
// var assets = xml.Descendants("Asset");
// Assert.True(assets.HasNoDuplicates(x => x.GetValueFromPath("Values/MapTemplate/TemplateFilename") ?? ""));
// }
//}
}
86 changes: 45 additions & 41 deletions AnnoMapEditor.Tests/RoundTrip.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AnnoMapEditor.MapTemplates.Enums;
using AnnoMapEditor.MapTemplates.Models;
using AnnoMapEditor.MapTemplates.Serializing;
using AnnoMapEditor.Tests.Utils;
Expand All @@ -7,46 +8,49 @@ namespace AnnoMapEditor.Tests
{
public class RoundTrip
{
[TheoryWithGameFiles]
[InlineData("./TestData/moderate_c_01.xml")]
[InlineData("./TestData/campaign_chapter03_colony01.xml")]
[InlineData("./TestData/moderate_islandarc_ss_01.xml")]
[InlineData("./TestData/colony02_01.xml")]
[InlineData("./TestData/scenario_02_colony_01.xml")]
public async Task XmlToA7tinfoToXml(string filePath)
{
await Settings.Instance.AwaitLoadingAsync();

using Stream inputXml = File.OpenRead(filePath);
Session? session = await Session.FromXmlAsync(inputXml, filePath);

Assert.NotNull(session);

var export = session!.ToTemplate();
Assert.NotNull(export);

using (Stream a7tinfo = new MemoryStream())
{
await Serializer.WriteAsync(export!, a7tinfo);

a7tinfo.Position = 0;
session = await Session.FromA7tinfoAsync(a7tinfo, filePath);
Assert.NotNull(session);
}

var template = session!.ToTemplate();
Assert.NotNull(template);

using (MemoryStream outStream = new MemoryStream())
{
await Serializer.WriteToXmlAsync(template!, outStream);

//Uncomment for debugging:
//string content = System.Text.Encoding.UTF8.GetString(outStream.ToArray());
//outStream.Seek(0, SeekOrigin.Begin);

Assert.True(StreamComparer.AreEqual(inputXml, outStream));
}
}
//[TheoryWithGameFiles]
//[InlineData("./TestData/moderate_c_01.xml")]
//[InlineData("./TestData/campaign_chapter03_colony01.xml")]
//[InlineData("./TestData/moderate_islandarc_ss_01.xml")]
//[InlineData("./TestData/colony02_01.xml")]
//[InlineData("./TestData/scenario_02_colony_01.xml")]
//public async Task XmlToA7tinfoToXml(string filePath)
//{
// await Settings.Instance.AwaitLoadingAsync();

// using Stream inputXml = File.OpenRead(filePath);
// Region region = Region.DetectFromPath(filePath);

// MapTemplateReader mapTemplateReader = new();
// MapTemplate? mapTemplate = await mapTemplateReader.FromXmlStreamAsync(region, inputXml);

// Assert.NotNull(mapTemplate);

// var export = mapTemplate!.ToTemplateDocument();
// Assert.NotNull(export);

// using (Stream a7tinfo = new MemoryStream())
// {
// await FileDBSerializer.WriteAsync(export!, a7tinfo);

// a7tinfo.Position = 0;
// mapTemplate = await mapTemplateReader.FromBinaryStreamAsync(region, a7tinfo);
// Assert.NotNull(mapTemplate);
// }

// var template = mapTemplate!.ToTemplateDocument();
// Assert.NotNull(template);

// using (MemoryStream outStream = new MemoryStream())
// {
// await FileDBSerializer.WriteToXmlAsync(template!, outStream);

// //Uncomment for debugging:
// //string content = System.Text.Encoding.UTF8.GetString(outStream.ToArray());
// //outStream.Seek(0, SeekOrigin.Begin);

// Assert.True(StreamComparer.AreEqual(inputXml, outStream));
// }
//}
}
}
38 changes: 19 additions & 19 deletions AnnoMapEditor.Tests/Utils/TheoryWithGameFilesAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
namespace AnnoMapEditor.Tests.Utils
{
internal class TheoryWithGameFilesAttribute : TheoryAttribute
{
/// <summary>
/// This Theory will be skipped if the game files are not automatically found by the App Settings.
/// </summary>
public TheoryWithGameFilesAttribute()
{
//Use a timer to show us how long we had to wait until we knew that we weren't gonna run this theory :D
System.Diagnostics.Stopwatch waitTimer = new ();
waitTimer.Start();
Utilities.Settings.Instance.WaitForLoadingBlocking();
waitTimer.Stop();
//internal class TheoryWithGameFilesAttribute : TheoryAttribute
//{
// /// <summary>
// /// This Theory will be skipped if the game files are not automatically found by the App Settings.
// /// </summary>
// public TheoryWithGameFilesAttribute()
// {
// //Use a timer to show us how long we had to wait until we knew that we weren't gonna run this theory :D
// System.Diagnostics.Stopwatch waitTimer = new ();
// waitTimer.Start();
// Utilities.Settings.Instance.WaitForLoadingBlocking();
// waitTimer.Stop();

if (!Utilities.Settings.Instance.IsValidDataPath)
{
Skip = "The curring test environment has not detected the game files required for this unit test. " +
$"Waited {waitTimer.ElapsedMilliseconds}ms for this information...";
}
}
}
// if (!Utilities.Settings.Instance.IsValidGamePath)
// {
// Skip = "The curring test environment has not detected the game files required for this unit test. " +
// $"Waited {waitTimer.ElapsedMilliseconds}ms for this information...";
// }
// }
//}
}
2 changes: 1 addition & 1 deletion AnnoMapEditor/AnnoMapEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="UI\Controls\SessionProperties.xaml">
<Page Update="UI\Controls\MapTemplateProperties.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
30 changes: 30 additions & 0 deletions AnnoMapEditor/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="AnnoMapEditor.UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<AnnoMapEditor.UserSettings>
<setting name="GamePath" serializeAs="String">
<value />
</setting>
<setting name="DataPath" serializeAs="String">
<value />
</setting>
<setting name="ModsPath" serializeAs="String">
<value />
</setting>
<setting name="EnableExpertMode" serializeAs="String">
<value>False</value>
</setting>
<setting name="AssetsHash" serializeAs="String">
<value />
</setting>
<setting name="Xpath" serializeAs="String">
<value />
</setting>
</AnnoMapEditor.UserSettings>
</userSettings>
</configuration>
2 changes: 1 addition & 1 deletion AnnoMapEditor/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AnnoMapEditor"
StartupUri="UI/Windows/Main/MainWindow.xaml">
StartupUri="UI/Windows/Start/StartWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="UI/Resources/Styles/Colors.xaml" />
</Application.Resources>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace AnnoMapEditor.DataArchives.Assets.Deserialization
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class AssetTemplateAttribute : Attribute
{
public string[] TemplateNames { get; init; }


public AssetTemplateAttribute(params string[] templateNames)
{
TemplateNames = templateNames;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;

namespace AnnoMapEditor.DataArchives.Assets.Attributes
namespace AnnoMapEditor.DataArchives.Assets.Deserialization
{
[AttributeUsage(AttributeTargets.Property)]
public class AssetReferenceAttribute : Attribute
public class GuidReferenceAttribute : Attribute
{
public string GuidPropertyName { get; init; }


public AssetReferenceAttribute(string guidPropertyName)
public GuidReferenceAttribute(string guidPropertyName)
{
GuidPropertyName = guidPropertyName;
}
Expand Down
Loading

0 comments on commit 05b0ac5

Please sign in to comment.