remove some duplication and dead code
This commit is contained in:
@@ -181,5 +181,19 @@ namespace OpenRA
|
||||
{
|
||||
return ts.Concat(moreTs);
|
||||
}
|
||||
|
||||
public static Color ColorLerp(float t, Color c1, Color c2)
|
||||
{
|
||||
return Color.FromArgb(
|
||||
(int)(t * c2.A + (1 - t) * c1.A),
|
||||
(int)(t * c2.R + (1 - t) * c1.R),
|
||||
(int)(t * c2.G + (1 - t) * c1.G),
|
||||
(int)(t * c2.B + (1 - t) * c1.B));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Enum<T>
|
||||
{
|
||||
public static T Parse(string s) { return (T)Enum.Parse(typeof(T), s); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,21 @@ namespace OpenRA.FileFormats
|
||||
static readonly int[] CncRemapRamp = new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 };
|
||||
static readonly int[] NormalRemapRamp = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
|
||||
public static int GetRemapBase(PaletteFormat fmt)
|
||||
static int GetRemapBase(PaletteFormat fmt)
|
||||
{
|
||||
return (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
|
||||
}
|
||||
|
||||
public static int[] GetRemapRamp(PaletteFormat fmt)
|
||||
static int[] GetRemapRamp(PaletteFormat fmt)
|
||||
{
|
||||
return (fmt == PaletteFormat.cnc) ? CncRemapRamp : NormalRemapRamp;
|
||||
}
|
||||
|
||||
public static int GetRemapIndex(PaletteFormat fmt, int i)
|
||||
{
|
||||
return GetRemapBase(fmt) + GetRemapRamp(fmt)[i];
|
||||
}
|
||||
|
||||
public PlayerColorRemap(PaletteFormat fmt, ColorRamp c)
|
||||
{
|
||||
var c1 = c.GetColor(0);
|
||||
@@ -42,18 +47,10 @@ namespace OpenRA.FileFormats
|
||||
var baseIndex = GetRemapBase(fmt);
|
||||
var ramp = GetRemapRamp(fmt);
|
||||
|
||||
remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2)))
|
||||
remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
|
||||
.ToDictionary(u => u.First, u => u.Second);
|
||||
}
|
||||
|
||||
public static Color ColorLerp(float t, Color c1, Color c2)
|
||||
{
|
||||
return Color.FromArgb(255,
|
||||
(int)(t * c2.R + (1 - t) * c1.R),
|
||||
(int)(t * c2.G + (1 - t) * c1.G),
|
||||
(int)(t * c2.B + (1 - t) * c1.B));
|
||||
}
|
||||
|
||||
public Color GetRemappedColor(Color original, int index)
|
||||
{
|
||||
Color c;
|
||||
|
||||
@@ -19,21 +19,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
public static string[] ReadAllLines(Stream s)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
using (StreamReader reader = new StreamReader(s))
|
||||
while(!reader.EndOfStream)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
if( !string.IsNullOrEmpty( line ) && line[0] != '#' )
|
||||
result.Add( line );
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static T[] MakeArray<T>(int count, Converter<int, T> f)
|
||||
public static T[] MakeArray<T>(int count, Func<int, T> f)
|
||||
{
|
||||
T[] result = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
@@ -59,6 +45,7 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
|
||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
||||
|
||||
public static void FastCopyIntoChannel(Sprite dest, byte[] src)
|
||||
{
|
||||
var data = dest.sheet.Data;
|
||||
@@ -79,28 +66,5 @@ namespace OpenRA.Graphics
|
||||
destOffset += destSkip;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color Lerp(float t, Color a, Color b)
|
||||
{
|
||||
return Color.FromArgb(
|
||||
LerpChannel(t, a.A, b.A),
|
||||
LerpChannel(t, a.R, b.R),
|
||||
LerpChannel(t, a.G, b.G),
|
||||
LerpChannel(t, a.B, b.B));
|
||||
}
|
||||
|
||||
public static int LerpARGBColor(float t, int c1, int c2)
|
||||
{
|
||||
int a = LerpChannel(t, (c1 >> 24) & 255, (c2 >> 24) & 255);
|
||||
int r = LerpChannel(t, (c1 >> 16) & 255, (c2 >> 16) & 255);
|
||||
int g = LerpChannel(t, (c1 >> 8) & 255, (c2 >> 8) & 255);
|
||||
int b = LerpChannel(t, c1 & 255, c2 & 255);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public static int LerpChannel(float t, int a, int b)
|
||||
{
|
||||
return (int)((1 - t) * a + t * b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Cnc
|
||||
else
|
||||
{
|
||||
var f = ColorForEffect(from, orig);
|
||||
pal.Value.SetColor(x, OpenRA.Graphics.Util.Lerp((float)remainingFrames / Info.FadeLength, t, f));
|
||||
pal.Value.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace OpenRA.Mods.RA
|
||||
if (remainingFrames > 0)
|
||||
remainingFrames--;
|
||||
}
|
||||
|
||||
static List<string> excludePalettes = new List<string>{"cursor", "chrome", "colorpicker", "shroud", "fog"};
|
||||
|
||||
public void AdjustPalette(Dictionary<string,Palette> palettes)
|
||||
{
|
||||
@@ -39,7 +41,7 @@ namespace OpenRA.Mods.RA
|
||||
return;
|
||||
|
||||
var frac = (float)remainingFrames / chronoEffectLength;
|
||||
var excludePalettes = new List<string>(){"cursor", "chrome", "colorpicker", "shroud", "fog"};
|
||||
|
||||
foreach (var pal in palettes)
|
||||
{
|
||||
if (excludePalettes.Contains(pal.Key))
|
||||
@@ -50,7 +52,7 @@ namespace OpenRA.Mods.RA
|
||||
var orig = pal.Value.GetColor(x);
|
||||
var lum = (int)(255 * orig.GetBrightness());
|
||||
var desat = Color.FromArgb(orig.A, lum, lum, lum);
|
||||
pal.Value.SetColor(x, OpenRA.Graphics.Util.Lerp(frac, orig, desat));
|
||||
pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, desat));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
|
||||
public static Color ChooseColor(Actor self)
|
||||
{
|
||||
var ownerColor = Color.FromArgb(255, self.Owner.ColorRamp.GetColor(0));
|
||||
return PlayerColorRemap.ColorLerp(0.5f, ownerColor, Color.White);
|
||||
return Exts.ColorLerp(0.5f, ownerColor, Color.White);
|
||||
}
|
||||
|
||||
public ContrailHistory(int trailLength, Color color)
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace OpenRA.Mods.RA
|
||||
if (remainingFrames > 0)
|
||||
remainingFrames--;
|
||||
}
|
||||
|
||||
static List<string> excludePalettes = new List<string>{ "cursor", "chrome", "colorpicker", "shroud", "fog" };
|
||||
|
||||
public void AdjustPalette(Dictionary<string,Palette> palettes)
|
||||
{
|
||||
@@ -40,7 +42,6 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
var frac = (float)remainingFrames / nukeEffectLength;
|
||||
|
||||
var excludePalettes = new List<string>(){"cursor", "chrome", "colorpicker", "shroud", "fog"};
|
||||
foreach (var pal in palettes)
|
||||
{
|
||||
if (excludePalettes.Contains(pal.Key))
|
||||
@@ -50,7 +51,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var orig = pal.Value.GetColor(x);
|
||||
var white = Color.FromArgb(orig.A, 255, 255, 255);
|
||||
pal.Value.SetColor(x, OpenRA.Graphics.Util.Lerp(frac,orig,white));
|
||||
pal.Value.SetColor(x, Exts.ColorLerp(frac,orig,white));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
var color = GetPowerColor(power);
|
||||
|
||||
var colorDark = Graphics.Util.Lerp(0.25f, color, Color.Black);
|
||||
var colorDark = Exts.ColorLerp(0.25f, color, Color.Black);
|
||||
for (int i = 0; i < powerSize.Height; i++)
|
||||
{
|
||||
color = (i - 1 < powerSize.Height / 2) ? color : colorDark;
|
||||
|
||||
@@ -15,7 +15,6 @@ using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using OpenRA.GameRules;
|
||||
@@ -190,13 +189,13 @@ namespace OpenRA.Utility
|
||||
for( var i = 0; i < 4; i++ )
|
||||
remap[i] = i;
|
||||
|
||||
var srcPaletteType = (PaletteFormat)Enum.Parse(typeof(PaletteFormat), args[1].Split(':')[0]);
|
||||
var destPaletteType = (PaletteFormat)Enum.Parse(typeof(PaletteFormat), args[2].Split(':')[0]);
|
||||
var srcPaletteType = Enum<PaletteFormat>.Parse(args[1].Split(':')[0]);
|
||||
var destPaletteType = Enum<PaletteFormat>.Parse(args[2].Split(':')[0]);
|
||||
|
||||
/* the remap range is always 16 entries, but their location and order changes */
|
||||
for( var i = 0; i < 16; i++ )
|
||||
remap[ PlayerColorRemap.GetRemapBase(srcPaletteType) + PlayerColorRemap.GetRemapRamp(srcPaletteType)[i] ]
|
||||
= PlayerColorRemap.GetRemapBase(destPaletteType) + PlayerColorRemap.GetRemapRamp(destPaletteType)[i];
|
||||
remap[ PlayerColorRemap.GetRemapIndex(srcPaletteType, i) ]
|
||||
= PlayerColorRemap.GetRemapIndex(destPaletteType, i);
|
||||
|
||||
/* map everything else to the best match based on channel-wise distance */
|
||||
var srcPalette = Palette.Load(args[1].Split(':')[1], false);
|
||||
|
||||
Reference in New Issue
Block a user