Skip to content

Commit e66b221

Browse files
committed
Update PyInstaller example and docs for loading tilesets
1 parent 10661ea commit e66b221

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

examples/distribution/PyInstaller/main.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# https://creativecommons.org/publicdomain/zero/1.0/
66
"""PyInstaller main script example."""
77

8-
import sys
98
from pathlib import Path
109

1110
import tcod.console
@@ -15,8 +14,8 @@
1514

1615
WIDTH, HEIGHT = 80, 60
1716

18-
# The base directory, this is sys._MEIPASS when in one-file mode.
19-
BASE_DIR = Path(getattr(sys, "_MEIPASS", "."))
17+
BASE_DIR = Path(__file__).parent
18+
"""The directory of this script."""
2019

2120
FONT_PATH = BASE_DIR / "data/terminal8x8_gs_ro.png"
2221

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
tcod==12.2.0
2-
pyinstaller==5.13.1
3-
pypiwin32; sys_platform=="win32"
1+
tcod==16.2.3
2+
pyinstaller==6.9.0
3+
pypiwin32; sys_platform=="win32"

tcod/tileset.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tileset and font related functions.
22
3+
If you want to load a tileset from a common tileset image then you only need :any:`tcod.tileset.load_tilesheet`.
4+
35
Tilesets can be loaded as a whole from tile-sheets or True-Type fonts, or they
46
can be put together from multiple tile images by loading them separately
57
using :any:`Tileset.set_tile`.
@@ -342,6 +344,24 @@ def load_tilesheet(path: str | PathLike[str], columns: int, rows: int, charmap:
342344
If `None` is used then no tiles will be mapped, you will need to use
343345
:any:`Tileset.remap` to assign codepoints to this Tileset.
344346
347+
Image alpha and key colors are handled automatically.
348+
For example any tileset from the `Dwarf Fortress tileset repository <https://dwarffortresswiki.org/index.php/DF2014:Tileset_repository>`_
349+
will load correctly with the following example:
350+
351+
Example::
352+
353+
from pathlib import Path
354+
355+
import tcod.tileset
356+
357+
THIS_DIR = Path(__file__, "..") # Directory of this script file
358+
FONT = THIS_DIR / "assets/tileset.png" # Replace with any tileset from the DF tileset repository
359+
360+
# Will raise FileNotFoundError if the font is missing!
361+
tileset = tcod.tileset.load_tilesheet(FONT, 16, 16, tcod.tileset.CHARMAP_CP437)
362+
363+
The tileset return value is usually passed to the `tileset` parameter of :any:`tcod.context.new`.
364+
345365
.. versionadded:: 11.12
346366
"""
347367
path = Path(path).resolve(strict=True)

0 commit comments

Comments
 (0)