|
1
|
|
|
"""This module handles loading of the libtcod cffi API. |
|
2
|
|
|
""" |
|
3
|
|
|
from __future__ import absolute_import as _ |
|
4
|
|
|
|
|
5
|
|
|
import sys as _sys |
|
6
|
|
|
import os as _os |
|
7
|
|
|
|
|
8
|
|
|
import platform as _platform |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
from tcod import __path__ |
|
12
|
|
|
|
|
13
|
|
|
# add Windows dll's to PATH |
|
14
|
|
|
if _sys.platform == 'win32': |
|
15
|
|
|
_bits, _linkage = _platform.architecture() |
|
16
|
|
|
_os.environ['PATH'] += (';' + |
|
17
|
|
|
_os.path.join(__path__[0], 'x86/' if _bits == '32bit' else 'x64')) |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
def _import_library_functions(lib): |
|
|
|
|
|
|
21
|
|
|
# imports libtcod namespace into thie module |
|
22
|
|
|
# does not override existing names |
|
23
|
|
|
g = globals() |
|
24
|
|
|
for name in dir(lib): |
|
25
|
|
|
if name[:5] == 'TCOD_': |
|
26
|
|
|
if name.isupper(): |
|
27
|
|
|
g[name[5:]] = getattr(lib, name) # const names |
|
28
|
|
|
elif name.startswith('FOV'): |
|
29
|
|
|
g[name] = getattr(lib, name) # fov const names |
|
30
|
|
|
elif name[:6] == 'TCODK_': # key name |
|
31
|
|
|
g['KEY_' + name[6:]] = getattr(lib, name) |
|
32
|
|
|
|
|
33
|
|
|
NOISE_DEFAULT_HURST = 0.5 |
|
34
|
|
|
NOISE_DEFAULT_LACUNARITY = 2.0 |
|
35
|
|
|
|
|
36
|
|
|
def FOV_PERMISSIVE(p) : |
|
|
|
|
|
|
37
|
|
|
return FOV_PERMISSIVE_0+p |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
def BKGND_ALPHA(a): |
|
|
|
|
|
|
40
|
|
|
return BKGND_ALPH | (int(a * 255) << 8) |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def BKGND_ADDALPHA(a): |
|
|
|
|
|
|
43
|
|
|
return BKGND_ADDA | (int(a * 255) << 8) |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
class _Mock(object): |
|
46
|
|
|
"""Mock object needed for ReadTheDocs.""" |
|
47
|
|
|
|
|
48
|
|
|
TCOD_RENDERER_SDL = 2 |
|
49
|
|
|
TCOD_FONT_LAYOUT_ASCII_INCOL = 1 |
|
50
|
|
|
TCOD_BKGND_SET = 1 |
|
51
|
|
|
TCOD_BKGND_DEFAULT = 13 |
|
52
|
|
|
TCOD_KEY_RELEASED = 2 |
|
53
|
|
|
TCOD_NOISE_DEFAULT = 0 |
|
54
|
|
|
TCOD_NOISE_SIMPLEX = 2 |
|
55
|
|
|
FOV_RESTRICTIVE = 12 |
|
56
|
|
|
|
|
57
|
|
|
TCOD_RNG_MT = 0 |
|
58
|
|
|
TCOD_RNG_CMWC = 1 |
|
59
|
|
|
|
|
60
|
|
|
CData = () # This gets passed to an isinstance call. |
|
61
|
|
|
|
|
62
|
|
|
def def_extern(self): |
|
|
|
|
|
|
63
|
|
|
"""Pass def_extern call silently.""" |
|
64
|
|
|
return lambda func:func |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
def __getattr__(self, attr): |
|
67
|
|
|
"""This object pretends to have everything.""" |
|
68
|
|
|
return self |
|
69
|
|
|
|
|
70
|
|
|
def __call__(self, *args, **kargs): |
|
71
|
|
|
"""Suppress any other calls""" |
|
72
|
|
|
return self |
|
73
|
|
|
|
|
74
|
|
|
def __str__(self): |
|
75
|
|
|
"""Just have ? in case anything leaks as a parameter default.""" |
|
76
|
|
|
return '?' |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
if _os.environ.get('READTHEDOCS'): |
|
80
|
|
|
# Mock the lib and ffi objects needed to compile docs for readthedocs.io |
|
81
|
|
|
# Allows an import without building the cffi module first. |
|
82
|
|
|
lib = ffi = _Mock() |
|
83
|
|
|
else: |
|
84
|
|
|
from tcod._libtcod import lib, ffi |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
_import_library_functions(lib) |
|
87
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.