Load rgb[a] hex colors from MiniYaml (+ Lua)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using Eluant;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Scripting;
|
||||
|
||||
@@ -30,11 +31,59 @@ namespace OpenRA.Mods.Common.Scripting.Global
|
||||
return new HSLColor(h, s, l);
|
||||
}
|
||||
|
||||
public HSLColor White { get { return HSLColor.FromRGB(Color.White.R, Color.White.G, Color.White.B); } }
|
||||
public HSLColor Black { get { return HSLColor.FromRGB(Color.Black.R, Color.Black.G, Color.Black.B); } }
|
||||
public HSLColor Blue { get { return HSLColor.FromRGB(Color.Blue.R, Color.Blue.G, Color.Blue.B); } }
|
||||
public HSLColor Red { get { return HSLColor.FromRGB(Color.Red.R, Color.Red.G, Color.Red.B); } }
|
||||
public HSLColor Yellow { get { return HSLColor.FromRGB(Color.Yellow.R, Color.Yellow.G, Color.Yellow.B); } }
|
||||
public HSLColor Green { get { return HSLColor.FromRGB(Color.Green.R, Color.Green.G, Color.Green.B); } }
|
||||
[Desc("Create a new HSL color with the specified red/green/blue/[alpha] values.")]
|
||||
public HSLColor FromRGB(int red, int green, int blue, int alpha = 255)
|
||||
{
|
||||
return new HSLColor(
|
||||
Color.FromArgb(
|
||||
alpha.Clamp(0, 255), red.Clamp(0, 255), green.Clamp(0, 255), blue.Clamp(0, 255)));
|
||||
}
|
||||
|
||||
[Desc("Create a new HSL color with the specified red/green/blue/[alpha] hex string (rrggbb[aa]).")]
|
||||
public HSLColor FromHex(string value)
|
||||
{
|
||||
Color rgb;
|
||||
if (HSLColor.TryParseRGB(value, out rgb))
|
||||
return new HSLColor(rgb);
|
||||
|
||||
throw new LuaException("Invalid rrggbb[aa] hex string.");
|
||||
}
|
||||
|
||||
public HSLColor Aqua { get { return new HSLColor(Color.Aqua); } }
|
||||
public HSLColor Black { get { return new HSLColor(Color.Black); } }
|
||||
public HSLColor Blue { get { return new HSLColor(Color.Blue); } }
|
||||
public HSLColor Brown { get { return new HSLColor(Color.Brown); } }
|
||||
public HSLColor Cyan { get { return new HSLColor(Color.Cyan); } }
|
||||
public HSLColor DarkBlue { get { return new HSLColor(Color.DarkBlue); } }
|
||||
public HSLColor DarkCyan { get { return new HSLColor(Color.DarkCyan); } }
|
||||
public HSLColor DarkGray { get { return new HSLColor(Color.DarkGray); } }
|
||||
public HSLColor DarkGreen { get { return new HSLColor(Color.DarkGreen); } }
|
||||
public HSLColor DarkOrange { get { return new HSLColor(Color.DarkOrange); } }
|
||||
public HSLColor DarkRed { get { return new HSLColor(Color.DarkRed); } }
|
||||
public HSLColor Fuchsia { get { return new HSLColor(Color.Fuchsia); } }
|
||||
public HSLColor Gold { get { return new HSLColor(Color.Gold); } }
|
||||
public HSLColor Gray { get { return new HSLColor(Color.Gray); } }
|
||||
public HSLColor Green { get { return new HSLColor(Color.Green); } }
|
||||
public HSLColor LawnGreen { get { return new HSLColor(Color.LawnGreen); } }
|
||||
public HSLColor LightBlue { get { return new HSLColor(Color.LightBlue); } }
|
||||
public HSLColor LightCyan { get { return new HSLColor(Color.LightCyan); } }
|
||||
public HSLColor LightGray { get { return new HSLColor(Color.LightGray); } }
|
||||
public HSLColor LightGreen { get { return new HSLColor(Color.LightGreen); } }
|
||||
public HSLColor LightYellow { get { return new HSLColor(Color.LightYellow); } }
|
||||
public HSLColor Lime { get { return new HSLColor(Color.Lime); } }
|
||||
public HSLColor LimeGreen { get { return new HSLColor(Color.LimeGreen); } }
|
||||
public HSLColor Magenta { get { return new HSLColor(Color.Magenta); } }
|
||||
public HSLColor Maroon { get { return new HSLColor(Color.Maroon); } }
|
||||
public HSLColor Navy { get { return new HSLColor(Color.Navy); } }
|
||||
public HSLColor Olive { get { return new HSLColor(Color.Olive); } }
|
||||
public HSLColor Orange { get { return new HSLColor(Color.Orange); } }
|
||||
public HSLColor OrangeRed { get { return new HSLColor(Color.OrangeRed); } }
|
||||
public HSLColor Purple { get { return new HSLColor(Color.Purple); } }
|
||||
public HSLColor Red { get { return new HSLColor(Color.Red); } }
|
||||
public HSLColor Salmon { get { return new HSLColor(Color.Salmon); } }
|
||||
public HSLColor SkyBlue { get { return new HSLColor(Color.SkyBlue); } }
|
||||
public HSLColor Teal { get { return new HSLColor(Color.Teal); } }
|
||||
public HSLColor Yellow { get { return new HSLColor(Color.Yellow); } }
|
||||
public HSLColor White { get { return new HSLColor(Color.White); } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.Common.Server
|
||||
return false;
|
||||
}
|
||||
|
||||
var mapPlayerColors = server.MapPlayers.Players.Values.Select(p => p.ColorRamp.RGB);
|
||||
var mapPlayerColors = server.MapPlayers.Players.Values.Select(p => p.Color.RGB);
|
||||
|
||||
if (!ValidateColorAgainstForbidden(askedColor, mapPlayerColors, out forbiddenColor))
|
||||
{
|
||||
|
||||
@@ -56,12 +56,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("The value range that can be swung to the left or right. SwingAmplitude min. and max. value in px/tick.")]
|
||||
public readonly float[] SwingAmplitude = { 1.0f, 1.5f };
|
||||
|
||||
[Desc("The randomly selected ArgbColors for the particles. Use this order: a,r,g,b, a,r,g,b, a,...")]
|
||||
[Desc("The randomly selected rgb(a) hex colors for the particles. Use this order: rrggbb[aa], rrggbb[aa], ...")]
|
||||
public readonly Color[] ParticleColors = {
|
||||
Color.FromArgb(255, 236, 236, 236),
|
||||
Color.FromArgb(255, 228, 228, 228),
|
||||
Color.FromArgb(255, 208, 208, 208),
|
||||
Color.FromArgb(255, 188, 188, 188)
|
||||
Color.FromArgb(236, 236, 236),
|
||||
Color.FromArgb(228, 228, 228),
|
||||
Color.FromArgb(208, 208, 208),
|
||||
Color.FromArgb(188, 188, 188)
|
||||
};
|
||||
|
||||
[Desc("Works only with line enabled and can get used to fade out the tail of the line like a contrail.")]
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
@@ -164,6 +165,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (t == typeof(WVec))
|
||||
return "3D World Vector";
|
||||
|
||||
if (t == typeof(HSLColor))
|
||||
return "Color";
|
||||
|
||||
return t.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,28 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
file.WriteLine(yaml.WriteToString());
|
||||
}
|
||||
|
||||
Console.WriteLine("Processing Chrome Metrics:");
|
||||
foreach (var filename in Game.ModData.Manifest.ChromeMetrics)
|
||||
{
|
||||
Console.WriteLine("\t" + filename);
|
||||
var yaml = MiniYaml.FromFile(filename);
|
||||
UpgradeRules.UpgradeChromeMetrics(engineDate, ref yaml, null, 0);
|
||||
|
||||
using (var file = new StreamWriter(filename))
|
||||
file.WriteLine(yaml.WriteToString());
|
||||
}
|
||||
|
||||
Console.WriteLine("Processing Chrome Layout:");
|
||||
foreach (var filename in Game.ModData.Manifest.ChromeLayout)
|
||||
{
|
||||
Console.WriteLine("\t" + filename);
|
||||
var yaml = MiniYaml.FromFile(filename);
|
||||
UpgradeRules.UpgradeChromeLayout(engineDate, ref yaml, null, 0);
|
||||
|
||||
using (var file = new StreamWriter(filename))
|
||||
file.WriteLine(yaml.WriteToString());
|
||||
}
|
||||
|
||||
Console.WriteLine("Processing Maps:");
|
||||
var maps = Game.ModData.MapCache
|
||||
.Where(m => m.Status == MapStatus.Available)
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
@@ -148,6 +150,72 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
internal static void TryUpdateColor(ref string value)
|
||||
{
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
value = FieldSaver.FormatValue(Color.FromArgb(
|
||||
Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255)));
|
||||
else if (parts.Length == 4)
|
||||
value = FieldSaver.FormatValue(Color.FromArgb(
|
||||
Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[3]).Clamp(0, 255)));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void TryUpdateColors(ref string value)
|
||||
{
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length % 4 != 0)
|
||||
return;
|
||||
|
||||
var colors = new Color[parts.Length / 4];
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
{
|
||||
colors[i] = Color.FromArgb(
|
||||
Exts.ParseIntegerInvariant(parts[4 * i]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 1]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 2]).Clamp(0, 255),
|
||||
Exts.ParseIntegerInvariant(parts[4 * i + 3]).Clamp(0, 255));
|
||||
}
|
||||
|
||||
value = FieldSaver.FormatValue(colors);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void TryUpdateHSLColor(ref string value)
|
||||
{
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3 || parts.Length == 4)
|
||||
value = FieldSaver.FormatValue(new HSLColor(
|
||||
(byte)Exts.ParseIntegerInvariant(parts[0]).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[1]).Clamp(0, 255),
|
||||
(byte)Exts.ParseIntegerInvariant(parts[2]).Clamp(0, 255)));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void UpgradeActorRules(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||
{
|
||||
var parentKey = parent != null ? parent.Key.Split('@').First() : null;
|
||||
@@ -2277,6 +2345,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
if (engineVersion < 20151027 && depth == 2)
|
||||
{
|
||||
if (node.Key == "Color")
|
||||
{
|
||||
if (parent.Key.StartsWith("FixedColorPalette"))
|
||||
TryUpdateHSLColor(ref node.Value.Value);
|
||||
else
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
}
|
||||
else if (node.Key == "RadarPingColor" || node.Key == "SelectionBoxColor" || node.Key == "BarColor")
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
else if (node.Key == "Fog" || node.Key == "Shroud" || node.Key == "ParticleColors")
|
||||
TryUpdateColors(ref node.Value.Value);
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
@@ -2764,6 +2847,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
node.Key = "TrailImage";
|
||||
}
|
||||
|
||||
if (engineVersion < 20151027)
|
||||
{
|
||||
if (node.Key == "Color" || node.Key == "ContrailColor")
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
}
|
||||
|
||||
UpgradeWeaponRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
@@ -2785,6 +2874,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (depth == 2 && node.Key == "Image")
|
||||
node.Key = "Images";
|
||||
|
||||
if (engineVersion < 20151027)
|
||||
{
|
||||
if (node.Key == "LeftColor" || node.Key == "RightColor" || node.Key == "Color")
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
else if (node.Key == "HeightDebugColors")
|
||||
TryUpdateColors(ref node.Value.Value);
|
||||
}
|
||||
|
||||
UpgradeTileset(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
|
||||
@@ -2829,10 +2926,49 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
lockRace.Key = "LockFaction";
|
||||
}
|
||||
|
||||
if (engineVersion < 20151027 && node.Key == "ColorRamp")
|
||||
{
|
||||
TryUpdateHSLColor(ref node.Value.Value);
|
||||
node.Key = "Color";
|
||||
}
|
||||
|
||||
UpgradePlayers(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpgradeChromeMetrics(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (engineVersion < 20151027)
|
||||
{
|
||||
if (node.Key.EndsWith("Color") || node.Key.EndsWith("ColorDisabled") || node.Key.EndsWith("ColorInvalid"))
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
}
|
||||
|
||||
UpgradeChromeMetrics(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpgradeChromeLayout(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (engineVersion < 20151027)
|
||||
{
|
||||
if (node.Key == "Color" || node.Key == "ReadyTextAltColor" || node.Key == "TextColor" || node.Key == "TextColorDisabled")
|
||||
{
|
||||
if (parent.Key.StartsWith("MapPreview@"))
|
||||
TryUpdateHSLColor(ref node.Value.Value);
|
||||
else
|
||||
TryUpdateColor(ref node.Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeChromeLayout(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
|
||||
Reference in New Issue
Block a user