Skip to content

Commit

Permalink
Latest Stellaris and HOI4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bcssov committed May 7, 2024
1 parent 107ebe9 commit eafb599
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 46 deletions.
36 changes: 36 additions & 0 deletions References/CopyAll/Maps/HeartsofIronIVParserMap.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[{
"DirectoryPath": "assets",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common",
"PreferredParser": "GenericWholeTextParser"
}, {
Expand Down Expand Up @@ -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"
Expand Down
72 changes: 72 additions & 0 deletions References/CopyAll/Maps/StellarisParserMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
}, {
"DirectoryPath": "common\\crisis_objectives",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\crisis_paths",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\decisions",
"PreferredParser": "DefaultParser"
Expand All @@ -154,6 +157,9 @@
}, {
"DirectoryPath": "common\\districts",
"PreferredParser": "StellarisOverwrittenParser"
}, {
"DirectoryPath": "common\\dust_clouds",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\economic_categories",
"PreferredParser": "DefaultParser"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -610,6 +625,9 @@
}, {
"DirectoryPath": "gfx\\portraits\\portraits",
"PreferredParser": "StellarisWholeTextParser"
}, {
"DirectoryPath": "gfx\\portraits\\sprite_configurations",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "gfx\\projectiles",
"PreferredParser": "GenericKeyParser"
Expand Down Expand Up @@ -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"
Expand Down
78 changes: 32 additions & 46 deletions src/IronyModManager.Parser/Generic/GraphicsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -26,11 +27,9 @@ namespace IronyModManager.Parser.Generic
/// <summary>
/// Class GraphicsParser.
/// Implements the <see cref="IronyModManager.Parser.Generic.KeyParser" />
/// Implements the <see cref="IGenericParser" />
/// </summary>
/// <seealso cref="IronyModManager.Parser.Generic.KeyParser" />
/// <seealso cref="IGenericParser" />
public class GraphicsParser : KeyParser, IGenericParser
public class GraphicsParser : KeyParser
{
#region Fields

Expand All @@ -42,32 +41,32 @@ public class GraphicsParser : KeyParser, IGenericParser
/// <summary>
/// The asset ids
/// </summary>
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={"];

/// <summary>
/// The expected graphics folders
/// </summary>
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"];

/// <summary>
/// The expected graphics ids
/// </summary>
protected static readonly string[] expectedGraphicsIds = new string[] { GuiTypesId, "spriteTypes={", "objectTypes={", "bitmapfonts={" };
protected static readonly string[] ExpectedGraphicsIds = [GuiTypesId, "spriteTypes={", "objectTypes={", "bitmapfonts={"];

/// <summary>
/// The valid extensions
/// </summary>
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];

/// <summary>
/// The object clone
/// </summary>
protected readonly IObjectClone objectClone;
protected readonly IObjectClone ObjectClone;

/// <summary>
/// The is generic key type
/// </summary>
protected bool isGenericKeyType = false;
protected bool IsGenericKeyType;

#endregion Fields

Expand All @@ -81,7 +80,7 @@ public class GraphicsParser : KeyParser, IGenericParser
/// <param name="logger">The logger.</param>
public GraphicsParser(IObjectClone objectClone, ICodeParser codeParser, ILogger logger) : base(codeParser, logger)
{
this.objectClone = objectClone;
ObjectClone = objectClone;
}

#endregion Constructors
Expand Down Expand Up @@ -111,7 +110,7 @@ public GraphicsParser(IObjectClone objectClone, ICodeParser codeParser, ILogger
/// <returns><c>true</c> if this instance can parse the specified arguments; otherwise, <c>false</c>.</returns>
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 _);
}

/// <summary>
Expand All @@ -121,58 +120,50 @@ public override bool CanParse(CanParseArgs args)
/// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
public override IEnumerable<IDefinition> 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<IDefinition> 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<IDefinition>();
}

var parsedResult = new List<IDefinition>();
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;
}

Expand All @@ -183,7 +174,7 @@ public override IEnumerable<IDefinition> Parse(ParserArgs args)
/// <returns>System.String.</returns>
protected override string EvalElementForId(IScriptElement value)
{
if (isGenericKeyType)
if (IsGenericKeyType)
{
return base.EvalElementForId(value);
}
Expand All @@ -193,6 +184,7 @@ protected override string EvalElementForId(IScriptElement value)
{
return value.Value;
}

return base.EvalElementForId(value);
}
}
Expand All @@ -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;
Expand All @@ -245,6 +230,7 @@ protected virtual bool IsContentGraphics(CanParseArgs args, bool skipExtensionVa
}
}
}

return false;
}

Expand Down

0 comments on commit eafb599

Please sign in to comment.