Table of Contents

Class Tile

Namespace
TinyLife.World
Assembly
Tiny Life.dll

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, Dictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type).

[JsonConverter(typeof(Tile.Converter))]
public class Tile
Inheritance
Tile
Derived
Inherited Members
Extension Methods

Constructors

Tile(string, string, int, Dictionary<Point, TextureRegion>, Dictionary<Direction2, Point[]>, ColorSettings, int[], bool, float, Category, TextureRegion, Func<Point, float>)

protected Tile(string baseName, string name, int price, Dictionary<Point, TextureRegion> textures, Dictionary<Direction2, Point[]> regions, ColorSettings colorSettings, int[] colors, bool canBuy, float pathCostModifier, Tile.Category categories, TextureRegion icon, Func<Point, float> regionWeights)

Parameters

baseName string
name string
price int
textures Dictionary<Point, TextureRegion>
regions Dictionary<Direction2, Point[]>
colorSettings ColorSettings
colors int[]
canBuy bool
pathCostModifier float
categories Tile.Category
icon TextureRegion
regionWeights Func<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

string

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

bool

Categories

The Tile.Category flags that this tile has.

public readonly Tile.Category Categories

Field Value

Tile.Category

CheckeredHardwood

public static readonly Tile[] CheckeredHardwood

Field Value

Tile[]

ColorSettings

The color settings used by this tile.

public readonly ColorSettings ColorSettings

Field Value

ColorSettings

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[]

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[]

FlowerGrass

public static readonly Tile[] FlowerGrass

Field Value

Tile[]

Grass

public static readonly Tile[] Grass

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[]

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

string

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

float

Price

The price of this tile

public readonly int Price

Field Value

int

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

int

RegionWeights

An optional weight function that determines how likely each variation texture is to be picked.

public readonly Func<Point, float> RegionWeights

Field Value

Func<Point, float>

Regions

The texture regions this tile uses, which refer to entries in Textures.

public readonly Dictionary<Direction2, Point[]> Regions

Field Value

Dictionary<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 Dictionary<Point, TextureRegion> Textures

Field Value

Dictionary<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

ReadOnlyDictionary<string, Tile[]>

Water

public static readonly Tile[] Water

Field Value

Tile[]

Methods

Draw(GameTime, object, Map, Point, int, Vector2, float, float, ICollection<Item>, bool, Func<Point, int, Tile>)

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, Map map, Point pos, int floor, Vector2 drawPos, float scale, float depthOffset, ICollection<StaticSpriteBatch.Item> items, bool hasStaticContext, Func<Point, int, Tile> getRelatedTileFunc = null)

Parameters

time GameTime

The game's current time.

batch object

The sprite batch to use for drawing, which can either be a Microsoft.Xna.Framework.Graphics.SpriteBatch or a MLEM.Graphics.StaticSpriteBatch.

map Map

The map that the tile is on.

pos Point

The position that the tile is on.

floor int

The floor that this tile is on.

drawPos Vector2

The position, in screen space, to draw at.

scale float

The scale to draw the tile with.

depthOffset float

A depth offset that can optionally be added to this tile's draw depth.

items ICollection<StaticSpriteBatch.Item>

The MLEM.Graphics.StaticSpriteBatch.Item collection that added items can optionally be added to.

hasStaticContext bool

Whether this tile also has a static context, that is, whether it will already be drawn using a MLEM.Graphics.StaticSpriteBatch.

getRelatedTileFunc Func<Point, int, Tile>

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 batch is 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

e Element

The element to draw on

time GameTime

The game's current time.

batch SpriteBatch

The sprite batch to use for drawing

drawScale float

The scale to draw the tile with.

GetAutoTileBorder(Map, Point, int, Point, Tile, int)

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 (Func<int, TextureRegion> Texture, Color Color, float Priority)? GetAutoTileBorder(Map map, Point pos, int floor, Point neighbor, Tile neighborTile, int layer)

Parameters

map Map

The map.

pos Point

The position of this tile.

floor int

The floor that this tile is on.

neighbor Point

The position of the neighbor tile querying the auto tile border on this tile.

neighborTile Tile

The neighbor tile querying the auto tile border on this tile.

layer int

The 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.

Returns

(Func<int, 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

map Map

The map to get depth on.

worldPos Vector2

The position to get depth for, in tile coordinates

floor float

The floor to get depth for.

offset float

An offset added to the depth value

borderOffset bool

Whether 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.

GetVariationTexture(Direction2, Point)

Returns a random texture that should be displayed at the given position, based on the Textures variations that this tile has. If a tile only has one variation texture, this method always returns that texture.

protected Point GetVariationTexture(Direction2 direction, Point pos)

Parameters

direction Direction2

The camera rotation.

pos Point

The position that the tile is at.

Returns

Point

The texture to display at the location.

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

direction Direction2

The rotation.

x int

The x coordinate to offset.

y int

The y coordinate to offset.

Returns

Point

The visual offset.

OnNeighborChanged(Map, Point, Point, int)

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(Map map, Point pos, Point neighbor, int floor)

Parameters

map Map

The map that the tile is on.

pos Point

The position that the tile is on.

neighbor Point

The position of the tile that changed.

floor int

The floor that this tile and the neighbor are on.

Register(string, int, Dictionary<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, Dictionary<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

name string

The name that the tile should have.

price int

The tile's price.

textures Dictionary<Point, TextureRegion>

The texture atlas to use.

textureRegion Point

The texture region that this tile should use for rendering.

color ColorScheme

The color scheme that this tile should have.

pathCostModifier float

The path cost modifier, >= 1, that this tile should have.

canBuy bool

Whether or not the tile can be bought in the tile tool.

categories Tile.Category

This tile's Tile.Category flags.

icon TextureRegion

The build mode category icon of this object.

variations Func<Direction2, Point?>

An optional set of variation textures that should be used based on the given camera rotation.

defaultColor int?

The color that this tile should display with in the tile tool by default.

regionWeights Func<Point, float>

An optional weight function that determines how likely each variation texture is to be picked.

constructedType Type

The type that tiles should be constructed from, or null to construct Tile instances.

Returns

Tile[]

Register(string, int, Dictionary<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, Dictionary<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

name string

The name that the tile should have.

price int

The tile's price.

textures Dictionary<Point, TextureRegion>

The texture atlas to use.

textureRegion Point

The texture region that this tile should use for rendering.

colors ColorScheme[]

The color scheme that this tile should have.

pathCostModifier float

The path cost modifier, >= 1, that this tile should have.

canBuy bool

Whether or not the tile can be bought in the tile tool.

categories Tile.Category

This tile's Tile.Category flags.

icon TextureRegion

The build mode category icon of this object.

variations Func<Direction2, Point?>

An optional set of variation textures that should be used based on the given camera rotation.

defaultColors int[]

The colors that this tile should display with in the tile tool by default.

regionWeights Func<Point, float>

An optional weight function that determines how likely each variation texture is to be picked.

constructedType Type

The type that tiles should be constructed from, or null to construct Tile instances.

Returns

Tile[]

Register(string, int, Dictionary<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, Dictionary<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

name string

The name that the tile should have.

price int

The tile's price.

textures Dictionary<Point, TextureRegion>

The texture atlas to use.

textureRegions Point[]

The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.

colors ColorScheme[]

The color scheme that this tile should have.

pathCostModifier float

The path cost modifier, >= 1, that this tile should have.

canBuy bool

Whether or not the tile can be bought in the tile tool.

categories Tile.Category

This tile's Tile.Category flags.

icon TextureRegion

The build mode category icon of this object.

variations Func<Direction2, Point[]>

An optional set of variation textures that should be used based on the given camera rotation.

defaultColors int[]

The default colors that will be passed to the ColorSettings Defaults.

regionWeights Func<Point, float>

An optional weight function that determines how likely each variation texture is to be picked.

constructedType Type

The type that tiles should be constructed from, or null to construct Tile instances.

Returns

Tile[]

The registered tiles.

Register(string, int, Dictionary<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, Dictionary<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

name string

The name that the tile should have.

price int

The tile's price.

textures Dictionary<Point, TextureRegion>

The texture atlas to use.

textureRegions Point[]

The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.

colors ColorSettings

The color scheme that this tile should have.

pathCostModifier float

The path cost modifier, >= 1, that this tile should have.

canBuy bool

Whether or not the tile can be bought in the tile tool.

categories Tile.Category

This tile's Tile.Category flags.

icon TextureRegion

The build mode category icon of this object.

variations Func<Direction2, Point[]>

An optional set of variation textures that should be used based on the given camera rotation.

regionWeights Func<Point, float>

An optional weight function that determines how likely each variation texture is to be picked.

constructedType Type

The type that tiles should be constructed from, or null to construct Tile instances.

Returns

Tile[]

The registered tiles.