diff --git a/OpenRA.FileFormats/PlayerColorRemap.cs b/OpenRA.FileFormats/PlayerColorRemap.cs index dd071ca122..e318096952 100755 --- a/OpenRA.FileFormats/PlayerColorRemap.cs +++ b/OpenRA.FileFormats/PlayerColorRemap.cs @@ -14,40 +14,34 @@ using System.Linq; namespace OpenRA.FileFormats { - // TODO: ship this out of here. - public enum PaletteFormat { ra, cnc, d2k } public class PlayerColorRemap : IPaletteRemap { Dictionary remapColors; - 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 }; - - static int GetRemapBase(PaletteFormat fmt) + static int[] GetRemapRamp(int[] Ramp) { - return (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80; + int[] RemapRamp = new int[Ramp.Length]; + for (var i=0; i < Ramp.Length; i++) + RemapRamp[i] = Ramp[i] - Ramp[0]; + + return RemapRamp; } - static int[] GetRemapRamp(PaletteFormat fmt) + public static int GetRemapIndex(int[] Ramp, int i) { - return (fmt == PaletteFormat.cnc) ? CncRemapRamp : NormalRemapRamp; + return Ramp[i]; } - public static int GetRemapIndex(PaletteFormat fmt, int i) - { - return GetRemapBase(fmt) + GetRemapRamp(fmt)[i]; - } - - public PlayerColorRemap(PaletteFormat fmt, ColorRamp c) + public PlayerColorRemap(int[] Ramp, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ - var baseIndex = GetRemapBase(fmt); - var ramp = GetRemapRamp(fmt); + var baseIndex = Ramp[0]; + var RemapRamp = GetRemapRamp(Ramp); - remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) + remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); } diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index 19c7d256af..6aaf6b5fc8 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -17,7 +17,7 @@ namespace OpenRA.Traits { public readonly string BasePalette = null; public readonly string BaseName = "player"; - public readonly PaletteFormat PaletteFormat = PaletteFormat.ra; + public readonly int[] RemapIndex = new[] {}; public object Create( ActorInitializer init ) { return new PlayerColorPalette( init.self.Owner, this ); } } @@ -37,7 +37,7 @@ namespace OpenRA.Traits { var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName ); var newpal = new Palette(wr.GetPalette(info.BasePalette), - new PlayerColorRemap(info.PaletteFormat, owner.ColorRamp)); + new PlayerColorRemap(info.RemapIndex, owner.ColorRamp)); wr.AddPalette(paletteName, newpal); } } diff --git a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs index 2f4f9937bd..ba343c9d53 100644 --- a/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs +++ b/OpenRA.Mods.RA/ColorPickerPaletteModifier.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA public class ColorPickerPaletteModifier : IPalette, IPaletteModifier { ColorPickerPaletteModifierInfo Info; - PaletteFormat format; + int[] index; public ColorRamp Ramp; public ColorPickerPaletteModifier(ColorPickerPaletteModifierInfo info) { Info = info; } @@ -34,14 +34,14 @@ namespace OpenRA.Mods.RA { var info = Rules.Info["player"].Traits.WithInterface() .First(p => p.BaseName == Info.PlayerPalette); - format = info.PaletteFormat; + index = info.RemapIndex; wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette)); } public void AdjustPalette(Dictionary palettes) { palettes["colorpicker"] = new Palette(palettes["colorpicker"], - new PlayerColorRemap(format, Ramp)); + new PlayerColorRemap(index, Ramp)); } } } diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 6fc2d02acc..3831273ccf 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -368,24 +368,25 @@ namespace OpenRA.Utility var remap = new Dictionary(); /* the first 4 entries are fixed */ - for( var i = 0; i < 4; i++ ) + for (var i = 0; i < 4; i++) remap[i] = i; - var srcPaletteType = Enum.Parse(args[1].Split(':')[0]); - var destPaletteType = Enum.Parse(args[2].Split(':')[0]); + // TODO: should read that from mods/*/system.yaml + var srcRemapIndex = Enum.Parse(args[1].Split(':')[0]); + var destRemapIndex = Enum.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.GetRemapIndex(srcPaletteType, i) ] - = PlayerColorRemap.GetRemapIndex(destPaletteType, i); + // the remap range is always 16 entries, but their location and order changes + for (var i = 0; i < 16; i++) + remap[PlayerColorRemap.GetRemapIndex(srcRemapIndex, i)] + = PlayerColorRemap.GetRemapIndex(destRemapIndex, i); - /* map everything else to the best match based on channel-wise distance */ + // map everything else to the best match based on channel-wise distance var srcPalette = Palette.Load(args[1].Split(':')[1], false); var destPalette = Palette.Load(args[2].Split(':')[1], false); var fullIndexRange = Exts.MakeArray(256, x => x); - for( var i = 0; i < 256; i++ ) + for (var i = 0; i < 256; i++) if (!remap.ContainsKey(i)) remap[i] = fullIndexRange .Where(a => !remap.ContainsValue(a)) @@ -394,7 +395,7 @@ namespace OpenRA.Utility var srcImage = ShpReader.Load(args[3]); - using( var destStream = File.Create(args[4]) ) + using (var destStream = File.Create(args[4])) ShpWriter.Write(destStream, srcImage.Width, srcImage.Height, srcImage.Frames.Select( im => im.Image.Select(px => (byte)remap[px]).ToArray() )); } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index d46783c004..08674a384c 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -60,7 +60,7 @@ namespace OpenRA.Utility Console.WriteLine(" --png SHPFILE PALETTE [--transparent] Convert a SHP to a PNG containing all of its frames, optionally setting up transparency"); Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages"); Console.WriteLine(" --tmp-png MOD[,MOD]* THEATER FILES Extract terrain tiles to PNG"); - Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette"); + Console.WriteLine(" --remap SRCREMAPINDEX:PAL DESTREMAPINDEX:PAL SRCSHP DESTSHP Remap SHPs to another palette"); Console.WriteLine(" --r8 R8FILE PALETTE START END FILENAME [--transparent] [--infrantry] [--vehicle] [--projectile] [--building] [--wall] [--tileset] Convert Dune 2000 DATA.R8 to PNGs choosing start- and endframe as well as type for correct offset to append multiple frames to one PNG named by filename optionally setting up transparency."); Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START."); } diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index 45ce795c21..9d0d944595 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -53,7 +53,7 @@ Player: orca: 5% PlayerColorPalette: BasePalette: terrain - PaletteFormat: cnc + RemapIndex: 176, 178, 180, 182, 184, 186, 189, 191, 177, 179, 181, 183, 185, 187, 188, 190 BaseAttackNotifier: World: diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index 6c57bc451c..2c27208c52 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -101,7 +101,7 @@ Player: SquadSize: 10 PlayerColorPalette: BasePalette: d2k - PaletteFormat: d2k + RemapIndex: 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 BaseAttackNotifier: Audio: AI_ATACK.AUD diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index a25b700feb..42c77b2350 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -185,6 +185,7 @@ Player: SquadSize: 7 PlayerColorPalette: BasePalette: terrain + RemapIndex: 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 DebugResourceCash: DebugResourceOre: DebugResourceOreCapacity: