Class catan.logic.FaceMap

An associative array with hexagonal grid faces as keys.

Methods

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


Methods

catan.logic.facemap:new ()
Create an empty face map.

Returns:

    catan.logic.FaceMap an empty face map
catan.logic.facemap:get (face)
Get the object associated with face.

Parameters:

  • face {q=number,r=number}

Returns:

    the object associated with face

Usage:

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

Parameters:

  • face {q=number,r=number}
  • o the object to associate face with

Usage:

    local facemap = FaceMap:new()
    local face = {q=1, r=0}
    print(facemap:get(face)) --> nil
    facemap:set(face, 'hah')
    print(facemap:get(face)) --> hah
catan.logic.facemap: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 and o, where q and r uniquely identify the face and o is the value associated with such face. If this function returns a value different from nil or false, iteration is interrupted and this value is returned immediately.

Usage:

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