本文整理汇总了C#中TileSet.Save方法的典型用法代码示例。如果您正苦于以下问题:C# TileSet.Save方法的具体用法?C# TileSet.Save怎么用?C# TileSet.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileSet
的用法示例。
在下文中一共展示了TileSet.Save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
void Export(string outputDir)
{
var dir = Platform.ResolvePath("^", outputDir);
Directory.CreateDirectory(dir);
var tilesetName = txtTilesetName.Text;
var tilesetID = txtID.Text;
var tilesetPalette = txtPal.Text;
var tilesetExt = txtExt.Text;
if (tilesetName.Length < 1) tilesetName = "Temperat";
if (tilesetID.Length < 1) tilesetID = "TEMPERAT";
if (tilesetPalette.Length < 1) tilesetPalette = "temperat";
if (tilesetExt.Length < 1) tilesetExt = ".tem";
// Create a Tileset definition
// TODO: Pull this info from the GUI
var tilesetFile = "";
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(),
palette: tilesetPalette.ToLower(),
terrainInfo: terrainType);
// List of files to add to the mix file
var fileList = new List<string>();
// Export palette (use the embedded palette)
var p = surface1.Image.Palette.Entries.ToList();
fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));
// 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;
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);
tileset.Templates.Add(cur, template);
cur++;
}
tileset.Save(Path.Combine(dir, tilesetFile));
Console.WriteLine("Finished export");
}
示例2: typeof
void IUtilityCommand.Run(Utility utility, string[] args)
{
// HACK: The engine code assumes that Game.modData is set.
var modData = Game.ModData = utility.ModData;
var imageField = typeof(TerrainTemplateInfo).GetField("Image");
var pickAnyField = typeof(TerrainTemplateInfo).GetField("PickAny");
var tileInfoField = typeof(TerrainTemplateInfo).GetField("tileInfo", BindingFlags.NonPublic | BindingFlags.Instance);
var terrainTypeField = typeof(TerrainTileInfo).GetField("TerrainType");
var terrainLeftColorField = typeof(TerrainTileInfo).GetField("LeftColor");
var terrainRightColorField = typeof(TerrainTileInfo).GetField("RightColor");
var empty = new Size(0, 0);
var single = new int2(1, 1);
var exts = new[] { "" }.Concat(args[1].Split(','));
foreach (var t in modData.Manifest.TileSets)
{
var ts = new TileSet(modData.DefaultFileSystem, t);
var frameCache = new FrameCache(modData.DefaultFileSystem, modData.SpriteLoaders);
Console.WriteLine("Tileset: " + ts.Name);
foreach (var template in ts.Templates.Values)
{
// Find the sprite associated with this template
foreach (var ext in exts)
{
Stream s;
if (modData.DefaultFileSystem.TryOpen(template.Images[0] + ext, out s))
s.Dispose();
else
continue;
// Rewrite the template image (normally readonly) using reflection
imageField.SetValue(template, template.Images[0] + ext);
// Fetch the private tileInfo array so that we can write new entries
var tileInfo = (TerrainTileInfo[])tileInfoField.GetValue(template);
// Open the file and search for any implicit frames
var allFrames = frameCache[template.Images[0]];
var frames = template.Frames != null ? template.Frames.Select(f => allFrames[f]).ToArray() : allFrames;
// Resize array for new entries
if (frames.Length > template.TilesCount)
{
var ti = new TerrainTileInfo[frames.Length];
Array.Copy(tileInfo, ti, template.TilesCount);
tileInfoField.SetValue(template, ti);
tileInfo = ti;
}
for (var i = 0; i < template.TilesCount; i++)
{
if (template[i] == null && frames[i] != null && frames[i].Size != empty)
{
tileInfo[i] = new TerrainTileInfo();
var ti = ts.GetTerrainIndex("Clear");
terrainTypeField.SetValue(tileInfo[i], ti);
terrainLeftColorField.SetValue(tileInfo[i], ts[ti].Color);
terrainRightColorField.SetValue(tileInfo[i], ts[ti].Color);
Console.WriteLine("Fixing entry for {0}:{1}", template.Images[0], i);
}
}
if (template.TilesCount > 1 && template.Size == single)
pickAnyField.SetValue(template, true);
}
}
ts.Save(t);
}
}
示例3: Export
public void Export(string outputDir)
{
var dir = Path.Combine(Path.GetDirectoryName(srcfile), Platform.SupportDir + outputDir);
Directory.CreateDirectory(dir);
var tilesetName = txtTilesetName.Text;
var tilesetID = txtID.Text;
var tilesetPalette = txtPal.Text;
var tilesetExt = txtExt.Text;
if (tilesetName.Length < 1) { tilesetName = "Temperat"; }
if (tilesetID.Length < 1) { tilesetID = "TEMPERAT"; }
if (tilesetPalette.Length < 1) { tilesetPalette = "temperat"; }
if (tilesetExt.Length < 1) { tilesetExt = ".tem,.shp"; }
// Create a Tileset definition
// TODO: Pull this info from the GUI
var tilesetFile = "";
tilesetFile = tilesetName.ToLower();
if (tilesetFile.Length < 8)
tilesetFile = tilesetName.ToLower() + ".yaml";
else
tilesetFile = tilesetName.ToLower().Substring(0, 8) + ".yaml";
var ext = tilesetExt.Split(',');
var tileset = new TileSet(
name: tilesetName,
id: tilesetID.ToUpper(),
palette: tilesetPalette.ToLower(),
extensions: new string[] { ext[0], ext[1] }
);
// List of files to add to the mix file
List<string> fileList = new List<string>();
// Export palette (use the embedded palette)
var p = surface1.Image.Palette.Entries.ToList();
fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));
// Export tile artwork
foreach (var t in surface1.Templates)
fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tileset.Extensions.First(), dir));
// Add the terraintypes
foreach (var tt in TerrainType)
{
tileset.Terrain.Add(tt.Type, tt);
}
// Add the templates
ushort cur = 0;
foreach (var tp in surface1.Templates)
{
var template = new TileTemplate(
id: cur,
image: "{0}{1:00}".F(txtTilesetName.Text, cur),
size: new int2(tp.Width, tp.Height)
);
foreach (var t in tp.Cells)
{
string ttype = "Clear";
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);
template.Tiles.Add((byte)idx, ttype);
}
tileset.Templates.Add(cur, template);
cur++;
}
tileset.Save(Path.Combine(dir, tilesetFile));
Console.WriteLine("Finished export");
}