Make ISpriteLoader aware of the source file name.

This commit is contained in:
Andre Mohren
2021-03-11 12:09:54 +01:00
committed by reaperrr
parent d60c05eff3
commit 3f510b6d93
13 changed files with 16 additions and 16 deletions

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
public interface ISpriteLoader public interface ISpriteLoader
{ {
bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata); bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata);
} }
public interface ISpriteFrame public interface ISpriteFrame
@@ -173,7 +173,7 @@ namespace OpenRA.Graphics
{ {
using (var stream = fileSystem.Open(filename)) using (var stream = fileSystem.Open(filename))
{ {
var spriteFrames = GetFrames(stream, loaders, out metadata); var spriteFrames = GetFrames(stream, loaders, filename, out metadata);
if (spriteFrames == null) if (spriteFrames == null)
throw new InvalidDataException(filename + " is not a valid sprite file!"); throw new InvalidDataException(filename + " is not a valid sprite file!");
@@ -181,12 +181,12 @@ namespace OpenRA.Graphics
} }
} }
public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, out TypeDictionary metadata) public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, string filename, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
foreach (var loader in loaders) foreach (var loader in loaders)
if (loader.TryParseSprite(stream, out var frames, out metadata)) if (loader.TryParseSprite(stream, filename, out var frames, out metadata))
return frames; return frames;
return null; return null;

View File

@@ -155,7 +155,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return frames; return frames;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsShpD2(s)) if (!IsShpD2(s))

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return isZipFile; return isZipFile;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsShpRemastered(s)) if (!IsShpRemastered(s))

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return b == 0x20 || b == 0x40 || b == 0x80; return b == 0x20 || b == 0x40 || b == 0x80;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsShpTD(s)) if (!IsShpTD(s))

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return tiles; return tiles;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsTmpRA(s)) if (!IsTmpRA(s))

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return tiles; return tiles;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsTmpTD(s)) if (!IsTmpTD(s))

View File

@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
return tiles; return tiles;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsTmpTS(s)) if (!IsTmpTS(s))

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
return isDds; return isDds;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsDds(s)) if (!IsDds(s))

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
public bool DisableExportPadding => false; public bool DisableExportPadding => false;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
frames = null; frames = null;

View File

@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
return frames; return frames;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsShpTS(s)) if (!IsShpTS(s))

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
} }
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsTga(s)) if (!IsTga(s))

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
for (var i = 0; i < Palette.Size; i++) for (var i = 0; i < Palette.Size; i++)
palColors[i] = palette.GetColor(i); palColors[i] = palette.GetColor(i);
var frames = FrameLoader.GetFrames(File.OpenRead(src), modData.SpriteLoaders, out _); var frames = FrameLoader.GetFrames(File.OpenRead(src), modData.SpriteLoaders, src, out _);
var usePadding = !args.Contains("--nopadding"); var usePadding = !args.Contains("--nopadding");
var count = 0; var count = 0;

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.D2k.SpriteLoaders
return d == 8; return d == 8;
} }
public bool TryParseSprite(Stream s, out ISpriteFrame[] frames, out TypeDictionary metadata) public bool TryParseSprite(Stream s, string filename, out ISpriteFrame[] frames, out TypeDictionary metadata)
{ {
metadata = null; metadata = null;
if (!IsR8(s)) if (!IsR8(s))