protected virtual TerrainTileInfo LoadTileInfo(ITerrainInfo terrainInfo, MiniYaml my) { var tile = new TerrainTileInfo(); FieldLoader.Load(tile, my); // Terrain type must be converted from a string to an index tile.GetType().GetField(nameof(tile.TerrainType)).SetValue(tile, terrainInfo.GetTerrainIndex(my.Value)); // Fall back to the terrain-type color if necessary var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color; if (tile.MinColor == default) { tile.GetType().GetField(nameof(tile.MinColor)).SetValue(tile, overrideColor); } if (tile.MaxColor == default) { tile.GetType().GetField(nameof(tile.MaxColor)).SetValue(tile, overrideColor); } return(tile); }
void Export(string outputDir) { var dir = Platform.ResolvePath("^", outputDir); Directory.CreateDirectory(dir); var tilesetName = txtTilesetName.Text; var tilesetID = txtID.Text; var tilesetExt = txtExt.Text; if (tilesetName.Length < 1) { tilesetName = "Temperat"; } if (tilesetID.Length < 1) { tilesetID = "TEMPERAT"; } if (tilesetExt.Length < 1) { tilesetExt = ".tem"; } // Create a Tileset definition // TODO: Pull this info from the GUI var tilesetFile = tilesetName.ToLower(); if (tilesetFile.Length < 8) { tilesetFile = tilesetName.ToLower() + ".yaml"; } else { tilesetFile = tilesetName.ToLower().Substring(0, 8) + ".yaml"; } var tileset = new TileSet( name: tilesetName, id: tilesetID.ToUpper(), terrainInfo: terrainType); // List of files to add to the mix file var fileList = new List <string>(); // Export tile artwork foreach (var t in surface1.Templates) { fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tilesetExt, dir)); } // Add the templates ushort cur = 0; templates.Clear(); foreach (var tp in surface1.Templates) { var tiles = new byte[tp.Width * tp.Height]; foreach (var t in tp.Cells) { var ttype = terrainType[surface1.TerrainTypes[t.Key.X, t.Key.Y]].Type; var idx = (t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top); tiles[idx] = tileset.GetTerrainIndex(ttype); } var template = new TerrainTemplateInfo( id: cur, images: new[] { "{0}{1:00}".F(txtTilesetName.Text, cur) }, size: new int2(tp.Width, tp.Height), tiles: tiles); // HACK: This part of the TileSet code is broken upstream var field = template.GetType() .GetField("tileInfo", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); field.SetValue(template, tiles.Select(t => { var info = new TerrainTileInfo(); info.GetType().GetField("TerrainType").SetValue(info, t); return(info); }).ToArray()); templates[cur] = template; cur++; } SaveTileSet(tileset, Path.Combine(dir, tilesetFile)); Console.WriteLine("Finished export"); }