1212"""
1313import itertools
1414import os
15- from typing import Any , Iterable , Optional , Tuple
15+ from pathlib import Path
16+ from typing import Any , Iterable , Optional , Tuple , Union
1617
1718import numpy as np
1819
@@ -200,7 +201,7 @@ def set_default(tileset: Tileset) -> None:
200201 lib .TCOD_set_default_tileset (tileset ._tileset_p )
201202
202203
203- def load_truetype_font (path : str , tile_width : int , tile_height : int ) -> Tileset :
204+ def load_truetype_font (path : Union [ str , Path ] , tile_width : int , tile_height : int ) -> Tileset :
204205 """Return a new Tileset from a `.ttf` or `.otf` file.
205206
206207 Same as :any:`set_truetype_font`, but returns a :any:`Tileset` instead.
@@ -210,14 +211,14 @@ def load_truetype_font(path: str, tile_width: int, tile_height: int) -> Tileset:
210211 """
211212 if not os .path .exists (path ):
212213 raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
213- cdata = lib .TCOD_load_truetype_font_ (path .encode (), tile_width , tile_height )
214+ cdata = lib .TCOD_load_truetype_font_ (str ( path ) .encode (), tile_width , tile_height )
214215 if not cdata :
215216 raise RuntimeError (ffi .string (lib .TCOD_get_error ()))
216217 return Tileset ._claim (cdata )
217218
218219
219220@deprecate ("Accessing the default tileset is deprecated." )
220- def set_truetype_font (path : str , tile_width : int , tile_height : int ) -> None :
221+ def set_truetype_font (path : Union [ str , Path ] , tile_width : int , tile_height : int ) -> None :
221222 """Set the default tileset from a `.ttf` or `.otf` file.
222223
223224 `path` is the file path for the font file.
@@ -239,11 +240,11 @@ def set_truetype_font(path: str, tile_width: int, tile_height: int) -> None:
239240 """
240241 if not os .path .exists (path ):
241242 raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
242- if lib .TCOD_tileset_load_truetype_ (path .encode (), tile_width , tile_height ):
243+ if lib .TCOD_tileset_load_truetype_ (str ( path ) .encode (), tile_width , tile_height ):
243244 raise RuntimeError (ffi .string (lib .TCOD_get_error ()))
244245
245246
246- def load_bdf (path : str ) -> Tileset :
247+ def load_bdf (path : Union [ str , Path ] ) -> Tileset :
247248 """Return a new Tileset from a `.bdf` file.
248249
249250 For the best results the font should be monospace, cell-based, and
@@ -258,13 +259,13 @@ def load_bdf(path: str) -> Tileset:
258259 """ # noqa: E501
259260 if not os .path .exists (path ):
260261 raise RuntimeError ("File not found:\n \t %s" % (os .path .realpath (path ),))
261- cdata = lib .TCOD_load_bdf (path .encode ())
262+ cdata = lib .TCOD_load_bdf (str ( path ) .encode ())
262263 if not cdata :
263264 raise RuntimeError (ffi .string (lib .TCOD_get_error ()).decode ())
264265 return Tileset ._claim (cdata )
265266
266267
267- def load_tilesheet (path : str , columns : int , rows : int , charmap : Optional [Iterable [int ]]) -> Tileset :
268+ def load_tilesheet (path : Union [ str , Path ] , columns : int , rows : int , charmap : Optional [Iterable [int ]]) -> Tileset :
268269 """Return a new Tileset from a simple tilesheet image.
269270
270271 `path` is the file path to a PNG file with the tileset.
@@ -289,7 +290,7 @@ def load_tilesheet(path: str, columns: int, rows: int, charmap: Optional[Iterabl
289290 mapping = []
290291 if charmap is not None :
291292 mapping = list (itertools .islice (charmap , columns * rows ))
292- cdata = lib .TCOD_tileset_load (path .encode (), columns , rows , len (mapping ), mapping )
293+ cdata = lib .TCOD_tileset_load (str ( path ) .encode (), columns , rows , len (mapping ), mapping )
293294 if not cdata :
294295 _raise_tcod_error ()
295296 return Tileset ._claim (cdata )
0 commit comments