Skip to content

Commit

Permalink
Remove HSLColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Feb 18, 2019
1 parent bd3131f commit 64d577b
Show file tree
Hide file tree
Showing 76 changed files with 256 additions and 416 deletions.
23 changes: 2 additions & 21 deletions OpenRA.Game/FieldLoader.cs
Expand Up @@ -228,7 +228,7 @@ public static object GetValue(string fieldName, Type fieldType, MiniYaml yaml, M
else if (fieldType == typeof(Color))
{
Color color;
if (value != null && HSLColor.TryParseRGB(value, out color))
if (value != null && Color.TryParse(value, out color))
return color;

return InvalidValueAction(value, fieldType, fieldName);
Expand All @@ -241,33 +241,14 @@ public static object GetValue(string fieldName, Type fieldType, MiniYaml yaml, M
var colors = new Color[parts.Length];

for (var i = 0; i < colors.Length; i++)
if (!HSLColor.TryParseRGB(parts[i], out colors[i]))
if (!Color.TryParse(parts[i], out colors[i]))
return InvalidValueAction(value, fieldType, fieldName);

return colors;
}

return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(HSLColor))
{
if (value != null)
{
Color rgb;
if (HSLColor.TryParseRGB(value, out rgb))
return new HSLColor(rgb);

// Allow old HSLColor/ColorRamp formats to be parsed as HSLColor
var parts = value.Split(',');
if (parts.Length == 3 || parts.Length == 4)
return 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));
}

return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType == typeof(Hotkey))
{
Hotkey res;
Expand Down
9 changes: 1 addition & 8 deletions OpenRA.Game/FieldSaver.cs
Expand Up @@ -74,16 +74,9 @@ public static string FormatValue(object v)

var t = v.GetType();

// Color.ToString() does the wrong thing; force it to format as rgb[a] hex
if (t == typeof(Color))
{
return HSLColor.ToHexString((Color)v);
}

// HSLColor.ToString() does the wrong thing; force it to format as rgb[a] hex
if (t == typeof(HSLColor))
{
return ((HSLColor)v).ToHexString();
return ((Color)v).ToString();
}

if (t == typeof(Rectangle))
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/GameInformation.cs
Expand Up @@ -12,8 +12,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Primitives;

namespace OpenRA
{
Expand Down Expand Up @@ -155,7 +155,7 @@ public class Player

/// <summary>The faction ID, a.k.a. the faction's internal name.</summary>
public string FactionId;
public HSLColor Color;
public Color Color;

/// <summary>The team ID on start-up, or 0 if the player is not part of a team.</summary>
public int Team;
Expand Down
147 changes: 0 additions & 147 deletions OpenRA.Game/Graphics/HSLColor.cs

This file was deleted.

12 changes: 8 additions & 4 deletions OpenRA.Game/Graphics/PlayerColorRemap.cs
Expand Up @@ -25,12 +25,16 @@ public static int GetRemapIndex(int[] ramp, int i)
return ramp[i];
}

public PlayerColorRemap(int[] ramp, HSLColor c, float rampFraction)
public PlayerColorRemap(int[] ramp, Color c, float rampFraction)
{
var h = c.GetHue() / 360.0f;
var s = c.GetSaturation();
var l = c.GetBrightness();

// Increase luminosity if required to represent the full ramp
var rampRange = (byte)((1 - rampFraction) * c.L);
var c1 = new HSLColor(c.H, c.S, Math.Max(rampRange, c.L)).RGB;
var c2 = new HSLColor(c.H, c.S, (byte)Math.Max(0, c.L - rampRange)).RGB;
var rampRange = (byte)((1 - rampFraction) * l);
var c1 = Color.FromAhsl(h, s, Math.Max(rampRange, l));
var c2 = Color.FromAhsl(h, s, (byte)Math.Max(0, l - rampRange));
var baseIndex = ramp[0];
var remapRamp = ramp.Select(r => r - ramp[0]);
var rampMaxIndex = ramp.Length - 1;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Graphics/WorldRenderer.cs
Expand Up @@ -67,7 +67,7 @@ internal WorldRenderer(ModData modData, World world)
debugVis = Exts.Lazy(() => world.WorldActor.TraitOrDefault<DebugVisualizations>());
}

public void UpdatePalettesForPlayer(string internalName, HSLColor color, bool replaceExisting)
public void UpdatePalettesForPlayer(string internalName, Color color, bool replaceExisting)
{
foreach (var pal in World.WorldActor.TraitsImplementing<ILoadsPlayerPalettes>())
pal.LoadPlayerPalettes(this, internalName, color, replaceExisting);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Map/PlayerReference.cs
Expand Up @@ -9,7 +9,7 @@
*/
#endregion

using OpenRA.Graphics;
using OpenRA.Primitives;

namespace OpenRA
{
Expand All @@ -30,7 +30,7 @@ public class PlayerReference
public string Faction;

public bool LockColor = false;
public HSLColor Color = new HSLColor(0, 0, 238);
public Color Color = Color.FromAhsl(0, 0, 238);

public bool LockSpawn = false;
public int Spawn = 0;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Network/GameServer.cs
Expand Up @@ -13,15 +13,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using OpenRA.Graphics;
using OpenRA.Primitives;

namespace OpenRA.Network
{
public class GameClient
{
public readonly string Name;
public readonly string Fingerprint;
public readonly HSLColor Color;
public readonly Color Color;
public readonly string Faction;
public readonly int Team;
public readonly int SpawnPoint;
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Game/Network/Session.cs
Expand Up @@ -12,7 +12,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;

namespace OpenRA.Network
{
Expand Down Expand Up @@ -110,8 +110,8 @@ public static Client Deserialize(MiniYaml data)
}

public int Index;
public HSLColor PreferredColor; // Color that the client normally uses from settings.yaml.
public HSLColor Color; // Actual color that the client is using. Usually the same as PreferredColor but can be different on maps with locked colors.
public Color PreferredColor; // Color that the client normally uses from settings.yaml.
public Color Color; // Actual color that the client is using. Usually the same as PreferredColor but can be different on maps with locked colors.
public string Faction;
public int SpawnPoint;
public string Name;
Expand Down
10 changes: 5 additions & 5 deletions OpenRA.Game/Network/UnitOrders.cs
Expand Up @@ -58,7 +58,7 @@ internal static void ProcessOrder(OrderManager orderManager, World world, int cl
if (orderManager.LocalClient != null && client != orderManager.LocalClient && client.Team > 0 && client.Team == orderManager.LocalClient.Team)
suffix += " (Ally)";

Game.AddChatLine(client.Color.RGB, client.Name + suffix, message);
Game.AddChatLine(client.Color, client.Name + suffix, message);
}
else
Game.AddChatLine(Color.White, "(player {0})".F(clientId), message);
Expand Down Expand Up @@ -86,17 +86,17 @@ internal static void ProcessOrder(OrderManager orderManager, World world, int cl
if (world == null)
{
if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team)
Game.AddChatLine(client.Color.RGB, "[Team] " + client.Name, order.TargetString);
Game.AddChatLine(client.Color, "[Team] " + client.Name, order.TargetString);
}
else
{
var player = world.FindPlayerByClient(client);
if (player != null && player.WinState == WinState.Lost)
Game.AddChatLine(client.Color.RGB, client.Name + " (Dead)", order.TargetString);
Game.AddChatLine(client.Color, client.Name + " (Dead)", order.TargetString);
else if ((player != null && world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally) || (world.IsReplay && player != null))
Game.AddChatLine(client.Color.RGB, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, order.TargetString);
Game.AddChatLine(client.Color, "[Team" + (world.IsReplay ? " " + client.Team : "") + "] " + client.Name, order.TargetString);
else if ((orderManager.LocalClient != null && orderManager.LocalClient.IsObserver && client.IsObserver) || (world.IsReplay && client.IsObserver))
Game.AddChatLine(client.Color.RGB, "[Spectators] " + client.Name, order.TargetString);
Game.AddChatLine(client.Color, "[Spectators] " + client.Name, order.TargetString);
}
}

Expand Down
1 change: 0 additions & 1 deletion OpenRA.Game/OpenRA.Game.csproj
Expand Up @@ -296,7 +296,6 @@
<Compile Include="Map\Map.cs" />
<Compile Include="Map\MapCache.cs" />
<Compile Include="Map\MapPreview.cs" />
<Compile Include="Graphics\HSLColor.cs" />
<Compile Include="CPos.cs" />
<Compile Include="CVec.cs" />
<Compile Include="WAngle.cs" />
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Player.cs
Expand Up @@ -44,7 +44,7 @@ struct StanceColors
}

public readonly Actor PlayerActor;
public readonly HSLColor Color;
public readonly Color Color;

public readonly string PlayerName;
public readonly string InternalName;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/Server.cs
Expand Up @@ -378,7 +378,7 @@ void ValidateClient(Connection newConn, string data)
if (client.Slot != null)
SyncClientToPlayerReference(client, Map.Players.Players[client.Slot]);
else
client.Color = HSLColor.FromRGB(255, 255, 255);
client.Color = Color.White;
// Promote connection to a valid client
PreConns.Remove(newConn);
Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Game/Settings.cs
Expand Up @@ -14,6 +14,7 @@
using System.IO;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA
Expand Down Expand Up @@ -186,9 +187,9 @@ public class PlayerSettings
{
[Desc("Sets the player nickname for in-game and IRC chat.")]
public string Name = "Newbie";
public HSLColor Color = new HSLColor(75, 255, 180);
public Color Color = Color.FromAhsl(75, 255, 180);
public string LastServer = "localhost:1234";
public HSLColor[] CustomColors = { };
public Color[] CustomColors = { };
}

public class GameSettings
Expand Down

0 comments on commit 64d577b

Please sign in to comment.