pyhexlib.layers module

class pyhexlib.layers.AxialCoordinateHexGridLayer(grid_id, hexagons=None, visible=False, comment=None)[source]

Bases: HexGridLayer

Parameters:
  • grid_id (str)

  • hexagons (HexagonalGrid)

  • visible (bool)

  • comment (str)

convert(rc)[source]
Parameters:

rc (Hexagon)

Return type:

AxialCoordinate

class pyhexlib.layers.Border(rc, direction)[source]

Bases: object

A border between two Hexagons, or the border of a HexGrid.

Parameters:
class pyhexlib.layers.CoordinateGridLayer(grid_id, visible=False, font_family='Arial', font_color=(0, 0, 0), font_size=12, comment=None)[source]

Bases: TextGridLayer

Parameters:
  • grid_id (str)

  • font_color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

  • font_size (int)

get_value(rc)[source]
Parameters:

rc (Hexagon)

Return type:

str

class pyhexlib.layers.FillGridLayer(grid_id, hexagons=None, visible=True, default_color=None, comment=None)[source]

Bases: StyledGridLayer

A grid that stores fill colors for each hexagon.

Parameters:

default_color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

class pyhexlib.layers.HexGridLayer(grid_id, hexagons=None, visible=True, comment=None)[source]

Bases: ABC

An abstract base class for all hexagon grids. It keeps track of the hexagons in the grid and whether the grid is visible.

Parameters:
  • grid_id (str)

  • hexagons (HexagonalGrid)

  • visible (bool)

  • comment (str)

clear()[source]
is_dirty()[source]
Return type:

bool

set_clean()[source]
Return type:

None

set_dirty()[source]
Return type:

None

class pyhexlib.layers.HexGridManager(hexagons)[source]

Bases: object

Parameters:

hexagons (HexagonalGrid)

add_layer(grid)[source]
Parameters:

grid (HexGridLayer)

Return type:

HexGridLayer

get_hexagons(clipping=None)[source]

Return a HexagonalGrid containing only the hex coordinates inside a clipping.

Parameters:

clipping (None | tuple[int,int,int,int] | object) – Either None (returns the full grid) or a 4-tuple (r_min, c_min, r_max, c_max) specifying top-left and bottom-right coordinates (inclusive). The method also accepts an object that exposes top_left and bottom_right attributes each being an (r, c) tuple.

Return type:

HexagonalGrid

The bounds are inclusive. The method normalizes min/max for each axis so the order of coordinates does not matter.

get_layer(grid_id)[source]
Parameters:

grid_id (str)

Return type:

HexGridLayer | None

property height: int
is_visible(grid_name)[source]
remove_layer(grid_id)[source]
Parameters:

grid_id (str)

Return type:

None

set_visible(name, visible)[source]
Parameters:
  • name (str)

  • visible (bool)

Return type:

None

property visible_layers: List[HexGridLayer]
property width: int
class pyhexlib.layers.ImageGridLayer(grid_id, hexagons=None, visible=True, comment=None)[source]

Bases: HexGridLayer

Parameters:
  • grid_id (str)

  • visible (bool)

abstract get_image(rc)[source]
Parameters:

rc (Hexagon)

Return type:

pygame.Surface

get_offset(rc)[source]
Parameters:

rc (Hexagon)

Return type:

pygame.Vector2

class pyhexlib.layers.OutlineGridLayer(grid_id, hexagons=None, visible=True, default_color=None, default_width=1, comment=None)[source]

Bases: StyledGridLayer

A grid that stores outline colors and widths for each hexagon.

Parameters:

default_color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

class pyhexlib.layers.PathGridLayer(grid_id, hexagons=None, visible=True, color=(0, 0, 0), width=5, comment=None)[source]

Bases: HexGridLayer

Parameters:
  • grid_id (str)

  • hexagons (HexagonalGrid)

  • color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

  • width (int)

  • comment (str)

get_path()[source]
Return type:

List[Hexagon]

remove_path()[source]
Return type:

None

set_path(path)[source]
Parameters:

path (List[Hexagon])

Return type:

None

class pyhexlib.layers.SimpleImageGridLayer(grid_id, hexagons=None, visible=True, comment=None)[source]

Bases: ImageGridLayer

Parameters:
  • grid_id (str)

  • visible (bool)

get_image(rc)[source]
Parameters:

rc (Hexagon)

Return type:

pygame.Surface

get_offset(rc)[source]
Parameters:

rc (Hexagon)

Return type:

pygame.Vector2

remove_image(rc)[source]
Parameters:

rc (Hexagon)

Return type:

None

set_image(rc, image, offset=pygame.Vector2)[source]
Parameters:
  • rc (Hexagon)

  • image (pygame.Surface)

  • offset (pygame.Vector2)

Return type:

None

class pyhexlib.layers.StyledGridLayer(grid_id, hexagons, visible=True, default_color=None, default_width=1, comment=None)[source]

Bases: HexGridLayer

A grid that stores styles (color and width) for each hexagon. 0 width means fill, >0 means outline with given width.

Parameters:
  • grid_id (str)

  • hexagons (List[Hexagon])

  • visible (bool)

  • comment (str)

property default_color: Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color | None
property default_width: Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color | None
get_color(rc)[source]
get_style(rc)[source]
remove_style(rc)[source]
Parameters:

rc (Hexagon)

Return type:

None

set_color(rc, color)[source]
Parameters:

color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

Return type:

None

set_style(rc, color, width)[source]
Parameters:
  • rc (Hexagon)

  • color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

  • width (int)

Return type:

None

class pyhexlib.layers.TextGridLayer(grid_id, hexagons=None, font_family='Arial', font_color=(0, 0, 0), font_size=12, visible=True, comment=None)[source]

Bases: ValueGridLayer

Parameters:
  • grid_id (str)

  • hexagons (HexagonalGrid)

  • font_color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

  • font_size (int)

  • comment (str)

class pyhexlib.layers.Token(token_id, image=None, rc=None)[source]

Bases: ABC

Parameters:
  • token_id (int | str)

  • image (pygame.Surface)

  • rc (Hexagon)

__repr__()[source]

Return a concise developer representation for DirectionToken.

Shows the token id, grid coordinate (rc), the direction name, the computed angle (degrees) and whether an image surface is present.

Return type:

str

abstract property angle: pygame.Surface
property image
class pyhexlib.layers.TokenGridLayer(grid_id, hexagons=None, visible=True, comment=None)[source]

Bases: ImageGridLayer

Parameters:
  • grid_id (str)

  • visible (bool)

  • comment (str)

get_image(rc)[source]
Parameters:

rc (Hexagon)

Return type:

pygame.Surface

get_token(rc)[source]
Parameters:

rc (Hexagon)

Return type:

Token

get_token_id(rc)[source]
remove_token(rc)[source]
Parameters:

rc (Hexagon)

Return type:

None

set_token(rc, token, offset=(0, 0))[source]
Parameters:
Return type:

None

class pyhexlib.layers.ValueGridLayer(grid_id, hexagons=None, default_value=None, visible=False, comment=None)[source]

Bases: HexGridLayer

Parameters:
get_value(rc)[source]
Parameters:

rc (Hexagon)

Return type:

object

set_value(rc, value)[source]
Parameters:
Return type:

None