Skip to content

Commit e4f0faa

Browse files
committed
Officially add the new rgb and rgba attributes.
1 parent 4dc1b3d commit e4f0faa

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Added
1717
- `tcod.event.get_keyboard_state`
1818
- `tcod.event.get_modifier_state`
1919
- Added `tcod.console.rgb_graphic` and `tcod.console.rgba_graphic` dtypes.
20+
- Another name for the Console array attributes: `Console.rgb` and `Console.rgba`.
21+
22+
Deprecated
23+
- `Console_tiles_rgb` is being renamed to `Console.rgb`.
24+
- `Console_tiles` being renamed to `Console.rgba`.
2025

2126
Fixed
2227
- Contexts now give a more useful error when pickled.

tcod/console.py

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -240,81 +240,94 @@ def ch(self) -> np.ndarray:
240240
"""
241241
return self._tiles["ch"].T if self._order == "F" else self._tiles["ch"] # type: ignore
242242

243-
@property
243+
@property # type: ignore
244+
@deprecate("This attribute has been renamed to `rgba`.")
244245
def tiles(self) -> np.ndarray:
245246
"""An array of this consoles raw tile data.
246247
247248
This acts as a combination of the `ch`, `fg`, and `bg` attributes.
248249
Colors include an alpha channel but how alpha works is currently
249250
undefined.
250251
251-
Example:
252-
>>> con = tcod.console.Console(10, 2)
253-
>>> con.tiles[0, 0] = (
254-
... ord("X"),
255-
... (*tcod.white, 255),
256-
... (*tcod.black, 255),
257-
... )
258-
>>> con.tiles[0, 0]
259-
(88, [255, 255, 255, 255], [ 0, 0, 0, 255])
260-
261252
.. versionadded:: 10.0
253+
254+
.. deprecated:: 12.3
255+
Use :any:`Console.rgba` instead.
262256
"""
263-
return self._tiles.T if self._order == "F" else self._tiles
257+
return self.rgba
264258

265259
@property # type: ignore
266-
@deprecate("This attribute has been renamed to `tiles`.")
260+
@deprecate("This attribute has been renamed to `rgba`.")
267261
def buffer(self) -> np.ndarray:
268262
"""An array of this consoles raw tile data.
269263
270264
.. versionadded:: 11.4
271265
272266
.. deprecated:: 11.8
273-
Use :any:`Console.tiles` instead.
267+
Use :any:`Console.rgba` instead.
274268
"""
275-
return self._tiles.T if self._order == "F" else self._tiles
269+
return self.rgba
276270

277-
@property
271+
@property # type: ignore
272+
@deprecate("This attribute has been renamed to `rgb`.")
278273
def tiles_rgb(self) -> np.ndarray:
279-
"""An array of this consoles tile data without the alpha channel.
280-
281-
The dtype of this array is effectively:
282-
``[("ch", np.intc), ("fg", "(3,)u1"), ("bg", "(3,)u1")]``
283-
284-
Example:
285-
>>> con = tcod.console.Console(10, 2)
286-
>>> con.tiles_rgb[0, 0] = ord("@"), tcod.yellow, tcod.black
287-
>>> con.tiles_rgb[0, 0]
288-
(64, [255, 255, 0], [0, 0, 0])
289-
>>> con.tiles_rgb["bg"] = tcod.blue
290-
>>> con.tiles_rgb[0, 0]
291-
(64, [255, 255, 0], [ 0, 0, 255])
274+
"""An array of this consoles data without the alpha channel.
292275
293276
.. versionadded:: 11.8
277+
278+
.. deprecated:: 12.3
279+
Use :any:`Console.rgb` instead.
294280
"""
295-
return self.tiles.view(self._DTYPE_RGB)
281+
return self.rgb
296282

297283
@property # type: ignore
298-
@deprecate("This attribute has been renamed to `tiles_rgb`.")
284+
@deprecate("This attribute has been renamed to `rgb`.")
299285
def tiles2(self) -> np.ndarray:
300-
"""This name is deprecated in favour of :any:`tiles_rgb`.
286+
"""This name is deprecated in favour of :any:`rgb`.
301287
302288
.. versionadded:: 11.3
303289
304290
.. deprecated:: 11.8
305-
Use :any:`Console.tiles_rgb` instead.
291+
Use :any:`Console.rgb` instead.
306292
"""
307-
return self.tiles_rgb
293+
return self.rgb
308294

309295
@property
310296
def rgba(self) -> np.ndarray:
311-
# This attribute is provisional and may be changed at anytime.
312-
return self.tiles
297+
"""An array of this consoles raw tile data.
298+
299+
Example:
300+
>>> con = tcod.console.Console(10, 2)
301+
>>> con.rgba[0, 0] = (
302+
... ord("X"),
303+
... (*tcod.white, 255),
304+
... (*tcod.black, 255),
305+
... )
306+
>>> con.rgba[0, 0]
307+
(88, [255, 255, 255, 255], [ 0, 0, 0, 255])
308+
309+
.. versionadded:: 12.3
310+
"""
311+
return self._tiles.T if self._order == "F" else self._tiles
313312

314313
@property
315314
def rgb(self) -> np.ndarray:
316-
# This attribute is provisional and may be changed at anytime.
317-
return self.tiles_rgb
315+
"""An array of this consoles data without the alpha channel.
316+
317+
The :any:`rgb_graphic` can be used to make arrays
318+
319+
Example:
320+
>>> con = tcod.console.Console(10, 2)
321+
>>> con.rgb[0, 0] = ord("@"), tcod.yellow, tcod.black
322+
>>> con.rgb[0, 0]
323+
(64, [255, 255, 0], [0, 0, 0])
324+
>>> con.rgb["bg"] = tcod.blue
325+
>>> con.rgb[0, 0]
326+
(64, [255, 255, 0], [ 0, 0, 255])
327+
328+
.. versionadded:: 12.3
329+
"""
330+
return self.rgba.view(self._DTYPE_RGB)
318331

319332
@property
320333
def default_bg(self) -> Tuple[int, int, int]:

0 commit comments

Comments
 (0)