PlayerColorPalette now using the full palette if no RemapIndex is set.

This commit is contained in:
Andre Mohren
2022-05-26 10:58:26 +02:00
committed by Gustas
parent df72d303b8
commit 0e5f33ef93
7 changed files with 18 additions and 13 deletions

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -31,7 +32,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The name of the palette to base off.")] [Desc("The name of the palette to base off.")]
public readonly string BasePalette = null; public readonly string BasePalette = null;
[FieldLoader.Require]
[Desc("Remap these indices to player colors.")] [Desc("Remap these indices to player colors.")]
public readonly int[] RemapIndex = Array.Empty<int>(); public readonly int[] RemapIndex = Array.Empty<int>();
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
color = colorManager.Color; color = colorManager.Color;
var (_, h, s, _) = color.ToAhsv(); 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); 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; color = colorManager.Color;
var (_, h, s, _) = color.ToAhsv(); 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)); wr.ReplacePalette(info.Name, new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap));
} }
} }

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var (_, h, s, _) = info.Color.ToAhsv(); 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); wr.AddPalette(info.Name, new ImmutablePalette(wr.Palette(info.Base).Palette, remap), info.AllowModifiers);
} }
} }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
public void RulesetLoaded(Ruleset rules, ActorInfo ai) public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{ {
foreach (var p in PlayerIndex) 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!"); throw new YamlException($"PlayerIndex for player `{p.Key}` length does not match RemapIndex!");
} }
} }
@@ -62,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
ImmutablePalette pal; ImmutablePalette pal;
if (info.PlayerIndex.TryGetValue(playerName, out var remap)) 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 else
pal = new ImmutablePalette(basePalette); pal = new ImmutablePalette(basePalette);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
[PaletteDefinition] [PaletteDefinition]
[FieldLoader.Require] [FieldLoader.Require]
[Desc("internal palette name")] [Desc("Internal palette name")]
public readonly string Name = null; public readonly string Name = null;
[Desc("If defined, load the palette only for this tileset.")] [Desc("If defined, load the palette only for this tileset.")]

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of * as published by the Free Software Foundation, either version 3 of
@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
[PaletteDefinition] [PaletteDefinition]
[FieldLoader.Require] [FieldLoader.Require]
[Desc("internal palette name")] [Desc("Internal palette name")]
public readonly string Name = null; public readonly string Name = null;
[Desc("If defined, load the palette only for this tileset.")] [Desc("If defined, load the palette only for this tileset.")]
@@ -49,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public void LoadPalettes(WorldRenderer wr) public void LoadPalettes(WorldRenderer wr)
{ {
// Enable palette only for a specific tileset // 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; 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); 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);

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -22,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
[PaletteDefinition] [PaletteDefinition]
[FieldLoader.Require] [FieldLoader.Require]
[Desc("internal palette name")] [Desc("Internal palette name")]
public readonly string Name = null; public readonly string Name = null;
[Desc("If defined, load the palette only for this tileset.")] [Desc("If defined, load the palette only for this tileset.")]
@@ -61,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
public void LoadPalettes(WorldRenderer wr) public void LoadPalettes(WorldRenderer wr)
{ {
// Enable palette only for a specific tileset // 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; return;
var a = info.A / 255f; var a = info.A / 255f;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -50,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var (_, h, s, _) = color.ToAhsv(); 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); var pal = new ImmutablePalette(wr.Palette(info.BasePalette).Palette, remap);
wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting); wr.AddPalette(info.BaseName + playerName, pal, info.AllowModifiers, replaceExisting);
} }