Class Tile
A tile is an object on a Map that represents the covering of the ground (or the ground itself). To register a tile, use Register(string,int,System.Collections.Generic.Dictionary<Microsoft.Xna.Framework.Point,MLEM.Textures.TextureRegion>,Microsoft.Xna.Framework.Point,TinyLife.Utilities.ColorScheme,float,bool,TinyLife.World.Tile.Category,MLEM.Textures.TextureRegion,System.Func<Direction2,System.Nullable<Microsoft.Xna.Framework.Point>>,System.Nullable<int>,System.Func<Microsoft.Xna.Framework.Point,float>,System.Type).
[JsonConverter(typeof(Tile.Converter))]
public class Tile
- Inheritance
-
Tile
- Derived
- Inherited Members
- Extension Methods
Constructors
Tile(string, string, int, IReadOnlyDictionary<Point, TextureRegion>, IReadOnlyDictionary<Direction2, Point[]>, ColorSettings, int[], bool, float, Category, TextureRegion, Func<Point, float>)
Creates a new tile with the given settings. To create an instance of a custom tile class, use Register(string, int, IReadOnlyDictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type).
protected Tile(string baseName, string name, int price, IReadOnlyDictionary<Point, TextureRegion> textures, IReadOnlyDictionary<Direction2, Point[]> regions, ColorSettings colorSettings, int[] colors, bool canBuy, float pathCostModifier, Tile.Category categories, TextureRegion icon, Func<Point, float> regionWeights)
Parameters
baseNamestringnamestringpriceinttexturesIReadOnlyDictionary<Point, TextureRegion>regionsIReadOnlyDictionary<Direction2, Point[]>colorSettingsColorSettingscolorsint[]canBuyboolpathCostModifierfloatcategoriesTile.CategoryiconTextureRegionregionWeightsFunc<Point, float>
Fields
BaseName
The name of this type of tile. Whereas Name has the index of its Colors appended to it, this one is just the type's name.
public readonly string BaseName
Field Value
BigTiles
public static readonly Tile[] BigTiles
Field Value
- Tile[]
CanBuy
A field that indicates whether this tile can be bought without the "ShowNonBuyable" cheat enabled
public readonly bool CanBuy
Field Value
Categories
The Tile.Category flags that this tile has.
public readonly Tile.Category Categories
Field Value
CheckeredHardwood
public static readonly Tile[] CheckeredHardwood
Field Value
- Tile[]
ColorSettings
The color settings used by this tile.
public readonly ColorSettings ColorSettings
Field Value
Colors
The indices of the colors in each ColorSettings entry that this tile has
public readonly int[] Colors
Field Value
- int[]
Concrete
public static readonly Tile[] Concrete
Field Value
- Tile[]
Dirt
public static readonly Tile[] Dirt
Field Value
- Tile[]
DirtPath
public static readonly Tile[] DirtPath
Field Value
- Tile[]
DirtRoad
public static readonly Tile[] DirtRoad
Field Value
- Tile[]
DirtRoadCorners
public static readonly Tile[][] DirtRoadCorners
Field Value
- Tile[][]
DirtRoadLines1
public static readonly Tile[] DirtRoadLines1
Field Value
- Tile[]
DirtRoadLines2
public static readonly Tile[] DirtRoadLines2
Field Value
- Tile[]
DirtWithGrass
public static readonly Tile[] DirtWithGrass
Field Value
- Tile[]
FlowerCovering
public static readonly Tile[] FlowerCovering
Field Value
- Tile[]
FlowerGrass
public static readonly Tile[] FlowerGrass
Field Value
- Tile[]
Grass
public static readonly Tile[] Grass
Field Value
- Tile[]
Gravel
public static readonly Tile[] Gravel
Field Value
- Tile[]
Icon
The build mode icon for this object, which represents the category / theme / mod that it comes from. If this value is nonnull, the icon will be displayed in the corner of the build mode button for this object.
public readonly TextureRegion Icon
Field Value
- TextureRegion
IntricateCarpet
public static readonly Tile[] IntricateCarpet
Field Value
- Tile[]
LargeConcreteTiles
public static readonly Tile[] LargeConcreteTiles
Field Value
- Tile[]
LongBoards
public static readonly Tile[] LongBoards
Field Value
- Tile[]
ModernBricks
public static readonly Tile[] ModernBricks
Field Value
- Tile[]
ModernTiles
public static readonly Tile[] ModernTiles
Field Value
- Tile[]
Moss
public static readonly Tile[] Moss
Field Value
- Tile[]
Name
The name of this specific tile. This is comprised of the BaseName with the Colors's index attached to it.
public readonly string Name
Field Value
OrnateHardwood
public static readonly Tile[] OrnateHardwood
Field Value
- Tile[]
PathCostModifier
A field that indicates the "cost" for pathfinding of this tile. The default modifier is 1, and it should not be set to a value lower than that.
public readonly float PathCostModifier
Field Value
Price
The price of this tile
public readonly int Price
Field Value
PuzzlePieces
public static readonly Tile[] PuzzlePieces
Field Value
- Tile[]
ReferencePrice
The reference price for tiles. Since Grass is replaced by Concrete in a newly created room, the two tiles have to cost the same. This is that price. This value is set to 5.
public const int ReferencePrice = 5
Field Value
RegionWeights
An optional weight function that determines how likely each variation texture is to be picked.
public readonly Func<Point, float> RegionWeights
Field Value
Regions
The texture regions this tile uses, which refer to entries in Textures.
public readonly IReadOnlyDictionary<Direction2, Point[]> Regions
Field Value
- IReadOnlyDictionary<Direction2, Point[]>
RicketyHardwood
public static readonly Tile[] RicketyHardwood
Field Value
- Tile[]
Road1
public static readonly Tile[] Road1
Field Value
- Tile[]
Road2
public static readonly Tile[] Road2
Field Value
- Tile[]
Road3
public static readonly Tile[] Road3
Field Value
- Tile[]
Road4
public static readonly Tile[] Road4
Field Value
- Tile[]
Road5
public static readonly Tile[] Road5
Field Value
- Tile[]
Rocks
public static readonly Tile[] Rocks
Field Value
- Tile[]
Sand
public static readonly Tile[] Sand
Field Value
- Tile[]
SimpleCarpet
public static readonly Tile[] SimpleCarpet
Field Value
- Tile[]
SmallCheckeredHardwood
public static readonly Tile[] SmallCheckeredHardwood
Field Value
- Tile[]
SoftCarpet
public static readonly Tile[] SoftCarpet
Field Value
- Tile[]
StraightBoards
public static readonly Tile[] StraightBoards
Field Value
- Tile[]
Textures
The texture atlas used for this tile.
public readonly IReadOnlyDictionary<Point, TextureRegion> Textures
Field Value
- IReadOnlyDictionary<Point, TextureRegion>
Tiles
A registry of all tiles that exist in the game and its mods
public static readonly ReadOnlyDictionary<string, Tile[]> Tiles
Field Value
Water
public static readonly Tile[] Water
Field Value
- Tile[]
Methods
CreateInstance(Map, Point, int)
Creates an instance of this tile to be placed on the given Map at the specified position and floor. This method can be overridden for custom tiles to add additional caching or serializable data.
public virtual TileInstance CreateInstance(Map map, Point position, int floor)
Parameters
mapMapThe map the tile instance should be on.
positionPointThe position the tile instance should be at.
floorintThe floor the tile instance should be on.
Returns
- TileInstance
The created tile instance.
Draw(GameTime, object, TileInstance, Vector2, float, float, ICollection<Item>, bool, Func<Point, int, TileInstance>)
Draws this tile at the given position in the world using a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch
public virtual bool Draw(GameTime time, object batch, TileInstance instance, Vector2 drawPos, float scale, float depthOffset, ICollection<StaticSpriteBatch.Item> items, bool hasStaticContext, Func<Point, int, TileInstance> getRelatedTileFunc = null)
Parameters
timeGameTimeThe game's current time.
batchobjectThe sprite batch to use for drawing, which can either be a Microsoft.Xna.Framework.Graphics.SpriteBatch or a MLEM.Graphics.StaticSpriteBatch.
instanceTileInstanceThe in-world instance of this tile being drawn. This may be null, in which case the tile is likely being draw in UI space.
drawPosVector2The position, in screen space, to draw at.
scalefloatThe scale to draw the tile with.
depthOffsetfloatA depth offset that can optionally be added to this tile's draw depth.
itemsICollection<StaticSpriteBatch.Item>The MLEM.Graphics.StaticSpriteBatch.Item collection that added items can optionally be added to.
hasStaticContextboolWhether this tile also has a static context, that is, whether it will already be drawn using a MLEM.Graphics.StaticSpriteBatch.
getRelatedTileFuncFunc<Point, int, TileInstance>A function that can optionally be supplied to override the GetTile(Point, int) method when checking for neighboring tiles. This is useful for when tile placement in the world is mocked, for example.
Returns
- bool
Whether this tile was fully drawn. If the
batchis a MLEM.Graphics.StaticSpriteBatch and false is returned, this tile will be marked as an animated tile, causing it to draw every frame.
DrawUi(Element, GameTime, SpriteBatch, float)
Draws this tile on the given ui element, in ui space
public virtual void DrawUi(Element e, GameTime time, SpriteBatch batch, float drawScale)
Parameters
eElementThe element to draw on
timeGameTimeThe game's current time.
batchSpriteBatchThe sprite batch to use for drawing
drawScalefloatThe scale to draw the tile with.
GetAutoTileBorder(TileInstance, TileInstance, int, int, Func<Point, int, TileInstance>)
Returns the texture that should be displayed as the border when a AutoTile draws next to this tile. By default, this method returns values only for some basegame tiles.
public virtual (TextureRegion Texture, Color Color, float Priority)? GetAutoTileBorder(TileInstance instance, TileInstance neighbor, int layer, int autoTileIndex, Func<Point, int, TileInstance> getRelatedTileFunc)
Parameters
instanceTileInstanceThe tile instance of the current tile.
neighborTileInstanceThe neighbor tile instance querying the auto tile border on this tile.
layerintThe layer of the border being drawn. By default, tiles use layer 0 for regular borders, and layer 1 for special borders, like the little "cliff" that displays on water tiles.
autoTileIndexintThe "offset" from the auto-tile's initial texture location that should be drawn. The value ranges from 0 to 15 and denotes the type of border (ie the corner) that is being drawn.
getRelatedTileFuncFunc<Point, int, TileInstance>A function that can optionally be used to return additional tile instances at the given offset and floor which aren't currently placed on the map.
Returns
- (TextureRegion Texture, Color Color, float Priority)?
The texture, or null to draw no auto-tile border.
GetDepth(Map, Vector2, float, float, bool)
Gets the depth that should be used for drawing a Tile at the given position
public static float GetDepth(Map map, Vector2 worldPos, float floor, float offset = 0, bool borderOffset = true)
Parameters
mapMapThe map to get depth on.
worldPosVector2The position to get depth for, in tile coordinates
floorfloatThe floor to get depth for.
offsetfloatAn offset added to the depth value
borderOffsetboolWhether the map border offset should be applied to the camera rotation using ApplyCameraRotation(Vector2, bool, Direction2?).
Returns
- float
The depth to pass to the draw call
GetPrice()
Returns the price for this tile, which is normally based on Price.
public virtual float GetPrice()
Returns
- float
The price for this tile.
GetVisualOffset(Direction2, int, int)
Returns the visual offset of the given x and y values, based on the given direction, which is usually the game's CameraRotation.
protected static Point GetVisualOffset(Direction2 direction, int x, int y)
Parameters
directionDirection2The rotation.
xintThe x coordinate to offset.
yintThe y coordinate to offset.
Returns
- Point
The visual offset.
OnNeighborChanged(TileInstance, Point)
A method that is called when a neighboring Tile on the Map changes. This method does nothing by default, but is overriden by AutoTile to notify neighboring tiles of changes.
public virtual void OnNeighborChanged(TileInstance instance, Point neighbor)
Parameters
instanceTileInstanceThe tile instance of the current tile.
neighborPointThe position of the tile that changed.
Register(string, int, IReadOnlyDictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, IReadOnlyDictionary<Point, TextureRegion> textures, Point textureRegion, ColorScheme color, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point?> variations = null, int? defaultColor = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
namestringThe name that the tile should have.
priceintThe tile's price.
texturesIReadOnlyDictionary<Point, TextureRegion>The texture atlas to use.
textureRegionPointThe texture region that this tile should use for rendering.
colorColorSchemeThe color scheme that this tile should have.
pathCostModifierfloatThe path cost modifier, >= 1, that this tile should have.
canBuyboolWhether or not the tile can be bought in the tile tool.
categoriesTile.CategoryThis tile's Tile.Category flags.
iconTextureRegionThe build mode category icon of this object.
variationsFunc<Direction2, Point?>An optional set of variation textures that should be used based on the given camera rotation.
defaultColorint?The color that this tile should display with in the tile tool by default.
regionWeightsFunc<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedTypeTypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
Register(string, int, IReadOnlyDictionary<Point, TextureRegion>, Point, ColorScheme[], float, bool, Category, TextureRegion, Func<Direction2, Point?>, int[], Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, IReadOnlyDictionary<Point, TextureRegion> textures, Point textureRegion, ColorScheme[] colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point?> variations = null, int[] defaultColors = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
namestringThe name that the tile should have.
priceintThe tile's price.
texturesIReadOnlyDictionary<Point, TextureRegion>The texture atlas to use.
textureRegionPointThe texture region that this tile should use for rendering.
colorsColorScheme[]The color scheme that this tile should have.
pathCostModifierfloatThe path cost modifier, >= 1, that this tile should have.
canBuyboolWhether or not the tile can be bought in the tile tool.
categoriesTile.CategoryThis tile's Tile.Category flags.
iconTextureRegionThe build mode category icon of this object.
variationsFunc<Direction2, Point?>An optional set of variation textures that should be used based on the given camera rotation.
defaultColorsint[]The colors that this tile should display with in the tile tool by default.
regionWeightsFunc<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedTypeTypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
Register(string, int, IReadOnlyDictionary<Point, TextureRegion>, Point[], ColorScheme[], float, bool, Category, TextureRegion, Func<Direction2, Point[]>, int[], Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, IReadOnlyDictionary<Point, TextureRegion> textures, Point[] textureRegions, ColorScheme[] colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point[]> variations = null, int[] defaultColors = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
namestringThe name that the tile should have.
priceintThe tile's price.
texturesIReadOnlyDictionary<Point, TextureRegion>The texture atlas to use.
textureRegionsPoint[]The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.
colorsColorScheme[]The color scheme that this tile should have.
pathCostModifierfloatThe path cost modifier, >= 1, that this tile should have.
canBuyboolWhether or not the tile can be bought in the tile tool.
categoriesTile.CategoryThis tile's Tile.Category flags.
iconTextureRegionThe build mode category icon of this object.
variationsFunc<Direction2, Point[]>An optional set of variation textures that should be used based on the given camera rotation.
defaultColorsint[]The default colors that will be passed to the ColorSettingsDefaults.
regionWeightsFunc<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedTypeTypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
The registered tiles.
Register(string, int, IReadOnlyDictionary<Point, TextureRegion>, Point[], ColorSettings, float, bool, Category, TextureRegion, Func<Direction2, Point[]>, Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, IReadOnlyDictionary<Point, TextureRegion> textures, Point[] textureRegions, ColorSettings colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point[]> variations = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
namestringThe name that the tile should have.
priceintThe tile's price.
texturesIReadOnlyDictionary<Point, TextureRegion>The texture atlas to use.
textureRegionsPoint[]The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.
colorsColorSettingsThe color scheme that this tile should have.
pathCostModifierfloatThe path cost modifier, >= 1, that this tile should have.
canBuyboolWhether or not the tile can be bought in the tile tool.
categoriesTile.CategoryThis tile's Tile.Category flags.
iconTextureRegionThe build mode category icon of this object.
variationsFunc<Direction2, Point[]>An optional set of variation textures that should be used based on the given camera rotation.
regionWeightsFunc<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedTypeTypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
The registered tiles.