diff --git a/OpenRA.Game/FileFormats/TmpTDReader.cs b/OpenRA.Game/FileFormats/TmpTDReader.cs deleted file mode 100644 index 44e8ca0872..0000000000 --- a/OpenRA.Game/FileFormats/TmpTDReader.cs +++ /dev/null @@ -1,70 +0,0 @@ -#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 - * 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.Drawing; -using System.IO; -using OpenRA.Graphics; - -namespace OpenRA.FileFormats -{ - public class TmpTile : ISpriteFrame - { - public Size Size { get; private set; } - public Size FrameSize { get; private set; } - public float2 Offset { get { return float2.Zero; } } - public byte[] Data { get; set; } - public bool DisableExportPadding { get { return false; } } - - public TmpTile(byte[] data, Size size) - { - FrameSize = size; - Data = data; - - if (data == null) - Data = new byte[0]; - else - Size = size; - } - } - - public class TmpTDReader : ISpriteSource - { - public IReadOnlyList Frames { get; private set; } - - public TmpTDReader(Stream s) - { - var width = s.ReadUInt16(); - var height = s.ReadUInt16(); - var size = new Size(width, height); - - s.Position += 8; - var imgStart = s.ReadUInt32(); - s.Position += 8; - var indexEnd = s.ReadInt32(); - var indexStart = s.ReadInt32(); - - s.Position = indexStart; - var count = indexEnd - indexStart; - var tiles = new TmpTile[count]; - Frames = tiles.AsReadOnly(); - var tilesIndex = 0; - foreach (var b in s.ReadBytes(count)) - { - if (b != 255) - { - s.Position = imgStart + b * width * height; - tiles[tilesIndex++] = new TmpTile(s.ReadBytes(width * height), size); - } - else - tiles[tilesIndex++] = new TmpTile(null, size); - } - } - } -} diff --git a/OpenRA.Game/Graphics/SpriteSource.cs b/OpenRA.Game/Graphics/SpriteSource.cs index 8ca32dd6ce..f9c790973f 100644 --- a/OpenRA.Game/Graphics/SpriteSource.cs +++ b/OpenRA.Game/Graphics/SpriteSource.cs @@ -15,21 +15,9 @@ using OpenRA.FileFormats; namespace OpenRA.Graphics { // TODO: Most of this should be moved into the format parsers themselves. - public enum SpriteType { Unknown, ShpD2, TmpTD, TmpTS } + public enum SpriteType { Unknown, ShpD2, TmpTS } public static class SpriteSource { - static bool IsTmpTD(Stream s) - { - var start = s.Position; - - s.Position += 16; - var a = s.ReadUInt32(); - var b = s.ReadUInt32(); - - s.Position = start; - return a == 0 && b == 0x0D1AFFFF; - } - static bool IsTmpTS(Stream s) { var start = s.Position; @@ -93,9 +81,6 @@ namespace OpenRA.Graphics public static SpriteType DetectSpriteType(Stream s) { - if (IsTmpTD(s)) - return SpriteType.TmpTD; - if (IsTmpTS(s)) return SpriteType.TmpTS; @@ -110,8 +95,6 @@ namespace OpenRA.Graphics var type = DetectSpriteType(s); switch (type) { - case SpriteType.TmpTD: - return new TmpTDReader(s); case SpriteType.TmpTS: return new TmpTSReader(s); case SpriteType.ShpD2: diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 9b63f7b96a..1b75b60b4a 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -278,7 +278,6 @@ - diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index d27764c409..4d2c16715a 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -116,6 +116,7 @@ + diff --git a/OpenRA.Mods.Common/SpriteLoaders/TmpTDLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/TmpTDLoader.cs new file mode 100644 index 0000000000..22617faecf --- /dev/null +++ b/OpenRA.Mods.Common/SpriteLoaders/TmpTDLoader.cs @@ -0,0 +1,99 @@ +#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 + * 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.FileFormats; +using OpenRA.Graphics; + +namespace OpenRA.Mods.Common.SpriteLoaders +{ + public class TmpTDLoader : ISpriteLoader + { + class TmpTDFrame : ISpriteFrame + { + public Size Size { get; private set; } + public Size FrameSize { get; private set; } + public float2 Offset { get { return float2.Zero; } } + public byte[] Data { get; set; } + public bool DisableExportPadding { get { return false; } } + + public TmpTDFrame(byte[] data, Size size) + { + FrameSize = size; + Data = data; + + if (data == null) + Data = new byte[0]; + else + Size = size; + } + } + + bool IsTmpTD(Stream s) + { + var start = s.Position; + + s.Position += 16; + var a = s.ReadUInt32(); + var b = s.ReadUInt32(); + + s.Position = start; + return a == 0 && b == 0x0D1AFFFF; + } + + TmpTDFrame[] ParseFrames(Stream s) + { + var start = s.Position; + var width = s.ReadUInt16(); + var height = s.ReadUInt16(); + var size = new Size(width, height); + + s.Position += 8; + var imgStart = s.ReadUInt32(); + s.Position += 8; + var indexEnd = s.ReadInt32(); + var indexStart = s.ReadInt32(); + + s.Position = indexStart; + var count = indexEnd - indexStart; + var tiles = new TmpTDFrame[count]; + var tilesIndex = 0; + foreach (var b in s.ReadBytes(count)) + { + if (b != 255) + { + s.Position = imgStart + b * width * height; + tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size); + } + else + tiles[tilesIndex++] = new TmpTDFrame(null, size); + } + + s.Position = start; + return tiles; + } + + public bool TryParseSprite(Stream s, out ISpriteFrame[] frames) + { + if (!IsTmpTD(s)) + { + frames = null; + return false; + } + + frames = ParseFrames(s); + return true; + } + } +} diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 676a01bd99..9f42c128dd 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -211,4 +211,4 @@ Missions: SupportsMapsFrom: cnc -SpriteFormats: ShpTD, ShpTS, TmpRA \ No newline at end of file +SpriteFormats: ShpTD, TmpTD, ShpTS, TmpRA \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 51875f95e3..076cc048f8 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -208,4 +208,4 @@ Missions: SupportsMapsFrom: ra -SpriteFormats: ShpTD, TmpRA, ShpTS \ No newline at end of file +SpriteFormats: ShpTD, TmpRA, TmpTD, ShpTS \ No newline at end of file