diff --git a/References/CopyAll/Maps/HeartsofIronIVParserMap.json b/References/CopyAll/Maps/HeartsofIronIVParserMap.json index ee7953e3..b361f58b 100644 --- a/References/CopyAll/Maps/HeartsofIronIVParserMap.json +++ b/References/CopyAll/Maps/HeartsofIronIVParserMap.json @@ -1,4 +1,7 @@ [{ + "DirectoryPath": "assets", + "PreferredParser": "DefaultParser" + }, { "DirectoryPath": "common", "PreferredParser": "GenericWholeTextParser" }, { @@ -325,6 +328,39 @@ }, { "DirectoryPath": "interface", "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\gfx\\entities", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\gfx\\models\\units", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\interface", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\music", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\music", + "PreferredParser": "DefaultParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc018_together_for_victory\\sound", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc020_death_or_dishonor\\music", + "PreferredParser": "DefaultParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc022_waking_the_tiger\\music", + "PreferredParser": "DefaultParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc022_waking_the_tiger\\portraits", + "PreferredParser": "GenericKeyParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc022_waking_the_tiger\\sound\\combat_ambient", + "PreferredParser": "GenericGraphicsParser" + }, { + "DirectoryPath": "integrated_dlc\\dlc022_waking_the_tiger\\sound\\combat_sounds", + "PreferredParser": "DefaultParser" }, { "DirectoryPath": "interface", "PreferredParser": "DefaultParser" diff --git a/References/CopyAll/Maps/StellarisParserMap.json b/References/CopyAll/Maps/StellarisParserMap.json index 56b093e7..644f6a1b 100644 --- a/References/CopyAll/Maps/StellarisParserMap.json +++ b/References/CopyAll/Maps/StellarisParserMap.json @@ -130,6 +130,9 @@ }, { "DirectoryPath": "common\\crisis_objectives", "PreferredParser": "DefaultParser" + }, { + "DirectoryPath": "common\\crisis_paths", + "PreferredParser": "DefaultParser" }, { "DirectoryPath": "common\\decisions", "PreferredParser": "DefaultParser" @@ -154,6 +157,9 @@ }, { "DirectoryPath": "common\\districts", "PreferredParser": "StellarisOverwrittenParser" + }, { + "DirectoryPath": "common\\dust_clouds", + "PreferredParser": "DefaultParser" }, { "DirectoryPath": "common\\economic_categories", "PreferredParser": "DefaultParser" @@ -241,6 +247,9 @@ }, { "DirectoryPath": "common\\inline_scripts\\buildings", "PreferredParser": "StellarisWholeTextParser" + }, { + "DirectoryPath": "common\\inline_scripts\\colony_types", + "PreferredParser": "StellarisWholeTextParser" }, { "DirectoryPath": "common\\inline_scripts\\deposits", "PreferredParser": "StellarisWholeTextParser" @@ -358,6 +367,12 @@ }, { "DirectoryPath": "common\\pop_jobs", "PreferredParser": "StellarisOverwrittenParser" + }, { + "DirectoryPath": "common\\portrait_categories", + "PreferredParser": "DefaultParser" + }, { + "DirectoryPath": "common\\portrait_sets", + "PreferredParser": "DefaultParser" }, { "DirectoryPath": "common\\precursor_civilizations", "PreferredParser": "DefaultParser" @@ -610,6 +625,9 @@ }, { "DirectoryPath": "gfx\\portraits\\portraits", "PreferredParser": "StellarisWholeTextParser" + }, { + "DirectoryPath": "gfx\\portraits\\sprite_configurations", + "PreferredParser": "DefaultParser" }, { "DirectoryPath": "gfx\\projectiles", "PreferredParser": "GenericKeyParser" @@ -790,6 +808,60 @@ }, { "DirectoryPath": "sound\\lithoids\\portraits", "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\portraits", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\ships", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\superstructures", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\00_act01_first_two_speeches", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\01_act02_first_demand", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\02_act02_random_demands", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\03_act02_zarqlan_head_demand", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\04_act02_player_initiated_conversation", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\05_act02_retributions", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\06.5_act02_player_is_accidentaly_in_war", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\06_act02_cetanas_gift", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\07_act02_raids_on_cetana", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\08_act02_storm_chain_ends", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\10_act03_cetana_goes_towar", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\11_act03_player_during_wartime", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\12_act03_cetana_wins", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\13_act03_player_wins", + "PreferredParser": "GenericWholeTextParser" + }, { + "DirectoryPath": "sound\\machineage\\synthqueen\\14_act03_player_wins_psi", + "PreferredParser": "GenericWholeTextParser" }, { "DirectoryPath": "sound\\megacorp", "PreferredParser": "GenericWholeTextParser" diff --git a/src/IronyModManager.Parser/Generic/GraphicsParser.cs b/src/IronyModManager.Parser/Generic/GraphicsParser.cs index faa0ad48..31f7ba50 100644 --- a/src/IronyModManager.Parser/Generic/GraphicsParser.cs +++ b/src/IronyModManager.Parser/Generic/GraphicsParser.cs @@ -11,6 +11,7 @@ // // // *********************************************************************** + using System; using System.Collections.Generic; using System.IO; @@ -26,11 +27,9 @@ namespace IronyModManager.Parser.Generic /// /// Class GraphicsParser. /// Implements the - /// Implements the /// /// - /// - public class GraphicsParser : KeyParser, IGenericParser + public class GraphicsParser : KeyParser { #region Fields @@ -42,32 +41,32 @@ public class GraphicsParser : KeyParser, IGenericParser /// /// The asset ids /// - protected static readonly string[] assetIds = new string[] { "animation={", "category={", "entity={", "falloff={", "font={", "light={", "master_compressor={", "particle={", "music={", "sound={", "soundeffect={", "soundgroup={" }; + protected static readonly string[] AssetIds = ["animation={", "category={", "entity={", "falloff={", "font={", "light={", "master_compressor={", "particle={", "music={", "sound={", "soundeffect={", "soundgroup={"]; /// /// The expected graphics folders /// - protected static readonly string[] expectedGraphicsFolders = new string[] { "gui", "gfx", "interface", "fonts", "dlc", "sound", "music", "pdx_launcher" }; + protected static readonly string[] ExpectedGraphicsFolders = ["gui", "gfx", "interface", "fonts", "dlc", "sound", "music", "pdx_launcher", "integrated_dlc"]; /// /// The expected graphics ids /// - protected static readonly string[] expectedGraphicsIds = new string[] { GuiTypesId, "spriteTypes={", "objectTypes={", "bitmapfonts={" }; + protected static readonly string[] ExpectedGraphicsIds = [GuiTypesId, "spriteTypes={", "objectTypes={", "bitmapfonts={"]; /// /// The valid extensions /// - protected static readonly string[] validExtensions = new string[] { Common.Constants.GuiExtension, Common.Constants.GfxExtension, Common.Constants.AssetExtension }; + protected static readonly string[] ValidExtensions = [Common.Constants.GuiExtension, Common.Constants.GfxExtension, Common.Constants.AssetExtension]; /// /// The object clone /// - protected readonly IObjectClone objectClone; + protected readonly IObjectClone ObjectClone; /// /// The is generic key type /// - protected bool isGenericKeyType = false; + protected bool IsGenericKeyType; #endregion Fields @@ -81,7 +80,7 @@ public class GraphicsParser : KeyParser, IGenericParser /// The logger. public GraphicsParser(IObjectClone objectClone, ICodeParser codeParser, ILogger logger) : base(codeParser, logger) { - this.objectClone = objectClone; + ObjectClone = objectClone; } #endregion Constructors @@ -111,7 +110,7 @@ public GraphicsParser(IObjectClone objectClone, ICodeParser codeParser, ILogger /// true if this instance can parse the specified arguments; otherwise, false. public override bool CanParse(CanParseArgs args) { - return validExtensions.Any(a => args.File.EndsWith(a, StringComparison.OrdinalIgnoreCase)) || IsContentGraphics(args, false, out var _, out var _); + return ValidExtensions.Any(a => args.File.EndsWith(a, StringComparison.OrdinalIgnoreCase)) || IsContentGraphics(args, false, out var _, out var _); } /// @@ -121,58 +120,50 @@ public override bool CanParse(CanParseArgs args) /// IEnumerable<IDefinition>. public override IEnumerable Parse(ParserArgs args) { - var canParseArgs = new CanParseArgs() - { - File = args.File, - GameType = args.GameType, - IsBinary = args.IsBinary, - Lines = args.Lines - }; + var canParseArgs = new CanParseArgs { File = args.File, GameType = args.GameType, IsBinary = args.IsBinary, Lines = args.Lines }; IEnumerable result; IsContentGraphics(canParseArgs, true, out var isAsset, out var type); if (isAsset) { - isGenericKeyType = IsKeyType(canParseArgs); + IsGenericKeyType = IsKeyType(canParseArgs); result = base.ParseRoot(args); } else { result = ParseSecondLevel(args); } + if (result.Any(p => p.ValueType == Shared.Models.ValueType.Invalid)) { return result; - } - var parsedResult = new List(); + } + + var parsedResult = new List(); var replaceFolder = Path.DirectorySeparatorChar + "replace"; var parent = args.File.StandardizeDirectorySeparator().Split(Path.DirectorySeparatorChar)[0]; - bool hasReplaceFolder = Path.GetDirectoryName(args.File).EndsWith(replaceFolder, StringComparison.OrdinalIgnoreCase); + var hasReplaceFolder = Path.GetDirectoryName(args.File)!.EndsWith(replaceFolder, StringComparison.OrdinalIgnoreCase); foreach (var definition in result.Where(p => p.ValueType != Shared.Models.ValueType.Namespace && p.ValueType != Shared.Models.ValueType.Variable)) { - if (hasReplaceFolder) - { - definition.VirtualPath = Path.Combine(parent.Replace(replaceFolder, string.Empty), definition.OriginalId, Path.GetFileName(args.File)); - } - else - { - definition.VirtualPath = Path.Combine(parent, definition.OriginalId, Path.GetFileName(args.File)); - } + definition.VirtualPath = hasReplaceFolder + ? Path.Combine(parent.Replace(replaceFolder, string.Empty), definition.OriginalId, Path.GetFileName(args.File)!) + : Path.Combine(parent, definition.OriginalId, Path.GetFileName(args.File)!); definition.Type = definition.VirtualPath.FormatDefinitionType(type); parsedResult.Add(definition); - if (result.Any(p => p.ValueType == Shared.Models.ValueType.Variable || p.ValueType == Shared.Models.ValueType.Namespace)) + if (result.Any(p => p.ValueType is Shared.Models.ValueType.Variable or Shared.Models.ValueType.Namespace)) { - foreach (var item in result.Where(p => p.ValueType == Shared.Models.ValueType.Variable || p.ValueType == Shared.Models.ValueType.Namespace)) + foreach (var item in result.Where(p => p.ValueType is Shared.Models.ValueType.Variable or Shared.Models.ValueType.Namespace)) { - var copy = objectClone.CloneDefinition(item, true); + var copy = ObjectClone.CloneDefinition(item, true); copy.VirtualPath = definition.VirtualPath; copy.Type = definition.Type; - if (!parsedResult.Any(p => p.TypeAndId == copy.TypeAndId)) + if (parsedResult.All(p => p.TypeAndId != copy.TypeAndId)) { parsedResult.Add(copy); } } } } + return parsedResult; } @@ -183,7 +174,7 @@ public override IEnumerable Parse(ParserArgs args) /// System.String. protected override string EvalElementForId(IScriptElement value) { - if (isGenericKeyType) + if (IsGenericKeyType) { return base.EvalElementForId(value); } @@ -193,6 +184,7 @@ protected override string EvalElementForId(IScriptElement value) { return value.Value; } + return base.EvalElementForId(value); } } @@ -216,26 +208,19 @@ protected virtual bool IsContentGraphics(CanParseArgs args, bool skipExtensionVa { var lines = codeParser.CleanCode(args.File, args.Lines); var parent = args.File.StandardizeDirectorySeparator().Split(Path.DirectorySeparatorChar)[0]; - if (!string.IsNullOrWhiteSpace(parent) && expectedGraphicsFolders.Any(a => parent.Equals(a, StringComparison.OrdinalIgnoreCase))) + if (!string.IsNullOrWhiteSpace(parent) && ExpectedGraphicsFolders.Any(a => parent.Equals(a, StringComparison.OrdinalIgnoreCase))) { // Means a wise guy used .bak extension var merged = string.Join(string.Empty, lines).ReplaceTabs().Replace(" ", string.Empty); if (merged.Contains(Common.Constants.Scripts.OpenObject)) { merged = merged[..(merged.IndexOf(Common.Constants.Scripts.OpenObject) + 1)]; - if (expectedGraphicsIds.Any(a => merged.Contains(a, StringComparison.OrdinalIgnoreCase))) + if (ExpectedGraphicsIds.Any(a => merged.Contains(a, StringComparison.OrdinalIgnoreCase))) { - if (merged.Contains(GuiTypesId, StringComparison.OrdinalIgnoreCase)) - { - type = Path.GetExtension(Common.Constants.GuiExtension).Trim('.'); - } - else - { - type = Path.GetExtension(Common.Constants.GfxExtension).Trim('.'); - } + type = merged.Contains(GuiTypesId, StringComparison.OrdinalIgnoreCase) ? Path.GetExtension(Common.Constants.GuiExtension).Trim('.') : Path.GetExtension(Common.Constants.GfxExtension).Trim('.'); return true; } - else if (assetIds.Any(a => merged.Contains(a, StringComparison.OrdinalIgnoreCase))) + else if (AssetIds.Any(a => merged.Contains(a, StringComparison.OrdinalIgnoreCase))) { type = Path.GetExtension(Common.Constants.AssetExtension).Trim('.'); isAsset = true; @@ -245,6 +230,7 @@ protected virtual bool IsContentGraphics(CanParseArgs args, bool skipExtensionVa } } } + return false; }