Make terrain tiles ISpriteSources.
This commit is contained in:
@@ -179,6 +179,10 @@ namespace OpenRA.FileFormats
|
|||||||
return new ShpTSReader(s);
|
return new ShpTSReader(s);
|
||||||
case SpriteType.R8:
|
case SpriteType.R8:
|
||||||
return new R8Reader(s);
|
return new R8Reader(s);
|
||||||
|
case SpriteType.TmpRA:
|
||||||
|
return new TmpRAReader(s);
|
||||||
|
case SpriteType.TmpTD:
|
||||||
|
return new TmpTDReader(s);
|
||||||
case SpriteType.Unknown:
|
case SpriteType.Unknown:
|
||||||
default:
|
default:
|
||||||
throw new InvalidDataException(filename + " is not a valid sprite file");
|
throw new InvalidDataException(filename + " is not a valid sprite file");
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
@@ -33,7 +34,22 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
|
|
||||||
using (var s = FileSystem.OpenWithExts(filename, exts))
|
using (var s = FileSystem.OpenWithExts(filename, exts))
|
||||||
return new Terrain(s).TileBitmapBytes;
|
{
|
||||||
|
var type = SpriteSource.DetectSpriteType(s);
|
||||||
|
ISpriteSource source;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SpriteType.TmpTD:
|
||||||
|
source = new TmpTDReader(s);
|
||||||
|
break;
|
||||||
|
case SpriteType.TmpRA:
|
||||||
|
source = new TmpRAReader(s);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidDataException(filename + " is not a valid terrain tile");
|
||||||
|
}
|
||||||
|
return source.Frames.Select(f => f.Data).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileSetRenderer(TileSet tileset, Size tileSize)
|
public TileSetRenderer(TileSet tileset, Size tileSize)
|
||||||
|
|||||||
49
OpenRA.FileFormats/Graphics/TmpRAReader.cs
Normal file
49
OpenRA.FileFormats/Graphics/TmpRAReader.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 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.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.FileFormats
|
||||||
|
{
|
||||||
|
public class TmpRAReader : ISpriteSource
|
||||||
|
{
|
||||||
|
readonly List<TmpTile> tiles = new List<TmpTile>();
|
||||||
|
public IEnumerable<ISpriteFrame> Frames { get { return tiles.Cast<ISpriteFrame>(); } }
|
||||||
|
|
||||||
|
public TmpRAReader(Stream s)
|
||||||
|
{
|
||||||
|
var width = s.ReadUInt16();
|
||||||
|
var height = s.ReadUInt16();
|
||||||
|
var size = new Size(width, height);
|
||||||
|
|
||||||
|
s.Position += 12;
|
||||||
|
var imgStart = s.ReadUInt32();
|
||||||
|
s.Position += 8;
|
||||||
|
var indexEnd = s.ReadInt32();
|
||||||
|
s.Position += 4;
|
||||||
|
var indexStart = s.ReadInt32();
|
||||||
|
|
||||||
|
s.Position = indexStart;
|
||||||
|
foreach (byte b in s.ReadBytes(indexEnd - indexStart))
|
||||||
|
{
|
||||||
|
if (b != 255)
|
||||||
|
{
|
||||||
|
s.Position = imgStart + b * width * height;
|
||||||
|
tiles.Add(new TmpTile(s.ReadBytes(width * height), size));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tiles.Add(new TmpTile(null, size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
67
OpenRA.FileFormats/Graphics/TmpTDReader.cs
Normal file
67
OpenRA.FileFormats/Graphics/TmpTDReader.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 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.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
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 TmpTile(byte[] data, Size size)
|
||||||
|
{
|
||||||
|
FrameSize = size;
|
||||||
|
Data = data;
|
||||||
|
|
||||||
|
if (data == null)
|
||||||
|
Data = new byte[0];
|
||||||
|
else
|
||||||
|
Size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TmpTDReader : ISpriteSource
|
||||||
|
{
|
||||||
|
readonly List<TmpTile> tiles = new List<TmpTile>();
|
||||||
|
public IEnumerable<ISpriteFrame> Frames { get { return tiles.Cast<ISpriteFrame>(); } }
|
||||||
|
|
||||||
|
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;
|
||||||
|
foreach (byte b in s.ReadBytes(indexEnd - indexStart))
|
||||||
|
{
|
||||||
|
if (b != 255)
|
||||||
|
{
|
||||||
|
s.Position = imgStart + b * width * height;
|
||||||
|
tiles.Add(new TmpTile(s.ReadBytes(width * height), size));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tiles.Add(new TmpTile(null, size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2011 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.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
|
||||||
{
|
|
||||||
public class Terrain
|
|
||||||
{
|
|
||||||
public readonly List<byte[]> TileBitmapBytes = new List<byte[]>();
|
|
||||||
public readonly int Width;
|
|
||||||
public readonly int Height;
|
|
||||||
|
|
||||||
public Terrain(Stream s)
|
|
||||||
{
|
|
||||||
// Try loading as a cnc .tem
|
|
||||||
Width = s.ReadUInt16();
|
|
||||||
Height = s.ReadUInt16();
|
|
||||||
|
|
||||||
/*NumTiles = */s.ReadUInt16();
|
|
||||||
/*Zero1 = */s.ReadUInt16();
|
|
||||||
/*uint Size = */s.ReadUInt32();
|
|
||||||
var imgStart = s.ReadUInt32();
|
|
||||||
/*Zero2 = */s.ReadUInt32();
|
|
||||||
|
|
||||||
int indexEnd, indexStart;
|
|
||||||
|
|
||||||
// ID1 = FFFFh for cnc
|
|
||||||
if (s.ReadUInt16() == 65535)
|
|
||||||
{
|
|
||||||
/*ID2 = */s.ReadUInt16();
|
|
||||||
indexEnd = s.ReadInt32();
|
|
||||||
indexStart = s.ReadInt32();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Load as a ra .tem
|
|
||||||
s.Position = 0;
|
|
||||||
Width = s.ReadUInt16();
|
|
||||||
Height = s.ReadUInt16();
|
|
||||||
|
|
||||||
/*NumTiles = */s.ReadUInt16();
|
|
||||||
s.ReadUInt16();
|
|
||||||
/*XDim = */s.ReadUInt16();
|
|
||||||
/*YDim = */s.ReadUInt16();
|
|
||||||
/*uint FileSize = */s.ReadUInt32();
|
|
||||||
imgStart = s.ReadUInt32();
|
|
||||||
s.ReadUInt32();
|
|
||||||
s.ReadUInt32();
|
|
||||||
indexEnd = s.ReadInt32();
|
|
||||||
s.ReadUInt32();
|
|
||||||
indexStart = s.ReadInt32();
|
|
||||||
}
|
|
||||||
|
|
||||||
s.Position = indexStart;
|
|
||||||
|
|
||||||
foreach (byte b in s.ReadBytes(indexEnd - indexStart))
|
|
||||||
{
|
|
||||||
if (b != 255)
|
|
||||||
{
|
|
||||||
s.Position = imgStart + b * Width * Height;
|
|
||||||
TileBitmapBytes.Add(s.ReadBytes(Width * Height));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
TileBitmapBytes.Add(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -101,7 +101,6 @@
|
|||||||
<Compile Include="Manifest.cs" />
|
<Compile Include="Manifest.cs" />
|
||||||
<Compile Include="Map\PlayerReference.cs" />
|
<Compile Include="Map\PlayerReference.cs" />
|
||||||
<Compile Include="Map\SmudgeReference.cs" />
|
<Compile Include="Map\SmudgeReference.cs" />
|
||||||
<Compile Include="Map\Terrain.cs" />
|
|
||||||
<Compile Include="Map\TileReference.cs" />
|
<Compile Include="Map\TileReference.cs" />
|
||||||
<Compile Include="Map\TileSet.cs" />
|
<Compile Include="Map\TileSet.cs" />
|
||||||
<Compile Include="MiniYaml.cs" />
|
<Compile Include="MiniYaml.cs" />
|
||||||
@@ -153,6 +152,8 @@
|
|||||||
<Compile Include="FileSystem\ZipFile.cs" />
|
<Compile Include="FileSystem\ZipFile.cs" />
|
||||||
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
||||||
<Compile Include="Graphics\SpriteSource.cs" />
|
<Compile Include="Graphics\SpriteSource.cs" />
|
||||||
|
<Compile Include="Graphics\TmpRAReader.cs" />
|
||||||
|
<Compile Include="Graphics\TmpTDReader.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
@@ -38,10 +39,21 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
using (var s = FileSystem.OpenWithExts(filename, exts))
|
using (var s = FileSystem.OpenWithExts(filename, exts))
|
||||||
{
|
{
|
||||||
var t = new Terrain(s);
|
var type = SpriteSource.DetectSpriteType(s);
|
||||||
return t.TileBitmapBytes
|
ISpriteSource source;
|
||||||
.Select(b => b != null ? sheetBuilder.Add(b, new Size(t.Width, t.Height)) : null)
|
switch (type)
|
||||||
.ToArray();
|
{
|
||||||
|
case SpriteType.TmpTD:
|
||||||
|
source = new TmpTDReader(s);
|
||||||
|
break;
|
||||||
|
case SpriteType.TmpRA:
|
||||||
|
source = new TmpRAReader(s);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidDataException(filename + " is not a valid terrain tile");
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.Frames.Select(f => sheetBuilder.Add(f)).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,11 +82,13 @@ namespace OpenRA.Graphics
|
|||||||
public Sprite TileSprite(TileReference<ushort, byte> r)
|
public Sprite TileSprite(TileReference<ushort, byte> r)
|
||||||
{
|
{
|
||||||
Sprite[] template;
|
Sprite[] template;
|
||||||
if (templates.TryGetValue(r.Type, out template))
|
if (!templates.TryGetValue(r.Type, out template))
|
||||||
if (template.Length > r.Index && template[r.Index] != null)
|
return missingTile;
|
||||||
return template[r.Index];
|
|
||||||
|
|
||||||
return missingTile;
|
if (r.Index >= template.Length)
|
||||||
|
return missingTile;
|
||||||
|
|
||||||
|
return template[r.Index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sheet Sheet { get { return sheetBuilder.Current; } }
|
public Sheet Sheet { get { return sheetBuilder.Current; } }
|
||||||
|
|||||||
Reference in New Issue
Block a user