Skip to content

Commit 20e1fba

Browse files
committed
feat: improve syntax and progress reporting
1 parent 81af4ca commit 20e1fba

76 files changed

Lines changed: 690 additions & 416 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Europa1400.Tools.Tests/Europa1400Test.cs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
using Europa1400.Tools.Pipeline.Converter;
44
using Europa1400.Tools.Pipeline.Decoder;
55
using Europa1400.Tools.Pipeline.Output;
6-
using Europa1400.Tools.Structs.Ageb;
7-
using Europa1400.Tools.Structs.Aobj;
8-
using Europa1400.Tools.Structs.Bgf;
9-
using Europa1400.Tools.Structs.Gfx;
10-
using Europa1400.Tools.Structs.Sbf;
116
using Xunit.Abstractions;
127

138
namespace Europa1400.Tools.Tests;
@@ -22,14 +17,14 @@ public async Task TestProgress()
2217
var progress = new Progress<PipelineProgress>(p =>
2318
{
2419
progressUpdates.Add(p);
25-
testOutputHelper.WriteLine($"[{p.CurrentStep}/{p.TotalSteps}] {p.Percent:P0} - {p.Message}");
20+
testOutputHelper.WriteLine(p.ToString());
2621
});
2722

2823
var pipeline = PipelineBuilder<DummyAsset>
2924
.Create()
30-
.DecodeWith<DummyDecoder, object>()
31-
.ConvertWith<DummyConverter, object, List<IFileExport>>()
32-
.WriteWith<DummyOutputHandler, List<IFileExport>>()
25+
.DecodeWith<DummyDecoder>()
26+
.ConvertWith<DummyConverter>()
27+
.Write()
3328
.Build();
3429

3530
await pipeline.ExecuteAsync(
@@ -38,80 +33,82 @@ await pipeline.ExecuteAsync(
3833
);
3934

4035
Assert.NotEmpty(progressUpdates);
41-
42-
var final = progressUpdates[^1];
43-
Assert.Equal(final.TotalSteps, final.CurrentStep);
44-
Assert.Equal(1.0, final.Percent, 2);
4536
}
4637

4738
[Fact(Skip = "This test does not work yet.")]
4839
public async Task TestMeshes()
4940
{
5041
await PipelineBuilder<BgfAsset>
5142
.Create()
52-
.DecodeWith<BgfDecoder, BgfStruct>()
43+
.DecodeWith<BgfDecoder>()
5344
.Build()
5445
.ExecuteAsync(GameAssets.OfType<BgfAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath));
5546
}
5647

5748
[Fact]
5849
public async Task TestSounds()
5950
{
60-
var outputPath = Path.Combine("output", "sounds");
51+
var outputPath = Path.Combine("output", "Sounds");
52+
var progress = new Progress<PipelineProgress>(p => testOutputHelper.WriteLine(p.ToString()));
6153

6254
await PipelineBuilder<SbfAsset>
6355
.Create()
64-
.DecodeWith<SbfDecoder, SbfStruct>()
65-
.ConvertWith<SbfConverter, SbfStruct, List<IFileExport>>()
66-
.WriteWith<FileExportOutputHandler, List<IFileExport>>(new OutputHandlerOptions { OutputRoot = outputPath })
56+
.DecodeWith<SbfDecoder>()
57+
.ConvertWith<SbfConverter>()
58+
.Write(new OutputHandlerOptions { OutputRoot = outputPath })
6759
.Build()
68-
.ExecuteAsync(GameAssets.OfType<SbfAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath));
60+
.ExecuteAsync(GameAssets.OfType<SbfAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath), progress);
6961

7062
Assert.True(Directory.GetFiles(outputPath, "*.wav", SearchOption.AllDirectories).Length > 0);
7163
}
7264

7365
[Fact]
7466
public async Task TestGraphics()
7567
{
76-
var outputPath = Path.Combine("output", "graphics");
68+
var outputPath = Path.Combine("output", "Graphics");
69+
var progress = new Progress<PipelineProgress>(p => testOutputHelper.WriteLine(p.ToString()));
7770

7871
await PipelineBuilder<GfxAsset>
7972
.Create()
80-
.DecodeWith<GfxDecoder, GfxStruct>()
81-
.ConvertWith<GfxConverter, GfxStruct, List<IFileExport>>()
82-
.WriteWith<FileExportOutputHandler, List<IFileExport>>(new OutputHandlerOptions { OutputRoot = outputPath })
73+
.DecodeWith<GfxDecoder>()
74+
.ConvertWith<GfxConverter>()
75+
.Write(new OutputHandlerOptions { OutputRoot = outputPath })
8376
.Build()
84-
.ExecuteAsync(GameAssets.OfType<GfxAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath));
77+
.ExecuteAsync(GameAssets.OfType<GfxAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath), progress);
8578

8679
Assert.True(Directory.GetFiles(outputPath, "*.png", SearchOption.AllDirectories).Length > 0);
8780
}
8881

8982
[Fact]
9083
public async Task TestAgeb()
9184
{
92-
var outputPath = Path.Combine("output", "ageb");
85+
var outputPath = Path.Combine("output");
86+
var progress = new Progress<PipelineProgress>(p => testOutputHelper.WriteLine(p.ToString()));
9387

9488
await PipelineBuilder<AgebAsset>
9589
.Create()
96-
.DecodeWith<AgebDecoder, AgebStruct>()
97-
.WriteWith<FileExportOutputHandler, List<IFileExport>>(new OutputHandlerOptions { OutputRoot = outputPath })
90+
.DecodeWith<AgebDecoder>()
91+
.Write(new OutputHandlerOptions { OutputRoot = outputPath })
9892
.Build()
99-
.ExecuteAsync(GameAssets.OfType<AgebAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath));
93+
.ExecuteAsync(GameAssets.OfType<AgebAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath),
94+
progress);
10095

10196
Assert.True(Directory.GetFiles(outputPath, "*.json", SearchOption.AllDirectories).Length > 0);
10297
}
10398

10499
[Fact]
105100
public async Task TestAobj()
106101
{
107-
var outputPath = Path.Combine("output", "aobj");
102+
var outputPath = Path.Combine("output");
103+
var progress = new Progress<PipelineProgress>(p => testOutputHelper.WriteLine(p.ToString()));
108104

109105
await PipelineBuilder<AobjAsset>
110106
.Create()
111-
.DecodeWith<AobjDecoder, AobjStruct>()
112-
.WriteWith<FileExportOutputHandler, List<IFileExport>>(new OutputHandlerOptions { OutputRoot = outputPath })
107+
.DecodeWith<AobjDecoder>()
108+
.Write(new OutputHandlerOptions { OutputRoot = outputPath })
113109
.Build()
114-
.ExecuteAsync(GameAssets.OfType<AobjAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath));
110+
.ExecuteAsync(GameAssets.OfType<AobjAsset>().FromGameInstallation(EnvVariables.GameDirectoryPath),
111+
progress);
115112

116113
Assert.True(Directory.GetFiles(outputPath, "*.json", SearchOption.AllDirectories).Length > 0);
117114
}

Europa1400.Tools/Pipeline/AssetDiscovererRegistry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static AssetDiscovererRegistry()
1919
Register(new DummyAssetDiscoverer());
2020
}
2121

22-
public static void Register<TAsset>(IAssetDiscoverer<TAsset> discoverer) where TAsset : IGameAsset
22+
public static void Register<TAsset>(IAssetDiscoverer<TAsset> discoverer) where TAsset : GameAsset
2323
{
2424
Discoverers[typeof(TAsset)] = discoverer;
2525
}
2626

27-
public static IAssetDiscoverer<TAsset> Get<TAsset>() where TAsset : IGameAsset
27+
public static IAssetDiscoverer<TAsset> Get<TAsset>() where TAsset : GameAsset
2828
{
2929
if (Discoverers.TryGetValue(typeof(TAsset), out var d))
3030
return (IAssetDiscoverer<TAsset>)d;

Europa1400.Tools/Pipeline/AssetSelection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
namespace Europa1400.Tools.Pipeline
66
{
7-
public class AssetSelection<TAsset> where TAsset : IGameAsset
7+
public class AssetSelection<TAsset> where TAsset : GameAsset
88
{
99
private readonly IEnumerable<TAsset> assets;
1010

1111
public AssetSelection(IEnumerable<TAsset> assets)
1212
{
1313
this.assets = assets;
1414
}
15-
15+
1616
public IReadOnlyList<TAsset> Assets => assets.ToList();
1717
}
1818
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace Europa1400.Tools.Pipeline.Assets
22
{
3-
public class AgebAsset : IGameAsset
3+
public class AgebAsset : GameAsset
44
{
5-
public string FilePath { get; set; }
5+
public AgebAsset(string filePath, string relativePath) : base(filePath, relativePath)
6+
{
7+
}
68
}
79
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace Europa1400.Tools.Pipeline.Assets
22
{
3-
public class AobjAsset : IGameAsset
3+
public class AobjAsset : GameAsset
44
{
5-
public string FilePath { get; set; }
5+
public AobjAsset(string filePath, string relativePath) : base(filePath, relativePath)
6+
{
7+
}
68
}
79
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
namespace Europa1400.Tools.Pipeline.Assets
22
{
3-
public class BafAsset : IGameAsset
3+
public class BafAsset : GameAsset
44
{
5-
public BafIniAsset? Descriptor { get; set; }
6-
public string FilePath { get; set; }
5+
public BafAsset(string filePath, string relativePath, BafIniAsset? bafIni) : base(filePath, relativePath)
6+
{
7+
BafIni = bafIni;
8+
}
9+
10+
public BafIniAsset? BafIni { get; set; }
711
}
812
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace Europa1400.Tools.Pipeline.Assets
22
{
3-
public class BafIniAsset : IGameAsset
3+
public class BafIniAsset : GameAsset
44
{
5-
public string FilePath { get; set; }
5+
public BafIniAsset(string filePath, string relativePath) : base(filePath, relativePath)
6+
{
7+
}
68
}
79
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
using System.Collections.Generic;
2-
using System.IO;
32

43
namespace Europa1400.Tools.Pipeline.Assets
54
{
6-
public class BgfAsset : IGameAsset
5+
public class BgfAsset : GameAsset
76
{
8-
private string? _relativePath;
9-
10-
public string RelativePath
7+
public BgfAsset(string filePath, string relativePath, TxsAsset? txs, List<TextureAsset>? textures,
8+
List<BafAsset>? animations) : base(filePath, relativePath)
119
{
12-
get => _relativePath ?? Path.GetFileName(FilePath);
13-
set => _relativePath = value;
10+
Txs = txs;
11+
Textures = textures;
12+
Animations = animations;
1413
}
1514

1615
public TxsAsset? Txs { get; set; }
1716
public List<TextureAsset>? Textures { get; set; }
1817
public List<BafAsset>? Animations { get; set; }
19-
20-
public string FilePath { get; set; }
2118
}
2219
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
using System;
2+
13
namespace Europa1400.Tools.Pipeline.Assets
24
{
3-
internal class DummyAsset : IGameAsset
5+
internal class DummyAsset : GameAsset
46
{
5-
public string FilePath => string.Empty;
7+
public DummyAsset() : base(string.Empty, string.Empty)
8+
{
9+
}
610
}
711
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Europa1400.Tools.Pipeline.Assets
2+
{
3+
public abstract class GameAsset
4+
{
5+
protected GameAsset(string filePath, string relativePath)
6+
{
7+
FilePath = filePath;
8+
RelativePath = relativePath;
9+
}
10+
11+
public string FilePath { get; set; }
12+
public string RelativePath { get; set; }
13+
}
14+
}

0 commit comments

Comments
 (0)