mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
some more tiled map extension utility methods
This commit is contained in:
parent
0411add4d1
commit
14e97abf87
1 changed files with 32 additions and 9 deletions
|
@ -115,15 +115,7 @@ namespace MLEM.Extended.Tiled {
|
||||||
if (tile.IsBlank)
|
if (tile.IsBlank)
|
||||||
return null;
|
return null;
|
||||||
var localId = tile.GetLocalIdentifier(tileset, map);
|
var localId = tile.GetLocalIdentifier(tileset, map);
|
||||||
var tilesetTile = tileset.Tiles.FirstOrDefault(t => t.LocalTileIdentifier == localId);
|
return tileset.GetTilesetTile(localId, createStub);
|
||||||
if (tilesetTile == null && createStub) {
|
|
||||||
var id = tile.GetLocalIdentifier(tileset, map);
|
|
||||||
if (!StubTilesetTiles.TryGetValue(id, out tilesetTile)) {
|
|
||||||
tilesetTile = new TiledMapTilesetTile(id);
|
|
||||||
StubTilesetTiles.Add(id, tilesetTile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tilesetTile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -141,6 +133,24 @@ namespace MLEM.Extended.Tiled {
|
||||||
return tileset.GetTilesetTile(tile, map, createStub);
|
return tileset.GetTilesetTile(tile, map, createStub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tileset tile on the given tileset for the given local id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tileset">The tileset</param>
|
||||||
|
/// <param name="localId">The tile's local id</param>
|
||||||
|
/// <param name="createStub">If a tileset tile has no special properties, there is no pre-made object for it. If this boolean is true, a stub object with no extra data will be created instead of returning null.</param>
|
||||||
|
/// <returns>null if the tile is blank or the tileset tile if there is one or createStub is true</returns>
|
||||||
|
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTileset tileset, int localId, bool createStub = true) {
|
||||||
|
var tilesetTile = tileset.Tiles.FirstOrDefault(t => t.LocalTileIdentifier == localId);
|
||||||
|
if (tilesetTile == null && createStub) {
|
||||||
|
if (!StubTilesetTiles.TryGetValue(localId, out tilesetTile)) {
|
||||||
|
tilesetTile = new TiledMapTilesetTile(localId);
|
||||||
|
StubTilesetTiles.Add(localId, tilesetTile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tilesetTile;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the layer index of the layer with the given name in the <see cref="TiledMap.Layers"/> array.
|
/// Gets the layer index of the layer with the given name in the <see cref="TiledMap.Layers"/> array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -179,6 +189,19 @@ namespace MLEM.Extended.Tiled {
|
||||||
layer.SetTile((ushort) x, (ushort) y, (uint) globalTile);
|
layer.SetTile((ushort) x, (ushort) y, (uint) globalTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the tiled map tile at the given location to the given tile from the given tileset
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="map">The map</param>
|
||||||
|
/// <param name="layerName">The name of the layer</param>
|
||||||
|
/// <param name="x">The x coordinate</param>
|
||||||
|
/// <param name="y">The y coordinate</param>
|
||||||
|
/// <param name="tileset">The tileset to use</param>R
|
||||||
|
/// <param name="tile">The tile to place, from the given tileset</param>
|
||||||
|
public static void SetTile(this TiledMap map, string layerName, int x, int y, TiledMapTileset tileset, TiledMapTilesetTile tile) {
|
||||||
|
map.SetTile(layerName, x, y, tile.GetGlobalIdentifier(tileset, map));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For an x and y coordinate, returns an enumerable of all of the tiles on each of the map's <see cref="TiledMap.TileLayers"/>.
|
/// For an x and y coordinate, returns an enumerable of all of the tiles on each of the map's <see cref="TiledMap.TileLayers"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue