forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibtcod.py
More file actions
91 lines (70 loc) · 2.33 KB
/
Copy pathlibtcod.py
File metadata and controls
91 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""This module handles loading of the libtcod cffi API.
"""
from __future__ import absolute_import as _
import sys as _sys
import os as _os
import platform as _platform
from tcod import __path__
if _sys.platform == 'win32':
# add Windows dll's to PATH
_bits, _linkage = _platform.architecture()
_os.environ['PATH'] = '%s;%s' % (
_os.path.join(__path__[0], 'x86' if _bits == '32bit' else 'x64'),
_os.environ['PATH'],
)
def _import_library_functions(lib):
# imports libtcod namespace into thie module
# does not override existing names
g = globals()
for name in dir(lib):
if name[:5] == 'TCOD_':
if name.isupper():
g[name[5:]] = getattr(lib, name) # const names
elif name.startswith('FOV'):
g[name] = getattr(lib, name) # fov const names
elif name[:6] == 'TCODK_': # key name
g['KEY_' + name[6:]] = getattr(lib, name)
NOISE_DEFAULT_HURST = 0.5
NOISE_DEFAULT_LACUNARITY = 2.0
def FOV_PERMISSIVE(p) :
return FOV_PERMISSIVE_0+p
def BKGND_ALPHA(a):
return BKGND_ALPH | (int(a * 255) << 8)
def BKGND_ADDALPHA(a):
return BKGND_ADDA | (int(a * 255) << 8)
class _Mock(object):
"""Mock object needed for ReadTheDocs."""
TCOD_RENDERER_GLSL = 0
TCOD_RENDERER_OPENGL = 1
TCOD_RENDERER_SDL = 2
TCOD_FONT_LAYOUT_ASCII_INCOL = 1
TCOD_BKGND_SET = 1
TCOD_BKGND_DEFAULT = 13
TCOD_KEY_RELEASED = 2
TCOD_NOISE_DEFAULT = 0
TCOD_NOISE_SIMPLEX = 2
TCOD_NOISE_WAVELET = 4
FOV_RESTRICTIVE = 12
TCOD_RNG_MT = 0
TCOD_RNG_CMWC = 1
CData = () # This gets passed to an isinstance call.
@staticmethod
def def_extern():
"""Pass def_extern call silently."""
return lambda func:func
def __getattr__(self, attr):
"""This object pretends to have everything."""
return self
def __call__(self, *args, **kargs):
"""Suppress any other calls"""
return self
def __str__(self):
"""Just have ? in case anything leaks as a parameter default."""
return '?'
if _os.environ.get('READTHEDOCS'):
# Mock the lib and ffi objects needed to compile docs for readthedocs.io
# Allows an import without building the cffi module first.
lib = ffi = _Mock()
else:
from tcod._libtcod import lib, ffi
_import_library_functions(lib)