Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework sequence documentation plumbing #20087

Merged
merged 2 commits into from Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions OpenRA.Mods.Cnc/Graphics/ClassicSpriteSequence.cs
Expand Up @@ -29,25 +29,24 @@ public override ISpriteSequence CreateSequence(ModData modData, string tileSet,
[Desc("A sprite sequence that has the oddities that come with first-generation Westwood titles.")]
public class ClassicSpriteSequence : DefaultSpriteSequence
{
// This needs to be a public property for the documentation generation to work.
[Desc("Incorporate a compensation factor due to the distortion caused by 3D-Studio " +
"when it tried to render 45% angles which was used by Westwood Studios at that time.")]
public bool UseClassicFacings { get; }
[Desc("Incorporate a compensation factor for the rotational distortion present in the first-generation Westwood games.")]
static readonly SpriteSequenceField<bool> UseClassicFacings = new SpriteSequenceField<bool>(nameof(UseClassicFacings), false);
readonly bool useClassicFacings;

public ClassicSpriteSequence(ModData modData, string tileSet, SpriteCache cache, ISpriteSequenceLoader loader, string sequence, string animation, MiniYaml info)
: base(modData, tileSet, cache, loader, sequence, animation, info)
{
var d = info.ToDictionary();
UseClassicFacings = LoadField(d, nameof(UseClassicFacings), UseClassicFacings);
useClassicFacings = LoadField(d, UseClassicFacings);

if (UseClassicFacings && Facings != 32)
if (useClassicFacings && facings != 32)
throw new InvalidOperationException(
$"{info.Nodes[0].Location}: Sequence {sequence}.{animation}: UseClassicFacings is only valid for 32 facings");
}

protected override int GetFacingFrameOffset(WAngle facing)
{
return UseClassicFacings ? Util.ClassicIndexFacing(facing, Facings) : Common.Util.IndexFacing(facing, Facings);
return useClassicFacings ? Util.ClassicIndexFacing(facing, facings) : Common.Util.IndexFacing(facing, facings);
}
}
}
23 changes: 11 additions & 12 deletions OpenRA.Mods.Cnc/Graphics/ClassicTilesetSpecificSpriteSequence.cs
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;

namespace OpenRA.Mods.Cnc.Graphics
{
Expand Down Expand Up @@ -45,21 +46,20 @@ public override ISpriteSequence CreateSequence(ModData modData, string tileSet,
"that come with first-generation Westwood titles.")]
public class ClassicTilesetSpecificSpriteSequence : ClassicSpriteSequence
{
// These need to be public properties for the documentation generation to work.
[Desc("Dictionary of <string: string> with tileset name to override -> tileset name to use instead.")]
public static Dictionary<string, string> TilesetOverrides => null;
static readonly SpriteSequenceField<Dictionary<string, string>> TilesetOverrides = new SpriteSequenceField<Dictionary<string, string>>(nameof(TilesetOverrides), null);

[Desc("Use `TilesetCodes` as defined in `mod.yaml` to add a letter as a second character " +
"into the sprite filename like the Westwood 2.5D titles did for tileset-specific variants.")]
public static bool UseTilesetCode => false;
"into the sprite filename like the Westwood 2.5D titles did for tileset-specific variants.")]
static readonly SpriteSequenceField<bool> UseTilesetCode = new SpriteSequenceField<bool>(nameof(UseTilesetCode), false);

[Desc("Append a tileset-specific extension to the file name " +
"- either as defined in `mod.yaml`'s `TilesetExtensions` (if `UseTilesetExtension` is used) " +
"or the default hardcoded one for this sequence type (.shp).")]
public static bool AddExtension => true;
"- either as defined in `mod.yaml`'s `TilesetExtensions` (if `UseTilesetExtension` is used) " +
"or the default hardcoded one for this sequence type (.shp).")]
static readonly SpriteSequenceField<bool> AddExtension = new SpriteSequenceField<bool>(nameof(AddExtension), true);

[Desc("Whether `mod.yaml`'s `TilesetExtensions` should be used with the sequence's file name.")]
public static bool UseTilesetExtension { get; private set; }
static readonly SpriteSequenceField<bool> UseTilesetExtension = new SpriteSequenceField<bool>(nameof(UseTilesetExtension), false);

public ClassicTilesetSpecificSpriteSequence(ModData modData, string tileSet, SpriteCache cache, ISpriteSequenceLoader loader, string sequence, string animation, MiniYaml info)
: base(modData, tileSet, cache, loader, sequence, animation, info) { }
Expand All @@ -82,16 +82,15 @@ protected override string GetSpriteSrc(ModData modData, string tileSet, string s

var spriteName = sprite ?? sequence;

if (LoadField(d, nameof(UseTilesetCode), UseTilesetCode))
if (LoadField(d, UseTilesetCode))
{
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}

if (LoadField(d, nameof(AddExtension), AddExtension))
if (LoadField(d, AddExtension))
{
UseTilesetExtension = LoadField(d, nameof(UseTilesetExtension), UseTilesetExtension);
if (UseTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
if (LoadField(d, UseTilesetExtension) && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
return spriteName + tilesetExtension;

return spriteName + loader.DefaultSpriteExtension;
Expand Down