diff --git a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs index 11eccbb3a9..6d3af86990 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/ColorPickerPalette.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; @@ -31,7 +32,6 @@ namespace OpenRA.Mods.Common.Traits [Desc("The name of the palette to base off.")] public readonly string BasePalette = null; - [FieldLoader.Require] [Desc("Remap these indices to player colors.")] public readonly int[] RemapIndex = Array.Empty(); @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits { color = colorManager.Color; var (_, h, s, _) = color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap), info.AllowModifiers); } @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits color = colorManager.Color; var (_, h, s, _) = color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); wr.ReplacePalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap)); } } diff --git a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs index e856bcd214..a0b7bc879c 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/FixedColorPalette.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; @@ -53,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits { var (_, h, s, _) = info.Color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers); } } diff --git a/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs index c5f4ba7a7e..8a2500ed62 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/IndexedPlayerPalette.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; @@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits public void RulesetLoaded(Ruleset rules, ActorInfo ai) { foreach (var p in PlayerIndex) - if (p.Value.Length != RemapIndex.Length) + if (p.Value.Length != (RemapIndex.Length == 0 ? 256 : RemapIndex.Length)) throw new YamlException($"PlayerIndex for player `{p.Key}` length does not match RemapIndex!"); } } @@ -62,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits ImmutablePalette pal; if (info.PlayerIndex.TryGetValue(playerName, out var remap)) - pal = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.RemapIndex, remap)); + pal = new ImmutablePalette(basePalette, new IndexedColorRemap(basePalette, info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, remap)); else pal = new ImmutablePalette(basePalette); diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs index dd5103ad1e..f309626cf5 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromFile.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits { [PaletteDefinition] [FieldLoader.Require] - [Desc("internal palette name")] + [Desc("Internal palette name")] public readonly string Name = null; [Desc("If defined, load the palette only for this tileset.")] diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs index ce30b98fd9..0c617b7b36 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromGrayscale.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2021 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2022 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; @@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits { [PaletteDefinition] [FieldLoader.Require] - [Desc("internal palette name")] + [Desc("Internal palette name")] public readonly string Name = null; [Desc("If defined, load the palette only for this tileset.")] @@ -49,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { // Enable palette only for a specific tileset - if (info.Tileset != null && !string.Equals(info.Tileset, world.Map.Tileset, System.StringComparison.InvariantCultureIgnoreCase)) + if (info.Tileset != null && !string.Equals(info.Tileset, world.Map.Tileset, StringComparison.InvariantCultureIgnoreCase)) return; wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == info.TransparentIndex) ? 0 : (uint)Color.FromArgb(255, i, i, i).ToArgb())), info.AllowModifiers); diff --git a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromRGBA.cs b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromRGBA.cs index 56461defe8..a0aa5db518 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PaletteFromRGBA.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PaletteFromRGBA.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; @@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits { [PaletteDefinition] [FieldLoader.Require] - [Desc("internal palette name")] + [Desc("Internal palette name")] public readonly string Name = null; [Desc("If defined, load the palette only for this tileset.")] @@ -61,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits public void LoadPalettes(WorldRenderer wr) { // Enable palette only for a specific tileset - if (info.Tileset != null && !string.Equals(info.Tileset, world.Map.Tileset, System.StringComparison.InvariantCultureIgnoreCase)) + if (info.Tileset != null && !string.Equals(info.Tileset, world.Map.Tileset, StringComparison.InvariantCultureIgnoreCase)) return; var a = info.A / 255f; diff --git a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs index 9aa0ec5610..9ec11b9b7d 100644 --- a/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs +++ b/OpenRA.Mods.Common/Traits/Palettes/PlayerColorPalette.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Linq; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; @@ -50,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits { var (_, h, s, _) = color.ToAhsv(); - var remap = new PlayerColorRemap(info.RemapIndex, h, s); + var remap = new PlayerColorRemap(info.RemapIndex.Length == 0 ? Enumerable.Range(0, 256).ToArray() : info.RemapIndex, h, s); var pal = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap); wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting); }