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 withface
by passing the valuenil
as parametero
.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
ando
, whereq
andr
uniquely identify the face ando
is the value associated with such face. If this function returns a value different fromnil
orfalse
, 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
- f
function
the iterator that will be called
for each association, receiving as parameter the
values