diff --git a/OpenRA.Game/Graphics/SpriteSource.cs b/OpenRA.Game/Graphics/SpriteSource.cs index 09c6f35e95..bf81824d60 100644 --- a/OpenRA.Game/Graphics/SpriteSource.cs +++ b/OpenRA.Game/Graphics/SpriteSource.cs @@ -15,7 +15,7 @@ using OpenRA.FileFormats; namespace OpenRA.Graphics { // TODO: Most of this should be moved into the format parsers themselves. - public enum SpriteType { Unknown, ShpD2, TmpTD, TmpRA, TmpTS, R8 } + public enum SpriteType { Unknown, ShpD2, TmpTD, TmpRA, TmpTS } public static class SpriteSource { static bool IsTmpRA(Stream s) @@ -104,30 +104,8 @@ namespace OpenRA.Graphics return b == 5 || b <= 3; } - static bool IsR8(Stream s) - { - var start = s.Position; - - // First byte is nonzero - if (s.ReadUInt8() == 0) - { - s.Position = start; - return false; - } - - // Check the format of the first frame - s.Position = start + 25; - var d = s.ReadUInt8(); - - s.Position = start; - return d == 8; - } - public static SpriteType DetectSpriteType(Stream s) { - if (IsR8(s)) - return SpriteType.R8; - if (IsTmpRA(s)) return SpriteType.TmpRA; @@ -148,8 +126,6 @@ namespace OpenRA.Graphics var type = DetectSpriteType(s); switch (type) { - case SpriteType.R8: - return new R8Reader(s); case SpriteType.TmpRA: return new TmpRAReader(s); case SpriteType.TmpTD: diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 83112e9a2d..11f17a7361 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -277,7 +277,6 @@ - diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index e547daf283..9dc1baf04c 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -84,6 +84,7 @@ + diff --git a/OpenRA.Game/FileFormats/R8Reader.cs b/OpenRA.Mods.D2k/R8Loader.cs similarity index 66% rename from OpenRA.Game/FileFormats/R8Reader.cs rename to OpenRA.Mods.D2k/R8Loader.cs index fdb6c78623..89ac184489 100644 --- a/OpenRA.Game/FileFormats/R8Reader.cs +++ b/OpenRA.Mods.D2k/R8Loader.cs @@ -1,23 +1,25 @@ #region Copyright & License Information /* * Copyright 2007-2014 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made + * 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. For more information, * see COPYING. */ #endregion +using System; using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using OpenRA.Graphics; -namespace OpenRA.FileFormats +namespace OpenRA.Mods.D2k.SpriteLoaders { - public class R8Reader : ISpriteSource + public class R8Loader : ISpriteLoader { - class R8Image : ISpriteFrame + class R8Frame : ISpriteFrame { public Size Size { get; private set; } public Size FrameSize { get; private set; } @@ -25,7 +27,7 @@ namespace OpenRA.FileFormats public byte[] Data { get; set; } public bool DisableExportPadding { get { return true; } } - public R8Image(Stream s) + public R8Frame(Stream s) { // Scan forward until we find some data var type = s.ReadUInt8(); @@ -62,19 +64,41 @@ namespace OpenRA.FileFormats } } - public IReadOnlyList Frames { get; private set; } - - public readonly int ImageCount; - public R8Reader(Stream stream) + bool IsR8(Stream s) { - var frames = new List(); - while (stream.Position < stream.Length) + var start = s.Position; + + // First byte is nonzero + if (s.ReadUInt8() == 0) { - frames.Add(new R8Image(stream)); - ImageCount++; + s.Position = start; + return false; } - Frames = frames.ToArray().AsReadOnly(); + // Check the format of the first frame + s.Position = start + 25; + var d = s.ReadUInt8(); + + s.Position = start; + return d == 8; + } + + public bool TryParseSprite(Stream s, out ISpriteFrame[] frames) + { + if (!IsR8(s)) + { + frames = null; + return false; + } + + var start = s.Position; + var tmp = new List(); + while (s.Position < s.Length) + tmp.Add(new R8Frame(s)); + s.Position = start; + + frames = tmp.ToArray(); + return true; } } } diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index daf9be261f..7cb31d3585 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -189,4 +189,4 @@ LuaScripts: SupportsMapsFrom: d2k -SpriteFormats: ShpTD \ No newline at end of file +SpriteFormats: R8, ShpTD \ No newline at end of file