Completed
Branch docs (a64d16)
by Kyle
01:29
created

BSP.walk()   A

Complexity

Conditions 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 17
rs 9.4285
1
"""This module focuses on improvements to the Python libtcod API.
2
"""
3
from __future__ import absolute_import as _
4
5
import os as _os
0 ignored issues
show
Unused Code introduced by
Unused os imported as _os
Loading history...
6
import sys as _sys
7
8
import platform as _platform
0 ignored issues
show
Unused Code introduced by
Unused platform imported as _platform
Loading history...
9
import weakref as _weakref
10
import functools as _functools
11
12
def _unpack_char_p(char_p):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13
    if char_p == ffi.NULL:
14
        return ''
15
    return ffi.string(char_p).decode()
16
17
def _int(int_or_str):
18
    'return an integer where a single character string may be expected'
19
    if isinstance(int_or_str, str):
20
        return ord(int_or_str)
21
    if isinstance(int_or_str, bytes):
22
        return int_or_str[0]
23
    return int(int_or_str)
24
25
def _cdata(cdata):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
26
    try:
27
        cdata = cdata.cdata
28
    except AttributeError:
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
29
        pass
30
    if cdata is None:
31
        cdata = ffi.NULL
32
    return cdata
33
34
if _sys.version_info[0] == 2: # Python 2
35
    def _bytes(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
36
        if isinstance(string, unicode):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unicode'
Loading history...
37
            return string.encode()
38
        return string
39
40
    def _unicode(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
41
        if not isinstance(string, unicode):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unicode'
Loading history...
42
            return string.decode()
43
        return string
44
45
else: # Python 3
46
    def _bytes(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
47
        if isinstance(string, str):
48
            return string.encode()
49
        return string
50
51
    def _unicode(string):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
        if isinstance(string, bytes):
53
            return string.decode()
54
        return string
55
56
class _PropagateException():
57
    ''' context manager designed to propagate exceptions outside of a cffi
58
    callback context.  normally cffi suppresses the exception
59
60
    when propagate is called this class will hold onto the error until the
61
    control flow leaves the context, then the error will be raised
62
63
    with _PropagateException as propagate:
64
    # give propagate as onerror parameter for ffi.def_extern
65
    '''
66
67
    def __init__(self):
68
        self.exc_info = None # (exception, exc_value, traceback)
69
70
    def propagate(self, *exc_info):
71
        ''' set an exception to be raised once this context exits
72
73
        if multiple errors are caught, only keep the first exception raised
74
        '''
75
        if not self.exc_info:
76
            self.exc_info = exc_info
77
78
    def __enter__(self):
79
        ''' once in context, only the propagate call is needed to use this
80
        class effectively
81
        '''
82
        return self.propagate
83
84
    def __exit__(self, type, value, traceback):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
85
        ''' if we're holding on to an exception, raise it now
86
87
        prefers our held exception over any current raising error
88
89
        self.exc_info is reset now in case of nested manager shenanigans
90
        '''
91
        if self.exc_info:
92
            type, value, traceback = self.exc_info
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 68.
Loading history...
Bug introduced by
The tuple unpacking with sequence seems to be unbalanced; 3 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
Bug Best Practice introduced by
It seems like you are trying to unpack a non-sequence, which was defined at line 93.
Loading history...
93
            self.exc_info = None
94
        if type:
95
            # Python 2/3 compatible throw
96
            exception = type(value)
97
            exception.__traceback__ = traceback
98
            raise exception
99
100
class _CDataWrapper(object):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
101
102
    def __init__(self, *args, **kargs):
103
        self.cdata = self._get_cdata_from_args(*args, **kargs)
104
        if self.cdata == None:
105
            self.cdata = ffi.NULL
106
        super(_CDataWrapper, self).__init__()
107
108
    def _get_cdata_from_args(self, *args, **kargs):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
109
        if len(args) == 1 and isinstance(args[0], ffi.CData) and not kargs:
110
            return args[0]
111
        else:
112
            return None
113
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
114
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
115
    def __hash__(self):
116
        return hash(self.cdata)
117
118
    def __eq__(self, other):
119
        try:
120
            return self.cdata == other.cdata
121
        except AttributeError:
122
            return NotImplemented
123
124
    def __getattr__(self, attr):
125
        return getattr(self.__dict__['cdata'], attr)
126
127
    def __setattr__(self, attr, value):
128
        if hasattr(self, 'cdata') and hasattr(self.cdata, attr):
129
            setattr(self.cdata, attr, value)
130
        else:
131
            super(_CDataWrapper, self).__setattr__(attr, value)
132
133
def _assert_cdata_is_not_null(func):
134
    """Any BSP methods which use a cdata object in a TCOD call need to have
135
    a sanity check, otherwise it may end up passing a NULL pointer"""
136
    if __debug__:
137
        @_functools.wraps(func)
138
        def check_sanity(*args, **kargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable check_sanity seems to be unused.
Loading history...
139
            assert self.cdata != ffi.NULL and self.cdata is not None, \
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'self'
Loading history...
140
                   'cannot use function, cdata is %r' % self.cdata
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'self'
Loading history...
141
            return func(*args, **kargs)
142
    return func
143
144
class BSP(_CDataWrapper):
145
    """
146
147
    .. attribute:: x
148
    .. attribute:: y
149
    .. attribute:: w
150
    .. attribute:: h
151
152
    :param int x: rectangle left coordinate
153
    :param int y: rectangle top coordinate
154
    :param int w: rectangle width
155
    :param int h: rectangle height
156
157
    .. versionchanged:: 2.0
158
       You can create BSP's with this class contructor instead of using
159
       :any:`bsp_new_with_size`.
160
161
    """
162
163
    def __init__(self, *args, **kargs):
164
        self._reference = None # to prevent garbage collection
165
        self._children = _weakref.WeakSet() # used by _invalidate_children
166
        super(BSP, self).__init__(*args, **kargs)
167
        if self._get_cdata_from_args(*args, **kargs) is None:
168
            self._init(*args, **kargs)
169
170
    def _init(self, x, y, w, h):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
171
        self.cdata = ffi.gc(lib.TCOD_bsp_new_with_size(x, y, w, h),
172
                             lib.TCOD_bsp_delete)
173
174
    def _pass_reference(self, reference):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
175
        self._reference = reference
176
        self._reference._children.add(self)
177
        return self
178
179
    def _invalidate_children(self):
180
        """Invalidates BSP instances known to be based off of this one."""
181
        for child in self._children:
182
            child._reference = None
183
            child._invalidate_children()
184
            child.cdata = ffi.NULL
185
        self._children.clear()
186
187
    def __repr__(self):
188
        """Provide a useful readout when printed."""
189
        if not self.cdata:
190
            return '<%s NULL!>' % self.__class__.__name__
191
192
        status = 'leaf'
193
        if not self.is_leaf():
194
            status = ('split at dicision=%i,orientation=%r' %
195
                      (self.get_division(), self.get_orientation()))
196
197
        return ('<%s(x=%i,y=%i,w=%i,h=%i)depth=%i,%s>' %
198
                (self.__class__.__name__,
199
                 self.x, self.y, self.w, self.h, self.get_depth(), status))
200
201
    def get_depth(self):
202
        """Return the depth of this node.
203
204
        :rtype: int
205
206
        .. versionadded:: 2.0
207
        """
208
        return self.cdata.level
209
210
    def get_division(self):
211
        """Return the point where this node was divided into parts.
212
213
        :rtype: :any:`int` or :any:`None`
214
215
        .. versionadded:: 2.0
216
        """
217
        if self.is_leaf():
218
            return None
219
        return self.cdata.position
220
221
    def get_orientation(self):
222
        """
223
224
        :rtype: str
225
226
        .. versionadded:: 2.0
227
        """
228
        if self.is_leaf():
229
            return ''
230
        elif self.cdata.horizontal:
231
            return 'horizontal'
232
        else:
233
            return 'vertical'
234
235
    @_assert_cdata_is_not_null
236
    def split_once(self, orientation, position):
237
        """
238
239
        :rtype: tuple
240
241
        .. versionadded:: 2.0
242
        """
243
        # orientation = horz
244
        if orientation[:1].lower() == 'h':
245
            lib.TCOD_bsp_split_once(self.cdata, True, position)
246
        elif orientation[:1].lower() == 'v':
247
            lib.TCOD_bsp_split_once(self.cdata, False, position)
248
        else:
249
            raise ValueError("orientation must be 'horizontal' or 'vertical'"
250
                             "\nNot %r" % orientation)
251
        return self.get_children()
252
253
    @_assert_cdata_is_not_null
254
    def split_recursive(self, depth, min_width, min_height,
255
                        max_horz_ratio, max_vert_raito, random=None):
256
        """
257
258
        :rtype: iter
259
260
        .. versionadded:: 2.0
261
        """
262
        lib.TCOD_bsp_split_recursive(self.cdata, random or ffi.NULL,
263
                                      depth, min_width, min_height,
264
                                      max_horz_ratio, max_vert_raito)
265
        return self.walk()
266
267
    @_assert_cdata_is_not_null
268
    def resize(self, x, y, w, h):
269
        """Resize this BSP to the provided rectangle.
270
271
        :param int x: rectangle left coordinate
272
        :param int y: rectangle top coordinate
273
        :param int w: rectangle width
274
        :param int h: rectangle height
275
276
        .. versionadded:: 2.0
277
        """
278
        lib.TCOD_bsp_resize(self.cdata, x, y, w, h)
279
280
    @_assert_cdata_is_not_null
281
    def get_left(self):
282
        """Return this BSP's 'left' child.
283
284
        Returns None if this BSP is a leaf node.
285
286
        :return: BSP's left/top child or None.
287
        :rtype: :any:`BSP` or :any:`None`
288
289
        .. versionadded:: 2.0
290
        """
291
        if self.is_leaf():
292
            return None
293
        return BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self)
294
295
    @_assert_cdata_is_not_null
296
    def get_right(self):
297
        """Return this BSP's 'right' child.
298
299
        Returns None if this BSP is a leaf node.
300
301
        :return: BSP's right/bottom child or None.
302
        :rtype: :any:`BSP` or :any:`None`
303
304
        .. versionadded:: 2.0
305
        """
306
        if self.is_leaf():
307
            return None
308
        return BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self)
309
310
    @_assert_cdata_is_not_null
311
    def get_parent(self):
312
        """Return this BSP's parent node.
313
314
        :return: Returns the parent node as a BSP instance.
315
                 Returns None if this BSP has no parent.
316
        :rtype: :any:`BSP` or :any:`None`
317
318
        .. versionadded:: 2.0
319
        """
320
        node = BSP(lib.TCOD_bsp_father(self.cdata))._pass_reference(self)
321
        if node.cdata == ffi.NULL:
322
            return None
323
        return node
324
325
    @_assert_cdata_is_not_null
326
    def get_children(self):
327
        """Return as a tuple, this instances immediate children, if any.
328
329
        :return: Returns a tuple of (left, right) BSP instances.
330
                 The returned tuple is empty if this BSP has no children.
331
        :rtype: tuple
332
333
        .. versionadded:: 2.0
334
        """
335
        if self.is_leaf():
336
            return ()
337
        return (BSP(lib.TCOD_bsp_left(self.cdata))._pass_reference(self),
338
                BSP(lib.TCOD_bsp_right(self.cdata))._pass_reference(self))
339
340
    @_assert_cdata_is_not_null
341
    def walk(self):
342
        """Iterate over this BSP's hieracrhy.
343
344
        The iterator will include the instance which called it.
345
        It will traverse its own children and grandchildren, in no particular
346
        order.
347
348
        :return: Returns an iterator of BSP instances.
349
        :rtype: iter
350
351
        .. versionadded:: 2.0
352
        """
353
        for child in self.get_children():
354
            for grandchild in child.walk():
355
                yield grandchild
356
        yield self
357
358
    @_assert_cdata_is_not_null
359
    def is_leaf(self):
360
        """Returns True if this node is a leaf.  False when this node has children.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
361
362
        :rtype: bool
363
364
        .. versionadded:: 2.0
365
        """
366
        return bool(lib.TCOD_bsp_is_leaf(self.cdata))
367
368
    @_assert_cdata_is_not_null
369
    def contains(self, x, y):
370
        """Returns True if this node contains these coordinates.
371
372
        :rtype: bool
373
374
        .. versionadded:: 2.0
375
        """
376
        return bool(lib.TCOD_bsp_contains(self.cdata, x, y))
377
378
    @_assert_cdata_is_not_null
379
    def find_node(self, x, y):
380
        """Return the deepest node which contains these coordinates.
381
382
        :rtype: :any:`BSP` or :any:`None`
383
384
        .. versionadded:: 2.0
385
        """
386
        node = BSP(lib.TCOD_bsp_find_node(self.cdata,
387
                                           x, y))._pass_reference(self)
388
        if node.cdata == ffi.NULL:
389
            node = None
390
        return node
391
392
class HeightMap(_CDataWrapper):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
393
394
    def __init__(self, *args, **kargs):
395
        super(HeightMap, self).__init__(*args, **kargs)
396
        if not self.cdata:
397
            self._init(*args, **kargs)
398
399
    def _init(self, width, height):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
400
        self.cdata = ffi.gc(lib.TCOD_heightmap_new(width, height),
401
                             lib.TCOD_heightmap_delete)
402
403
404
class Color(list):
405
    '''list-like behaviour could change in the future'''
406
407
    def __init__(self, *rgb):
0 ignored issues
show
Bug introduced by
The __init__ method of the super-class list is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
408
        if len(rgb) < 3:
409
            rgb += (0,) * (3 - len(rgb))
410
        self[:] = rgb
411
412
    @classmethod
413
    def from_cdata(cls, tcod_color):
414
        '''new in libtcod-cffi'''
415
        return cls(tcod_color.r, tcod_color.g, tcod_color.b)
416
417
    @classmethod
418
    def from_int(cls, integer):
419
        '''a TDL int color: 0xRRGGBB
420
421
        new in libtcod-cffi'''
422
        return cls.from_cdata(lib.TDL_color_from_int(integer))
423
424
    def __eq__(self, other):
425
        return (isinstance(other, (Color, FrozenColor)) and
426
                lib.TCOD_color_equals(self, other))
427
428
    def __mul__(self, other):
429
        if isinstance(other,(list, tuple)):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
if isinstance(other,(list, tuple)):
^
Loading history...
430
            return Color.from_cdata(lib.TCOD_color_multiply(self, other))
431
        else:
432
            return Color.from_cdata(lib.TCOD_color_multiply_scalar(self, other))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
433
434
    def __add__(self, other):
435
        return Color.from_cdata(lib.TCOD_color_add(self, other))
436
437
    def __sub__(self, other):
438
        return Color.from_cdata(lib.TCOD_color_subtract(self, other))
439
440
    def __repr__(self):
441
        return "<%s%s>" % (self.__class__.__name__, list.__repr__(self))
442
443
    def _get_r(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
444
        return self[0]
445
446
    def _set_r(self, val):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
447
        self[0] = val & 0xff
448
449
    def _get_g(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
450
        return self[1]
451
452
    def _set_g(self, val):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
453
        self[1] = val & 0xff
454
455
    def _get_b(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
456
        return self[2]
457
458
    def _set_b(self, val):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
459
        self[2] = val & 0xff
460
461
    r = property(_get_r, _set_r)
462
    g = property(_get_g, _set_g)
463
    b = property(_get_b, _set_b)
464
465
    def __int__(self):
466
        # new in libtcod-cffi
467
        return lib.TDL_color_RGB(*self)
468
469
470
class FrozenColor(tuple):
471
    '''new in libtcod-cffi'''
472
    def __new__(cls, *rgb):
473
        if len(rgb) < 3:
474
            rgb += (0,) * (3 - len(rgb))
475
        return tuple.__new__(cls, (rgb))
476
477
    @classmethod
478
    def from_cdata(cls, tcod_color):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
479
        return cls(tcod_color.r, tcod_color.g, tcod_color.b)
480
481
    @classmethod
482
    def from_int(cls, integer):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
483
        return cls.from_cdata(lib.TDL_color_from_int(integer))
484
485
    __mul__ = Color.__mul__
486
    __add__ = Color.__add__
487
    __sub__ = Color.__sub__
488
489
    def __repr__(self):
490
        return "<%s%s>" % (self.__class__.__name__, tuple.__repr__(self))
491
492
    _get_r = Color._get_r
493
    _get_g = Color._get_g
494
    _get_b = Color._get_b
495
    def _set_rgb(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
496
        raise TypleError('can not assign colors directally to %s' %
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'TypleError'
Loading history...
497
                         (self.__class__))
498
499
    r = property(_get_r, _set_rgb)
500
    g = property(_get_g, _set_rgb)
501
    b = property(_get_b, _set_rgb)
502
503
    __int__ = Color.__int__
504
505
class Key(_CDataWrapper):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
506
507
    def __init__(self, *args):
508
        super(Key, self).__init__(*args)
509
        if self.cdata == ffi.NULL:
510
            self.cdata = ffi.new('TCOD_key_t*')
511
512
    def __getattr__(self, attr):
513
        if attr == 'c':
514
            return ord(getattr(self.cdata, attr))
515
        else:
516
            return super(Key, self).__getattr__(attr)
517
518
class Mouse(_CDataWrapper):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
519
520
    def __init__(self, *args):
521
        super(Mouse, self).__init__(*args)
522
        if self.cdata == ffi.NULL:
523
            self.cdata = ffi.new('TCOD_mouse_t*')
524
525
526
def clipboard_set(string):
527
    """Set the clipboard contents to string.
528
529
    .. versionadded:: 2.0
530
    """
531
    lib.TCOD_sys_clipboard_set(_bytes(string))
532
533
def clipboard_get():
534
    """Return the current contents of the clipboard.
535
536
    .. versionadded:: 2.0
537
    """
538
    return _unpack_char_p(lib.TCOD_sys_clipboard_get())
539
540
from tcod.libtcod import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like tcod.libtcod should generally be avoided.
Loading history...
Unused Code introduced by
NOISE_DEFAULT_HURST was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BKGND_ALPHA was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
FOV_PERMISSIVE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
NOISE_DEFAULT_LACUNARITY was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BKGND_ADDALPHA was imported with wildcard, but is not used.
Loading history...
541
542
@ffi.def_extern()
543
def _pycall_bsp_callback(node, handle):
544
    """static bool _pycall_bsp_callback(TCOD_bsp_t *node, void *userData);"""
545
    func, userData, propagate = ffi.from_handle(handle)
546
    try:
547
        return func(BSP(node), userData)
548
    except BaseException:
549
        propagate(*_sys.exc_info())
550
        return False
551
552
553
__all__ = [_name for _name in list(globals()) if _name[0] != '_']
554