tcod 20.0.0__cp310-abi3-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. libtcodpy.py +12 -0
  2. tcod/__init__.py +40 -0
  3. tcod/__pyinstaller/__init__.py +10 -0
  4. tcod/__pyinstaller/hook-tcod.py +14 -0
  5. tcod/_internal.py +225 -0
  6. tcod/_libtcod.pyd +0 -0
  7. tcod/_libtcod.pyi +9593 -0
  8. tcod/arm64/SDL3.dll +0 -0
  9. tcod/bsp.py +271 -0
  10. tcod/cdef.h +23 -0
  11. tcod/cffi.h +11 -0
  12. tcod/cffi.py +77 -0
  13. tcod/color.py +135 -0
  14. tcod/console.py +1651 -0
  15. tcod/constants.py +805 -0
  16. tcod/context.py +627 -0
  17. tcod/event.py +3041 -0
  18. tcod/event_constants.py +568 -0
  19. tcod/image.py +418 -0
  20. tcod/libtcodpy.py +4847 -0
  21. tcod/los.py +66 -0
  22. tcod/map.py +264 -0
  23. tcod/noise.c +64 -0
  24. tcod/noise.h +35 -0
  25. tcod/noise.py +500 -0
  26. tcod/path.c +492 -0
  27. tcod/path.h +154 -0
  28. tcod/path.py +1553 -0
  29. tcod/py.typed +0 -0
  30. tcod/random.h +16 -0
  31. tcod/random.py +181 -0
  32. tcod/render.py +106 -0
  33. tcod/sdl/__init__.py +5 -0
  34. tcod/sdl/_internal.py +219 -0
  35. tcod/sdl/audio.py +1075 -0
  36. tcod/sdl/constants.py +489 -0
  37. tcod/sdl/joystick.py +397 -0
  38. tcod/sdl/mouse.py +269 -0
  39. tcod/sdl/render.py +819 -0
  40. tcod/sdl/sys.py +80 -0
  41. tcod/sdl/video.py +582 -0
  42. tcod/tcod.c +32 -0
  43. tcod/tcod.h +15 -0
  44. tcod/tcod.py +90 -0
  45. tcod/tileset.py +925 -0
  46. tcod/version.py +34 -0
  47. tcod-20.0.0.dist-info/METADATA +149 -0
  48. tcod-20.0.0.dist-info/RECORD +54 -0
  49. tcod-20.0.0.dist-info/WHEEL +5 -0
  50. tcod-20.0.0.dist-info/entry_points.txt +2 -0
  51. tcod-20.0.0.dist-info/licenses/LICENSE.txt +25 -0
  52. tcod-20.0.0.dist-info/licenses/libtcod/LIBTCOD-CREDITS.txt +47 -0
  53. tcod-20.0.0.dist-info/licenses/libtcod/LICENSE.txt +30 -0
  54. tcod-20.0.0.dist-info/top_level.txt +2 -0
libtcodpy.py ADDED
@@ -0,0 +1,12 @@
1
+ """Deprecated module alias for tcod.libtcodpy, use 'import tcod as libtcodpy' instead."""
2
+
3
+ import warnings
4
+
5
+ from tcod.libtcodpy import * # noqa: F403
6
+ from tcod.libtcodpy import __getattr__ # noqa: F401
7
+
8
+ warnings.warn(
9
+ "'import tcod as libtcodpy' is preferred.",
10
+ DeprecationWarning,
11
+ stacklevel=2,
12
+ )
tcod/__init__.py ADDED
@@ -0,0 +1,40 @@
1
+ """The fast Python port of libtcod.
2
+
3
+ This module can be used as a drop in replacement for the official libtcodpy module.
4
+
5
+ Bring any issues or feature requests to GitHub: https://github.com/libtcod/python-tcod
6
+
7
+ Read the documentation online: https://python-tcod.readthedocs.io/en/latest/
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from pkgutil import extend_path
13
+
14
+ __path__ = extend_path(__path__, __name__)
15
+
16
+ from tcod import bsp, color, console, context, event, image, los, map, noise, path, random, tileset # noqa: A004
17
+ from tcod.cffi import __sdl_version__, ffi, lib
18
+ from tcod.tcod import __getattr__ # noqa: F401
19
+ from tcod.version import __version__
20
+
21
+ __all__ = [
22
+ "Console",
23
+ "__sdl_version__",
24
+ "__version__",
25
+ "bsp",
26
+ "color",
27
+ "console",
28
+ "context",
29
+ "event",
30
+ "ffi",
31
+ "image",
32
+ "lib",
33
+ "los",
34
+ "map",
35
+ "noise",
36
+ "path",
37
+ "random",
38
+ "tileset",
39
+ "tileset",
40
+ ]
@@ -0,0 +1,10 @@
1
+ """PyInstaller entry point for tcod."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+
8
+ def get_hook_dirs() -> list[str]:
9
+ """Return the current directory."""
10
+ return [str(Path(__file__).parent)]
@@ -0,0 +1,14 @@
1
+ """PyInstaller hook for tcod.
2
+
3
+ There were added since tcod 12.0.0.
4
+
5
+ If this hook is ever modified then the contributed hook needs to be removed from:
6
+ https://github.com/pyinstaller/pyinstaller-hooks-contrib
7
+ """
8
+
9
+ from PyInstaller.utils.hooks import collect_dynamic_libs # type: ignore
10
+
11
+ hiddenimports = ["_cffi_backend"]
12
+
13
+ # Install shared libraries to the working directory.
14
+ binaries = collect_dynamic_libs("tcod")
tcod/_internal.py ADDED
@@ -0,0 +1,225 @@
1
+ """Internal helper functions used by the rest of the library."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import locale
6
+ import sys
7
+ import warnings
8
+ from collections.abc import Callable
9
+ from typing import TYPE_CHECKING, Any, AnyStr, Literal, NoReturn, SupportsInt, TypeVar
10
+
11
+ from typing_extensions import deprecated
12
+
13
+ from tcod.cffi import ffi, lib
14
+
15
+ if TYPE_CHECKING:
16
+ from pathlib import Path
17
+ from types import TracebackType
18
+
19
+
20
+ FuncType = Callable[..., Any]
21
+ F = TypeVar("F", bound=FuncType)
22
+ T = TypeVar("T")
23
+
24
+
25
+ def _deprecate_passthrough(
26
+ message: str, # noqa: ARG001
27
+ /,
28
+ *,
29
+ category: type[Warning] = DeprecationWarning, # noqa: ARG001
30
+ stacklevel: int = 0, # noqa: ARG001
31
+ ) -> Callable[[F], F]:
32
+ """Return a decorator which skips wrapping a warning onto functions. This is used for non-debug runs."""
33
+
34
+ def decorator(func: F) -> F:
35
+ return func
36
+
37
+ return decorator
38
+
39
+
40
+ deprecate = deprecated if __debug__ or TYPE_CHECKING else _deprecate_passthrough
41
+
42
+
43
+ def verify_order(order: Literal["C", "F"]) -> Literal["C", "F"]:
44
+ """Verify and return a Numpy order string."""
45
+ order = order.upper() # type: ignore[assignment]
46
+ if order not in ("C", "F"):
47
+ msg = f"order must be 'C' or 'F', not {order!r}"
48
+ raise TypeError(msg)
49
+ return order
50
+
51
+
52
+ def _raise_tcod_error() -> NoReturn:
53
+ """Raise an error from libtcod, this function assumes an error exists."""
54
+ raise RuntimeError(ffi.string(lib.TCOD_get_error()).decode("utf-8"))
55
+
56
+
57
+ def _check(error: int) -> int:
58
+ """Detect and convert a libtcod error code into an exception."""
59
+ if error < 0:
60
+ _raise_tcod_error()
61
+ return error
62
+
63
+
64
+ def _check_p(pointer: T) -> T:
65
+ """Treats NULL pointers as errors and raises a libtcod exception."""
66
+ if not pointer:
67
+ _raise_tcod_error()
68
+ return pointer
69
+
70
+
71
+ def _check_warn(error: int, stacklevel: int = 2) -> int:
72
+ """Like _check, but raises a warning on positive error codes."""
73
+ if _check(error) > 0:
74
+ warnings.warn(
75
+ ffi.string(lib.TCOD_get_error()).decode(),
76
+ RuntimeWarning,
77
+ stacklevel=stacklevel + 1,
78
+ )
79
+ return error
80
+
81
+
82
+ def _unpack_char_p(char_p: Any) -> str: # noqa: ANN401
83
+ if char_p == ffi.NULL:
84
+ return ""
85
+ return str(ffi.string(char_p), encoding="utf-8")
86
+
87
+
88
+ def _int(int_or_str: SupportsInt | str | bytes) -> int:
89
+ """Return an integer where a single character string may be expected."""
90
+ if isinstance(int_or_str, str):
91
+ return ord(int_or_str)
92
+ if isinstance(int_or_str, bytes):
93
+ return int_or_str[0]
94
+ return int(int_or_str)
95
+
96
+
97
+ def _bytes(string: AnyStr) -> bytes:
98
+ if isinstance(string, str):
99
+ return string.encode("utf-8")
100
+ return string
101
+
102
+
103
+ def _unicode(string: AnyStr, stacklevel: int = 2) -> str:
104
+ if isinstance(string, bytes):
105
+ warnings.warn(
106
+ "Passing byte strings as parameters to Unicode functions is deprecated.",
107
+ FutureWarning,
108
+ stacklevel=stacklevel + 1,
109
+ )
110
+ return string.decode("latin-1")
111
+ return str(string)
112
+
113
+
114
+ def _fmt(string: str, stacklevel: int = 2) -> bytes:
115
+ if isinstance(string, bytes):
116
+ warnings.warn(
117
+ "Passing byte strings as parameters to Unicode functions is deprecated.",
118
+ FutureWarning,
119
+ stacklevel=stacklevel + 1,
120
+ )
121
+ string = string.decode("latin-1")
122
+ return string.encode("utf-8").replace(b"%", b"%%")
123
+
124
+
125
+ def _path_encode(path: Path) -> bytes:
126
+ """Return a bytes file path for the current locale when on Windows, uses fsdecode for other platforms."""
127
+ if sys.platform != "win32":
128
+ return bytes(path) # Sane and expected behavior for converting Path into bytes
129
+ try:
130
+ return str(path).encode(locale.getlocale()[1] or "utf-8") # Stay classy, Windows
131
+ except UnicodeEncodeError as exc:
132
+ if sys.version_info >= (3, 11):
133
+ exc.add_note("""Consider calling 'locale.setlocale(locale.LC_CTYPES, ".UTF8")' to support Unicode paths.""")
134
+ raise
135
+
136
+
137
+ class _PropagateException:
138
+ """Context manager designed to propagate exceptions outside of a cffi callback context.
139
+
140
+ Normally cffi suppresses the exception.
141
+
142
+ When propagate is called this class will hold onto the error until the
143
+ control flow leaves the context, then the error will be raised.
144
+
145
+ with _PropagateException as propagate:
146
+ # give propagate as onerror parameter for ffi.def_extern
147
+ """
148
+
149
+ def __init__(self) -> None:
150
+ self.caught: BaseException | None = None
151
+
152
+ def propagate(self, *exc_info: Any) -> None: # noqa: ANN401
153
+ """Set an exception to be raised once this context exits.
154
+
155
+ If multiple errors are caught, only keep the first exception raised.
156
+ """
157
+ if self.caught is None:
158
+ self.caught = exc_info[1]
159
+
160
+ def __enter__(self) -> Callable[[Any], None]:
161
+ """Once in context, only the propagate call is needed to use this class effectively."""
162
+ return self.propagate
163
+
164
+ def __exit__(
165
+ self, _type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
166
+ ) -> None:
167
+ """If we're holding on to an exception, raise it now.
168
+
169
+ self.caught is reset now in case of nested manager shenanigans.
170
+ """
171
+ to_raise, self.caught = self.caught, None
172
+ if to_raise is not None:
173
+ raise to_raise from value
174
+
175
+
176
+ class _CDataWrapper:
177
+ """A generally deprecated CData wrapper class used by libtcodpy."""
178
+
179
+ def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
180
+ self.cdata = self._get_cdata_from_args(*args, **kwargs)
181
+ if self.cdata is None:
182
+ self.cdata = ffi.NULL
183
+ super().__init__()
184
+
185
+ @staticmethod
186
+ def _get_cdata_from_args(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401
187
+ if len(args) == 1 and isinstance(args[0], ffi.CData) and not kwargs:
188
+ return args[0]
189
+ return None
190
+
191
+ def __hash__(self) -> int:
192
+ return hash(self.cdata)
193
+
194
+ def __eq__(self, other: object) -> bool:
195
+ if not isinstance(other, _CDataWrapper):
196
+ return NotImplemented
197
+ return bool(self.cdata == other.cdata)
198
+
199
+ def __getattr__(self, attr: str) -> Any: # noqa: ANN401
200
+ if "cdata" in self.__dict__:
201
+ return getattr(self.__dict__["cdata"], attr)
202
+ raise AttributeError(attr)
203
+
204
+ def __setattr__(self, attr: str, value: Any) -> None: # noqa: ANN401
205
+ if hasattr(self, "cdata") and hasattr(self.cdata, attr):
206
+ setattr(self.cdata, attr, value)
207
+ else:
208
+ super().__setattr__(attr, value)
209
+
210
+
211
+ def _console(console: Any) -> Any: # noqa: ANN401
212
+ """Return a cffi console pointer."""
213
+ try:
214
+ return console.console_c
215
+ except AttributeError:
216
+ warnings.warn(
217
+ (
218
+ "Falsy console parameters are deprecated, "
219
+ "always use the root console instance returned by "
220
+ "console_init_root."
221
+ ),
222
+ DeprecationWarning,
223
+ stacklevel=3,
224
+ )
225
+ return ffi.NULL
tcod/_libtcod.pyd ADDED
Binary file