Allow terrain depth sprites to be loaded from a second file.

This commit is contained in:
Paul Chote
2020-12-29 15:04:29 +00:00
committed by reaperrr
parent 632af7c7e6
commit 223a0015a6
2 changed files with 27 additions and 3 deletions

View File

@@ -37,6 +37,7 @@ namespace OpenRA.Mods.Common.Terrain
public class DefaultTerrainTemplateInfo : TerrainTemplateInfo
{
public readonly string[] Images;
public readonly string[] DepthImages;
public readonly int[] Frames;
public readonly string Palette;

View File

@@ -52,9 +52,13 @@ namespace OpenRA.Mods.Common.Terrain
var variants = new List<Sprite[]>();
var templateInfo = (DefaultTerrainTemplateInfo)t.Value;
foreach (var i in templateInfo.Images)
for (var ii = 0; ii < templateInfo.Images.Length; ii++)
{
var i = templateInfo.Images[ii];
ISpriteFrame[] allFrames;
ISpriteFrame[] depthFrames = null;
if (onMissingImage != null)
{
try
@@ -70,7 +74,26 @@ namespace OpenRA.Mods.Common.Terrain
else
allFrames = frameCache[i];
var frameCount = terrainInfo.EnableDepth ? allFrames.Length / 2 : allFrames.Length;
if (terrainInfo.EnableDepth && templateInfo.DepthImages != null && templateInfo.DepthImages.Length == templateInfo.Images.Length)
{
var di = templateInfo.DepthImages[ii];
if (onMissingImage != null)
{
try
{
depthFrames = frameCache[di];
}
catch (FileNotFoundException)
{
onMissingImage(t.Key, di);
continue;
}
}
else
depthFrames = frameCache[di];
}
var frameCount = terrainInfo.EnableDepth && depthFrames == null ? allFrames.Length / 2 : allFrames.Length;
var indices = templateInfo.Frames != null ? templateInfo.Frames : Exts.MakeArray(t.Value.TilesCount, j => j);
var start = indices.Min();
@@ -95,7 +118,7 @@ namespace OpenRA.Mods.Common.Terrain
if (terrainInfo.EnableDepth)
{
var depthFrame = allFrames[j + frameCount];
var depthFrame = depthFrames != null ? depthFrames[j] : allFrames[j + frameCount];
var depthType = SheetBuilder.FrameTypeToSheetType(depthFrame.Type);
var ss = sheetBuilders[depthType].Allocate(depthFrame.Size, zRamp, offset);
OpenRA.Graphics.Util.FastCopyIntoChannel(ss, depthFrame.Data, depthFrame.Type);