Skip to content

Commit 8b9c6f3

Browse files
committed
Update console docs.
1 parent 4615008 commit 8b9c6f3

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tcod/console.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ class Console:
4343
4444
`width` and `height` are the size of the console (in tiles.)
4545
46-
`order` determines how the axes of NumPy array attributes are arraigned.
46+
`order` determines how the axes of NumPy array attributes are arranged.
47+
With the default setting of `"C"` you use [y, x] to index a consoles
48+
arrays such as :any:`Console.rgb`.
4749
`order="F"` will swap the first two axes which allows for more intuitive
48-
`[x, y]` indexing.
50+
`[x, y]` indexing. To be consistent you may have to do this for every
51+
NumPy array to create.
4952
5053
With `buffer` the console can be initialized from another array. The
5154
`buffer` should be compatible with the `width`, `height`, and `order`
@@ -297,6 +300,9 @@ def tiles2(self) -> np.ndarray:
297300
def rgba(self) -> np.ndarray:
298301
"""An array of this consoles raw tile data.
299302
303+
The axes of this array is affected by the `order` parameter given to
304+
initialize the console.
305+
300306
Example:
301307
>>> con = tcod.console.Console(10, 2)
302308
>>> con.rgba[0, 0] = (
@@ -315,7 +321,11 @@ def rgba(self) -> np.ndarray:
315321
def rgb(self) -> np.ndarray:
316322
"""An array of this consoles data without the alpha channel.
317323
318-
The :any:`rgb_graphic` can be used to make arrays
324+
The axes of this array is affected by the `order` parameter given to
325+
initialize the console.
326+
327+
The :any:`rgb_graphic` can be used to make arrays similar to these
328+
independent of a :any:`Console`.
319329
320330
Example:
321331
>>> con = tcod.console.Console(10, 2)
@@ -1256,9 +1266,10 @@ def load_xp(
12561266
# The comma after console is used to unpack a single item tuple.
12571267
console, = tcod.console.load_xp(path, order="F")
12581268
1259-
# Convert from REXPaint's encoding to Unicode.
1269+
# Convert tcod's Code Page 437 character mapping into a NumPy array.
12601270
CP437_TO_UNICODE = np.asarray(tcod.tileset.CHARMAP_CP437)
12611271
1272+
# Convert from REXPaint's CP437 encoding to Unicode in-place.
12621273
console.ch[:] = CP437_TO_UNICODE[console.ch]
12631274
12641275
# Apply REXPaint's alpha key color.
@@ -1307,10 +1318,18 @@ def save_xp(
13071318
13081319
# Convert from Unicode to REXPaint's encoding.
13091320
# Required to load this console correctly in the REXPaint tool.
1321+
1322+
# Convert tcod's Code Page 437 character mapping into a NumPy array.
13101323
CP437_TO_UNICODE = np.asarray(tcod.tileset.CHARMAP_CP437)
1311-
UNICODE_TO_CP437 = np.full(0x1FFFF, fill_value=ord("?"))
1324+
1325+
# Initialize a Unicode-to-CP437 array.
1326+
# 0x20000 is the current full range of Unicode.
1327+
# fill_value=ord("?") means that "?" will be the result of any unknown codepoint.
1328+
UNICODE_TO_CP437 = np.full(0x20000, fill_value=ord("?"))
1329+
# Assign the CP437 mappings.
13121330
UNICODE_TO_CP437[CP437_TO_UNICODE] = np.arange(len(CP437_TO_UNICODE))
13131331
1332+
# Convert from Unicode to CP437 in-place.
13141333
console.ch[:] = UNICODE_TO_CP437[console.ch]
13151334
13161335
# Convert console alpha into REXPaint's alpha key color.

0 commit comments

Comments
 (0)