Completed
Push — master ( 7346d5...9162fc )
by Kyle
01:25
created

console_from_xp()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 4
rs 10
1
"""This module handles backward compatibility with the ctypes libtcodpy module.
2
"""
3
4
from __future__ import absolute_import as _
5
6
import threading as _threading
7
8
import numpy as _np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
9
10
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
FOV_PERMISSIVE 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
BKGND_ADDALPHA was imported with wildcard, but is not used.
Loading history...
11
12
from tcod.tcod import _int, _cdata, _unpack_char_p
13
from tcod.tcod import _bytes, _unicode, _fmt_bytes, _fmt_unicode
14
from tcod.tcod import _CDataWrapper
15
from tcod.tcod import _PropagateException
16
17
import tcod.bsp
18
from tcod.color import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like tcod.color should generally be avoided.
Loading history...
Unused Code introduced by
absolute_import was imported with wildcard, but is not used.
Loading history...
19
import tcod.console
20
import tcod.image
21
import tcod.map
22
import tcod.noise
23
import tcod.path
24
import tcod.random
25
26
Bsp = tcod.bsp.BSP
27
28
29
class ConsoleBuffer(object):
30
    """Simple console that allows direct (fast) access to cells. simplifies
31
    use of the "fill" functions.
32
33
    Args:
34
        width (int): Width of the new ConsoleBuffer.
35
        height (int): Height of the new ConsoleBuffer.
36
        back_r (int): Red background color, from 0 to 255.
37
        back_g (int): Green background color, from 0 to 255.
38
        back_b (int): Blue background color, from 0 to 255.
39
        fore_r (int): Red foreground color, from 0 to 255.
40
        fore_g (int): Green foreground color, from 0 to 255.
41
        fore_b (int): Blue foreground color, from 0 to 255.
42
        char (AnyStr): A single character str or bytes object.
43
    """
44
    def __init__(self, width, height, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/79).

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

Loading history...
45
        """initialize with given width and height. values to fill the buffer
46
        are optional, defaults to black with no characters.
47
        """
48
        n = width * height
0 ignored issues
show
Unused Code introduced by
The variable n seems to be unused.
Loading history...
49
        self.width = width
50
        self.height = height
51
        self.clear(back_r, back_g, back_b, fore_r, fore_g, fore_b, char)
52
53
    def clear(self, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/79).

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

Loading history...
54
        """Clears the console.  Values to fill it with are optional, defaults
55
        to black with no characters.
56
57
        Args:
58
            back_r (int): Red background color, from 0 to 255.
59
            back_g (int): Green background color, from 0 to 255.
60
            back_b (int): Blue background color, from 0 to 255.
61
            fore_r (int): Red foreground color, from 0 to 255.
62
            fore_g (int): Green foreground color, from 0 to 255.
63
            fore_b (int): Blue foreground color, from 0 to 255.
64
            char (AnyStr): A single character str or bytes object.
65
        """
66
        n = self.width * self.height
67
        self.back_r = [back_r] * n
68
        self.back_g = [back_g] * n
69
        self.back_b = [back_b] * n
70
        self.fore_r = [fore_r] * n
71
        self.fore_g = [fore_g] * n
72
        self.fore_b = [fore_b] * n
73
        self.char = [ord(char)] * n
74
75
    def copy(self):
76
        """Returns a copy of this ConsoleBuffer.
77
78
        Returns:
79
            ConsoleBuffer: A new ConsoleBuffer copy.
80
        """
81
        other = ConsoleBuffer(0, 0)
82
        other.width = self.width
83
        other.height = self.height
84
        other.back_r = list(self.back_r)  # make explicit copies of all lists
0 ignored issues
show
Coding Style introduced by
The attribute back_r was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
85
        other.back_g = list(self.back_g)
0 ignored issues
show
Coding Style introduced by
The attribute back_g was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
86
        other.back_b = list(self.back_b)
0 ignored issues
show
Coding Style introduced by
The attribute back_b was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
87
        other.fore_r = list(self.fore_r)
0 ignored issues
show
Coding Style introduced by
The attribute fore_r was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
88
        other.fore_g = list(self.fore_g)
0 ignored issues
show
Coding Style introduced by
The attribute fore_g was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
89
        other.fore_b = list(self.fore_b)
0 ignored issues
show
Coding Style introduced by
The attribute fore_b was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
90
        other.char = list(self.char)
0 ignored issues
show
Coding Style introduced by
The attribute char was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
91
        return other
92
93
    def set_fore(self, x, y, r, g, b, char):
94
        """Set the character and foreground color of one cell.
95
96
        Args:
97
            x (int): X position to change.
98
            y (int): Y position to change.
99
            r (int): Red foreground color, from 0 to 255.
100
            g (int): Green foreground color, from 0 to 255.
101
            b (int): Blue foreground color, from 0 to 255.
102
            char (AnyStr): A single character str or bytes object.
103
        """
104
        i = self.width * y + x
105
        self.fore_r[i] = r
106
        self.fore_g[i] = g
107
        self.fore_b[i] = b
108
        self.char[i] = ord(char)
109
110
    def set_back(self, x, y, r, g, b):
111
        """Set the background color of one cell.
112
113
        Args:
114
            x (int): X position to change.
115
            y (int): Y position to change.
116
            r (int): Red background color, from 0 to 255.
117
            g (int): Green background color, from 0 to 255.
118
            b (int): Blue background color, from 0 to 255.
119
            char (AnyStr): A single character str or bytes object.
120
        """
121
        i = self.width * y + x
122
        self.back_r[i] = r
123
        self.back_g[i] = g
124
        self.back_b[i] = b
125
126
    def set(self, x, y, back_r, back_g, back_b, fore_r, fore_g, fore_b, char):
127
        """Set the background color, foreground color and character of one cell.
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...
128
129
        Args:
130
            x (int): X position to change.
131
            y (int): Y position to change.
132
            back_r (int): Red background color, from 0 to 255.
133
            back_g (int): Green background color, from 0 to 255.
134
            back_b (int): Blue background color, from 0 to 255.
135
            fore_r (int): Red foreground color, from 0 to 255.
136
            fore_g (int): Green foreground color, from 0 to 255.
137
            fore_b (int): Blue foreground color, from 0 to 255.
138
            char (AnyStr): A single character str or bytes object.
139
        """
140
        i = self.width * y + x
141
        self.back_r[i] = back_r
142
        self.back_g[i] = back_g
143
        self.back_b[i] = back_b
144
        self.fore_r[i] = fore_r
145
        self.fore_g[i] = fore_g
146
        self.fore_b[i] = fore_b
147
        self.char[i] = ord(char)
148
149
    def blit(self, dest, fill_fore=True, fill_back=True):
150
        """Use libtcod's "fill" functions to write the buffer to a console.
151
152
        Args:
153
            dest (Console): Console object to modify.
154
            fill_fore (bool):
155
                If True, fill the foreground color and characters.
156
            fill_back (bool):
157
                If True, fill the background color.
158
        """
159
        dest = _cdata(dest)
160
        if (console_get_width(dest) != self.width or
161
            console_get_height(dest) != self.height):
162
            raise ValueError('ConsoleBuffer.blit: Destination console has an incorrect size.')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (94/79).

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

Loading history...
163
164
        if fill_back:
165
            lib.TCOD_console_fill_background(dest or ffi.NULL,
166
                                              ffi.new('int[]', self.back_r),
167
                                              ffi.new('int[]', self.back_g),
168
                                              ffi.new('int[]', self.back_b))
169
        if fill_fore:
170
            lib.TCOD_console_fill_foreground(dest or ffi.NULL,
171
                                              ffi.new('int[]', self.fore_r),
172
                                              ffi.new('int[]', self.fore_g),
173
                                              ffi.new('int[]', self.fore_b))
174
            lib.TCOD_console_fill_char(dest or ffi.NULL,
175
                                        ffi.new('int[]', self.char))
176
177
178
class Dice(_CDataWrapper):
179
    """
180
181
    Args:
182
        nb_dices (int): Number of dice.
183
        nb_faces (int): Number of sides on a die.
184
        multiplier (float): Multiplier.
185
        addsub (float): Addition.
186
187
    .. versionchanged:: 2.0
188
        This class now acts like the other CData wrapped classes
189
        and no longer acts like a list.
190
191
    .. deprecated:: 2.0
192
        You should make your own dice functions instead of using this class
193
        which is tied to a CData object.
194
    """
195
196
    def __init__(self, *args, **kargs):
197
        super(Dice, self).__init__(*args, **kargs)
198
        if self.cdata == ffi.NULL:
199
            self._init(*args, **kargs)
200
201
    def _init(self, nb_dices=0, nb_faces=0, multiplier=0, addsub=0):
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...
202
        self.cdata = ffi.new('TCOD_dice_t*')
203
        self.nb_dices = nb_dices
204
        self.nb_faces = nb_faces
205
        self.multiplier = multiplier
206
        self.addsub = addsub
207
208
    def _get_nb_dices(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...
209
        return self.nb_rolls
210
    def _set_nb_dices(self, value):
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...
211
        self.nb_rolls = value
0 ignored issues
show
Coding Style introduced by
The attribute nb_rolls was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
212
    nb_dices = property(_get_nb_dices, _set_nb_dices)
213
214
    def __str__(self):
215
        add = '+(%s)' % self.addsub if self.addsub != 0 else ''
216
        return '%id%ix%s%s' % (self.nb_dices, self.nb_faces,
217
                               self.multiplier, add)
218
219
    def __repr__(self):
220
        return ('%s(nb_dices=%r,nb_faces=%r,multiplier=%r,addsub=%r)' %
221
                (self.__class__.__name__, self.nb_dices, self.nb_faces,
222
                 self.multiplier, self.addsub))
223
224
225
class Key(_CDataWrapper):
226
    """Key Event instance
227
228
    Attributes:
229
        vk (int): TCOD_keycode_t key code
230
        c (int): character if vk == TCODK_CHAR else 0
231
        text (Text): text[TCOD_KEY_TEXT_SIZE]; text if vk == TCODK_TEXT else text[0] == '\0'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (92/79).

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

Loading history...
232
        pressed (bool): does this correspond to a key press or key release event ?
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

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

Loading history...
233
        lalt (bool): True when left alt is held.
234
        lctrl (bool): True when left control is held.
235
        lmeta (bool): True when left meta key is held.
236
        ralt (bool): True when right alt is held.
237
        rctrl (bool): True when right control is held.
238
        rmeta (bool): True when right meta key is held.
239
        shift (bool): True when any shift is held.
240
    """
241
242
    _BOOL_ATTRIBUTES = ('lalt', 'lctrl', 'lmeta',
243
                        'ralt', 'rctrl', 'rmeta', 'pressed', 'shift')
244
245
    def __init__(self, *args, **kargs):
246
        super(Key, self).__init__(*args, **kargs)
247
        if self.cdata == ffi.NULL:
248
            self.cdata = ffi.new('TCOD_key_t*')
249
250
    def __getattr__(self, attr):
251
        if attr in self._BOOL_ATTRIBUTES:
252
            return bool(getattr(self.cdata, attr))
253
        if attr == 'c':
254
            return ord(getattr(self.cdata, attr))
255
        if attr == 'text':
256
            return _unpack_char_p(getattr(self.cdata, attr))
257
        return super(Key, self).__getattr__(attr)
258
259
260
class Mouse(_CDataWrapper):
261
    """Mouse event instance
262
263
    Attributes:
264
        x (int): Absolute mouse position at pixel x.
265
        y (int):
266
        dx (int): Movement since last update in pixels.
267
        dy (int):
268
        cx (int): Cell coordinates in the root console.
269
        cy (int):
270
        dcx (int): Movement since last update in console cells.
271
        dcy (int):
272
        lbutton (bool): Left button status.
273
        rbutton (bool): Right button status.
274
        mbutton (bool): Middle button status.
275
        lbutton_pressed (bool): Left button pressed event.
276
        rbutton_pressed (bool): Right button pressed event.
277
        mbutton_pressed (bool): Middle button pressed event.
278
        wheel_up (bool): Wheel up event.
279
        wheel_down (bool): Wheel down event.
280
    """
281
282
    def __init__(self, *args, **kargs):
283
        super(Mouse, self).__init__(*args, **kargs)
284
        if self.cdata == ffi.NULL:
285
            self.cdata = ffi.new('TCOD_mouse_t*')
286
287
288
def bsp_new_with_size(x, y, w, h):
289
    """Create a new BSP instance with the given rectangle.
290
291
    Args:
292
        x (int): Rectangle left coordinate.
293
        y (int): Rectangle top coordinate.
294
        w (int): Rectangle width.
295
        h (int): Rectangle height.
296
297
    Returns:
298
        BSP: A new BSP instance.
299
300
    .. deprecated:: 2.0
301
       Call the :any:`BSP` class instead.
302
    """
303
    return Bsp(x, y, w, h)
304
305
def bsp_split_once(node, horizontal, position):
306
    """
307
    .. deprecated:: 2.0
308
       Use :any:`BSP.split_once` instead.
309
    """
310
    node.split_once(horizontal, position)
311
312
def bsp_split_recursive(node, randomizer, nb, minHSize, minVSize, maxHRatio,
313
                        maxVRatio):
314
    """
315
    .. deprecated:: 2.0
316
       Use :any:`BSP.split_recursive` instead.
317
    """
318
    node.split_recursive(nb, minHSize, minVSize,
319
                         maxHRatio, maxVRatio, randomizer)
320
321
def bsp_resize(node, x, y, w, h):
322
    """
323
    .. deprecated:: 2.0
324
        Assign directly to :any:`BSP` attributes instead.
325
    """
326
    node.x = x
327
    node.y = y
328
    node.width = w
329
    node.height = h
330
331
def bsp_left(node):
332
    """
333
    .. deprecated:: 2.0
334
       Use :any:`BSP.children` instead.
335
    """
336
    return None if not node.children else node.children[0]
337
338
def bsp_right(node):
339
    """
340
    .. deprecated:: 2.0
341
       Use :any:`BSP.children` instead.
342
    """
343
    return None if not node.children else node.children[1]
344
345
def bsp_father(node):
346
    """
347
    .. deprecated:: 2.0
348
       Use :any:`BSP.parent` instead.
349
    """
350
    return node.parent
351
352
def bsp_is_leaf(node):
353
    """
354
    .. deprecated:: 2.0
355
       Use :any:`BSP.children` instead.
356
    """
357
    return not node.children
358
359
def bsp_contains(node, cx, cy):
360
    """
361
    .. deprecated:: 2.0
362
       Use :any:`BSP.contains` instead.
363
    """
364
    return node.contains(cx, cy)
365
366
def bsp_find_node(node, cx, cy):
367
    """
368
    .. deprecated:: 2.0
369
       Use :any:`BSP.find_node` instead.
370
    """
371
    return node.find_node(cx, cy)
372
373
def _bsp_traverse(node_iter, callback, userData):
374
    """pack callback into a handle for use with the callback
375
    _pycall_bsp_callback
376
    """
377
    for node in node_iter:
378
        callback(node, userData)
379
380
def bsp_traverse_pre_order(node, callback, userData=0):
381
    """Traverse this nodes hierarchy with a callback.
382
383
    .. deprecated:: 2.0
384
       Use :any:`BSP.walk` instead.
385
    """
386
    _bsp_traverse(node._iter_pre_order(), callback, userData)
387
388
def bsp_traverse_in_order(node, callback, userData=0):
389
    """Traverse this nodes hierarchy with a callback.
390
391
    .. deprecated:: 2.0
392
       Use :any:`BSP.walk` instead.
393
    """
394
    _bsp_traverse(node._iter_in_order(), callback, userData)
395
396
def bsp_traverse_post_order(node, callback, userData=0):
397
    """Traverse this nodes hierarchy with a callback.
398
399
    .. deprecated:: 2.0
400
       Use :any:`BSP.walk` instead.
401
    """
402
    _bsp_traverse(node._iter_post_order(), callback, userData)
403
404
def bsp_traverse_level_order(node, callback, userData=0):
405
    """Traverse this nodes hierarchy with a callback.
406
407
    .. deprecated:: 2.0
408
       Use :any:`BSP.walk` instead.
409
    """
410
    _bsp_traverse(node._iter_level_order(), callback, userData)
411
412
def bsp_traverse_inverted_level_order(node, callback, userData=0):
413
    """Traverse this nodes hierarchy with a callback.
414
415
    .. deprecated:: 2.0
416
       Use :any:`BSP.walk` instead.
417
    """
418
    _bsp_traverse(node._iter_inverted_level_order(), callback, userData)
419
420
def bsp_remove_sons(node):
421
    """Delete all children of a given node.  Not recommended.
422
423
    .. note::
424
       This function will add unnecessary complexity to your code.
425
       Don't use it.
426
427
    .. deprecated:: 2.0
428
       BSP deletion is automatic.
429
    """
430
    node.children = ()
431
432
def bsp_delete(node):
0 ignored issues
show
Unused Code introduced by
The argument node seems to be unused.
Loading history...
433
    """Exists for backward compatibility.  Does nothing.
434
435
    BSP's created by this library are automatically garbage collected once
436
    there are no references to the tree.
437
    This function exists for backwards compatibility.
438
439
    .. deprecated:: 2.0
440
       BSP deletion is automatic.
441
    """
442
    pass
443
444
def color_lerp(c1, c2, a):
445
    """Return the linear interpolation between two colors.
446
447
    ``a`` is the interpolation value, with 0 returing ``c1``,
448
    1 returning ``c2``, and 0.5 returing a color halfway between both.
449
450
    Args:
451
        c1 (Union[Tuple[int, int, int], Sequence[int]]):
452
            The first color.  At a=0.
453
        c2 (Union[Tuple[int, int, int], Sequence[int]]):
454
            The second color.  At a=1.
455
        a (float): The interpolation value,
456
457
    Returns:
458
        Color: The interpolated Color.
459
    """
460
    return Color._new_from_cdata(lib.TCOD_color_lerp(c1, c2, a))
461
462
def color_set_hsv(c, h, s, v):
463
    """Set a color using: hue, saturation, and value parameters.
464
465
    Does not return a new Color.  ``c`` is modified inplace.
466
467
    Args:
468
        c (Union[Color, List[Any]]): A Color instance, or a list of any kind.
469
        h (float): Hue, from 0 to 360.
470
        s (float): Saturation, from 0 to 1.
471
        v (float): Value, from 0 to 1.
472
    """
473
    new_color = ffi.new('TCOD_color_t*')
474
    lib.TCOD_color_set_HSV(new_color, h, s, v)
475
    c[:] = new_color.r, new_color.g, new_color.b
476
477
def color_get_hsv(c):
478
    """Return the (hue, saturation, value) of a color.
479
480
    Args:
481
        c (Union[Tuple[int, int, int], Sequence[int]]):
482
            An (r, g, b) sequence or Color instance.
483
484
    Returns:
485
        Tuple[float, float, float]:
486
            A tuple with (hue, saturation, value) values, from 0 to 1.
487
    """
488
    hsv = ffi.new('float [3]')
489
    lib.TCOD_color_get_HSV(c, hsv, hsv + 1, hsv + 2)
490
    return hsv[0], hsv[1], hsv[2]
491
492
def color_scale_HSV(c, scoef, vcoef):
493
    """Scale a color's saturation and value.
494
495
    Does not return a new Color.  ``c`` is modified inplace.
496
497
    Args:
498
        c (Union[Color, List[int]]): A Color instance, or an [r, g, b] list.
499
        scoef (float): Saturation multiplier, from 0 to 1.
500
                       Use 1 to keep current saturation.
501
        vcoef (float): Value multiplier, from 0 to 1.
502
                       Use 1 to keep current value.
503
    """
504
    color_p = ffi.new('TCOD_color_t*')
505
    color_p.r, color_p.g, color_p.b = c.r, c.g, c.b
506
    lib.TCOD_color_scale_HSV(color_p, scoef, vcoef)
507
    c[:] = color_p.r, color_p.g, color_p.b
508
509
def color_gen_map(colors, indexes):
510
    """Return a smoothly defined scale of colors.
511
512
    If ``indexes`` is [0, 3, 9] for example, the first color from ``colors``
513
    will be returned at 0, the 2nd will be at 3, and the 3rd will be at 9.
514
    All in-betweens will be filled with a gradient.
515
516
    Args:
517
        colors (Iterable[Union[Tuple[int, int, int], Sequence[int]]]):
518
            Array of colors to be sampled.
519
        indexes (Iterable[int]): A list of indexes.
520
521
    Returns:
522
        List[Color]: A list of Color instances.
523
524
    Example:
525
        >>> tcod.color_gen_map([(0, 0, 0), (255, 128, 0)], [0, 5])
526
        [Color(0,0,0), Color(51,25,0), Color(102,51,0), Color(153,76,0), \
527
Color(204,102,0), Color(255,128,0)]
528
    """
529
    ccolors = ffi.new('TCOD_color_t[]', colors)
530
    cindexes = ffi.new('int[]', indexes)
531
    cres = ffi.new('TCOD_color_t[]', max(indexes) + 1)
532
    lib.TCOD_color_gen_map(cres, len(colors), ccolors, cindexes)
533
    return [Color._new_from_cdata(cdata) for cdata in cres]
534
535
_numpy = None
536
537
def _numpy_available():
538
    'check if numpy is available and lazily load it when needed'
539
    global _numpy
540
    if _numpy is None:
541
        try:
542
            import numpy as _numpy
0 ignored issues
show
Comprehensibility Bug introduced by
_numpy is re-defining a name which is already available in the outer-scope (previously defined on line 535).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
543
        except ImportError:
544
            _numpy = False
545
    return _numpy
546
547
# initializing the console
548
def console_init_root(w, h, title, fullscreen=False,
549
                      renderer=RENDERER_SDL):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'RENDERER_SDL'
Loading history...
550
    """Set up the primary display and return the root console.
551
552
    Note:
553
        Currently only the SDL renderer is supported at the moment.
554
        Do not attempt to change it.
555
556
    Args:
557
        w (int): Width in character tiles for the root console.
558
        h (int): Height in character tiles for the root console.
559
        title (AnyStr):
560
            This string will be displayed on the created windows title bar.
561
        renderer: Rendering mode for libtcod to use.
562
563
    Returns:
564
        Console:
565
            Returns a special Console instance representing the root console.
566
    """
567
    lib.TCOD_console_init_root(w, h, _bytes(title), fullscreen, renderer)
568
    return tcod.console.Console._from_cdata(ffi.NULL) # root console is null
569
570
571
def console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL,
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'FONT_LAYOUT_ASCII_INCOL'
Loading history...
572
                            nb_char_horiz=0, nb_char_vertic=0):
573
    """Load a custom font file.
574
575
    Call this before function before calling :any:`tcod.console_init_root`.
576
577
    Flags can be a mix of the following:
578
579
    * tcod.FONT_LAYOUT_ASCII_INCOL
580
    * tcod.FONT_LAYOUT_ASCII_INROW
581
    * tcod.FONT_TYPE_GREYSCALE
582
    * tcod.FONT_TYPE_GRAYSCALE
583
    * tcod.FONT_LAYOUT_TCOD
584
585
    Args:
586
        fontFile (AnyStr): Path to a font file.
587
        flags (int):
588
        nb_char_horiz (int):
589
        nb_char_vertic (int):
590
    """
591
    lib.TCOD_console_set_custom_font(_bytes(fontFile), flags,
592
                                     nb_char_horiz, nb_char_vertic)
593
594
595
def console_get_width(con):
596
    """Return the width of a console.
597
598
    Args:
599
        con (Console): Any Console instance.
600
601
    Returns:
602
        int: The width of a Console.
603
604
    .. deprecated:: 2.0
605
        Use `Console.get_width` instead.
606
    """
607
    return lib.TCOD_console_get_width(_cdata(con))
608
609
def console_get_height(con):
610
    """Return the height of a console.
611
612
    Args:
613
        con (Console): Any Console instance.
614
615
    Returns:
616
        int: The height of a Console.
617
618
    .. deprecated:: 2.0
619
        Use `Console.get_hright` instead.
620
    """
621
    return lib.TCOD_console_get_height(_cdata(con))
622
623
def console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY):
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...
624
    lib.TCOD_console_map_ascii_code_to_font(_int(asciiCode), fontCharX,
625
                                                              fontCharY)
626
627
def console_map_ascii_codes_to_font(firstAsciiCode, nbCodes, fontCharX,
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...
628
                                    fontCharY):
629
    lib.TCOD_console_map_ascii_codes_to_font(_int(firstAsciiCode), nbCodes,
630
                                              fontCharX, fontCharY)
631
632
def console_map_string_to_font(s, fontCharX, fontCharY):
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...
633
    lib.TCOD_console_map_string_to_font_utf(_unicode(s), fontCharX, fontCharY)
634
635
def console_is_fullscreen():
636
    """Returns True if the display is fullscreen.
637
638
    Returns:
639
        bool: True if the display is fullscreen, otherwise False.
640
    """
641
    return bool(lib.TCOD_console_is_fullscreen())
642
643
def console_set_fullscreen(fullscreen):
644
    """Change the display to be fullscreen or windowed.
645
646
    Args:
647
        fullscreen (bool): Use True to change to fullscreen.
648
                           Use False to change to windowed.
649
    """
650
    lib.TCOD_console_set_fullscreen(fullscreen)
651
652
def console_is_window_closed():
653
    """Returns True if the window has received and exit event."""
654
    return lib.TCOD_console_is_window_closed()
655
656
def console_set_window_title(title):
657
    """Change the current title bar string.
658
659
    Args:
660
        title (AnyStr): A string to change the title bar to.
661
    """
662
    lib.TCOD_console_set_window_title(_bytes(title))
663
664
def console_credits():
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...
665
    lib.TCOD_console_credits()
666
667
def console_credits_reset():
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...
668
    lib.TCOD_console_credits_reset()
669
670
def console_credits_render(x, y, alpha):
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...
671
    return lib.TCOD_console_credits_render(x, y, alpha)
672
673
def console_flush():
674
    """Update the display to represent the root consoles current state."""
675
    lib.TCOD_console_flush()
676
677
# drawing on a console
678
def console_set_default_background(con, col):
679
    """Change the default background color for a console.
680
681
    Args:
682
        con (Console): Any Console instance.
683
        col (Union[Tuple[int, int, int], Sequence[int]]):
684
            An (r, g, b) sequence or Color instance.
685
    """
686
    lib.TCOD_console_set_default_background(_cdata(con), col)
687
688
def console_set_default_foreground(con, col):
689
    """Change the default foreground color for a console.
690
691
    Args:
692
        con (Console): Any Console instance.
693
        col (Union[Tuple[int, int, int], Sequence[int]]):
694
            An (r, g, b) sequence or Color instance.
695
    """
696
    lib.TCOD_console_set_default_foreground(_cdata(con), col)
697
698
def console_clear(con):
699
    """Reset a console to its default colors and the space character.
700
701
    Args:
702
        con (Console): Any Console instance.
703
704
    .. seealso::
705
       :any:`console_set_default_background`
706
       :any:`console_set_default_foreground`
707
    """
708
    return lib.TCOD_console_clear(_cdata(con))
709
710
def console_put_char(con, x, y, c, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
711
    """Draw the character c at x,y using the default colors and a blend mode.
712
713
    Args:
714
        con (Console): Any Console instance.
715
        x (int): Character x position from the left.
716
        y (int): Character y position from the top.
717
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
718
        flag (int): Blending mode to use, defaults to BKGND_DEFAULT.
719
    """
720
    lib.TCOD_console_put_char(_cdata(con), x, y, _int(c), flag)
721
722
def console_put_char_ex(con, x, y, c, fore, back):
723
    """Draw the character c at x,y using the colors fore and back.
724
725
    Args:
726
        con (Console): Any Console instance.
727
        x (int): Character x position from the left.
728
        y (int): Character y position from the top.
729
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
730
        fore (Union[Tuple[int, int, int], Sequence[int]]):
731
            An (r, g, b) sequence or Color instance.
732
        back (Union[Tuple[int, int, int], Sequence[int]]):
733
            An (r, g, b) sequence or Color instance.
734
    """
735
    lib.TCOD_console_put_char_ex(_cdata(con), x, y,
736
                                 _int(c), fore, back)
737
738
def console_set_char_background(con, x, y, col, flag=BKGND_SET):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_SET'
Loading history...
739
    """Change the background color of x,y to col using a blend mode.
740
741
    Args:
742
        con (Console): Any Console instance.
743
        x (int): Character x position from the left.
744
        y (int): Character y position from the top.
745
        col (Union[Tuple[int, int, int], Sequence[int]]):
746
            An (r, g, b) sequence or Color instance.
747
        flag (int): Blending mode to use, defaults to BKGND_SET.
748
    """
749
    lib.TCOD_console_set_char_background(_cdata(con), x, y, col, flag)
750
751
def console_set_char_foreground(con, x, y, col):
752
    """Change the foreground color of x,y to col.
753
754
    Args:
755
        con (Console): Any Console instance.
756
        x (int): Character x position from the left.
757
        y (int): Character y position from the top.
758
        col (Union[Tuple[int, int, int], Sequence[int]]):
759
            An (r, g, b) sequence or Color instance.
760
    """
761
    lib.TCOD_console_set_char_foreground(_cdata(con), x, y, col)
762
763
def console_set_char(con, x, y, c):
764
    """Change the character at x,y to c, keeping the current colors.
765
766
    Args:
767
        con (Console): Any Console instance.
768
        x (int): Character x position from the left.
769
        y (int): Character y position from the top.
770
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
771
    """
772
    lib.TCOD_console_set_char(_cdata(con), x, y, _int(c))
773
774
def console_set_background_flag(con, flag):
775
    """Change the default blend mode for this console.
776
777
    Args:
778
        con (Console): Any Console instance.
779
        flag (int): Blend mode to use by default.
780
    """
781
    lib.TCOD_console_set_background_flag(_cdata(con), flag)
782
783
def console_get_background_flag(con):
784
    """Return this consoles current blend mode.
785
786
    Args:
787
        con (Console): Any Console instance.
788
    """
789
    return lib.TCOD_console_get_background_flag(_cdata(con))
790
791
def console_set_alignment(con, alignment):
792
    """Change this consoles current alignment mode.
793
794
    * tcod.LEFT
795
    * tcod.CENTER
796
    * tcod.RIGHT
797
798
    Args:
799
        con (Console): Any Console instance.
800
        alignment (int):
801
    """
802
    lib.TCOD_console_set_alignment(_cdata(con), alignment)
803
804
def console_get_alignment(con):
805
    """Return this consoles current alignment mode.
806
807
    Args:
808
        con (Console): Any Console instance.
809
    """
810
    return lib.TCOD_console_get_alignment(_cdata(con))
811
812
def console_print(con, x, y, fmt):
813
    """Print a color formatted string on a console.
814
815
    Args:
816
        con (Console): Any Console instance.
817
        x (int): Character x position from the left.
818
        y (int): Character y position from the top.
819
        fmt (AnyStr): A unicode or bytes string optionaly using color codes.
820
    """
821
    lib.TCOD_console_print_utf(_cdata(con), x, y, _fmt_unicode(fmt))
822
823
def console_print_ex(con, x, y, flag, alignment, fmt):
824
    """Print a string on a console using a blend mode and alignment mode.
825
826
    Args:
827
        con (Console): Any Console instance.
828
        x (int): Character x position from the left.
829
        y (int): Character y position from the top.
830
    """
831
    lib.TCOD_console_print_ex_utf(_cdata(con), x, y,
832
                                   flag, alignment, _fmt_unicode(fmt))
833
834
def console_print_rect(con, x, y, w, h, fmt):
835
    """Print a string constrained to a rectangle.
836
837
    If h > 0 and the bottom of the rectangle is reached,
838
    the string is truncated. If h = 0,
839
    the string is only truncated if it reaches the bottom of the console.
840
841
842
843
    Returns:
844
        int: The number of lines of text once word-wrapped.
845
    """
846
    return lib.TCOD_console_print_rect_utf(_cdata(con), x, y, w, h,
847
                                            _fmt_unicode(fmt))
848
849
def console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt):
850
    """Print a string constrained to a rectangle with blend and alignment.
851
852
    Returns:
853
        int: The number of lines of text once word-wrapped.
854
    """
855
    return lib.TCOD_console_print_rect_ex_utf(_cdata(con), x, y, w, h,
856
                                              flag, alignment,
857
                                              _fmt_unicode(fmt))
858
859
def console_get_height_rect(con, x, y, w, h, fmt):
860
    """Return the height of this text once word-wrapped into this rectangle.
861
862
    Returns:
863
        int: The number of lines of text once word-wrapped.
864
    """
865
    return lib.TCOD_console_get_height_rect_utf(_cdata(con), x, y, w, h,
866
                                                 _fmt_unicode(fmt))
867
868
def console_rect(con, x, y, w, h, clr, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
869
    """Draw a the background color on a rect optionally clearing the text.
870
871
    If clr is True the affected tiles are changed to space character.
872
    """
873
    lib.TCOD_console_rect(_cdata(con), x, y, w, h, clr, flag)
874
875
def console_hline(con, x, y, l, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
876
    """Draw a horizontal line on the console.
877
878
    This always uses the character 196, the horizontal line character.
879
    """
880
    lib.TCOD_console_hline(_cdata(con), x, y, l, flag)
881
882
def console_vline(con, x, y, l, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
883
    """Draw a vertical line on the console.
884
885
    This always uses the character 179, the vertical line character.
886
    """
887
    lib.TCOD_console_vline(_cdata(con), x, y, l, flag)
888
889
def console_print_frame(con, x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=b''):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

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

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
890
    """Draw a framed rectangle with optinal text.
891
892
    This uses the default background color and blend mode to fill the
893
    rectangle and the default foreground to draw the outline.
894
895
    fmt will be printed on the inside of the rectangle, word-wrapped.
896
    """
897
    lib.TCOD_console_print_frame(_cdata(con), x, y, w, h, clear, flag,
898
                                  _fmt_bytes(fmt))
899
900
def console_set_color_control(con, fore, back):
901
    """Configure :any:`color controls`.
902
903
    Args:
904
        con (int): :any:`Color control` constant to modify.
905
        fore (Union[Tuple[int, int, int], Sequence[int]]):
906
            An (r, g, b) sequence or Color instance.
907
        back (Union[Tuple[int, int, int], Sequence[int]]):
908
            An (r, g, b) sequence or Color instance.
909
    """
910
    lib.TCOD_console_set_color_control(_cdata(con), fore, back)
911
912
def console_get_default_background(con):
913
    """Return this consoles default background color."""
914
    return Color._new_from_cdata(
915 View Code Duplication
        lib.TCOD_console_get_default_background(_cdata(con)))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
916
917
def console_get_default_foreground(con):
918
    """Return this consoles default foreground color."""
919
    return Color._new_from_cdata(
920
        lib.TCOD_console_get_default_foreground(_cdata(con)))
921
922
def console_get_char_background(con, x, y):
923
    """Return the background color at the x,y of this console."""
924
    return Color._new_from_cdata(
925
        lib.TCOD_console_get_char_background(_cdata(con), x, y))
926
927
def console_get_char_foreground(con, x, y):
928
    """Return the foreground color at the x,y of this console."""
929
    return Color._new_from_cdata(
930
        lib.TCOD_console_get_char_foreground(_cdata(con), x, y))
931
932
def console_get_char(con, x, y):
933
    """Return the character at the x,y of this console."""
934
    return lib.TCOD_console_get_char(_cdata(con), x, y)
935
936
def console_set_fade(fade, fadingColor):
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...
937
    lib.TCOD_console_set_fade(fade, fadingColor)
938
939
def console_get_fade():
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...
940
    return lib.TCOD_console_get_fade()
941
942
def console_get_fading_color():
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...
943 View Code Duplication
    return Color._new_from_cdata(lib.TCOD_console_get_fading_color())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
944
945
# handling keyboard input
946
def console_wait_for_keypress(flush):
947
    """Block until the user presses a key, then returns a new Key.
948
949
    Args:
950
        flush bool: If True then the event queue is cleared before waiting
951
                    for the next event.
952
953
    Returns:
954
        Key: A new Key instance.
955
    """
956
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
957
    lib.TCOD_console_wait_for_keypress_wrapper(k.cdata, flush)
958
    return k
959
960
def console_check_for_keypress(flags=KEY_RELEASED):
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...
Comprehensibility Best Practice introduced by
Undefined variable 'KEY_RELEASED'
Loading history...
961
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
962
    lib.TCOD_console_check_for_keypress_wrapper(k.cdata, flags)
963
    return k
964
965
def console_is_key_pressed(key):
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...
966
    return lib.TCOD_console_is_key_pressed(key)
967
968
# using offscreen consoles
969
def console_new(w, h):
970
    """Return an offscreen console of size: w,h."""
971
    return tcod.console.Console(w, h)
972
973
def console_from_file(filename):
974
    """Return a new console object from a filename.
975
976
    The file format is automactially determined.  This can load REXPaint `.xp`,
977
    ASCII Paint `.apf`, or Non-delimited ASCII `.asc` files.
978
979
    Args:
980
        filename (Text): The path to the file, as a string.
981
982
    Returns: A new :any`Console` instance.
983
    """
984
    return tcod.console.Console._from_cdata(
985
        lib.TCOD_console_from_file(filename.encode('utf-8')))
986
987
def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
^
Loading history...
988
    """Blit the console src from x,y,w,h to console dst at xdst,ydst."""
989
    lib.TCOD_console_blit(_cdata(src), x, y, w, h,
990
                          _cdata(dst), xdst, ydst, ffade, bfade)
991
992
def console_set_key_color(con, col):
993
    """Set a consoles blit transparent color."""
994
    lib.TCOD_console_set_key_color(_cdata(con), col)
995
996
def console_delete(con):
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...
997
    con = _cdata(con)
998
    if con == ffi.NULL:
999
        lib.TCOD_console_delete(con)
1000
1001
# fast color filling
1002
def console_fill_foreground(con, r, g, b):
1003
    """Fill the foregound of a console with r,g,b.
1004
1005
    Args:
1006
        con (Console): Any Console instance.
1007
        r (Sequence[int]): An array of integers with a length of width*height.
1008
        g (Sequence[int]): An array of integers with a length of width*height.
1009
        b (Sequence[int]): An array of integers with a length of width*height.
1010
    """
1011
    if len(r) != len(g) or len(r) != len(b):
1012
        raise TypeError('R, G and B must all have the same size.')
1013
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1014
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1015
        #numpy arrays, use numpy's ctypes functions
1016
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1017
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1018
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1019
        cr = ffi.cast('int *', r.ctypes.data)
1020
        cg = ffi.cast('int *', g.ctypes.data)
1021
        cb = ffi.cast('int *', b.ctypes.data)
1022
    else:
1023
        # otherwise convert using ffi arrays
1024
        cr = ffi.new('int[]', r)
1025
        cg = ffi.new('int[]', g)
1026
        cb = ffi.new('int[]', b)
1027
1028
    lib.TCOD_console_fill_foreground(_cdata(con), cr, cg, cb)
1029
1030
def console_fill_background(con, r, g, b):
1031
    """Fill the backgound of a console with r,g,b.
1032
1033
    Args:
1034
        con (Console): Any Console instance.
1035
        r (Sequence[int]): An array of integers with a length of width*height.
1036
        g (Sequence[int]): An array of integers with a length of width*height.
1037
        b (Sequence[int]): An array of integers with a length of width*height.
1038
    """
1039
    if len(r) != len(g) or len(r) != len(b):
1040
        raise TypeError('R, G and B must all have the same size.')
1041
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1042
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1043
        #numpy arrays, use numpy's ctypes functions
1044
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1045
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1046
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1047
        cr = ffi.cast('int *', r.ctypes.data)
1048
        cg = ffi.cast('int *', g.ctypes.data)
1049
        cb = ffi.cast('int *', b.ctypes.data)
1050
    else:
1051
        # otherwise convert using ffi arrays
1052
        cr = ffi.new('int[]', r)
1053
        cg = ffi.new('int[]', g)
1054
        cb = ffi.new('int[]', b)
1055
1056
    lib.TCOD_console_fill_background(_cdata(con), cr, cg, cb)
1057
1058
def console_fill_char(con,arr):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def console_fill_char(con,arr):
^
Loading history...
1059
    """Fill the character tiles of a console with an array.
1060
1061
    Args:
1062
        con (Console): Any Console instance.
1063
        arr (Sequence[int]): An array of integers with a length of width*height.
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...
1064
    """
1065
    if (_numpy_available() and isinstance(arr, _numpy.ndarray) ):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after if.
Loading history...
Coding Style introduced by
No space allowed before bracket
if (_numpy_available() and isinstance(arr, _numpy.ndarray) ):
^
Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1066
        #numpy arrays, use numpy's ctypes functions
1067
        arr = _numpy.ascontiguousarray(arr, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
1068
        carr = ffi.cast('int *', arr.ctypes.data)
1069
    else:
1070
        #otherwise convert using the ffi module
1071
        carr = ffi.new('int[]', arr)
1072
1073
    lib.TCOD_console_fill_char(_cdata(con), carr)
1074
1075
def console_load_asc(con, filename):
1076
    """Update a console from a non-delimited ASCII `.asc` file."""
1077
    return lib.TCOD_console_load_asc(_cdata(con), _bytes(filename))
1078
1079
def console_save_asc(con, filename):
1080
    """Save a console to a non-delimited ASCII `.asc` file."""
1081
    return lib.TCOD_console_save_asc(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return lib.TCOD_console_save_asc(_cdata(con),_bytes(filename))
^
Loading history...
1082
1083
def console_load_apf(con, filename):
1084
    """Update a console from an ASCII Paint `.apf` file."""
1085
    return lib.TCOD_console_load_apf(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return lib.TCOD_console_load_apf(_cdata(con),_bytes(filename))
^
Loading history...
1086
1087
def console_save_apf(con, filename):
1088
    """Save a console to an ASCII Paint `.apf` file."""
1089
    return lib.TCOD_console_save_apf(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return lib.TCOD_console_save_apf(_cdata(con),_bytes(filename))
^
Loading history...
1090
1091
def console_load_xp(con, filename):
1092
    """Update a console from a REXPaint `.xp` file."""
1093
    return lib.TCOD_console_load_xp(_cdata(con), filename.encode('utf-8'))
1094
1095
def console_save_xp(con, filename, compress_level=9):
1096
    """Save a console to a REXPaint `.xp` file."""
1097
    return lib.TCOD_console_save_xp(
1098
        _cdata(con), filename.encode('utf-8'), compress_level)
1099
1100
def console_from_xp(filename):
1101
    """Return a single console from a REXPaint `.xp` file."""
1102
    return tcod.console.Console._from_cdata(
1103
        lib.TCOD_console_from_xp(filename.encode('utf-8')))
1104
1105
def console_list_load_xp(filename):
1106
    """Return a list of consoles from a REXPaint `.xp` file."""
1107
    tcod_list = lib.TCOD_console_list_from_xp(filename.encode('utf-8'))
1108
    if tcod_list == ffi.NULL:
1109
        return None
1110
    try:
1111
        python_list = []
1112
        lib.TCOD_list_reverse(tcod_list)
1113
        while not lib.TCOD_list_is_empty(tcod_list):
1114
            python_list.append(
1115
                tcod.console.Console._from_cdata(lib.TCOD_list_pop(tcod_list)),
1116
                )
1117
        return python_list
1118
    finally:
1119
        lib.TCOD_list_delete(tcod_list)
1120
1121
def console_list_save_xp(console_list, filename, compress_level=9):
1122
    """Save a list of consoles to a REXPaint `.xp` file."""
1123
    tcod_list = lib.TCOD_list_new()
1124
    try:
1125
        for console in console_list:
1126
            lib.TCOD_list_push(tcod_list, _cdata(console))
1127
        return lib.TCOD_console_list_save_xp(
1128
            tcod_list, filename.encode('utf-8'), compress_level
1129
            )
1130
    finally:
1131
        lib.TCOD_list_delete(tcod_list)
1132
1133
def path_new_using_map(m, dcost=1.41):
1134
    """Return a new AStar using the given Map.
1135
1136
    Args:
1137
        m (Map): A Map instance.
1138
        dcost (float): The path-finding cost of diagonal movement.
1139
                       Can be set to 0 to disable diagonal movement.
1140
    Returns:
1141
        AStar: A new AStar instance.
1142
    """
1143
    return tcod.path.AStar(m, dcost)
1144
1145
def path_new_using_function(w, h, func, userData=0, dcost=1.41):
1146
    """Return a new AStar using the given callable function.
1147
1148
    Args:
1149
        w (int): Clipping width.
1150
        h (int): Clipping height.
1151
        func (Callable[[int, int, int, int, Any], float]):
1152
        userData (Any):
1153
        dcost (float): A multiplier for the cost of diagonal movement.
1154
                       Can be set to 0 to disable diagonal movement.
1155
    Returns:
1156
        AStar: A new AStar instance.
1157
    """
1158
    return tcod.path.AStar((func, userData), dcost, w, h)
1159
1160
def path_compute(p, ox, oy, dx, dy):
1161
    """Find a path from (ox, oy) to (dx, dy).  Return True if path is found.
1162
1163
    Args:
1164
        p (AStar): An AStar instance.
1165
        ox (int): Starting x position.
1166
        oy (int): Starting y position.
1167
        dx (int): Destination x position.
1168
        dy (int): Destination y position.
1169
    Returns:
1170
        bool: True if a valid path was found.  Otherwise False.
1171
    """
1172
    return lib.TCOD_path_compute(p.cdata, ox, oy, dx, dy)
1173
1174
def path_get_origin(p):
1175
    """Get the current origin position.
1176
1177
    This point moves when :any:`path_walk` returns the next x,y step.
1178
1179
    Args:
1180
        p (AStar): An AStar instance.
1181
    Returns:
1182
        Tuple[int, int]: An (x, y) point.
1183
    """
1184
    x = ffi.new('int *')
1185
    y = ffi.new('int *')
1186
    lib.TCOD_path_get_origin(p.cdata, x, y)
1187
    return x[0], y[0]
1188
1189
def path_get_destination(p):
1190
    """Get the current destination position.
1191
1192
    Args:
1193
        p (AStar): An AStar instance.
1194
    Returns:
1195
        Tuple[int, int]: An (x, y) point.
1196
    """
1197
    x = ffi.new('int *')
1198
    y = ffi.new('int *')
1199
    lib.TCOD_path_get_destination(p.cdata, x, y)
1200
    return x[0], y[0]
1201
1202
def path_size(p):
1203
    """Return the current length of the computed path.
1204
1205
    Args:
1206
        p (AStar): An AStar instance.
1207
    Returns:
1208
        int: Length of the path.
1209
    """
1210
    return lib.TCOD_path_size(p.cdata)
1211
1212
def path_reverse(p):
1213
    """Reverse the direction of a path.
1214
1215
    This effectively swaps the origin and destination points.
1216
1217
    Args:
1218
        p (AStar): An AStar instance.
1219
    """
1220
    lib.TCOD_path_reverse(p.cdata)
1221
1222
def path_get(p, idx):
1223
    """Get a point on a path.
1224
1225
    Args:
1226
        p (AStar): An AStar instance.
1227
        idx (int): Should be in range: 0 <= inx < :any:`path_size`
1228
    """
1229
    x = ffi.new('int *')
1230
    y = ffi.new('int *')
1231
    lib.TCOD_path_get(p.cdata, idx, x, y)
1232
    return x[0], y[0]
1233
1234
def path_is_empty(p):
1235
    """Return True if a path is empty.
1236
1237
    Args:
1238
        p (AStar): An AStar instance.
1239
    Returns:
1240
        bool: True if a path is empty.  Otherwise False.
1241
    """
1242
    return lib.TCOD_path_is_empty(p.cdata)
1243
1244
def path_walk(p, recompute):
1245
    """Return the next (x, y) point in a path, or (None, None) if it's empty.
1246
1247
    When ``recompute`` is True and a previously valid path reaches a point
1248
    where it is now blocked, a new path will automatically be found.
1249
1250
    Args:
1251
        p (AStar): An AStar instance.
1252
        recompute (bool): Recompute the path automatically.
1253
    Returns:
1254
        Union[Tuple[int, int], Tuple[None, None]]:
1255
            A single (x, y) point, or (None, None)
1256
    """
1257
    x = ffi.new('int *')
1258
    y = ffi.new('int *')
1259
    if lib.TCOD_path_walk(p.cdata, x, y, recompute):
1260
        return x[0], y[0]
1261
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1262
1263
def path_delete(p):
0 ignored issues
show
Unused Code introduced by
The argument p seems to be unused.
Loading history...
1264
    """Does nothing."""
1265
    pass
1266
1267
def dijkstra_new(m, dcost=1.41):
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...
1268
    return tcod.path.Dijkstra(m, dcost)
1269
1270
def dijkstra_new_using_function(w, h, func, userData=0, dcost=1.41):
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...
1271
    return tcod.path.Dijkstra((func, userData), dcost, w, h)
1272
1273
def dijkstra_compute(p, ox, oy):
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...
1274
    lib.TCOD_dijkstra_compute(p.cdata, ox, oy)
1275
1276
def dijkstra_path_set(p, x, y):
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...
1277
    return lib.TCOD_dijkstra_path_set(p.cdata, x, y)
1278
1279
def dijkstra_get_distance(p, x, y):
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...
1280
    return lib.TCOD_dijkstra_get_distance(p.cdata, x, y)
1281
1282
def dijkstra_size(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...
1283
    return lib.TCOD_dijkstra_size(p.cdata)
1284
1285
def dijkstra_reverse(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...
1286
    lib.TCOD_dijkstra_reverse(p.cdata)
1287
1288
def dijkstra_get(p, idx):
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...
1289
    x = ffi.new('int *')
1290
    y = ffi.new('int *')
1291
    lib.TCOD_dijkstra_get(p.cdata, idx, x, y)
1292
    return x[0], y[0]
1293
1294
def dijkstra_is_empty(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...
1295
    return lib.TCOD_dijkstra_is_empty(p.cdata)
1296
1297
def dijkstra_path_walk(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...
1298
    x = ffi.new('int *')
1299
    y = ffi.new('int *')
1300
    if lib.TCOD_dijkstra_path_walk(p.cdata, x, y):
1301
        return x[0], y[0]
1302
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1303
1304
def dijkstra_delete(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...
Unused Code introduced by
The argument p seems to be unused.
Loading history...
1305
    pass
1306
1307
def _heightmap_cdata(array):
1308
    """Return a new TCOD_heightmap_t instance using an array.
1309
1310
    Formatting is verified during this function.
1311
    """
1312
    if not array.flags['C_CONTIGUOUS']:
1313
        raise ValueError('array must be a C-style contiguous segment.')
1314
    if array.dtype != _np.float32:
1315
        raise ValueError('array dtype must be float32, not %r' % array.dtype)
1316
    width, height = array.shape
1317
    pointer = ffi.cast('float *', array.ctypes.data)
1318
    return ffi.new('TCOD_heightmap_t *', (width, height, pointer))
1319
1320
def heightmap_new(w, h):
1321
    """Return a new numpy.ndarray formatted for use with heightmap functions.
1322
1323
    You can pass a numpy array to any heightmap function as long as all the
1324
    following are true::
1325
    * The array is 2 dimentional.
1326
    * The array has the C_CONTIGUOUS flag.
1327
    * The array's dtype is :any:`dtype.float32`.
1328
1329
    Args:
1330
        w (int): The width of the new HeightMap.
1331
        h (int): The height of the new HeightMap.
1332
1333
    Returns:
1334
        numpy.ndarray: A C-contiguous mapping of float32 values.
1335
    """
1336
    return _np.ndarray((h, w), _np.float32)
1337
1338
def heightmap_set_value(hm, x, y, value):
1339
    """Set the value of a point on a heightmap.
1340
1341
    Args:
1342
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1343
        x (int): The x position to change.
1344
        y (int): The y position to change.
1345
        value (float): The value to set.
1346
1347
    .. deprecated:: 2.0
1348
        Do ``hm[y, x] = value`` instead.
1349
    """
1350
    hm[y, x] = value
1351
1352
def heightmap_add(hm, value):
1353
    """Add value to all values on this heightmap.
1354
1355
    Args:
1356
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1357
        value (float): A number to add to this heightmap.
1358
1359
    .. deprecated:: 2.0
1360
        Do ``hm[:] += value`` instead.
1361
    """
1362
    hm[:] += value
1363
1364
def heightmap_scale(hm, value):
1365
    """Multiply all items on this heightmap by value.
1366
1367
    Args:
1368
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1369
        value (float): A number to scale this heightmap by.
1370
1371
    .. deprecated:: 2.0
1372
        Do ``hm[:] *= value`` instead.
1373
    """
1374
    hm[:] *= value
1375
1376
def heightmap_clear(hm):
1377
    """Add value to all values on this heightmap.
1378
1379
    Args:
1380
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1381
1382
    .. deprecated:: 2.0
1383
        Do ``hm.array[:] = 0`` instead.
1384
    """
1385
    hm[:] = 0
1386
1387
def heightmap_clamp(hm, mi, ma):
1388
    """Clamp all values on this heightmap between ``mi`` and ``ma``
1389
1390
    Args:
1391
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1392
        mi (float): The lower bound to clamp to.
1393
        ma (float): The upper bound to clamp to.
1394
1395
    .. deprecated:: 2.0
1396
        Do ``hm.clip(mi, ma)`` instead.
1397
    """
1398
    hm.clip(mi, ma)
1399
1400
def heightmap_copy(hm1, hm2):
1401
    """Copy the heightmap ``hm1`` to ``hm2``.
1402
1403
    Args:
1404
        hm1 (numpy.ndarray): The source heightmap.
1405
        hm2 (numpy.ndarray): The destination heightmap.
1406
1407
    .. deprecated:: 2.0
1408
        Do ``hm2[:] = hm1[:]`` instead.
1409
    """
1410
    hm2[:] = hm1[:]
1411
1412
def heightmap_normalize(hm,  mi=0.0, ma=1.0):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def heightmap_normalize(hm, mi=0.0, ma=1.0):
^
Loading history...
1413
    """Normalize heightmap values between ``mi`` and ``ma``.
1414
1415
    Args:
1416
        mi (float): The lowest value after normalization.
1417
        ma (float): The highest value after normalization.
1418
    """
1419
    lib.TCOD_heightmap_normalize(_heightmap_cdata(hm), mi, ma)
1420
1421
def heightmap_lerp_hm(hm1, hm2, hm3, coef):
1422
    """Perform linear interpolation between two heightmaps storing the result
1423
    in ``hm3``.
1424
1425
    This is the same as doing ``hm3[:] = hm1[:] + (hm2[:] - hm1[:]) * coef``
1426
1427
    Args:
1428
        hm1 (numpy.ndarray): The first heightmap.
1429
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1430
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1431
        coef (float): The linear interpolation coefficient.
1432
    """
1433
    lib.TCOD_heightmap_lerp_hm(_heightmap_cdata(hm1), _heightmap_cdata(hm2),
1434
                               _heightmap_cdata(hm3), coef)
1435
1436
def heightmap_add_hm(hm1, hm2, hm3):
1437
    """Add two heightmaps together and stores the result in ``hm3``.
1438
1439
    Args:
1440
        hm1 (numpy.ndarray): The first heightmap.
1441
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1442
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1443
1444
    .. deprecated:: 2.0
1445
        Do ``hm3[:] = hm1[:] + hm2[:]`` instead.
1446
    """
1447
    hm3[:] = hm1[:] + hm2[:]
1448
1449
def heightmap_multiply_hm(hm1, hm2, hm3):
1450
    """Multiplies two heightmap's together and stores the result in ``hm3``.
1451
1452
    Args:
1453
        hm1 (numpy.ndarray): The first heightmap.
1454
        hm2 (numpy.ndarray): The second heightmap to multiply with the first.
1455
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1456
1457
    .. deprecated:: 2.0
1458
        Do ``hm3[:] = hm1[:] * hm2[:]`` instead.
1459
        Alternatively you can do ``HeightMap(hm1.array[:] * hm2.array[:])``.
1460
    """
1461
    hm3[:] = hm1[:] * hm2[:]
1462
1463
def heightmap_add_hill(hm, x, y, radius, height):
1464
    """Add a hill (a half spheroid) at given position.
1465
1466
    If height == radius or -radius, the hill is a half-sphere.
1467
1468
    Args:
1469
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1470
        x (float): The x position at the center of the new hill.
1471
        y (float): The y position at the center of the new hill.
1472
        radius (float): The size of the new hill.
1473
        height (float): The height or depth of the new hill.
1474
    """
1475
    lib.TCOD_heightmap_add_hill(_heightmap_cdata(hm), x, y, radius, height)
1476
1477
def heightmap_dig_hill(hm, x, y, radius, height):
1478
    """
1479
1480
    This function takes the highest value (if height > 0) or the lowest
1481
    (if height < 0) between the map and the hill.
1482
1483
    It's main goal is to carve things in maps (like rivers) by digging hills along a curve.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/79).

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

Loading history...
1484
1485
    Args:
1486
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1487
        x (float): The x position at the center of the new carving.
1488
        y (float): The y position at the center of the new carving.
1489
        radius (float): The size of the carving.
1490
        height (float): The height or depth of the hill to dig out.
1491
    """
1492
    lib.TCOD_heightmap_dig_hill(_heightmap_cdata(hm), x, y, radius, height)
1493
1494
def heightmap_rain_erosion(hm, nbDrops, erosionCoef, sedimentationCoef, rnd=None):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

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

Loading history...
1495
    """Simulate the effect of rain drops on the terrain, resulting in erosion.
1496
1497
    ``nbDrops`` should be at least hm.size.
1498
1499
    Args:
1500
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1501
        nbDrops (int): Number of rain drops to simulate.
1502
        erosionCoef (float): Amount of ground eroded on the drop's path.
1503
        sedimentationCoef (float): Amount of ground deposited when the drops
1504
                                   stops to flow.
1505
        rnd (Optional[Random]): A tcod.Random instance, or None.
1506
    """
1507
    lib.TCOD_heightmap_rain_erosion(_heightmap_cdata(hm), nbDrops, erosionCoef,
1508
                                    sedimentationCoef, _cdata(rnd))
1509
1510
def heightmap_kernel_transform(hm, kernelsize, dx, dy, weight, minLevel,
1511
                               maxLevel):
1512
    """Apply a generic transformation on the map, so that each resulting cell
1513
    value is the weighted sum of several neighbour cells.
1514
1515
    This can be used to smooth/sharpen the map.
1516
1517
    Args:
1518
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1519
        kernelsize (int): Should be set to the length of the parameters::
1520
                          dx, dy, and weight.
1521
        dx (Sequence[int]): A sequence of x coorinates.
1522
        dy (Sequence[int]): A sequence of y coorinates.
1523
        weight (Sequence[float]): A sequence of kernelSize cells weight.
1524
                                  The value of each neighbour cell is scaled by
1525
                                  its corresponding weight
1526
        minLevel (float): No transformation will apply to cells
1527
                          below this value.
1528
        maxLevel (float): No transformation will apply to cells
1529
                          above this value.
1530
1531
    See examples below for a simple horizontal smoothing kernel :
1532
    replace value(x,y) with
1533
    0.33*value(x-1,y) + 0.33*value(x,y) + 0.33*value(x+1,y).
1534
    To do this, you need a kernel of size 3
1535
    (the sum involves 3 surrounding cells).
1536
    The dx,dy array will contain
1537
    * dx=-1, dy=0 for cell (x-1, y)
1538
    * dx=1, dy=0 for cell (x+1, y)
1539
    * dx=0, dy=0 for cell (x, y)
1540
    * The weight array will contain 0.33 for each cell.
1541
1542
    Example:
1543
        >>> dx = [-1, 1, 0]
1544
        >>> dy = [0, 0, 0]
1545
        >>> weight = [0.33, 0.33, 0.33]
1546
        >>> tcod.heightMap_kernel_transform(heightmap,3,dx,dy,weight,0.0,1.0)
1547
    """
1548
    cdx = ffi.new('int[]', dx)
1549
    cdy = ffi.new('int[]', dy)
1550
    cweight = ffi.new('float[]', weight)
1551
    lib.TCOD_heightmap_kernel_transform(_heightmap_cdata(hm), kernelsize,
1552
                                        cdx, cdy, cweight, minLevel, maxLevel)
1553
1554
def heightmap_add_voronoi(hm, nbPoints, nbCoef, coef, rnd=None):
1555
    """Add values from a Voronoi diagram to the heightmap.
1556
1557
    Args:
1558
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1559
        nbPoints (Any): Number of Voronoi sites.
1560
        nbCoef (int): The diagram value is calculated from the nbCoef
1561
                      closest sites.
1562
        coef (Sequence[float]): The distance to each site is scaled by the
1563
                                corresponding coef.
1564
                                Closest site : coef[0],
1565
                                second closest site : coef[1], ...
1566
        rnd (Optional[Random]): A Random instance, or None.
1567
    """
1568
    nbPoints = len(coef)
1569
    ccoef = ffi.new('float[]', coef)
1570
    lib.TCOD_heightmap_add_voronoi(_heightmap_cdata(hm), nbPoints,
1571
                                   nbCoef, ccoef, _cdata(rnd))
1572
1573
def heightmap_add_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta, scale):
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...
1574
    """Add FBM noise to the heightmap.
1575
1576
    The noise coordinate for each map cell is
1577
    `((x + addx) * mulx / width, (y + addy) * muly / height)`.
1578
1579
    The value added to the heightmap is `delta + noise * scale`.
1580
1581
    Args:
1582
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1583
        noise (Noise): A Noise instance.
1584
        mulx (float): Scaling of each x coordinate.
1585
        muly (float): Scaling of each y coordinate.
1586
        addx (float): Translation of each x coordinate.
1587
        addy (float): Translation of each y coordinate.
1588
        octaves (float): Number of octaves in the FBM sum.
1589
        delta (float): The value added to all heightmap cells.
1590
        scale (float): The noise value is scaled with this parameter.
1591
    """
1592
    noise = noise.noise_c if noise is not None else ffi.NULL
1593
    lib.TCOD_heightmap_add_fbm(_heightmap_cdata(hm), noise,
1594
                               mulx, muly, addx, addy, octaves, delta, scale)
1595
1596
def heightmap_scale_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta,
1597
                        scale):
1598
    """Multiply the heighmap values with FBM noise.
1599
1600
    Args:
1601
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1602
        noise (Noise): A Noise instance.
1603
        mulx (float): Scaling of each x coordinate.
1604
        muly (float): Scaling of each y coordinate.
1605
        addx (float): Translation of each x coordinate.
1606
        addy (float): Translation of each y coordinate.
1607
        octaves (float): Number of octaves in the FBM sum.
1608
        delta (float): The value added to all heightmap cells.
1609
        scale (float): The noise value is scaled with this parameter.
1610
    """
1611
    noise = noise.noise_c if noise is not None else ffi.NULL
1612
    lib.TCOD_heightmap_scale_fbm(_heightmap_cdata(hm), noise,
1613
                                 mulx, muly, addx, addy, octaves, delta, scale)
1614
1615
def heightmap_dig_bezier(hm, px, py, startRadius, startDepth, endRadius,
1616
                         endDepth):
1617
    """Carve a path along a cubic Bezier curve.
1618
1619
    Both radius and depth can vary linearly along the path.
1620
1621
    Args:
1622
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1623
        px (Sequence[int]): The 4 `x` coordinates of the Bezier curve.
1624
        py (Sequence[int]): The 4 `y` coordinates of the Bezier curve.
1625
        startRadius (float): The starting radius size.
1626
        startDepth (float): The starting depth.
1627
        endRadius (float): The ending radius size.
1628
        endDepth (float): The ending depth.
1629
    """
1630
    lib.TCOD_heightmap_dig_bezier(_heightmap_cdata(hm), px, py, startRadius,
1631
                                   startDepth, endRadius,
1632
                                   endDepth)
1633
1634
def heightmap_get_value(hm, x, y):
1635
    """Return the value at ``x``, ``y`` in a heightmap.
1636
1637
    Args:
1638
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1639
        x (int): The x position to pick.
1640
        y (int): The y position to pick.
1641
1642
    Returns:
1643
        float: The value at ``x``, ``y``.
1644
1645
    .. deprecated:: 2.0
1646
        Do ``value = hm[y, x]`` instead.
1647
    """
1648
    # explicit type conversion to pass test, (test should have been better.)
1649
    return float(hm[y, x])
1650
1651
def heightmap_get_interpolated_value(hm, x, y):
1652
    """Return the interpolated height at non integer coordinates.
1653
1654
    Args:
1655
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1656
        x (float): A floating point x coordinate.
1657
        y (float): A floating point y coordinate.
1658
1659
    Returns:
1660
        float: The value at ``x``, ``y``.
1661
    """
1662
    return lib.TCOD_heightmap_get_interpolated_value(_heightmap_cdata(hm),
1663
                                                     x, y)
1664
1665
def heightmap_get_slope(hm, x, y):
1666
    """Return the slope between 0 and (pi / 2) at given coordinates.
1667
1668
    Args:
1669
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1670
        x (int): The x coordinate.
1671
        y (int): The y coordinate.
1672
1673
    Returns:
1674
        float: The steepness at ``x``, ``y``.  From 0 to (pi / 2)
1675
    """
1676
    return lib.TCOD_heightmap_get_slope(_heightmap_cdata(hm), x, y)
1677
1678
def heightmap_get_normal(hm, x, y, waterLevel):
1679
    """Return the map normal at given coordinates.
1680
1681
    Args:
1682
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1683
        x (float): The x coordinate.
1684
        y (float): The y coordinate.
1685
        waterLevel (float): The heightmap is considered flat below this value.
1686
1687
    Returns:
1688
        Tuple[float, float, float]: An (x, y, z) vector normal.
1689
    """
1690
    cn = ffi.new('float[3]')
1691
    lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)
1692
    return tuple(cn)
1693
1694
def heightmap_count_cells(hm, mi, ma):
1695
    """Return the number of map cells which value is between ``mi`` and ``ma``.
1696
1697
    Args:
1698
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1699
        mi (float): The lower bound.
1700
        ma (float): The upper bound.
1701
1702
    Returns:
1703
        int: The count of values which fall between ``mi`` and ``ma``.
1704
    """
1705
    return lib.TCOD_heightmap_count_cells(_heightmap_cdata(hm), mi, ma)
1706
1707
def heightmap_has_land_on_border(hm, waterlevel):
1708
    """Returns True if the map edges are below ``waterlevel``, otherwise False.
1709
1710
    Args:
1711
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1712
        waterLevel (float): The water level to use.
1713
1714
    Returns:
1715
        bool: True if the map edges are below ``waterlevel``, otherwise False.
1716
    """
1717
    return lib.TCOD_heightmap_has_land_on_border(_heightmap_cdata(hm),
1718
                                                 waterlevel)
1719
1720
def heightmap_get_minmax(hm):
1721
    """Return the min and max values of this heightmap.
1722
1723
    Args:
1724
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1725
1726
    Returns:
1727
        Tuple[float, float]: The (min, max) values.
1728
1729
    .. deprecated:: 2.0
1730
        Do ``hm.min()`` or ``hm.max()`` instead.
1731
    """
1732
    mi = ffi.new('float *')
1733
    ma = ffi.new('float *')
1734
    lib.TCOD_heightmap_get_minmax(_heightmap_cdata(hm), mi, ma)
1735
    return mi[0], ma[0]
1736
1737
def heightmap_delete(hm):
0 ignored issues
show
Unused Code introduced by
The argument hm seems to be unused.
Loading history...
1738
    """Does nothing.
1739
1740
    .. deprecated:: 2.0
1741
        libtcod-cffi deletes heightmaps automatically.
1742
    """
1743
    pass
1744
1745
def image_new(width, height):
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...
1746
    return tcod.image.Image(width, height)
1747
1748
def image_clear(image, col):
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...
1749
    image.clear(col)
1750
1751
def image_invert(image):
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...
1752
    image.invert()
1753
1754
def image_hflip(image):
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...
1755
    image.hflip()
1756
1757
def image_rotate90(image, num=1):
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...
1758
    image.rotate90(num)
1759
1760
def image_vflip(image):
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...
1761
    image.vflip()
1762
1763
def image_scale(image, neww, newh):
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...
1764
    image.scale(neww, newh)
1765
1766
def image_set_key_color(image, col):
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...
1767
    image.set_key_color(col)
1768
1769
def image_get_alpha(image, x, y):
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...
1770
    image.get_alpha(x, y)
1771
1772
def image_is_pixel_transparent(image, x, y):
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...
1773
    lib.TCOD_image_is_pixel_transparent(image.image_c, x, y)
1774
1775
def image_load(filename):
1776
    """Load an image file into an Image instance and return it.
1777
1778
    Args:
1779
        filename (AnyStr): Path to a .bmp or .png image file.
1780
    """
1781
    return tcod.image.Image._from_cdata(
1782
        ffi.gc(lib.TCOD_image_load(_bytes(filename)),
1783
               lib.TCOD_image_delete)
1784
        )
1785
1786
def image_from_console(console):
1787
    """Return an Image with a Consoles pixel data.
1788
1789
    This effectively takes a screen-shot of the Console.
1790
1791
    Args:
1792
        console (Console): Any Console instance.
1793
    """
1794
    return tcod.image.Image._from_cdata(
1795
        ffi.gc(lib.TCOD_image_from_console(_cdata(console)),
1796
               lib.TCOD_image_delete)
1797
        )
1798
1799
def image_refresh_console(image, console):
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...
1800
    image.refresh_console(console)
1801
1802
def image_get_size(image):
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...
1803
    return image.width, image.height
1804
1805
def image_get_pixel(image, x, y):
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...
1806
    return image.get_pixel(x, y)
1807
1808
def image_get_mipmap_pixel(image, x0, y0, x1, y1):
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...
1809
    return image.get_mipmap_pixel(x0, y0, x1, y1)
1810
1811
def image_put_pixel(image, x, y, col):
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...
1812
    image.put_pixel(x, y, col)
1813
1814
def image_blit(image, console, x, y, bkgnd_flag, scalex, scaley, angle):
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...
1815
    image.blit(console, x, y, bkgnd_flag, scalex, scaley, angle)
1816
1817
def image_blit_rect(image, console, x, y, w, h, bkgnd_flag):
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...
1818
    image.blit_rect(console, x, y, w, h, bkgnd_flag)
1819
1820
def image_blit_2x(image, console, dx, dy, sx=0, sy=0, w=-1, h=-1):
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...
1821
    image.blit_2x(console, dx, dy, sx, sy, w, h)
1822
1823
def image_save(image, filename):
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...
1824
    image.save_as(filename)
1825
1826
def image_delete(image):
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 argument image seems to be unused.
Loading history...
1827
    pass
1828
1829
def line_init(xo, yo, xd, yd):
1830
    """Initilize a line whose points will be returned by `line_step`.
1831
1832
    This function does not return anything on its own.
1833
1834
    Does not include the origin point.
1835
1836
    Args:
1837
        xo (int): X starting point.
1838
        yo (int): Y starting point.
1839
        xd (int): X destination point.
1840
        yd (int): Y destination point.
1841
1842
    .. deprecated:: 2.0
1843
       Use `line_iter` instead.
1844
    """
1845
    lib.TCOD_line_init(xo, yo, xd, yd)
1846
1847
def line_step():
1848
    """After calling line_init returns (x, y) points of the line.
1849
1850
    Once all points are exhausted this function will return (None, None)
1851
1852
    Returns:
1853
        Union[Tuple[int, int], Tuple[None, None]]:
1854
            The next (x, y) point of the line setup by line_init,
1855
            or (None, None) if there are no more points.
1856
1857
    .. deprecated:: 2.0
1858
       Use `line_iter` instead.
1859
    """
1860
    x = ffi.new('int *')
1861
    y = ffi.new('int *')
1862
    ret = lib.TCOD_line_step(x, y)
1863
    if not ret:
1864
        return x[0], y[0]
1865
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1866
1867
_line_listener_lock = _threading.Lock()
1868
1869
def line(xo, yo, xd, yd, py_callback):
1870
    """ Iterate over a line using a callback function.
1871
1872
    Your callback function will take x and y parameters and return True to
1873
    continue iteration or False to stop iteration and return.
1874
1875
    This function includes both the start and end points.
1876
1877
    Args:
1878
        xo (int): X starting point.
1879
        yo (int): Y starting point.
1880
        xd (int): X destination point.
1881
        yd (int): Y destination point.
1882
        py_callback (Callable[[int, int], bool]):
1883
            A callback which takes x and y parameters and returns bool.
1884
1885
    Returns:
1886
        bool: False if the callback cancels the line interation by
1887
              returning False or None, otherwise True.
1888
1889
    .. deprecated:: 2.0
1890
       Use `line_iter` instead.
1891
    """
1892
    with _PropagateException() as propagate:
1893
        with _line_listener_lock:
1894
            @ffi.def_extern(onerror=propagate)
1895
            def _pycall_line_listener(x, y):
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 _pycall_line_listener seems to be unused.
Loading history...
1896
                return py_callback(x, y)
1897
            return bool(lib.TCOD_line(xo, yo, xd, yd,
1898
                                       lib._pycall_line_listener))
1899
1900
def line_iter(xo, yo, xd, yd):
1901
    """ returns an iterator
1902
1903
    This iterator does not include the origin point.
1904
1905
    Args:
1906
        xo (int): X starting point.
1907
        yo (int): Y starting point.
1908
        xd (int): X destination point.
1909
        yd (int): Y destination point.
1910
1911
    Returns:
1912
        Iterator[Tuple[int,int]]: An iterator of (x,y) points.
1913
    """
1914
    data = ffi.new('TCOD_bresenham_data_t *')
1915
    lib.TCOD_line_init_mt(xo, yo, xd, yd, data)
1916
    x = ffi.new('int *')
1917
    y = ffi.new('int *')
1918
    yield xo, yo
1919
    while not lib.TCOD_line_step_mt(x, y, data):
1920
        yield (x[0], y[0])
1921
1922
FOV_BASIC = 0
1923
FOV_DIAMOND = 1
1924
FOV_SHADOW = 2
1925
FOV_PERMISSIVE_0 = 3
1926
FOV_PERMISSIVE_1 = 4
1927
FOV_PERMISSIVE_2 = 5
1928
FOV_PERMISSIVE_3 = 6
1929
FOV_PERMISSIVE_4 = 7
1930
FOV_PERMISSIVE_5 = 8
1931
FOV_PERMISSIVE_6 = 9
1932
FOV_PERMISSIVE_7 = 10
1933
FOV_PERMISSIVE_8 = 11
1934
FOV_RESTRICTIVE = 12
1935
NB_FOV_ALGORITHMS = 13
1936
1937
def map_new(w, h):
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...
1938
    return tcod.map.Map(w, h)
1939
1940
def map_copy(source, dest):
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...
1941
    return lib.TCOD_map_copy(source.cdata, dest.cdata)
1942
1943
def map_set_properties(m, x, y, isTrans, isWalk):
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...
1944
    lib.TCOD_map_set_properties(m.cdata, x, y, isTrans, isWalk)
1945
1946
def map_clear(m,walkable=False,transparent=False):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def map_clear(m,walkable=False,transparent=False):
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
def map_clear(m,walkable=False,transparent=False):
^
Loading history...
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...
1947
    # walkable/transparent looks incorrectly ordered here.
1948
    # TODO: needs test.
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1949
    lib.TCOD_map_clear(m.cdata, walkable, transparent)
1950
1951
def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
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...
Coding Style introduced by
No space allowed before bracket
def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
^
Loading history...
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...
1952
    lib.TCOD_map_compute_fov(m.cdata, x, y, radius, light_walls, algo)
1953
1954
def map_is_in_fov(m, x, y):
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...
1955
    return lib.TCOD_map_is_in_fov(m.cdata, x, y)
1956
1957
def map_is_transparent(m, x, y):
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...
1958
    return lib.TCOD_map_is_transparent(m.cdata, x, y)
1959
1960
def map_is_walkable(m, x, y):
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...
1961
    return lib.TCOD_map_is_walkable(m.cdata, x, y)
1962
1963
def map_delete(m):
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 argument m seems to be unused.
Loading history...
1964
    pass
1965
1966
def map_get_width(map):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in map.

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

Loading history...
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...
1967
    return map.width
1968
1969
def map_get_height(map):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in map.

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

Loading history...
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...
1970
    return map.height
1971
1972
def mouse_show_cursor(visible):
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...
1973
    lib.TCOD_mouse_show_cursor(visible)
1974
1975
def mouse_is_cursor_visible():
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...
1976
    return lib.TCOD_mouse_is_cursor_visible()
1977
1978
def mouse_move(x, y):
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...
1979
    lib.TCOD_mouse_move(x, y)
1980
1981
def mouse_get_status():
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...
1982
    return Mouse(lib.TCOD_mouse_get_status())
1983
1984
def namegen_parse(filename,random=None):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def namegen_parse(filename,random=None):
^
Loading history...
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...
1985
    lib.TCOD_namegen_parse(_bytes(filename), random or ffi.NULL)
1986
1987
def namegen_generate(name):
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...
1988
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name), False))
1989
1990
def namegen_generate_custom(name, rule):
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...
1991
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name),
1992
                                                     _bytes(rule), False))
1993
1994
def namegen_get_sets():
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...
1995
    sets = lib.TCOD_namegen_get_sets()
1996
    try:
1997
        lst = []
1998
        while not lib.TCOD_list_is_empty(sets):
1999
            lst.append(_unpack_char_p(ffi.cast('char *', lib.TCOD_list_pop(sets))))
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...
2000
    finally:
2001
        lib.TCOD_list_delete(sets)
2002
    return lst
2003
2004
def namegen_destroy():
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...
2005
    lib.TCOD_namegen_destroy()
2006
2007
def noise_new(dim, h=NOISE_DEFAULT_HURST, l=NOISE_DEFAULT_LACUNARITY,
2008
        random=None):
2009
    """Return a new Noise instance.
2010
2011
    Args:
2012
        dim (int): Number of dimensions.  From 1 to 4.
2013
        h (float): The hurst exponent.  Should be in the 0.0-1.0 range.
2014
        l (float): The noise lacunarity.
2015
        random (Optional[Random]): A Random instance, or None.
2016
2017
    Returns:
2018
        Noise: The new Noise instance.
2019
    """
2020
    return tcod.noise.Noise(dim, hurst=h, lacunarity=l, rand=random)
2021
2022
def noise_set_type(n, typ):
2023
    """Set a Noise objects default noise algorithm.
2024
2025
    Args:
2026
        typ (int): Any NOISE_* constant.
2027
    """
2028
    n.algorithm = typ
2029
2030
def noise_get(n, f, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
2031
    """Return the noise value sampled from the ``f`` coordinate.
2032
2033
    ``f`` should be a tuple or list with a length matching
2034
    :any:`Noise.dimensions`.
2035
    If ``f`` is shoerter than :any:`Noise.dimensions` the missing coordinates
2036
    will be filled with zeros.
2037
2038
    Args:
2039
        n (Noise): A Noise instance.
2040
        f (Sequence[float]): The point to sample the noise from.
2041
        typ (int): The noise algorithm to use.
2042
2043
    Returns:
2044
        float: The sampled noise value.
2045
    """
2046
    return lib.TCOD_noise_get_ex(n.noise_c, ffi.new('float[4]', f), typ)
2047
2048
def noise_get_fbm(n, f, oc, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
2049
    """Return the fractal Brownian motion sampled from the ``f`` coordinate.
2050
2051
    Args:
2052
        n (Noise): A Noise instance.
2053
        f (Sequence[float]): The point to sample the noise from.
2054
        typ (int): The noise algorithm to use.
2055
        octaves (float): The level of level.  Should be more than 1.
2056
2057
    Returns:
2058
        float: The sampled noise value.
2059
    """
2060
    return lib.TCOD_noise_get_fbm_ex(n.noise_c, ffi.new('float[4]', f),
2061
                                     oc, typ)
2062
2063
def noise_get_turbulence(n, f, oc, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
2064
    """Return the turbulence noise sampled from the ``f`` coordinate.
2065
2066
    Args:
2067
        n (Noise): A Noise instance.
2068
        f (Sequence[float]): The point to sample the noise from.
2069
        typ (int): The noise algorithm to use.
2070
        octaves (float): The level of level.  Should be more than 1.
2071
2072
    Returns:
2073
        float: The sampled noise value.
2074
    """
2075
    return lib.TCOD_noise_get_turbulence_ex(n.noise_c, ffi.new('float[4]', f),
2076
                                            oc, typ)
2077
2078
def noise_delete(n):
0 ignored issues
show
Unused Code introduced by
The argument n seems to be unused.
Loading history...
2079
    """Does nothing."""
2080
    pass
2081
2082
_chr = chr
2083
try:
2084
    _chr = unichr # Python 2
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unichr'
Loading history...
2085
except NameError:
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...
2086
    pass
2087
2088
def _unpack_union(type, union):
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...
2089
    '''
2090
        unpack items from parser new_property (value_converter)
2091
    '''
2092
    if type == lib.TCOD_TYPE_BOOL:
2093
        return bool(union.b)
2094
    elif type == lib.TCOD_TYPE_CHAR:
2095
        return _unicode(union.c)
2096
    elif type == lib.TCOD_TYPE_INT:
2097
        return union.i
2098
    elif type == lib.TCOD_TYPE_FLOAT:
2099
        return union.f
2100
    elif (type == lib.TCOD_TYPE_STRING or
2101
         lib.TCOD_TYPE_VALUELIST15 >= type >= lib.TCOD_TYPE_VALUELIST00):
2102
         return _unpack_char_p(union.s)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 9 were found.
Loading history...
2103
    elif type == lib.TCOD_TYPE_COLOR:
2104
        return Color._new_from_cdata(union.col)
2105
    elif type == lib.TCOD_TYPE_DICE:
2106
        return Dice(union.dice)
2107
    elif type & lib.TCOD_TYPE_LIST:
2108
        return _convert_TCODList(union.list, type & 0xFF)
2109
    else:
2110
        raise RuntimeError('Unknown libtcod type: %i' % type)
2111
2112
def _convert_TCODList(clist, type):
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...
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...
2113
    return [_unpack_union(type, lib.TDL_list_get_union(clist, i))
2114
            for i in range(lib.TCOD_list_size(clist))]
2115
2116
def parser_new():
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...
2117
    return ffi.gc(lib.TCOD_parser_new(), lib.TCOD_parser_delete)
2118
2119
def parser_new_struct(parser, name):
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...
2120
    return lib.TCOD_parser_new_struct(parser, name)
2121
2122
# prevent multiple threads from messing with def_extern callbacks
2123
_parser_callback_lock = _threading.Lock()
2124
2125
def parser_run(parser, filename, listener=None):
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...
2126
    if not listener:
2127
        lib.TCOD_parser_run(parser, _bytes(filename), ffi.NULL)
2128
        return
2129
2130
    propagate_manager = _PropagateException()
2131
    propagate = propagate_manager.propagate
2132
2133
    with _parser_callback_lock:
2134
        clistener = ffi.new('TCOD_parser_listener_t *')
2135
2136
        @ffi.def_extern(onerror=propagate)
2137
        def pycall_parser_new_struct(struct, name):
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...
2138
            return listener.end_struct(struct, _unpack_char_p(name))
2139
2140
        @ffi.def_extern(onerror=propagate)
2141
        def pycall_parser_new_flag(name):
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...
2142
            return listener.new_flag(_unpack_char_p(name))
2143
2144
        @ffi.def_extern(onerror=propagate)
2145
        def pycall_parser_new_property(propname, type, value):
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...
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...
2146
            return listener.new_property(_unpack_char_p(propname), type,
2147
                                         _unpack_union(type, value))
2148
2149
        @ffi.def_extern(onerror=propagate)
2150
        def pycall_parser_end_struct(struct, name):
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...
2151
            return listener.end_struct(struct, _unpack_char_p(name))
2152
2153
        @ffi.def_extern(onerror=propagate)
2154
        def pycall_parser_error(msg):
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...
2155
            listener.error(_unpack_char_p(msg))
2156
2157
        clistener.new_struct = lib.pycall_parser_new_struct
2158
        clistener.new_flag = lib.pycall_parser_new_flag
2159
        clistener.new_property = lib.pycall_parser_new_property
2160
        clistener.end_struct = lib.pycall_parser_end_struct
2161
        clistener.error = lib.pycall_parser_error
2162
2163
        with propagate_manager:
2164
            lib.TCOD_parser_run(parser, _bytes(filename), clistener)
2165
2166
def parser_delete(parser):
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 argument parser seems to be unused.
Loading history...
2167
    pass
2168
2169
def parser_get_bool_property(parser, name):
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...
2170
    return bool(lib.TCOD_parser_get_bool_property(parser, _bytes(name)))
2171
2172
def parser_get_int_property(parser, name):
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...
2173
    return lib.TCOD_parser_get_int_property(parser, _bytes(name))
2174
2175
def parser_get_char_property(parser, name):
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...
2176
    return _chr(lib.TCOD_parser_get_char_property(parser, _bytes(name)))
2177
2178
def parser_get_float_property(parser, name):
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...
2179
    return lib.TCOD_parser_get_float_property(parser, _bytes(name))
2180
2181
def parser_get_string_property(parser, name):
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...
2182
    return _unpack_char_p(
2183
        lib.TCOD_parser_get_string_property(parser, _bytes(name)))
2184
2185
def parser_get_color_property(parser, name):
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...
2186
    return Color._new_from_cdata(
2187
        lib.TCOD_parser_get_color_property(parser, _bytes(name)))
2188
2189
def parser_get_dice_property(parser, name):
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...
2190
    d = ffi.new('TCOD_dice_t *')
2191
    lib.TCOD_parser_get_dice_property_py(parser, _bytes(name), d)
2192
    return Dice(d)
2193
2194
def parser_get_list_property(parser, name, type):
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...
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...
2195
    clist = lib.TCOD_parser_get_list_property(parser, _bytes(name), type)
2196
    return _convert_TCODList(clist, type)
2197
2198
RNG_MT = 0
2199
RNG_CMWC = 1
2200
2201
DISTRIBUTION_LINEAR = 0
2202
DISTRIBUTION_GAUSSIAN = 1
2203
DISTRIBUTION_GAUSSIAN_RANGE = 2
2204
DISTRIBUTION_GAUSSIAN_INVERSE = 3
2205
DISTRIBUTION_GAUSSIAN_RANGE_INVERSE = 4
2206
2207
def random_get_instance():
2208
    """Return the default Random instance.
2209
2210
    Returns:
2211
        Random: A Random instance using the default random number generator.
2212
    """
2213
    return tcod.random.Random._new_from_cdata(
2214
        ffi.cast('mersenne_data_t*', lib.TCOD_random_get_instance()))
2215
2216
def random_new(algo=RNG_CMWC):
2217
    """Return a new Random instance.  Using ``algo``.
2218
2219
    Args:
2220
        algo (int): The random number algorithm to use.
2221
2222
    Returns:
2223
        Random: A new Random instance using the given algorithm.
2224
    """
2225
    return tcod.random.Random(algo)
2226
2227
def random_new_from_seed(seed, algo=RNG_CMWC):
2228
    """Return a new Random instance.  Using the given ``seed`` and ``algo``.
2229
2230
    Args:
2231
        seed (Hashable): The RNG seed.  Should be a 32-bit integer, but any
2232
                         hashable object is accepted.
2233
        algo (int): The random number algorithm to use.
2234
2235
    Returns:
2236
        Random: A new Random instance using the given algorithm.
2237
    """
2238
    return tcod.random.Random(algo, seed)
2239
2240
def random_set_distribution(rnd, dist):
2241
    """Change the distribution mode of a random number generator.
2242
2243
    Args:
2244
        rnd (Optional[Random]): A Random instance, or None to use the default.
2245
        dist (int): The distribution mode to use.  Should be DISTRIBUTION_*.
2246
    """
2247
    lib.TCOD_random_set_distribution(_cdata(rnd), dist)
2248
2249
def random_get_int(rnd, mi, ma):
2250
    """Return a random integer in the range: ``mi`` <= n <= ``ma``.
2251
2252
    The result is affacted by calls to :any:`random_set_distribution`.
2253
2254
    Args:
2255
        rnd (Optional[Random]): A Random instance, or None to use the default.
2256
        low (int): The lower bound of the random range, inclusive.
2257
        high (int): The upper bound of the random range, inclusive.
2258
2259
    Returns:
2260
        int: A random integer in the range ``mi`` <= n <= ``ma``.
2261
    """
2262
    return lib.TCOD_random_get_int(_cdata(rnd), mi, ma)
2263
2264
def random_get_float(rnd, mi, ma):
2265
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2266
2267
    The result is affacted by calls to :any:`random_set_distribution`.
2268
2269
    Args:
2270
        rnd (Optional[Random]): A Random instance, or None to use the default.
2271
        low (float): The lower bound of the random range, inclusive.
2272
        high (float): The upper bound of the random range, inclusive.
2273
2274
    Returns:
2275
        float: A random double precision float
2276
               in the range ``mi`` <= n <= ``ma``.
2277
    """
2278
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2279
2280
def random_get_double(rnd, mi, ma):
2281
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2282
2283
    .. deprecated:: 2.0
2284
        Use :any:`random_get_float` instead.
2285
        Both funtions return a double precision float.
2286
    """
2287
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2288
2289
def random_get_int_mean(rnd, mi, ma, mean):
2290
    """Return a random weighted integer in the range: ``mi`` <= n <= ``ma``.
2291
2292
    The result is affacted by calls to :any:`random_set_distribution`.
2293
2294
    Args:
2295
        rnd (Optional[Random]): A Random instance, or None to use the default.
2296
        low (int): The lower bound of the random range, inclusive.
2297
        high (int): The upper bound of the random range, inclusive.
2298
        mean (int): The mean return value.
2299
2300
    Returns:
2301
        int: A random weighted integer in the range ``mi`` <= n <= ``ma``.
2302
    """
2303
    return lib.TCOD_random_get_int_mean(_cdata(rnd), mi, ma, mean)
2304
2305
def random_get_float_mean(rnd, mi, ma, mean):
2306
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2307
2308
    The result is affacted by calls to :any:`random_set_distribution`.
2309
2310
    Args:
2311
        rnd (Optional[Random]): A Random instance, or None to use the default.
2312
        low (float): The lower bound of the random range, inclusive.
2313
        high (float): The upper bound of the random range, inclusive.
2314
        mean (float): The mean return value.
2315
2316
    Returns:
2317
        float: A random weighted double precision float
2318
               in the range ``mi`` <= n <= ``ma``.
2319
    """
2320
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2321
2322
def random_get_double_mean(rnd, mi, ma, mean):
2323
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2324
2325
    .. deprecated:: 2.0
2326
        Use :any:`random_get_float_mean` instead.
2327
        Both funtions return a double precision float.
2328
    """
2329
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2330
2331
def random_save(rnd):
2332
    """Return a copy of a random number generator.
2333
2334
    Args:
2335
        rnd (Optional[Random]): A Random instance, or None to use the default.
2336
2337
    Returns:
2338
        Random: A Random instance with a copy of the random generator.
2339
    """
2340
    return tcod.random.Random._new_from_cdata(
2341
        ffi.gc(ffi.cast('mersenne_data_t*', lib.TCOD_random_save(rnd.cdata)),
2342
               lib.TCOD_random_delete))
2343
2344
def random_restore(rnd, backup):
2345
    """Restore a random number generator from a backed up copy.
2346
2347
    Args:
2348
        rnd (Optional[Random]): A Random instance, or None to use the default.
2349
        backup (Random): The Random instance which was used as a backup.
2350
    """
2351
    lib.TCOD_random_restore(_cdata(rnd), backup.cdata)
2352
2353
def random_delete(rnd):
0 ignored issues
show
Unused Code introduced by
The argument rnd seems to be unused.
Loading history...
2354
    """Does nothing."""
2355
    pass
2356
2357
def struct_add_flag(struct, name):
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...
2358
    lib.TCOD_struct_add_flag(struct, name)
2359
2360
def struct_add_property(struct, name, typ, mandatory):
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...
2361
    lib.TCOD_struct_add_property(struct, name, typ, mandatory)
2362
2363
def struct_add_value_list(struct, name, value_list, mandatory):
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...
2364
    CARRAY = c_char_p * (len(value_list) + 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'c_char_p'
Loading history...
2365
    cvalue_list = CARRAY()
2366
    for i in range(len(value_list)):
2367
        cvalue_list[i] = cast(value_list[i], c_char_p)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'cast'
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'c_char_p'
Loading history...
2368
    cvalue_list[len(value_list)] = 0
2369
    lib.TCOD_struct_add_value_list(struct, name, cvalue_list, mandatory)
2370
2371
def struct_add_list_property(struct, name, typ, mandatory):
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...
2372
    lib.TCOD_struct_add_list_property(struct, name, typ, mandatory)
2373
2374
def struct_add_structure(struct, sub_struct):
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...
2375
    lib.TCOD_struct_add_structure(struct, sub_struct)
2376
2377
def struct_get_name(struct):
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...
2378
    return _unpack_char_p(lib.TCOD_struct_get_name(struct))
2379
2380
def struct_is_mandatory(struct, name):
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...
2381
    return lib.TCOD_struct_is_mandatory(struct, name)
2382
2383
def struct_get_type(struct, name):
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...
2384
    return lib.TCOD_struct_get_type(struct, name)
2385
2386
# high precision time functions
2387
def sys_set_fps(fps):
2388
    """Set the maximum frame rate.
2389
2390
    You can disable the frame limit again by setting fps to 0.
2391
2392
    Args:
2393
        fps (int): A frame rate limit (i.e. 60)
2394
    """
2395
    lib.TCOD_sys_set_fps(fps)
2396
2397
def sys_get_fps():
2398
    """Return the current frames per second.
2399
2400
    This the actual frame rate, not the frame limit set by
2401
    :any:`tcod.sys_set_fps`.
2402
2403
    This number is updated every second.
2404
2405
    Returns:
2406
        int: The currently measured frame rate.
2407
    """
2408
    return lib.TCOD_sys_get_fps()
2409
2410
def sys_get_last_frame_length():
2411
    """Return the delta time of the last rendered frame in seconds.
2412
2413
    Returns:
2414
        float: The delta time of the last rendered frame.
2415
    """
2416
    return lib.TCOD_sys_get_last_frame_length()
2417
2418
def sys_sleep_milli(val):
2419
    """Sleep for 'val' milliseconds.
2420
2421
    Args:
2422
        val (int): Time to sleep for in milliseconds.
2423
2424
    .. deprecated:: 2.0
2425
       Use :any:`time.sleep` instead.
2426
    """
2427
    lib.TCOD_sys_sleep_milli(val)
2428
2429
def sys_elapsed_milli():
2430
    """Get number of milliseconds since the start of the program.
2431
2432
    Returns:
2433
        int: Time since the progeam has started in milliseconds.
2434
2435
    .. deprecated:: 2.0
2436
       Use :any:`time.clock` instead.
2437
    """
2438
    return lib.TCOD_sys_elapsed_milli()
2439
2440
def sys_elapsed_seconds():
2441
    """Get number of seconds since the start of the program.
2442
2443
    Returns:
2444
        float: Time since the progeam has started in seconds.
2445
2446
    .. deprecated:: 2.0
2447
       Use :any:`time.clock` instead.
2448
    """
2449
    return lib.TCOD_sys_elapsed_seconds()
2450
2451
def sys_set_renderer(renderer):
2452
    """Change the current rendering mode to renderer.
2453
2454
    .. deprecated:: 2.0
2455
       RENDERER_GLSL and RENDERER_OPENGL are not currently available.
2456
    """
2457
    lib.TCOD_sys_set_renderer(renderer)
2458
2459
def sys_get_renderer():
2460
    """Return the current rendering mode.
2461
2462
    """
2463
    return lib.TCOD_sys_get_renderer()
2464
2465
# easy screenshots
2466
def sys_save_screenshot(name=None):
2467
    """Save a screenshot to a file.
2468
2469
    By default this will automatically save screenshots in the working
2470
    directory.
2471
2472
    The automatic names are formatted as screenshotNNN.png.  For example:
2473
    screenshot000.png, screenshot001.png, etc.  Whichever is available first.
2474
2475
    Args:
2476
        file Optional[AnyStr]: File path to save screenshot.
2477
    """
2478
    if name is not None:
2479
        name = _bytes(name)
2480
    lib.TCOD_sys_save_screenshot(name or ffi.NULL)
2481
2482
# custom fullscreen resolution
2483
def sys_force_fullscreen_resolution(width, height):
2484
    """Force a specific resolution in fullscreen.
2485
2486
    Will use the smallest available resolution so that:
2487
2488
    * resolution width >= width and
2489
      resolution width >= root console width * font char width
2490
    * resolution height >= height and
2491
      resolution height >= root console height * font char height
2492
2493
    Args:
2494
        width (int): The desired resolution width.
2495
        height (int): The desired resolution height.
2496
    """
2497
    lib.TCOD_sys_force_fullscreen_resolution(width, height)
2498
2499
def sys_get_current_resolution():
2500
    """Return the current resolution as (width, height)
2501
2502
    Returns:
2503
        Tuple[int,int]: The current resolution.
2504
    """
2505
    w = ffi.new('int *')
2506
    h = ffi.new('int *')
2507
    lib.TCOD_sys_get_current_resolution(w, h)
2508
    return w[0], h[0]
2509
2510
def sys_get_char_size():
2511
    """Return the current fonts character size as (width, height)
2512
2513
    Returns:
2514
        Tuple[int,int]: The current font glyph size in (width, height)
2515
    """
2516
    w = ffi.new('int *')
2517
    h = ffi.new('int *')
2518
    lib.TCOD_sys_get_char_size(w, h)
2519
    return w[0], h[0]
2520
2521
# update font bitmap
2522
def sys_update_char(asciiCode, fontx, fonty, img, x, y):
2523
    """Dynamically update the current frot with img.
2524
2525
    All cells using this asciiCode will be updated
2526
    at the next call to :any:`tcod.console_flush`.
2527
2528
    Args:
2529
        asciiCode (int): Ascii code corresponding to the character to update.
2530
        fontx (int): Left coordinate of the character
2531
                     in the bitmap font (in tiles)
2532
        fonty (int): Top coordinate of the character
2533
                     in the bitmap font (in tiles)
2534
        img (Image): An image containing the new character bitmap.
2535
        x (int): Left pixel of the character in the image.
2536
        y (int): Top pixel of the character in the image.
2537
    """
2538
    lib.TCOD_sys_update_char(_int(asciiCode), fontx, fonty, img, x, y)
2539
2540
def sys_register_SDL_renderer(callback):
2541
    """Register a custom randering function with libtcod.
2542
2543
    The callack will receive a :any:`CData <ffi-cdata>` void* to an
2544
    SDL_Surface* struct.
2545
2546
    The callback is called on every call to :any:`tcod.console_flush`.
2547
2548
    Args:
2549
        callback Callable[[CData], None]:
2550
            A function which takes a single argument.
2551
    """
2552
    with _PropagateException() as propagate:
2553
        @ffi.def_extern(onerror=propagate)
2554
        def _pycall_sdl_hook(sdl_surface):
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 _pycall_sdl_hook seems to be unused.
Loading history...
2555
            callback(sdl_surface)
2556
        lib.TCOD_sys_register_SDL_renderer(lib._pycall_sdl_hook)
2557
2558
def sys_check_for_event(mask, k, m):
2559
    """Check for and return an event.
2560
2561
    Args:
2562
        mask (int): :any:`Event types` to wait for.
2563
        k (Optional[Key]): A tcod.Key instance which might be updated with
2564
                           an event.  Can be None.
2565
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2566
                             with an event.  Can be None.
2567
    """
2568
    return lib.TCOD_sys_check_for_event(mask, _cdata(k), _cdata(m))
2569
2570
def sys_wait_for_event(mask, k, m, flush):
2571
    """Wait for an event then return.
2572
2573
    If flush is True then the buffer will be cleared before waiting. Otherwise
2574
    each available event will be returned in the order they're recieved.
2575
2576
    Args:
2577
        mask (int): :any:`Event types` to wait for.
2578
        k (Optional[Key]): A tcod.Key instance which might be updated with
2579
                           an event.  Can be None.
2580
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2581
                             with an event.  Can be None.
2582
        flush (bool): Clear the event buffer before waiting.
2583
    """
2584
    return lib.TCOD_sys_wait_for_event(mask, _cdata(k), _cdata(m), flush)
2585
2586
def sys_clipboard_set(text):
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...
2587
    return lib.TCOD_sys_clipboard_set(text.encode('utf-8'))
2588
2589
def sys_clipboard_get():
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...
2590
    return ffi.string(lib.TCOD_sys_clipboard_get()).decode('utf-8')
2591