Skip to content

Commit e7d8689

Browse files
committed
added option to disable map specific generation
1 parent 03e035b commit e7d8689

6 files changed

Lines changed: 58 additions & 17 deletions

File tree

HeroesDataParser/Cli/Commands/RootCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private void SetOptions(RootSettings settings)
102102
_options.GameStringText.ReplaceFontStylesVars = true;
103103

104104
_options.LocalizedText = settings.LocalizedTextOption;
105+
_options.DisableMapSpecificJson = settings.DisableMapSpecificJson;
105106
_options.MapSpecificWriterJsonOutputType = settings.MapSpecificWriterJsonOutputType;
106107
_options.AllowEmptyMapSpecificPatchFiles = settings.AllowEmptyMapSpecificPatchFiles;
107108
_options.AllowEmptyMapSpecificDirectories = settings.AllowEmptyMapSpecificDirectories;

HeroesDataParser/Cli/Settings/RootSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public class RootSettings : CommandSettings
5252
[DefaultValue(LocalizedTextOption.None)]
5353
public LocalizedTextOption LocalizedTextOption { get; init; }
5454

55+
[CommandOption("--no-map-specific")]
56+
[Description("Disable the map specific JSON file creation when 'map' extractor is specified")]
57+
public bool DisableMapSpecificJson { get; init; }
58+
5559
[CommandOption("--map-specific-json-output <TYPE>")]
5660
[Description("Specifies how to handle the map specific JSON file creation")]
5761
[DefaultValue(MapSpecificWriterJsonOutputType.Patch)]

HeroesDataParser/Infrastructure/Extractors/MapDataExtractorService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public MapDataExtractorService(
2828
_resultSummaryService = resultSummaryService;
2929
}
3030

31-
public async Task<SortedDictionary<string, Map>> Extract(Func<Map, Task> elementParsersForMap)
31+
public async Task<SortedDictionary<string, Map>> Extract(Func<Map, Task> dataParsers)
3232
{
3333
_stopwatch.Restart();
3434

@@ -77,11 +77,17 @@ public async Task<SortedDictionary<string, Map>> Extract(Func<Map, Task> element
7777
{
7878
parsedMaps.Add(mapTitle, map);
7979

80-
_logger.LogInformation("Running element processors for {MapId}", mapTitle);
80+
if (_options.DisableMapSpecificJson)
81+
{
82+
_logger.LogWarning("Map specific JSON generation is disabled, skipping data processors for {MapId}", mapTitle);
83+
continue;
84+
}
8185

82-
await elementParsersForMap.Invoke(map);
86+
_logger.LogInformation("Running data processors for {MapId}", mapTitle);
8387

84-
_logger.LogInformation("Completed element processors for {MapId}", mapTitle);
88+
await dataParsers.Invoke(map);
89+
90+
_logger.LogInformation("Completed data processors for {MapId}", mapTitle);
8591
}
8692
else
8793
{

HeroesDataParser/Options/RootOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class RootOptions
3030

3131
public int Threads { get; set; }
3232

33+
public bool DisableMapSpecificJson { get; set; }
34+
3335
public HiddenOptions Hidden { get; set; } = new();
3436

3537
// properties below here a set/overridden during runtime

HeroesDataParser/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
//"zhCN",
110110
//"zhTW"
111111
],
112+
"DisableMapSpecificJson": false,
112113
"LocalizedText": "None", // 0 = None, 1 = Extract, 2 = Copy
113114
"GameStringText": {
114115
"Type": 0, // 0 = RawText, 1 = PlainText, 2 = PlainTextWithNewlines, 3 = PlainTextWithScaling, 4 = PlainTextWithScalingWithNewlines, 5 = ColoredText, 6 = ColoredTextWithScaling

Tests/HeroesDataParser.Tests/Cli/Commands/RootCommandTests.cs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,12 @@ public async Task RootCommand_WithDefaultValidArguments_ExecutesSuccessfully(str
394394
rootOptions.AllowEmptyMapSpecificPatchFiles.Should().BeFalse();
395395
rootOptions.AllowEmptyMapSpecificDirectories.Should().BeFalse();
396396
rootOptions.ShowLoadedCustomConfigFiles.Should().BeFalse();
397+
rootOptions.DisableMapSpecificJson.Should().BeFalse();
397398
rootOptions.JsonIndent.Should().BeTrue();
398399
}
399400

400401
[TestMethod]
401-
public async Task RootCommand_WithOnlineArgument_ExecutesSuccessfully()
402+
public async Task RootCommand_WithOnlineOption_ExecutesSuccessfully()
402403
{
403404
// arrange
404405
RootOptions rootOptions = new();
@@ -429,7 +430,7 @@ public async Task RootCommand_WithOnlineArgument_ExecutesSuccessfully()
429430
}
430431

431432
[TestMethod]
432-
public async Task RootCommand_WithOutputArgument_ExecutesSuccessfully()
433+
public async Task RootCommand_WithOutputOption_ExecutesSuccessfully()
433434
{
434435
// arrange
435436
RootOptions rootOptions = new();
@@ -461,7 +462,7 @@ public async Task RootCommand_WithOutputArgument_ExecutesSuccessfully()
461462
}
462463

463464
[TestMethod]
464-
public async Task RootCommand_WithHeroesVersionArgument_ExecutesSuccessfully()
465+
public async Task RootCommand_WithHeroesVersionOption_ExecutesSuccessfully()
465466
{
466467
// arrange
467468
RootOptions rootOptions = new();
@@ -497,7 +498,7 @@ public async Task RootCommand_WithHeroesVersionArgument_ExecutesSuccessfully()
497498
}
498499

499500
[TestMethod]
500-
public async Task RootCommand_WithExtractorArguments_ExecutesSuccessfully()
501+
public async Task RootCommand_WithExtractorOptions_ExecutesSuccessfully()
501502
{
502503
// arrange
503504
RootOptions rootOptions = new();
@@ -528,7 +529,7 @@ public async Task RootCommand_WithExtractorArguments_ExecutesSuccessfully()
528529
}
529530

530531
[TestMethod]
531-
public async Task RootCommand_WithExtractorArgumentAsAll_ExecutesSuccessfully()
532+
public async Task RootCommand_WithExtractorOptionAsAll_ExecutesSuccessfully()
532533
{
533534
// arrange
534535
RootOptions rootOptions = new();
@@ -561,7 +562,7 @@ public async Task RootCommand_WithExtractorArgumentAsAll_ExecutesSuccessfully()
561562
}
562563

563564
[TestMethod]
564-
public async Task RootCommand_WithLocalizationArguments_ExecutesSuccessfully()
565+
public async Task RootCommand_WithLocalizationOptions_ExecutesSuccessfully()
565566
{
566567
// arrange
567568
RootOptions rootOptions = new();
@@ -589,7 +590,7 @@ public async Task RootCommand_WithLocalizationArguments_ExecutesSuccessfully()
589590
}
590591

591592
[TestMethod]
592-
public async Task RootCommand_WithLocalizationAllArgument_ExecutesSuccessfully()
593+
public async Task RootCommand_WithLocalizationAllOptions_ExecutesSuccessfully()
593594
{
594595
// arrange
595596
RootOptions rootOptions = new();
@@ -619,7 +620,7 @@ public async Task RootCommand_WithLocalizationAllArgument_ExecutesSuccessfully()
619620
}
620621

621622
[TestMethod]
622-
public async Task RootCommand_WithGameStringTextArguments_ExecutesSuccessfully()
623+
public async Task RootCommand_WithGameStringTextOptions_ExecutesSuccessfully()
623624
{
624625
// arrange
625626
RootOptions rootOptions = new();
@@ -653,7 +654,7 @@ public async Task RootCommand_WithGameStringTextArguments_ExecutesSuccessfully()
653654
}
654655

655656
[TestMethod]
656-
public async Task RootCommand_LocalizedTextArgument_ExecutesSuccessfully()
657+
public async Task RootCommand_LocalizedTextOption_ExecutesSuccessfully()
657658
{
658659
// arrange
659660
RootOptions rootOptions = new();
@@ -679,7 +680,7 @@ public async Task RootCommand_LocalizedTextArgument_ExecutesSuccessfully()
679680
}
680681

681682
[TestMethod]
682-
public async Task RootCommand_MapSpecificArguments_ExecutesSuccessfully()
683+
public async Task RootCommand_MapSpecificOptions_ExecutesSuccessfully()
683684
{
684685
// arrange
685686
RootOptions rootOptions = new();
@@ -709,7 +710,7 @@ public async Task RootCommand_MapSpecificArguments_ExecutesSuccessfully()
709710
}
710711

711712
[TestMethod]
712-
public async Task RootCommand_CustomConfigArgument_ExecutesSuccessfully()
713+
public async Task RootCommand_CustomConfigOption_ExecutesSuccessfully()
713714
{
714715
// arrange
715716
RootOptions rootOptions = new();
@@ -735,7 +736,7 @@ public async Task RootCommand_CustomConfigArgument_ExecutesSuccessfully()
735736
}
736737

737738
[TestMethod]
738-
public async Task RootCommand_NoIndentArgument_ExecutesSuccessfully()
739+
public async Task RootCommand_NoIndentOption_ExecutesSuccessfully()
739740
{
740741
// arrange
741742
RootOptions rootOptions = new();
@@ -761,7 +762,7 @@ public async Task RootCommand_NoIndentArgument_ExecutesSuccessfully()
761762
}
762763

763764
[TestMethod]
764-
public async Task RootCommand_ThreadsArgument_ExecutesSuccessfully()
765+
public async Task RootCommand_ThreadsOption_ExecutesSuccessfully()
765766
{
766767
// arrange
767768
RootOptions rootOptions = new();
@@ -786,6 +787,32 @@ public async Task RootCommand_ThreadsArgument_ExecutesSuccessfully()
786787
rootOptions.Threads.Should().Be(4);
787788
}
788789

790+
[TestMethod]
791+
public async Task RootCommand_DisableMapSpecificOption_ExecutesSuccessfully()
792+
{
793+
// arrange
794+
RootOptions rootOptions = new();
795+
_options.Value.Returns(rootOptions);
796+
797+
TypeRegistrar registrar = new(GetServiceCollection());
798+
CommandAppTester app = new(registrar);
799+
app.SetDefaultCommand<RootCommand>();
800+
801+
// act
802+
CommandAppResult result = await app.RunAsync(
803+
[
804+
"game",
805+
"--storage-path", "TestXmlFiles",
806+
"--no-map-specific",
807+
],
808+
TestContext.CancellationToken);
809+
810+
// assert
811+
await AssertCommandSuccessful(result);
812+
813+
rootOptions.DisableMapSpecificJson.Should().BeTrue();
814+
}
815+
789816
private ServiceCollection GetServiceCollection()
790817
{
791818
ServiceCollection services = new();

0 commit comments

Comments
 (0)