Table of Contents

Class AutoTile

Namespace
TinyLife.World
Assembly
TinyLife.dll

An auto-tile is a Tile that visually connects to other tiles around it, while leaving a border around tiles that it doesn't connect to. Implementors can override ConnectsToTile(TileInstance, int, int, Func<Point, int, TileInstance>) to edit this behavior.

public class AutoTile : Tile
Inheritance
AutoTile
Derived
Inherited Members
Extension Methods

Constructors

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

protected AutoTile(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

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

Methods

ConnectsToTile(TileInstance, int, int, Func<Point, int, TileInstance>)

Override this method to determine what other tiles this auto-tile should connect to. By default, auto-tiles connect to other tiles of the same type.

protected virtual bool ConnectsToTile(TileInstance instance, int x, int y, Func<Point, int, TileInstance> getRelatedTileFunc = null)

Parameters

instance TileInstance

The tile instance of the current tile.

x int

The offset from the instance's position in the x axis.

y int

The offset from the instance's position in the y axis.

getRelatedTileFunc Func<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 should connect to the tile at the offset position.

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 override TileInstance CreateInstance(Map map, Point position, int floor)

Parameters

map Map

The map the tile instance should be on.

position Point

The position the tile instance should be at.

floor int

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

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.

instance TileInstance

The in-world instance of this tile being drawn. This may be null, in which case the tile is likely being draw in UI space.

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

DrawBorder(object, TileInstance, int, Vector2, float, float, ICollection<Item>, Func<Point, int, TileInstance>)

Draws the auto-tile border.

protected virtual void DrawBorder(object batch, TileInstance instance, int layer, Vector2 drawPos, float scale, float depthOffset, ICollection<StaticSpriteBatch.Item> items, Func<Point, int, TileInstance> getRelatedTileFunc = null)

Parameters

batch object

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

instance TileInstance

The tile instance of the current tile.

layer int

The layer of the border to draw. By default, tiles use layer 0 for regular borders, and layer 1 for special borders, like the little "cliff" that displays on water tiles. This is passed to GetAutoTileBorder(TileInstance, TileInstance, int, int, Func<Point, int, TileInstance>).

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 is optionally added to the calculated draw depth.

items ICollection<StaticSpriteBatch.Item>

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

getRelatedTileFunc Func<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.

GetDefaultBorderTile(int)

Returns the tile information that should be used in place of GetAutoTileBorder(TileInstance, TileInstance, int, int, Func<Point, int, TileInstance>) if no relevant border tiles are around. This defaults to the grass tile border with the default color.

protected virtual (TextureRegion, Color) GetDefaultBorderTile(int autoTileIndex)

Parameters

autoTileIndex int

Returns

(TextureRegion, Color)

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 override void OnNeighborChanged(TileInstance instance, Point neighbor)

Parameters

instance TileInstance

The tile instance of the current tile.

neighbor Point

The position of the tile that changed.