本文整理汇总了C#中TileSet.GetTerrainIndex方法的典型用法代码示例。如果您正苦于以下问题:C# TileSet.GetTerrainIndex方法的具体用法?C# TileSet.GetTerrainIndex怎么用?C# TileSet.GetTerrainIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileSet
的用法示例。
在下文中一共展示了TileSet.GetTerrainIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: AddStaticResources
// Add the static resources defined in the map; if the map lives
// in a world use AddCustomTerrain instead
static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap)
{
var terrain = new Bitmap(terrainBitmap);
var b = map.Bounds;
var bitmapData = terrain.LockBits(terrain.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
var colors = (int*)bitmapData.Scan0;
var stride = bitmapData.Stride / 4;
for (var y = 0; y < b.Height; y++)
{
for (var x = 0; x < b.Width; x++)
{
var mapX = x + b.Left;
var mapY = y + b.Top;
if (map.MapResources.Value[mapX, mapY].Type == 0)
continue;
var res = resourceRules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>()
.Where(t => t.ResourceType == map.MapResources.Value[mapX, mapY].Type)
.Select(t => t.TerrainType).FirstOrDefault();
if (res == null)
continue;
colors[y * stride + x] = tileset[tileset.GetTerrainIndex(res)].Color.ToArgb();
}
}
}
terrain.UnlockBits(bitmapData);
return terrain;
}
示例3: 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");
}
示例4: AddStaticResources
// Add the static resources defined in the map; if the map lives
// in a world use AddCustomTerrain instead
static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap)
{
var terrain = new Bitmap(terrainBitmap);
var isDiamond = map.TileShape == TileShape.Diamond;
var b = map.Bounds;
// Fudge the heightmap offset by adding as much extra as we need / can
// This tries to correct for our incorrect assumption that MPos == PPos
var heightOffset = Math.Min(map.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
var width = b.Width;
var height = b.Height + heightOffset;
var resources = resourceRules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>()
.ToDictionary(r => r.ResourceType, r => r.TerrainType);
var bitmapData = terrain.LockBits(terrain.Bounds(),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
var colors = (int*)bitmapData.Scan0;
var stride = bitmapData.Stride / 4;
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var uv = new MPos(x + b.Left, y + b.Top);
if (map.MapResources.Value[uv].Type == 0)
continue;
string res;
if (!resources.TryGetValue(map.MapResources.Value[uv].Type, out res))
continue;
var color = tileset[tileset.GetTerrainIndex(res)].Color.ToArgb();
if (isDiamond)
{
// Odd rows are shifted right by 1px
var dx = uv.V & 1;
if (x + dx > 0)
colors[y * stride + 2 * x + dx - 1] = color;
if (2 * x + dx < stride)
colors[y * stride + 2 * x + dx] = color;
}
else
colors[y * stride + x] = color;
}
}
}
terrain.UnlockBits(bitmapData);
return terrain;
}