Add an upgrade rule

This commit is contained in:
abcdefg30
2015-04-30 17:54:19 +02:00
parent 8d2307db83
commit 95e3713b69
2 changed files with 22 additions and 1 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -32,6 +33,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
.Select(s => ((int)Math.Round(FieldLoader.GetValue<float>("(float value)", s) * 100)).ToString()));
}
internal static void ConvertFloatToIntPercentage(ref string input)
{
var value = float.Parse(input, CultureInfo.InvariantCulture);
if (value < 1)
value = (int)Math.Round(value * 100, 0);
else
value = (int)Math.Round(value, 0);
input = value.ToString();
}
internal static void ConvertPxToRange(ref string input)
{
ConvertPxToRange(ref input, 1, 1);
@@ -1369,7 +1382,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
if (engineVersion < 20150430)
{
if (node.Key == "Health")
ConvertFloatToIntPercentage(ref node.Value.Value);
}
UpgradeActors(engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
}
}