Class catan.logic.EdgeMap

An associative array with hexagonal grid edges as keys.

Methods

catan.logic.edgemap:new () Create an empty edge map.
catan.logic.edgemap:get (edge) Get the object associated with edge.
catan.logic.edgemap:set (edge, o) Associate edge with some object.
catan.logic.edgemap:iter (f) Iterate through all the associations.


Methods

catan.logic.edgemap:new ()
Create an empty edge map.

Returns:

    catan.logic.EdgeMap an empty edge map
catan.logic.edgemap:get (edge)
Get the object associated with edge.

Parameters:

  • edge {q=number,r=number,e='NW', 'W' or 'NE'}

Returns:

    the object associated with edge

Usage:

    local edgemap = EdgeMap:new()
    local edge = {q=1, r=0, e='W'}
    print(edgemap:get(edge)) --> nil
    edgemap:set(edge, 'hah')
    print(edgemap:get(edge)) --> hah
catan.logic.edgemap:set (edge, o)
Associate edge with some object. You can also remove any association with edge by passing the value nil as parameter o.

Parameters:

  • edge {q=number,r=number,e='NW', 'W' or 'NE'}
  • o the object to associate edge with

Usage:

    local edgemap = EdgeMap:new()
    local edge = {q=1, r=0, e='W'}
    print(edgemap:get(edge)) --> nil
    edgemap:set(edge, 'hah')
    print(edgemap:get(edge)) --> hah
catan.logic.edgemap:iter (f)
Iterate through all the associations.

Parameters:

  • f function the iterator that will be called for each association, receiving as parameter the values q, r, e and o, where q, r and e uniquely identify the edge and o is the value associated with such edge. If this function returns a value different from nil or false, iteration is interrupted and this value is returned immediately.

Usage:

    local haystack = EdgeMap:new()
    -- ...
    local edge = haystack:iter(function (q, r, e, o)
      if o == 'needle' then
        return {q = q, r = r, e = e}
      end
    end)
    if edge ~= nil then
      print(haystack:get(edge)) --> needle
    end
generated by LDoc 1.5.0 Last updated 2023-07-02 05:10:58