Move ClassicFacingFudge support to Mods.Cnc

This moves the TD/RA-specific re-mapping of sprite facings
and coordinates to Mods.Cnc.
This commit is contained in:
reaperrr
2020-01-31 14:54:57 +01:00
committed by abcdefg30
parent bc9b3bef74
commit c10487d635
12 changed files with 237 additions and 51 deletions

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 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;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
namespace OpenRA.Mods.Cnc.Graphics
{
public class ClassicSpriteSequenceLoader : DefaultSpriteSequenceLoader
{
public ClassicSpriteSequenceLoader(ModData modData)
: base(modData) { }
public override ISpriteSequence CreateSequence(ModData modData, TileSet tileSet, SpriteCache cache, string sequence, string animation, MiniYaml info)
{
return new ClassicSpriteSequence(modData, tileSet, cache, this, sequence, animation, info);
}
}
public class ClassicSpriteSequence : DefaultSpriteSequence
{
readonly bool useClassicFacings;
public ClassicSpriteSequence(ModData modData, TileSet 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, "UseClassicFacings", false);
if (useClassicFacings && Facings != 32)
throw new InvalidOperationException(
"{0}: Sequence {1}.{2}: UseClassicFacings is only valid for 32 facings"
.F(info.Nodes[0].Location, sequence, animation));
}
protected override int QuantizeFacing(int facing)
{
return OpenRA.Mods.Cnc.Util.ClassicQuantizeFacing(facing, Facings, useClassicFacings);
}
}
}

View File

@@ -0,0 +1,92 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 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;
using System.Linq;
using OpenRA.Graphics;
namespace OpenRA.Mods.Cnc.Graphics
{
public class ClassicTilesetSpecificSpriteSequenceLoader : ClassicSpriteSequenceLoader
{
public readonly string DefaultSpriteExtension = ".shp";
public readonly Dictionary<string, string> TilesetExtensions = new Dictionary<string, string>();
public readonly Dictionary<string, string> TilesetCodes = new Dictionary<string, string>();
public ClassicTilesetSpecificSpriteSequenceLoader(ModData modData)
: base(modData)
{
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
MiniYaml yaml;
if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
DefaultSpriteExtension = yaml.Value;
if (metadata.TryGetValue("TilesetExtensions", out yaml))
TilesetExtensions = yaml.ToDictionary(kv => kv.Value);
if (metadata.TryGetValue("TilesetCodes", out yaml))
TilesetCodes = yaml.ToDictionary(kv => kv.Value);
}
public override ISpriteSequence CreateSequence(ModData modData, TileSet tileSet, SpriteCache cache, string sequence, string animation, MiniYaml info)
{
return new ClassicTilesetSpecificSpriteSequence(modData, tileSet, cache, this, sequence, animation, info);
}
}
public class ClassicTilesetSpecificSpriteSequence : ClassicSpriteSequence
{
public ClassicTilesetSpecificSpriteSequence(ModData modData, TileSet tileSet, SpriteCache cache, ISpriteSequenceLoader loader, string sequence, string animation, MiniYaml info)
: base(modData, tileSet, cache, loader, sequence, animation, info) { }
string ResolveTilesetId(TileSet tileSet, Dictionary<string, MiniYaml> d)
{
var tsId = tileSet.Id;
MiniYaml yaml;
if (d.TryGetValue("TilesetOverrides", out yaml))
{
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
if (tsNode != null)
tsId = tsNode.Value.Value;
}
return tsId;
}
protected override string GetSpriteSrc(ModData modData, TileSet tileSet, string sequence, string animation, string sprite, Dictionary<string, MiniYaml> d)
{
var loader = (ClassicTilesetSpecificSpriteSequenceLoader)Loader;
var spriteName = sprite ?? sequence;
if (LoadField(d, "UseTilesetCode", false))
{
string code;
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
}
if (LoadField(d, "AddExtension", true))
{
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
string tilesetExtension;
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
return spriteName + tilesetExtension;
return spriteName + loader.DefaultSpriteExtension;
}
return spriteName;
}
}
}

View File

@@ -74,8 +74,8 @@ namespace OpenRA.Mods.Cnc.Graphics
t[14] *= l.Scale * (l.Bounds[5] - l.Bounds[2]) / l.Size[2];
// Center, flip and scale
t = Util.MatrixMultiply(t, Util.TranslationMatrix(l.Bounds[0], l.Bounds[1], l.Bounds[2]));
t = Util.MatrixMultiply(Util.ScaleMatrix(l.Scale, -l.Scale, l.Scale), t);
t = OpenRA.Graphics.Util.MatrixMultiply(t, OpenRA.Graphics.Util.TranslationMatrix(l.Bounds[0], l.Bounds[1], l.Bounds[2]));
t = OpenRA.Graphics.Util.MatrixMultiply(OpenRA.Graphics.Util.ScaleMatrix(l.Scale, -l.Scale, l.Scale), t);
return t;
}
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Cnc.Graphics
};
// Calculate limb bounding box
var bb = Util.MatrixAABBMultiply(TransformationMatrix(j, frame), b);
var bb = OpenRA.Graphics.Util.MatrixAABBMultiply(TransformationMatrix(j, frame), b);
for (var i = 0; i < 3; i++)
{
ret[i] = Math.Min(ret[i], bb[i]);

View File

@@ -77,8 +77,8 @@ namespace OpenRA.Mods.Cnc.Graphics
var size = new Size(su, sv);
var s = sheetBuilder.Allocate(size);
var t = sheetBuilder.Allocate(size);
Util.FastCopyIntoChannel(s, colors);
Util.FastCopyIntoChannel(t, normals);
OpenRA.Graphics.Util.FastCopyIntoChannel(s, colors);
OpenRA.Graphics.Util.FastCopyIntoChannel(t, normals);
// s and t are guaranteed to use the same sheet because
// of the custom voxel sheet allocation implementation