Skip to content

Commit

Permalink
Replace Sequence EmbeddedPalette with HasEmbeddedPalette.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jun 26, 2022
1 parent c3c5dbf commit 6f0469d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
14 changes: 7 additions & 7 deletions OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs
Expand Up @@ -212,10 +212,10 @@ public class DefaultSpriteSequence : ISpriteSequence
[Desc("")]
public static float2 DepthSpriteOffset => float2.Zero;

[Desc("Use the palette embedded in the defined sprite. (Note: The name given here is actually irrelevant)")]
public static string EmbeddedPalette => null;
[Desc("Make a custom palette embedded in the sprite available to the PaletteFromEmbeddedSpritePalette trait.")]
public static bool HasEmbeddedPalette => false;

public readonly uint[] EmbeddedPaletteData;
public readonly uint[] EmbeddedPalette;

protected virtual string GetSpriteSrc(ModData modData, string tileSet, string sequence, string animation, string sprite, Dictionary<string, MiniYaml> d)
{
Expand Down Expand Up @@ -436,16 +436,16 @@ public DefaultSpriteSequence(ModData modData, string tileSet, SpriteCache cache,
}).ToArray();
}

var exportPalette = LoadField<string>(d, nameof(EmbeddedPalette), null);
if (exportPalette != null)
var hasEmbeddedPalette = LoadField<bool>(d, nameof(HasEmbeddedPalette), HasEmbeddedPalette);
if (hasEmbeddedPalette)
{
var src = GetSpriteSrc(modData, tileSet, sequence, animation, info.Value, d);

var metadata = cache.FrameMetadata(src);
var i = Frames != null ? Frames[0] : Start;
var palettes = metadata?.GetOrDefault<EmbeddedSpritePalette>();
if (palettes == null || !palettes.TryGetPaletteForFrame(i, out EmbeddedPaletteData))
throw new YamlException($"Cannot export palettes from {src}: frame {i} does not define an embedded palette");
if (palettes == null || !palettes.TryGetPaletteForFrame(i, out EmbeddedPalette))
throw new YamlException($"Cannot export palette from {src}: frame {i} does not define an embedded palette");
}

var boundSprites = SpriteBounds(sprites, Frames, Start, Facings, Length, Stride, transpose);
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class PaletteFromEmbeddedSpritePaletteInfo : TraitInfo, IProvidesCursorPa
ImmutablePalette IProvidesCursorPaletteInfo.ReadPalette(IReadOnlyFileSystem fileSystem)
{
var sequence = (DefaultSpriteSequence)Game.ModData.DefaultSequences.Values.First().GetSequence(Image, Sequence);
return new ImmutablePalette(sequence.EmbeddedPaletteData);
return new ImmutablePalette(sequence.EmbeddedPalette);
}
}

Expand All @@ -59,7 +59,7 @@ public class PaletteFromEmbeddedSpritePalette : ILoadsPalettes, IProvidesAssetBr
public void LoadPalettes(WorldRenderer wr)
{
var sequence = (DefaultSpriteSequence)wr.World.Map.Rules.Sequences.GetSequence(info.Image, info.Sequence);
wr.AddPalette(info.Name, new ImmutablePalette(sequence.EmbeddedPaletteData), info.AllowModifiers);
wr.AddPalette(info.Name, new ImmutablePalette(sequence.EmbeddedPalette), info.AllowModifiers);
}

public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
Expand Down
@@ -0,0 +1,31 @@
#region Copyright & License Information
/*
* 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
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;

namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class ReplaceSequenceEmbeddedPalette : UpdateRule
{
public override string Name => "Replace Sequence EmbeddedPalette with HasEmbeddedPalette.";

public override string Description => "The EmbeddedPalette sequence option was replaced with a boolean HasEmbeddedPalette.";

public override IEnumerable<string> UpdateSequenceNode(ModData modData, MiniYamlNode sequenceNode)
{
foreach (var sequence in sequenceNode.Value.Nodes)
if (sequence.RemoveNodes("EmbeddedPalette") > 0)
sequence.AddNode("HasEmbeddedPalette", true);

yield break;
}
}
}
1 change: 1 addition & 0 deletions OpenRA.Mods.Common/UpdateRules/UpdatePath.cs
Expand Up @@ -93,6 +93,7 @@ public class UpdatePath
new AttackFrontalFacingTolerance(),
new RenameCloakTypes(),
new SplitNukePowerMissileImage(),
new ReplaceSequenceEmbeddedPalette(),
})
};

Expand Down
4 changes: 2 additions & 2 deletions mods/d2k/sequences/misc.yaml
Expand Up @@ -441,7 +441,7 @@ moveflsh:
Tick: 80
BlendMode: Multiply
ZOffset: 2047
EmbeddedPalette: moveflash
HasEmbeddedPalette: True

resources:
spicea: BLOXBASE.R8
Expand All @@ -468,7 +468,7 @@ shroud:
Length: 14
palette: DATA.R8
Start: 38
EmbeddedPalette: shroud
HasEmbeddedPalette: True
shrouda: DATA.R8
Start: 40
shroudb: DATA.R8
Expand Down

0 comments on commit 6f0469d

Please sign in to comment.