Skip to content

Commit 722b89f

Browse files
committed
refactor: rework conversion flag handling
1 parent e705629 commit 722b89f

17 files changed

Lines changed: 80 additions & 91 deletions
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FEZRepacker.Core.Definitions.Game.ArtObject;
2+
using FEZRepacker.Core.Definitions.Game.Graphics;
23
using FEZRepacker.Core.Definitions.Game.TrileSet;
34

45
namespace FEZRepacker.Core.Conversion
@@ -9,17 +10,10 @@ namespace FEZRepacker.Core.Conversion
910
public struct FormatConverterSettings()
1011
{
1112
/// <summary>
12-
/// By default, the <see href="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html">glTF</see>
13-
/// all-in-one format is used for transmitting and editing <see cref="ArtObject"/> properties.
13+
/// By default, the <see href="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html">glTF</see> all-in-one
14+
/// format is used for transmitting and editing <see cref="ArtObject"/> and <see cref="TrileSet"/> properties.
1415
/// If the flag is true, the converter will use a legacy bundle with separate files.
1516
/// </summary>
16-
public bool UseLegacyArtObjectBundle = false;
17-
18-
/// <summary>
19-
/// By default, the <see href="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html">glTF</see>
20-
/// all-in-one format is used for transmitting and editing <see cref="TrileSet"/> properties.
21-
/// If the flag is true, the converter will use a legacy bundle with separate files.
22-
/// </summary>
23-
public bool UseLegacyTrileSetBundle = false;
17+
public bool UseTrixelArtBundle = false;
2418
}
2519
}

Core/Conversion/Formats/ArtObjectConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class ArtObjectConverter : FormatConverter<ArtObject>
1717

1818
public override FileBundle ConvertTyped(ArtObject data)
1919
{
20-
if (!Settings.UseLegacyArtObjectBundle)
20+
if (!Settings.UseTrixelArtBundle)
2121
{
2222
return FileBundle.Single(GetTransmissionFormatStream(data), FileFormat, ".glb");
2323
}

Core/Conversion/Formats/TrileSetConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class TrileSetConverter : FormatConverter<TrileSet>
2323

2424
public override FileBundle ConvertTyped(TrileSet data)
2525
{
26-
if (!Settings.UseLegacyTrileSetBundle)
26+
if (!Settings.UseTrixelArtBundle)
2727
{
2828
return FileBundle.Single(GetTransmissionFormatStream(data), FileFormat, ".glb");
2929
}

Interface/Actions/ConvertFromXnbAction.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ internal class ConvertFromXnbAction : CommandLineAction
1111

1212
private const string FileOutput = "file-output";
1313

14-
private const string UseLegacyAo = "use-legacy-ao";
15-
16-
private const string UseLegacyTs = "use-legacy-ts";
17-
1814
public string Name => "--convert-from-xnb";
1915

2016
public string[] Aliases => new[] { "-x" };
@@ -24,12 +20,10 @@ internal class ConvertFromXnbAction : CommandLineAction
2420
"and save it at given output directory. If input is a directory, dumps all converted files in specified " +
2521
"path recursively. If output directory is not given, outputs next to the input file(s).";
2622

27-
public CommandLineArgument[] Arguments => new[] {
23+
public IEnumerable<CommandLineArgument> Arguments => new[] {
2824
new CommandLineArgument(XnbInput),
2925
new CommandLineArgument(FileOutput, ArgumentType.OptionalPositional),
30-
new CommandLineArgument(UseLegacyAo, ArgumentType.Flag),
31-
new CommandLineArgument(UseLegacyTs, ArgumentType.Flag)
32-
};
26+
}.Concat(FormatConverterSettingsFlags.Arguments);
3327

3428
private List<string> FindXnbFilesAtPath(string path)
3529
{
@@ -69,11 +63,7 @@ public void Execute(Dictionary<string, string> args)
6963
Console.WriteLine($"Converting {xnbFilesToConvert.Count()} XNB files...");
7064

7165
var filesDone = 0;
72-
var settings = new FormatConverterSettings
73-
{
74-
UseLegacyArtObjectBundle = args.ContainsKey(UseLegacyAo),
75-
UseLegacyTrileSetBundle = args.ContainsKey(UseLegacyTs)
76-
};
66+
var settings = FormatConverterSettingsFlags.ReadFromArguments(args);
7767

7868
foreach (var xnbPath in xnbFilesToConvert)
7969
{

Interface/Actions/ConvertToXnbAction.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ internal class ConvertToXnbAction : CommandLineAction
1313

1414
private const string XnbOutput = "xnb-output";
1515

16-
private const string UseLegacyAo = "use-legacy-ao";
17-
18-
private const string UseLegacyTs = "use-legacy-ts";
19-
2016
public string Name => "--convert-to-xnb";
2117

2218
public string[] Aliases => new[] { "-X" };
@@ -26,10 +22,10 @@ internal class ConvertToXnbAction : CommandLineAction
2622
"into XNB file(s) and save it at given output directory. If input is a directory, dumps all converted files in" +
2723
"specified path recursively. If output directory is not given, outputs next to the input file(s).";
2824

29-
public CommandLineArgument[] Arguments => new[] {
30-
new CommandLineArgument(FileInput),
31-
new CommandLineArgument(XnbOutput, ArgumentType.OptionalPositional)
32-
};
25+
public IEnumerable<CommandLineArgument> Arguments => [
26+
new(FileInput),
27+
new(XnbOutput, ArgumentType.OptionalPositional)
28+
];
3329

3430
public delegate void ConversionFunc(string path, string extension, Stream stream, bool converted);
3531

Interface/Actions/HelpAction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ internal class HelpAction : CommandLineAction
88
public string[] Aliases => new[] { "help", "?", "-?", "-h" };
99
public string Description => "Displays help for all commands or help for given command.";
1010

11-
public CommandLineArgument[] Arguments => new[] {
12-
new CommandLineArgument(Command, ArgumentType.OptionalPositional)
13-
};
11+
public IEnumerable<CommandLineArgument> Arguments => [
12+
new(Command, ArgumentType.OptionalPositional)
13+
];
1414

1515
public void Execute(Dictionary<string, string> args)
1616
{

Interface/Actions/ListPackageContentAction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ internal class ListPackageContentAction : CommandLineAction
1010
public string Name => "--list";
1111
public string[] Aliases => new[] { "-l" };
1212
public string Description => "Lists all files contained withing given .PAK package.";
13-
public CommandLineArgument[] Arguments => new[] {
14-
new CommandLineArgument(PakPath)
15-
};
13+
public IEnumerable<CommandLineArgument> Arguments => [
14+
new(PakPath)
15+
];
1616

1717
public void Execute(Dictionary<string, string> args)
1818
{

Interface/Actions/PackAction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ internal class PackAction : CommandLineAction
1515
public string Description =>
1616
"Loads files from given input directory path, tries to deconvert them and pack into a destination " +
1717
".PAK file with given path. If include .PAK path is provided, it'll add its content into the new .PAK package.";
18-
public CommandLineArgument[] Arguments => new[] {
19-
new CommandLineArgument(InputDirectoryPath),
20-
new CommandLineArgument(DestinationPakPath),
21-
new CommandLineArgument(IncludePakPath, ArgumentType.OptionalPositional)
22-
};
18+
public IEnumerable<CommandLineArgument> Arguments => [
19+
new(InputDirectoryPath),
20+
new(DestinationPakPath),
21+
new(IncludePakPath, ArgumentType.OptionalPositional)
22+
];
2323

2424
private class TemporaryPak : IDisposable
2525
{

Interface/Actions/UnpackAction.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ namespace FEZRepacker.Interface.Actions
99
{
1010
internal abstract class UnpackAction : CommandLineAction
1111
{
12-
private const string PakPath = "pak-path";
13-
private const string DestinationFolder = "destination-folder";
14-
private const string UseLegacyAo = "use-legacy-ao";
15-
private const string UseLegacyTs = "use-legacy-ts";
12+
protected const string PakPath = "pak-path";
13+
protected const string DestinationFolder = "destination-folder";
1614

1715
public enum UnpackingMode
1816
{
@@ -24,23 +22,12 @@ public enum UnpackingMode
2422
public abstract string Name { get; }
2523
public abstract string Description { get; }
2624
public abstract string[] Aliases { get; }
27-
28-
public CommandLineArgument[] Arguments => new[] {
29-
new CommandLineArgument(PakPath),
30-
new CommandLineArgument(DestinationFolder),
31-
new CommandLineArgument(UseLegacyAo, ArgumentType.Flag),
32-
new CommandLineArgument(UseLegacyTs, ArgumentType.Flag)
33-
};
34-
25+
public abstract IEnumerable<CommandLineArgument> Arguments { get; }
3526
public void Execute(Dictionary<string, string> args)
3627
{
3728
var pakPath = args[PakPath];
3829
var outputDir = args[DestinationFolder];
39-
var settings = new FormatConverterSettings
40-
{
41-
UseLegacyArtObjectBundle = args.ContainsKey(UseLegacyAo),
42-
UseLegacyTrileSetBundle = args.ContainsKey(UseLegacyTs)
43-
};
30+
var settings = FormatConverterSettingsFlags.ReadFromArguments(args);
4431

4532
UnpackPackage(pakPath, outputDir, Mode, settings);
4633
}

Interface/Actions/UnpackConvertAction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ internal class UnpackConvertAction : UnpackAction
88
public override string Description =>
99
"Unpacks entire .PAK package into specified directory (creates one if doesn't exist) " +
1010
"and attempts to convert XNB assets into their corresponding format in the process.";
11+
12+
public override IEnumerable<CommandLineArgument> Arguments => new[] {
13+
new CommandLineArgument(PakPath),
14+
new CommandLineArgument(DestinationFolder),
15+
}.Concat(FormatConverterSettingsFlags.Arguments);
1116
}
1217
}

0 commit comments

Comments
 (0)