Kryzeth Standard Library

StdLib.Area.Tile

supers: StdLib.Core

Tools for working with tiles. A tile represents a 1 unit<sup>2</sup> on a surface in Factorio.

See:

LuaTile

@usage local Tile = require('kry_stdlib/stdlib/area/tile')

Methods5

function Tile.adjacent(surface: LuaSurface, position: TilePosition, diagonal: nil | boolean, tile_name) -> TilePosition[]

Creates an array of tile positions for all adjacent tiles (N, E, S, W) OR (N, NE, E, SE, S, SW, W, NW) if diagonal is set to true.

Parameters
surfaceLuaSurface

the surface to examine for adjacent tiles

positionTilePosition

the tile position of the origin tile

diagonalnil | boolean

[opt=false] whether to include diagonal tiles

tile_name
Returns
TilePosition[]

an array of tile positions of the tiles that are adjacent to the origin tile

@paramtile_name string? [opt] whether to restrict adjacent tiles to a particular tile name (example: "water-tile")

function Tile.get_data(surface: LuaSurface, tile_pos: TilePosition, default_value: any) -> any

Gets the user data that is associated with a tile. The user data is stored in the global object and it persists between loads.

Parameters
surfaceLuaSurface

the surface on which the user data is looked up

tile_posTilePosition

the tile position on which the user data is looked up

default_valueany

the user data to set for the tile and returned if it did not have user data

Returns
any

the user data OR nil if it does not exist for the tile and no default_value was set

function Tile.get(surface: LuaSurface, tile_pos: TilePosition, default_value: any) -> any
Parameters
surfaceLuaSurface

the surface on which the user data is looked up

tile_posTilePosition

the tile position on which the user data is looked up

default_valueany

the user data to set for the tile and returned if it did not have user data

Returns
any

the user data OR nil if it does not exist for the tile and no default_value was set

function Tile.set_data(surface: LuaSurface, tile_pos: TilePosition, value: any) -> any

Associates the user data to a tile. The user data will be stored in the global object and it will persist between loads.

Parameters
surfaceLuaSurface

the surface on which the user data will reside

tile_posTilePosition

the tile position of a tile that will be associated with the user data

valueany

the user data to set OR nil to erase the existing user data for the tile

Returns
any

the previous user data associated with the tile OR nil if the tile had no previous user data

function Tile.set(surface: LuaSurface, tile_pos: TilePosition, value: any) -> any
Parameters
surfaceLuaSurface

the surface on which the user data will reside

tile_posTilePosition

the tile position of a tile that will be associated with the user data

valueany

the user data to set OR nil to erase the existing user data for the tile

Returns
any

the previous user data associated with the tile OR nil if the tile had no previous user data

Fields5

Tile.__class: string = "Tile"
Tile.__index : unknown
Tile.__call : any
Tile.from_position : any

Get the @{TilePosition|tile position} of a tile where the given position resides. @function Tile.from_position @see StdLib.Area.Position.floor

Tile.to_area : any

Converts a tile position to the @{BoundingBox|area} of the tile it is in. @function Tile.to_area @see StdLib.Area.Position.totilearea