combine tileset.{Tiles,Templates}; image data now accessed via Templates[].Data
This commit is contained in:
@@ -26,8 +26,8 @@ namespace OpenRA.Editor
|
|||||||
public void Apply(Surface surface)
|
public void Apply(Surface surface)
|
||||||
{
|
{
|
||||||
// change the bits in the map
|
// change the bits in the map
|
||||||
var tile = surface.TileSet.Tiles[Brush.N];
|
|
||||||
var template = surface.TileSet.Templates[Brush.N];
|
var template = surface.TileSet.Templates[Brush.N];
|
||||||
|
var tile = template.Data;
|
||||||
var pos = surface.GetBrushLocation();
|
var pos = surface.GetBrushLocation();
|
||||||
|
|
||||||
if (surface.GetModifiers() == Keys.Shift)
|
if (surface.GetModifiers() == Keys.Shift)
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ namespace OpenRA.Editor
|
|||||||
var tr = surface1.Map.MapTiles.Value[i, j];
|
var tr = surface1.Map.MapTiles.Value[i, j];
|
||||||
if (tr.type == 0xff || tr.type == 0xffff || tr.type == 1 || tr.type == 2)
|
if (tr.type == 0xff || tr.type == 0xffff || tr.type == 1 || tr.type == 2)
|
||||||
tr.index = (byte)r.Next(0,
|
tr.index = (byte)r.Next(0,
|
||||||
Rules.TileSets[surface1.Map.Tileset].Tiles[tr.type].TileBitmapBytes.Count);
|
Rules.TileSets[surface1.Map.Tileset].Templates[tr.type].Data.TileBitmapBytes.Count);
|
||||||
|
|
||||||
surface1.Map.MapTiles.Value[i, j] = tr;
|
surface1.Map.MapTiles.Value[i, j] = tr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ namespace OpenRA.Editor
|
|||||||
for (var j = 0; j < ChunkSize; j++)
|
for (var j = 0; j < ChunkSize; j++)
|
||||||
{
|
{
|
||||||
var tr = Map.MapTiles.Value[u * ChunkSize + i, v * ChunkSize + j];
|
var tr = Map.MapTiles.Value[u * ChunkSize + i, v * ChunkSize + j];
|
||||||
var tile = TileSet.Tiles[tr.type];
|
var tile = TileSet.Templates[tr.type].Data;
|
||||||
var index = (tr.index < tile.TileBitmapBytes.Count) ? tr.index : (byte)0;
|
var index = (tr.index < tile.TileBitmapBytes.Count) ? tr.index : (byte)0;
|
||||||
var rawImage = tile.TileBitmapBytes[index];
|
var rawImage = tile.TileBitmapBytes[index];
|
||||||
for (var x = 0; x < TileSet.TileSize; x++)
|
for (var x = 0; x < TileSet.TileSize; x++)
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
return new MiniYaml(null, root);
|
return new MiniYaml(null, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Terrain Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TileSet
|
public class TileSet
|
||||||
@@ -77,7 +79,6 @@ namespace OpenRA.FileFormats
|
|||||||
public int TileSize = 24;
|
public int TileSize = 24;
|
||||||
public string[] Extensions;
|
public string[] Extensions;
|
||||||
public Dictionary<string, TerrainTypeInfo> Terrain = new Dictionary<string, TerrainTypeInfo>();
|
public Dictionary<string, TerrainTypeInfo> Terrain = new Dictionary<string, TerrainTypeInfo>();
|
||||||
public Dictionary<ushort, Terrain> Tiles = new Dictionary<ushort, Terrain>();
|
|
||||||
public Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
|
public Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
|
||||||
|
|
||||||
static readonly string[] fields = {"Name", "TileSize", "Id", "Palette", "Extensions"};
|
static readonly string[] fields = {"Name", "TileSize", "Id", "Palette", "Extensions"};
|
||||||
@@ -103,23 +104,23 @@ namespace OpenRA.FileFormats
|
|||||||
public void LoadTiles()
|
public void LoadTiles()
|
||||||
{
|
{
|
||||||
foreach (var t in Templates)
|
foreach (var t in Templates)
|
||||||
using( Stream s = FileSystem.OpenWithExts(t.Value.Image, Extensions) )
|
if (t.Value.Data == null)
|
||||||
{
|
using( var s = FileSystem.OpenWithExts(t.Value.Image, Extensions) )
|
||||||
if( !Tiles.ContainsKey( t.Key ) )
|
t.Value.Data = new Terrain(s, TileSize);
|
||||||
Tiles.Add( t.Key, new Terrain( s, TileSize ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(string filepath)
|
public void Save(string filepath)
|
||||||
{
|
{
|
||||||
var root = new List<MiniYamlNode>();
|
var root = new List<MiniYamlNode>();
|
||||||
var gen = new List<MiniYamlNode>();
|
var gen = new List<MiniYamlNode>();
|
||||||
|
|
||||||
foreach (var field in fields)
|
foreach (var field in fields)
|
||||||
{
|
{
|
||||||
FieldInfo f = this.GetType().GetField(field);
|
FieldInfo f = this.GetType().GetField(field);
|
||||||
if (f.GetValue(this) == null) continue;
|
if (f.GetValue(this) == null) continue;
|
||||||
gen.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
|
gen.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
root.Add( new MiniYamlNode( "General", null, gen ) );
|
root.Add( new MiniYamlNode( "General", null, gen ) );
|
||||||
|
|
||||||
root.Add( new MiniYamlNode( "Terrain", null,
|
root.Add( new MiniYamlNode( "Terrain", null,
|
||||||
@@ -136,9 +137,9 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
public byte[] GetBytes(TileReference<ushort,byte> r)
|
public byte[] GetBytes(TileReference<ushort,byte> r)
|
||||||
{
|
{
|
||||||
Terrain tile;
|
TileTemplate tile;
|
||||||
if( Tiles.TryGetValue( r.type, out tile ) )
|
if( Templates.TryGetValue( r.type, out tile ) )
|
||||||
return tile.TileBitmapBytes[ r.index ];
|
return tile.Data.TileBitmapBytes[ r.index ];
|
||||||
|
|
||||||
byte[] missingTile = new byte[ TileSize * TileSize ];
|
byte[] missingTile = new byte[ TileSize * TileSize ];
|
||||||
for( int i = 0 ; i < missingTile.Length ; i++ )
|
for( int i = 0 ; i < missingTile.Length ; i++ )
|
||||||
@@ -159,7 +160,6 @@ namespace OpenRA.FileFormats
|
|||||||
public Bitmap RenderTemplate(ushort n, Palette p)
|
public Bitmap RenderTemplate(ushort n, Palette p)
|
||||||
{
|
{
|
||||||
var template = Templates[n];
|
var template = Templates[n];
|
||||||
var tile = Tiles[n];
|
|
||||||
|
|
||||||
var bitmap = new Bitmap(TileSize * template.Size.X, TileSize * template.Size.Y,
|
var bitmap = new Bitmap(TileSize * template.Size.X, TileSize * template.Size.Y,
|
||||||
PixelFormat.Format8bppIndexed);
|
PixelFormat.Format8bppIndexed);
|
||||||
@@ -176,9 +176,9 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
for (var u = 0; u < template.Size.X; u++)
|
for (var u = 0; u < template.Size.X; u++)
|
||||||
for (var v = 0; v < template.Size.Y; v++)
|
for (var v = 0; v < template.Size.Y; v++)
|
||||||
if (tile.TileBitmapBytes[u + v * template.Size.X] != null)
|
if (template.Data.TileBitmapBytes[u + v * template.Size.X] != null)
|
||||||
{
|
{
|
||||||
var rawImage = tile.TileBitmapBytes[u + v * template.Size.X];
|
var rawImage = template.Data.TileBitmapBytes[u + v * template.Size.X];
|
||||||
for (var i = 0; i < TileSize; i++)
|
for (var i = 0; i < TileSize; i++)
|
||||||
for (var j = 0; j < TileSize; j++)
|
for (var j = 0; j < TileSize; j++)
|
||||||
q[(v * TileSize + j) * stride + u * TileSize + i] = rawImage[i + TileSize * j];
|
q[(v * TileSize + j) * stride + u * TileSize + i] = rawImage[i + TileSize * j];
|
||||||
|
|||||||
Reference in New Issue
Block a user