Skip to content

Commit ebe2895

Browse files
committed
Support patching Localization tokens.
* Support wildcards in nodetype matching so you can do @*,* {} * Support # in value names since loc names start with # * Tell Localizer to reload the language after MM finishes
1 parent 86e60c3 commit ebe2895

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

ModuleManager/MMPatchLoader.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ public IEnumerable<IProtoUrlConfig> Run()
231231
}
232232
}
233233

234+
if (KSP.Localization.Localizer.Instance != null)
235+
KSP.Localization.Localizer.SwitchToLanguage(KSP.Localization.Localizer.CurrentLanguage);
236+
234237
logger.Info(status + "\n" + errors);
235238

236239
patchSw.Stop();
@@ -564,7 +567,7 @@ private void StatusUpdate(IPatchProgress progress, string activity = null)
564567
#region Applying Patches
565568

566569
// Name is group 1, index is group 2, vector related filed is group 3, vector separator is group 4, operator is group 5
567-
private static readonly Regex parseValue = new Regex(@"([\w\&\-\.\?\*+/^!\(\) ]+(?:,[^*\d][\w\&\-\.\?\*\(\) ]*)*)(?:,(-?[0-9\*]+))?(?:\[((?:[0-9\*]+)+)(?:,(.))?\])?");
570+
private static readonly Regex parseValue = new Regex(@"([\w\&\-\.\?\*\#+/^!\(\) ]+(?:,[^*\d][\w\&\-\.\?\*\(\) ]*)*)(?:,(-?[0-9\*]+))?(?:\[((?:[0-9\*]+)+)(?:,(.))?\])?");
568571

569572
// ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
570573
// it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
@@ -1712,19 +1715,26 @@ public static ConfigNode FindConfigNodeIn(
17121715
string nodeName = null,
17131716
int index = 0)
17141717
{
1715-
ConfigNode[] nodes = src.GetNodes(nodeType);
1716-
if (nodes.Length == 0)
1718+
List<ConfigNode> nodes = new List<ConfigNode>();
1719+
int c = src.nodes.Count;
1720+
for(int i = 0; i < c; ++i)
1721+
{
1722+
if (WildcardMatch(src.nodes[i].name, nodeType))
1723+
nodes.Add(src.nodes[i]);
1724+
}
1725+
int nodeCount = nodes.Count;
1726+
if (nodeCount == 0)
17171727
return null;
17181728
if (nodeName == null)
17191729
{
17201730
if (index >= 0)
1721-
return nodes[Math.Min(index, nodes.Length - 1)];
1722-
return nodes[Math.Max(0, nodes.Length + index)];
1731+
return nodes[Math.Min(index, nodeCount - 1)];
1732+
return nodes[Math.Max(0, nodeCount + index)];
17231733
}
17241734
ConfigNode last = null;
17251735
if (index >= 0)
17261736
{
1727-
for (int i = 0; i < nodes.Length; ++i)
1737+
for (int i = 0; i < nodeCount; ++i)
17281738
{
17291739
if (nodes[i].HasValue("name") && WildcardMatch(nodes[i].GetValue("name"), nodeName))
17301740
{
@@ -1735,7 +1745,7 @@ public static ConfigNode FindConfigNodeIn(
17351745
}
17361746
return last;
17371747
}
1738-
for (int i = nodes.Length - 1; i >= 0; --i)
1748+
for (int i = nodeCount - 1; i >= 0; --i)
17391749
{
17401750
if (nodes[i].HasValue("name") && WildcardMatch(nodes[i].GetValue("name"), nodeName))
17411751
{

0 commit comments

Comments
 (0)