Move TmpTD sprite loading into Mods.Common.
This commit is contained in:
@@ -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<ISpriteFrame> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,21 +15,9 @@ using OpenRA.FileFormats;
|
|||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
// TODO: Most of this should be moved into the format parsers themselves.
|
// 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
|
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)
|
static bool IsTmpTS(Stream s)
|
||||||
{
|
{
|
||||||
var start = s.Position;
|
var start = s.Position;
|
||||||
@@ -93,9 +81,6 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public static SpriteType DetectSpriteType(Stream s)
|
public static SpriteType DetectSpriteType(Stream s)
|
||||||
{
|
{
|
||||||
if (IsTmpTD(s))
|
|
||||||
return SpriteType.TmpTD;
|
|
||||||
|
|
||||||
if (IsTmpTS(s))
|
if (IsTmpTS(s))
|
||||||
return SpriteType.TmpTS;
|
return SpriteType.TmpTS;
|
||||||
|
|
||||||
@@ -110,8 +95,6 @@ namespace OpenRA.Graphics
|
|||||||
var type = DetectSpriteType(s);
|
var type = DetectSpriteType(s);
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case SpriteType.TmpTD:
|
|
||||||
return new TmpTDReader(s);
|
|
||||||
case SpriteType.TmpTS:
|
case SpriteType.TmpTS:
|
||||||
return new TmpTSReader(s);
|
return new TmpTSReader(s);
|
||||||
case SpriteType.ShpD2:
|
case SpriteType.ShpD2:
|
||||||
|
|||||||
@@ -278,7 +278,6 @@
|
|||||||
<Compile Include="FileFormats\HvaReader.cs" />
|
<Compile Include="FileFormats\HvaReader.cs" />
|
||||||
<Compile Include="FileFormats\PngLoader.cs" />
|
<Compile Include="FileFormats\PngLoader.cs" />
|
||||||
<Compile Include="FileFormats\ShpD2Reader.cs" />
|
<Compile Include="FileFormats\ShpD2Reader.cs" />
|
||||||
<Compile Include="FileFormats\TmpTDReader.cs" />
|
|
||||||
<Compile Include="FileFormats\TmpTSReader.cs" />
|
<Compile Include="FileFormats\TmpTSReader.cs" />
|
||||||
<Compile Include="FileFormats\VqaReader.cs" />
|
<Compile Include="FileFormats\VqaReader.cs" />
|
||||||
<Compile Include="FileFormats\VxlReader.cs" />
|
<Compile Include="FileFormats\VxlReader.cs" />
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
<Compile Include="SpriteLoaders\ShpTDLoader.cs" />
|
<Compile Include="SpriteLoaders\ShpTDLoader.cs" />
|
||||||
<Compile Include="SpriteLoaders\ShpTSLoader.cs" />
|
<Compile Include="SpriteLoaders\ShpTSLoader.cs" />
|
||||||
<Compile Include="SpriteLoaders\TmpRALoader.cs" />
|
<Compile Include="SpriteLoaders\TmpRALoader.cs" />
|
||||||
|
<Compile Include="SpriteLoaders\TmpTDLoader.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
99
OpenRA.Mods.Common/SpriteLoaders/TmpTDLoader.cs
Normal file
99
OpenRA.Mods.Common/SpriteLoaders/TmpTDLoader.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -211,4 +211,4 @@ Missions:
|
|||||||
|
|
||||||
SupportsMapsFrom: cnc
|
SupportsMapsFrom: cnc
|
||||||
|
|
||||||
SpriteFormats: ShpTD, ShpTS, TmpRA
|
SpriteFormats: ShpTD, TmpTD, ShpTS, TmpRA
|
||||||
@@ -208,4 +208,4 @@ Missions:
|
|||||||
|
|
||||||
SupportsMapsFrom: ra
|
SupportsMapsFrom: ra
|
||||||
|
|
||||||
SpriteFormats: ShpTD, TmpRA, ShpTS
|
SpriteFormats: ShpTD, TmpRA, TmpTD, ShpTS
|
||||||
Reference in New Issue
Block a user