Skip to content

Commit

Permalink
Implemented @key,* = something to resolve #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas committed Dec 30, 2015
1 parent fc5db39 commit ce20e25
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ public IEnumerator ApplyPatch(List<string> excludePaths, string Stage)
}

// Name is group 1, index is group 2, operator is group 3
private static Regex parseValue = new Regex(@"([\w\&\-\.\?\*]*)(?:,(-?[0-9]+))?(?:\s([+\-*/^!]))?");
private static Regex parseValue = new Regex(@"([\w\&\-\.\?\*]*)(?:,(-?[0-9\*]+))?(?:\s([+\-*/^!]))?");

// ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
// it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
Expand Down Expand Up @@ -1488,10 +1488,13 @@ public ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)

// In this case insert the value at position index (with the same node names)
int index = 0;
bool isStar = false;
if (match.Groups[2].Success)
{
if (match.Groups[2].Value == "*")
isStar = true;
// can have "node,n *" (for *= ect)
if (!int.TryParse(match.Groups[2].Value, out index))
else if (!int.TryParse(match.Groups[2].Value, out index))
{
Debug.LogError("Error - Unable to parse number as number. Very odd.");
errorCount++;
Expand Down Expand Up @@ -1562,29 +1565,35 @@ public ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
// Format is @key = value or @key *= value or @key += value or @key -= value
// or @key,index = value or @key,index *= value or @key,index += value or @key,index -= value

varValue = ProcessVariableSearch(modVal.value, newNode);

if (varValue != null)
while(index < newNode.values.Count)
{
ConfigNode.Value origVal;
string value = FindAndReplaceValue(mod, ref valName, varValue, newNode, op, index,
out origVal);
varValue = ProcessVariableSearch(modVal.value, newNode);

if (value != null)
if (varValue != null)
{
if (origVal.value != value)
vals += ": " + origVal.value + " -> " + value;
ConfigNode.Value origVal;
string value = FindAndReplaceValue(mod, ref valName, varValue, newNode, op, index,
out origVal);

if (value != null)
{
if (origVal.value != value)
vals += ": " + origVal.value + " -> " + value;

if (cmd != Command.Copy)
origVal.value = value;
else
newNode.AddValue(valName, value);
if (cmd != Command.Copy)
origVal.value = value;
else
newNode.AddValue(valName, value);
}
}
}
else
{
log("Error - Cannot parse variable search when editing key " + valName + " = " + modVal.value);
errorCount++;
else
{
log("Error - Cannot parse variable search when editing key " + valName + " = " + modVal.value);
errorCount++;
}

if (isStar) index++;
else break;
}
break;

Expand Down

0 comments on commit ce20e25

Please sign in to comment.