Skip to content

Commit b637537

Browse files
committed
Deprecate implicit libtcodpy and constants.
These are needed to move away from the `tcod` module, so that it can eventually be converted to an implicit namespace.
1 parent a140581 commit b637537

File tree

9 files changed

+158
-622
lines changed

9 files changed

+158
-622
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changes relevant to the users of python-tcod are documented here.
44
This project adheres to [Semantic Versioning](https://semver.org/) since version `2.0.0`.
55

66
## [Unreleased]
7+
### Deprecated
8+
- Deprecated using `tcod` as an implicit alias for `libtcodpy`.
9+
You should use `from tcod import libtcodpy` if you want to access this module.
10+
- Deprecated constants being held in `tcod`, get these from `tcod.constants` instead.
11+
- Deprecated `tcod.Console` which should be accessed from `tcod.console.Console` instead.
712

813
## [16.0.2] - 2023-06-02
914
### Fixed

build_libtcod.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ def write_library_constants() -> None:
366366

367367
all_names_merged = ",\n ".join(f'"{name}"' for name in all_names)
368368
f.write(f"\n__all__ = [\n {all_names_merged},\n]\n")
369-
update_module_all(Path("tcod/__init__.py"), all_names_merged)
370369
update_module_all(Path("tcod/libtcodpy.py"), all_names_merged)
371370

372371
with Path("tcod/event_constants.py").open("w", encoding="utf-8") as f:

examples/samples_tcod.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import tcod.render
2626
import tcod.sdl.mouse
2727
import tcod.sdl.render
28+
from tcod import libtcodpy
2829

2930
# ruff: noqa: S311
3031

@@ -746,76 +747,76 @@ def on_draw(self) -> None:
746747
for y in range(SAMPLE_SCREEN_HEIGHT):
747748
for x in range(SAMPLE_SCREEN_WIDTH):
748749
if SAMPLE_MAP[x, y] != "#":
749-
tcod.console_set_char_background(
750+
libtcodpy.console_set_char_background(
750751
sample_console,
751752
x,
752753
y,
753-
tcod.color_lerp( # type: ignore
754+
libtcodpy.color_lerp( # type: ignore
754755
LIGHT_GROUND,
755756
DARK_GROUND,
756-
0.9 * tcod.dijkstra_get_distance(self.dijkstra, x, y) / self.dijkstra_dist,
757+
0.9 * libtcodpy.dijkstra_get_distance(self.dijkstra, x, y) / self.dijkstra_dist,
757758
),
758759
tcod.BKGND_SET,
759760
)
760-
for i in range(tcod.dijkstra_size(self.dijkstra)):
761-
x, y = tcod.dijkstra_get(self.dijkstra, i)
762-
tcod.console_set_char_background(sample_console, x, y, LIGHT_GROUND, tcod.BKGND_SET)
761+
for i in range(libtcodpy.dijkstra_size(self.dijkstra)):
762+
x, y = libtcodpy.dijkstra_get(self.dijkstra, i)
763+
libtcodpy.console_set_char_background(sample_console, x, y, LIGHT_GROUND, tcod.constants.BKGND_SET)
763764

764765
# move the creature
765766
self.busy -= frame_length[-1]
766767
if self.busy <= 0.0:
767768
self.busy = 0.2
768769
if self.using_astar:
769-
if not tcod.path_is_empty(self.path):
770-
tcod.console_put_char(sample_console, self.px, self.py, " ", tcod.BKGND_NONE)
771-
self.px, self.py = tcod.path_walk(self.path, True) # type: ignore
772-
tcod.console_put_char(sample_console, self.px, self.py, "@", tcod.BKGND_NONE)
770+
if not libtcodpy.path_is_empty(self.path):
771+
libtcodpy.console_put_char(sample_console, self.px, self.py, " ", tcod.constants.BKGND_NONE)
772+
self.px, self.py = libtcodpy.path_walk(self.path, True) # type: ignore
773+
libtcodpy.console_put_char(sample_console, self.px, self.py, "@", tcod.constants.BKGND_NONE)
773774
else:
774-
if not tcod.dijkstra_is_empty(self.dijkstra):
775-
tcod.console_put_char(sample_console, self.px, self.py, " ", tcod.BKGND_NONE)
776-
self.px, self.py = tcod.dijkstra_path_walk(self.dijkstra) # type: ignore
777-
tcod.console_put_char(sample_console, self.px, self.py, "@", tcod.BKGND_NONE)
775+
if not libtcodpy.dijkstra_is_empty(self.dijkstra):
776+
libtcodpy.console_put_char(sample_console, self.px, self.py, " ", tcod.constants.BKGND_NONE)
777+
self.px, self.py = libtcodpy.dijkstra_path_walk(self.dijkstra) # type: ignore
778+
libtcodpy.console_put_char(sample_console, self.px, self.py, "@", tcod.constants.BKGND_NONE)
778779
self.recalculate = True
779780

780781
def ev_keydown(self, event: tcod.event.KeyDown) -> None:
781782
if event.sym == tcod.event.KeySym.i and self.dy > 0:
782783
# destination move north
783-
tcod.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.BKGND_NONE)
784+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.constants.BKGND_NONE)
784785
self.dy -= 1
785786
self.oldchar = sample_console.ch[self.dx, self.dy]
786-
tcod.console_put_char(sample_console, self.dx, self.dy, "+", tcod.BKGND_NONE)
787+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, "+", tcod.constants.BKGND_NONE)
787788
if SAMPLE_MAP[self.dx, self.dy] == " ":
788789
self.recalculate = True
789790
elif event.sym == tcod.event.KeySym.k and self.dy < SAMPLE_SCREEN_HEIGHT - 1:
790791
# destination move south
791-
tcod.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.BKGND_NONE)
792+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.constants.BKGND_NONE)
792793
self.dy += 1
793794
self.oldchar = sample_console.ch[self.dx, self.dy]
794-
tcod.console_put_char(sample_console, self.dx, self.dy, "+", tcod.BKGND_NONE)
795+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, "+", tcod.constants.BKGND_NONE)
795796
if SAMPLE_MAP[self.dx, self.dy] == " ":
796797
self.recalculate = True
797798
elif event.sym == tcod.event.KeySym.j and self.dx > 0:
798799
# destination move west
799-
tcod.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.BKGND_NONE)
800+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.constants.BKGND_NONE)
800801
self.dx -= 1
801802
self.oldchar = sample_console.ch[self.dx, self.dy]
802-
tcod.console_put_char(sample_console, self.dx, self.dy, "+", tcod.BKGND_NONE)
803+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, "+", tcod.constants.BKGND_NONE)
803804
if SAMPLE_MAP[self.dx, self.dy] == " ":
804805
self.recalculate = True
805806
elif event.sym == tcod.event.KeySym.l and self.dx < SAMPLE_SCREEN_WIDTH - 1:
806807
# destination move east
807-
tcod.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.BKGND_NONE)
808+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.constants.BKGND_NONE)
808809
self.dx += 1
809810
self.oldchar = sample_console.ch[self.dx, self.dy]
810-
tcod.console_put_char(sample_console, self.dx, self.dy, "+", tcod.BKGND_NONE)
811+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, "+", tcod.constants.BKGND_NONE)
811812
if SAMPLE_MAP[self.dx, self.dy] == " ":
812813
self.recalculate = True
813814
elif event.sym == tcod.event.KeySym.TAB:
814815
self.using_astar = not self.using_astar
815816
if self.using_astar:
816-
tcod.console_print(sample_console, 1, 4, "Using : A* ")
817+
libtcodpy.console_print(sample_console, 1, 4, "Using : A* ")
817818
else:
818-
tcod.console_print(sample_console, 1, 4, "Using : Dijkstra")
819+
libtcodpy.console_print(sample_console, 1, 4, "Using : Dijkstra")
819820
self.recalculate = True
820821
else:
821822
super().ev_keydown(event)
@@ -824,11 +825,11 @@ def ev_mousemotion(self, event: tcod.event.MouseMotion) -> None:
824825
mx = event.tile.x - SAMPLE_SCREEN_X
825826
my = event.tile.y - SAMPLE_SCREEN_Y
826827
if 0 <= mx < SAMPLE_SCREEN_WIDTH and 0 <= my < SAMPLE_SCREEN_HEIGHT and (self.dx != mx or self.dy != my):
827-
tcod.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.BKGND_NONE)
828+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, self.oldchar, tcod.constants.BKGND_NONE)
828829
self.dx = mx
829830
self.dy = my
830831
self.oldchar = sample_console.ch[self.dx, self.dy]
831-
tcod.console_put_char(sample_console, self.dx, self.dy, "+", tcod.BKGND_NONE)
832+
libtcodpy.console_put_char(sample_console, self.dx, self.dy, "+", tcod.constants.BKGND_NONE)
832833
if SAMPLE_MAP[self.dx, self.dy] == " ":
833834
self.recalculate = True
834835

libtcodpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"""Module alias for tcod."""
1+
"""Deprecated module alias for tcod.libtcodpy, use 'import tcod as libtcodpy' instead."""
22
import warnings
33

4-
from tcod import * # noqa: F4
4+
from tcod.libtcodpy import * # noqa: F403
55
from tcod.libtcodpy import __getattr__ # noqa: F401
66

77
warnings.warn(

0 commit comments

Comments
 (0)