Module map

The map module Has a Map class, which is used to hold a 2D grid of elements.

Functions

Map:initialize (width, height) Initializes a Map instance filled with solid Tiles.
Map:to_index (x, y) Converts position(x, y) to index in map.
Map:to_index_str (xy) Converts position in string format("X;Y") to index in map.
Map:in_bounds (x, y) Checks if position is in bounds of a map.
Map:set (x, y, v) Sets a value in position(x, y) to the new value Errors if a position is outside of map's bounds.
Map:set_all (v) Sets all values in the map to the new value.
Map:get_str (xy) Gets a value on the position.
Map:get (x, y) Gets a value on the position.
Map:iter (x, y, w, h, func) Iterate over map region.
Map:iter_xy (x, y, w, h, func) Iterate over map region.
Map:foreach (func) Iterate over all map.
Map:foreach_xy (func) Iterate over all map.
Map:submap (x, y, w, h) Gets a piece of a map.
Map:find_region (x, y, w, h, v) Finds a value in region.
Map:find_region_rand (x, y, w, h, v, attempts) Finds a value in region, randomly.
Map:find (v) Finds a value in the map.
Map:find_rand (v) Finds a value in the map, randomly.
Map:check (x, y, w, h, func) Checks values in the region using a function.
Map:check_xy (x, y, w, h, func) Checks values in the region using a function.
Map:check_all (func) Checks values in the map using a function.
Map:check_xy_all (func) Checks values in the map using a function.
Map:clone () Makes an exact copy of the map.


Functions

Map:initialize (width, height)
Initializes a Map instance filled with solid Tiles.

Parameters:

  • width a positive integer
  • height a positive integer
Map:to_index (x, y)
Converts position(x, y) to index in map.

Parameters:

  • x a positive integer
  • y a positive integer

Returns:

    an index for this map
Map:to_index_str (xy)
Converts position in string format("X;Y") to index in map.

Parameters:

  • xy a string in X;Y format

Returns:

    an index for this map
Map:in_bounds (x, y)
Checks if position is in bounds of a map.

Parameters:

  • x an integer
  • y an integer

Returns:

    a bool
Map:set (x, y, v)
Sets a value in position(x, y) to the new value Errors if a position is outside of map's bounds.

Parameters:

  • x an integer
  • y an integer
  • v any value
Map:set_all (v)
Sets all values in the map to the new value.

Parameters:

  • v any value
Map:get_str (xy)
Gets a value on the position.

Parameters:

  • xy a string in X;Y format

Returns:

    any value, nil if doesn't exist
Map:get (x, y)
Gets a value on the position.

Parameters:

  • x an integer or a string in X;Y format
  • y an integer

Returns:

    any value, nil if doesn't exist
Map:iter (x, y, w, h, func)
Iterate over map region.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • func a function which will get values and which will return new values
Map:iter_xy (x, y, w, h, func)
Iterate over map region.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • func a function which will get values and positions and which will return new values
Map:foreach (func)
Iterate over all map.

Parameters:

  • func a function which will get values and which will return new values
Map:foreach_xy (func)
Iterate over all map.

Parameters:

  • func a function which will get values and positions and which will return new values
Map:submap (x, y, w, h)
Gets a piece of a map.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)

Returns:

    a new Map
Map:find_region (x, y, w, h, v)
Finds a value in region.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • v any value

Returns:

    a position{x, y} or nil if there is no that value in the region
Map:find_region_rand (x, y, w, h, v, attempts)
Finds a value in region, randomly.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • v any value
  • attempts number of attemptsof finding

Returns:

    a position{x, y} or nil if there is no that value in the region
Map:find (v)
Finds a value in the map.

Parameters:

  • v any value

Returns:

    a position{x, y} or nil if there is no that value in the map
Map:find_rand (v)
Finds a value in the map, randomly.

Parameters:

  • v any value

Returns:

    a position{x, y} or nil if there is no that value in the map
Map:check (x, y, w, h, func)
Checks values in the region using a function.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • func a function which will get values and which will return a bool

Returns:

    a set of positions in the "X;Y" format
Map:check_xy (x, y, w, h, func)
Checks values in the region using a function.

Parameters:

  • x an integer
  • y an integer
  • w an integer(width)
  • h an integer(height)
  • func a function which will get values and positions and which will return a bool

Returns:

    a set of positions in the "X;Y" format
Map:check_all (func)
Checks values in the map using a function.

Parameters:

  • func a function which will get values and which will return a bool

Returns:

    a set of positions in the "X;Y" format
Map:check_xy_all (func)
Checks values in the map using a function.

Parameters:

  • func a function which will get values and positions and which will return a bool

Returns:

    a set of positions in the "X;Y" format
Map:clone ()
Makes an exact copy of the map.

Returns:

    a new Map
generated by LDoc 1.4.6 Last updated 2017-11-19 16:11:59