Completed
Push — master ( d5b420...9d7785 )
by Kyle
01:39
created

console_from_file()   D

Complexity

Conditions 1

Size

Total Lines 13

Duplication

Lines 1
Ratio 7.69 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 1
c 6
b 0
f 0
dl 1
loc 13
rs 4.8292
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...
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_GLSL):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'RENDERER_GLSL'
Loading history...
550
    """Set up the primary display and return the root console.
551
552
    Args:
553
        w (int): Width in character tiles for the root console.
554
        h (int): Height in character tiles for the root console.
555
        title (AnyStr):
556
            This string will be displayed on the created windows title bar.
557
        renderer: Rendering mode for libtcod to use.
558
559
    Returns:
560
        Console:
561
            Returns a special Console instance representing the root console.
562
    """
563
    lib.TCOD_console_init_root(w, h, _bytes(title), fullscreen, renderer)
564
    return tcod.console.Console._from_cdata(ffi.NULL) # root console is null
565
566
567
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...
568
                            nb_char_horiz=0, nb_char_vertic=0):
569
    """Load a custom font file.
570
571
    Call this before function before calling :any:`tcod.console_init_root`.
572
573
    Flags can be a mix of the following:
574
575
    * tcod.FONT_LAYOUT_ASCII_INCOL
576
    * tcod.FONT_LAYOUT_ASCII_INROW
577
    * tcod.FONT_TYPE_GREYSCALE
578
    * tcod.FONT_TYPE_GRAYSCALE
579
    * tcod.FONT_LAYOUT_TCOD
580
581
    Args:
582
        fontFile (AnyStr): Path to a font file.
583
        flags (int):
584
        nb_char_horiz (int):
585
        nb_char_vertic (int):
586
    """
587
    lib.TCOD_console_set_custom_font(_bytes(fontFile), flags,
588
                                     nb_char_horiz, nb_char_vertic)
589
590
591
def console_get_width(con):
592
    """Return the width of a console.
593
594
    Args:
595
        con (Console): Any Console instance.
596
597
    Returns:
598
        int: The width of a Console.
599
600
    .. deprecated:: 2.0
601
        Use `Console.get_width` instead.
602
    """
603
    return lib.TCOD_console_get_width(_cdata(con))
604
605
def console_get_height(con):
606
    """Return the height of a console.
607
608
    Args:
609
        con (Console): Any Console instance.
610
611
    Returns:
612
        int: The height of a Console.
613
614
    .. deprecated:: 2.0
615
        Use `Console.get_hright` instead.
616
    """
617
    return lib.TCOD_console_get_height(_cdata(con))
618
619
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...
620
    lib.TCOD_console_map_ascii_code_to_font(_int(asciiCode), fontCharX,
621
                                                              fontCharY)
622
623
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...
624
                                    fontCharY):
625
    lib.TCOD_console_map_ascii_codes_to_font(_int(firstAsciiCode), nbCodes,
626
                                              fontCharX, fontCharY)
627
628
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...
629
    lib.TCOD_console_map_string_to_font_utf(_unicode(s), fontCharX, fontCharY)
630
631
def console_is_fullscreen():
632
    """Returns True if the display is fullscreen.
633
634
    Returns:
635
        bool: True if the display is fullscreen, otherwise False.
636
    """
637
    return bool(lib.TCOD_console_is_fullscreen())
638
639
def console_set_fullscreen(fullscreen):
640
    """Change the display to be fullscreen or windowed.
641
642
    Args:
643
        fullscreen (bool): Use True to change to fullscreen.
644
                           Use False to change to windowed.
645
    """
646
    lib.TCOD_console_set_fullscreen(fullscreen)
647
648
def console_is_window_closed():
649
    """Returns True if the window has received and exit event."""
650
    return lib.TCOD_console_is_window_closed()
651
652
def console_set_window_title(title):
653
    """Change the current title bar string.
654
655
    Args:
656
        title (AnyStr): A string to change the title bar to.
657
    """
658
    lib.TCOD_console_set_window_title(_bytes(title))
659
660
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...
661
    lib.TCOD_console_credits()
662
663
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...
664
    lib.TCOD_console_credits_reset()
665
666
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...
667
    return lib.TCOD_console_credits_render(x, y, alpha)
668
669
def console_flush():
670
    """Update the display to represent the root consoles current state."""
671
    lib.TCOD_console_flush()
672
673
# drawing on a console
674
def console_set_default_background(con, col):
675
    """Change the default background color for a console.
676
677
    Args:
678
        con (Console): Any Console instance.
679
        col (Union[Tuple[int, int, int], Sequence[int]]):
680
            An (r, g, b) sequence or Color instance.
681
    """
682
    lib.TCOD_console_set_default_background(_cdata(con), col)
683
684
def console_set_default_foreground(con, col):
685
    """Change the default foreground color for a console.
686
687
    Args:
688
        con (Console): Any Console instance.
689
        col (Union[Tuple[int, int, int], Sequence[int]]):
690
            An (r, g, b) sequence or Color instance.
691
    """
692
    lib.TCOD_console_set_default_foreground(_cdata(con), col)
693
694
def console_clear(con):
695
    """Reset a console to its default colors and the space character.
696
697
    Args:
698
        con (Console): Any Console instance.
699
700
    .. seealso::
701
       :any:`console_set_default_background`
702
       :any:`console_set_default_foreground`
703
    """
704
    return lib.TCOD_console_clear(_cdata(con))
705
706
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...
707
    """Draw the character c at x,y using the default colors and a blend mode.
708
709
    Args:
710
        con (Console): Any Console instance.
711
        x (int): Character x position from the left.
712
        y (int): Character y position from the top.
713
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
714
        flag (int): Blending mode to use, defaults to BKGND_DEFAULT.
715
    """
716
    lib.TCOD_console_put_char(_cdata(con), x, y, _int(c), flag)
717
718
def console_put_char_ex(con, x, y, c, fore, back):
719
    """Draw the character c at x,y using the colors fore and back.
720
721
    Args:
722
        con (Console): Any Console instance.
723
        x (int): Character x position from the left.
724
        y (int): Character y position from the top.
725
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
726
        fore (Union[Tuple[int, int, int], Sequence[int]]):
727
            An (r, g, b) sequence or Color instance.
728
        back (Union[Tuple[int, int, int], Sequence[int]]):
729
            An (r, g, b) sequence or Color instance.
730
    """
731
    lib.TCOD_console_put_char_ex(_cdata(con), x, y,
732
                                 _int(c), fore, back)
733
734
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...
735
    """Change the background color of x,y to col using a blend mode.
736
737
    Args:
738
        con (Console): Any Console instance.
739
        x (int): Character x position from the left.
740
        y (int): Character y position from the top.
741
        col (Union[Tuple[int, int, int], Sequence[int]]):
742
            An (r, g, b) sequence or Color instance.
743
        flag (int): Blending mode to use, defaults to BKGND_SET.
744
    """
745
    lib.TCOD_console_set_char_background(_cdata(con), x, y, col, flag)
746
747
def console_set_char_foreground(con, x, y, col):
748
    """Change the foreground color of x,y to col.
749
750
    Args:
751
        con (Console): Any Console instance.
752
        x (int): Character x position from the left.
753
        y (int): Character y position from the top.
754
        col (Union[Tuple[int, int, int], Sequence[int]]):
755
            An (r, g, b) sequence or Color instance.
756
    """
757
    lib.TCOD_console_set_char_foreground(_cdata(con), x, y, col)
758
759
def console_set_char(con, x, y, c):
760
    """Change the character at x,y to c, keeping the current colors.
761
762
    Args:
763
        con (Console): Any Console instance.
764
        x (int): Character x position from the left.
765
        y (int): Character y position from the top.
766
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
767
    """
768
    lib.TCOD_console_set_char(_cdata(con), x, y, _int(c))
769
770
def console_set_background_flag(con, flag):
771
    """Change the default blend mode for this console.
772
773
    Args:
774
        con (Console): Any Console instance.
775
        flag (int): Blend mode to use by default.
776
    """
777
    lib.TCOD_console_set_background_flag(_cdata(con), flag)
778
779
def console_get_background_flag(con):
780
    """Return this consoles current blend mode.
781
782
    Args:
783
        con (Console): Any Console instance.
784
    """
785
    return lib.TCOD_console_get_background_flag(_cdata(con))
786
787
def console_set_alignment(con, alignment):
788
    """Change this consoles current alignment mode.
789
790
    * tcod.LEFT
791
    * tcod.CENTER
792
    * tcod.RIGHT
793
794
    Args:
795
        con (Console): Any Console instance.
796
        alignment (int):
797
    """
798
    lib.TCOD_console_set_alignment(_cdata(con), alignment)
799
800
def console_get_alignment(con):
801
    """Return this consoles current alignment mode.
802
803
    Args:
804
        con (Console): Any Console instance.
805
    """
806
    return lib.TCOD_console_get_alignment(_cdata(con))
807
808
def console_print(con, x, y, fmt):
809
    """Print a color formatted string on a console.
810
811
    Args:
812
        con (Console): Any Console instance.
813
        x (int): Character x position from the left.
814
        y (int): Character y position from the top.
815
        fmt (AnyStr): A unicode or bytes string optionaly using color codes.
816
    """
817
    lib.TCOD_console_print_utf(_cdata(con), x, y, _fmt_unicode(fmt))
818
819
def console_print_ex(con, x, y, flag, alignment, fmt):
820
    """Print a string on a console using a blend mode and alignment mode.
821
822
    Args:
823
        con (Console): Any Console instance.
824
        x (int): Character x position from the left.
825
        y (int): Character y position from the top.
826
    """
827
    lib.TCOD_console_print_ex_utf(_cdata(con), x, y,
828
                                   flag, alignment, _fmt_unicode(fmt))
829
830
def console_print_rect(con, x, y, w, h, fmt):
831
    """Print a string constrained to a rectangle.
832
833
    If h > 0 and the bottom of the rectangle is reached,
834
    the string is truncated. If h = 0,
835
    the string is only truncated if it reaches the bottom of the console.
836
837
838
839
    Returns:
840
        int: The number of lines of text once word-wrapped.
841
    """
842
    return lib.TCOD_console_print_rect_utf(_cdata(con), x, y, w, h,
843
                                            _fmt_unicode(fmt))
844
845
def console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt):
846
    """Print a string constrained to a rectangle with blend and alignment.
847
848
    Returns:
849
        int: The number of lines of text once word-wrapped.
850
    """
851
    return lib.TCOD_console_print_rect_ex_utf(_cdata(con), x, y, w, h,
852
                                              flag, alignment,
853
                                              _fmt_unicode(fmt))
854
855
def console_get_height_rect(con, x, y, w, h, fmt):
856
    """Return the height of this text once word-wrapped into this rectangle.
857
858
    Returns:
859
        int: The number of lines of text once word-wrapped.
860
    """
861
    return lib.TCOD_console_get_height_rect_utf(_cdata(con), x, y, w, h,
862
                                                 _fmt_unicode(fmt))
863
864
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...
865
    """Draw a the background color on a rect optionally clearing the text.
866
867
    If clr is True the affected tiles are changed to space character.
868
    """
869
    lib.TCOD_console_rect(_cdata(con), x, y, w, h, clr, flag)
870
871
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...
872
    """Draw a horizontal line on the console.
873
874
    This always uses the character 196, the horizontal line character.
875
    """
876
    lib.TCOD_console_hline(_cdata(con), x, y, l, flag)
877
878
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...
879
    """Draw a vertical line on the console.
880
881
    This always uses the character 179, the vertical line character.
882
    """
883
    lib.TCOD_console_vline(_cdata(con), x, y, l, flag)
884
885
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...
886
    """Draw a framed rectangle with optinal text.
887
888
    This uses the default background color and blend mode to fill the
889
    rectangle and the default foreground to draw the outline.
890
891
    fmt will be printed on the inside of the rectangle, word-wrapped.
892
    """
893
    lib.TCOD_console_print_frame(_cdata(con), x, y, w, h, clear, flag,
894
                                  _fmt_bytes(fmt))
895
896
def console_set_color_control(con, fore, back):
897
    """Configure :any:`color controls`.
898
899
    Args:
900
        con (int): :any:`Color control` constant to modify.
901
        fore (Union[Tuple[int, int, int], Sequence[int]]):
902
            An (r, g, b) sequence or Color instance.
903
        back (Union[Tuple[int, int, int], Sequence[int]]):
904
            An (r, g, b) sequence or Color instance.
905
    """
906
    lib.TCOD_console_set_color_control(_cdata(con), fore, back)
907
908
def console_get_default_background(con):
909
    """Return this consoles default background color."""
910
    return Color._new_from_cdata(
911
        lib.TCOD_console_get_default_background(_cdata(con)))
912
913
def console_get_default_foreground(con):
914
    """Return this consoles default foreground color."""
915 View Code Duplication
    return Color._new_from_cdata(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
916
        lib.TCOD_console_get_default_foreground(_cdata(con)))
917
918
def console_get_char_background(con, x, y):
919
    """Return the background color at the x,y of this console."""
920
    return Color._new_from_cdata(
921
        lib.TCOD_console_get_char_background(_cdata(con), x, y))
922
923
def console_get_char_foreground(con, x, y):
924
    """Return the foreground color at the x,y of this console."""
925
    return Color._new_from_cdata(
926
        lib.TCOD_console_get_char_foreground(_cdata(con), x, y))
927
928
def console_get_char(con, x, y):
929
    """Return the character at the x,y of this console."""
930
    return lib.TCOD_console_get_char(_cdata(con), x, y)
931
932
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...
933
    lib.TCOD_console_set_fade(fade, fadingColor)
934
935
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...
936
    return lib.TCOD_console_get_fade()
937
938
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...
939
    return Color._new_from_cdata(lib.TCOD_console_get_fading_color())
940
941
# handling keyboard input
942
def console_wait_for_keypress(flush):
943 View Code Duplication
    """Block until the user presses a key, then returns a new Key.
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
944
945
    Args:
946
        flush bool: If True then the event queue is cleared before waiting
947
                    for the next event.
948
949
    Returns:
950
        Key: A new Key instance.
951
    """
952
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
953
    lib.TCOD_console_wait_for_keypress_wrapper(k.cdata, flush)
954
    return k
955
956
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...
957
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
958
    lib.TCOD_console_check_for_keypress_wrapper(k.cdata, flags)
959
    return k
960
961
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...
962
    return lib.TCOD_console_is_key_pressed(key)
963
964
# using offscreen consoles
965
def console_new(w, h):
966
    """Return an offscreen console of size: w,h."""
967
    return tcod.console.Console(w, h)
968
969
def console_from_file(filename):
970
    """Return a new console object from a filename.
971
972
    The file format is automactially determined.  This can load REXPaint `.xp`,
973
    ASCII Paint `.apf`, or Non-delimited ASCII `.asc` files.
974
975
    Args:
976
        filename (Text): The path to the file, as a string.
977
978
    Returns: A new :any`Console` instance.
979
    """
980
    return tcod.console.Console._from_cdata(
981
        lib.TCOD_console_from_file(filename.encode('utf-8')))
982
983
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...
984
    """Blit the console src from x,y,w,h to console dst at xdst,ydst."""
985
    lib.TCOD_console_blit(_cdata(src), x, y, w, h,
986
                          _cdata(dst), xdst, ydst, ffade, bfade)
987
988
def console_set_key_color(con, col):
989
    """Set a consoles blit transparent color."""
990
    lib.TCOD_console_set_key_color(_cdata(con), col)
991
992
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...
993
    con = _cdata(con)
994
    if con == ffi.NULL:
995
        lib.TCOD_console_delete(con)
996
997
# fast color filling
998
def console_fill_foreground(con, r, g, b):
999
    """Fill the foregound of a console with r,g,b.
1000
1001
    Args:
1002
        con (Console): Any Console instance.
1003
        r (Sequence[int]): An array of integers with a length of width*height.
1004
        g (Sequence[int]): An array of integers with a length of width*height.
1005
        b (Sequence[int]): An array of integers with a length of width*height.
1006
    """
1007
    if len(r) != len(g) or len(r) != len(b):
1008
        raise TypeError('R, G and B must all have the same size.')
1009 View Code Duplication
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
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...
1010
        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...
1011
        #numpy arrays, use numpy's ctypes functions
1012
        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...
1013
        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...
1014
        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...
1015
        cr = ffi.cast('int *', r.ctypes.data)
1016
        cg = ffi.cast('int *', g.ctypes.data)
1017
        cb = ffi.cast('int *', b.ctypes.data)
1018
    else:
1019
        # otherwise convert using ffi arrays
1020
        cr = ffi.new('int[]', r)
1021
        cg = ffi.new('int[]', g)
1022
        cb = ffi.new('int[]', b)
1023
1024
    lib.TCOD_console_fill_foreground(_cdata(con), cr, cg, cb)
1025
1026
def console_fill_background(con, r, g, b):
1027
    """Fill the backgound of a console with r,g,b.
1028
1029
    Args:
1030
        con (Console): Any Console instance.
1031
        r (Sequence[int]): An array of integers with a length of width*height.
1032
        g (Sequence[int]): An array of integers with a length of width*height.
1033
        b (Sequence[int]): An array of integers with a length of width*height.
1034
    """
1035
    if len(r) != len(g) or len(r) != len(b):
1036
        raise TypeError('R, G and B must all have the same size.')
1037 View Code Duplication
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
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...
1038
        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...
1039
        #numpy arrays, use numpy's ctypes functions
1040
        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...
1041
        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...
1042
        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...
1043
        cr = ffi.cast('int *', r.ctypes.data)
1044
        cg = ffi.cast('int *', g.ctypes.data)
1045
        cb = ffi.cast('int *', b.ctypes.data)
1046
    else:
1047
        # otherwise convert using ffi arrays
1048
        cr = ffi.new('int[]', r)
1049
        cg = ffi.new('int[]', g)
1050
        cb = ffi.new('int[]', b)
1051
1052
    lib.TCOD_console_fill_background(_cdata(con), cr, cg, cb)
1053
1054
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...
1055
    """Fill the character tiles of a console with an array.
1056
1057
    Args:
1058
        con (Console): Any Console instance.
1059
        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...
1060
    """
1061
    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...
1062
        #numpy arrays, use numpy's ctypes functions
1063
        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...
1064
        carr = ffi.cast('int *', arr.ctypes.data)
1065
    else:
1066
        #otherwise convert using the ffi module
1067
        carr = ffi.new('int[]', arr)
1068
1069
    lib.TCOD_console_fill_char(_cdata(con), carr)
1070
1071
def console_load_asc(con, filename):
1072
    """Update a console from a non-delimited ASCII `.asc` file."""
1073
    return lib.TCOD_console_load_asc(_cdata(con), _bytes(filename))
1074
1075
def console_save_asc(con, filename):
1076
    """Save a console to a non-delimited ASCII `.asc` file."""
1077
    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...
1078
1079
def console_load_apf(con, filename):
1080
    """Update a console from an ASCII Paint `.apf` file."""
1081
    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...
1082
1083
def console_save_apf(con, filename):
1084
    """Save a console to an ASCII Paint `.apf` file."""
1085
    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...
1086
1087
def console_load_xp(con, filename):
1088
    """Update a console from a REXPaint `.xp` file."""
1089
    return lib.TCOD_console_load_xp(_cdata(con), filename.encode('utf-8'))
1090
1091
def console_save_xp(con, filename, compress_level=9):
1092
    """Save a console to a REXPaint `.xp` file."""
1093
    return lib.TCOD_console_save_xp(
1094
        _cdata(con), filename.encode('utf-8'), compress_level)
1095
1096
def console_from_xp(filename):
1097
    """Return a single console from a REXPaint `.xp` file."""
1098
    return tcod.console.Console._from_cdata(
1099
        lib.TCOD_console_from_xp(filename.encode('utf-8')))
1100
1101
def console_list_load_xp(filename):
1102
    """Return a list of consoles from a REXPaint `.xp` file."""
1103
    tcod_list = lib.TCOD_console_list_from_xp(filename.encode('utf-8'))
1104
    if tcod_list == ffi.NULL:
1105
        return None
1106
    try:
1107
        python_list = []
1108
        lib.TCOD_list_reverse(tcod_list)
1109
        while not lib.TCOD_list_is_empty(tcod_list):
1110
            python_list.append(
1111
                tcod.console.Console._from_cdata(lib.TCOD_list_pop(tcod_list)),
1112
                )
1113
        return python_list
1114
    finally:
1115
        lib.TCOD_list_delete(tcod_list)
1116
1117
def console_list_save_xp(console_list, filename, compress_level=9):
1118
    """Save a list of consoles to a REXPaint `.xp` file."""
1119
    tcod_list = lib.TCOD_list_new()
1120
    try:
1121
        for console in console_list:
1122
            lib.TCOD_list_push(tcod_list, _cdata(console))
1123
        return lib.TCOD_console_list_save_xp(
1124
            tcod_list, filename.encode('utf-8'), compress_level
1125
            )
1126
    finally:
1127
        lib.TCOD_list_delete(tcod_list)
1128
1129
def path_new_using_map(m, dcost=1.41):
1130
    """Return a new AStar using the given Map.
1131
1132
    Args:
1133
        m (Map): A Map instance.
1134
        dcost (float): The path-finding cost of diagonal movement.
1135
                       Can be set to 0 to disable diagonal movement.
1136
    Returns:
1137
        AStar: A new AStar instance.
1138
    """
1139
    return tcod.path.AStar(m, dcost)
1140
1141
def path_new_using_function(w, h, func, userData=0, dcost=1.41):
1142
    """Return a new AStar using the given callable function.
1143
1144
    Args:
1145
        w (int): Clipping width.
1146
        h (int): Clipping height.
1147
        func (Callable[[int, int, int, int, Any], float]):
1148
        userData (Any):
1149
        dcost (float): A multiplier for the cost of diagonal movement.
1150
                       Can be set to 0 to disable diagonal movement.
1151
    Returns:
1152
        AStar: A new AStar instance.
1153
    """
1154
    return tcod.path.AStar((func, userData), dcost, w, h)
1155
1156
def path_compute(p, ox, oy, dx, dy):
1157
    """Find a path from (ox, oy) to (dx, dy).  Return True if path is found.
1158
1159
    Args:
1160
        p (AStar): An AStar instance.
1161
        ox (int): Starting x position.
1162
        oy (int): Starting y position.
1163
        dx (int): Destination x position.
1164
        dy (int): Destination y position.
1165
    Returns:
1166
        bool: True if a valid path was found.  Otherwise False.
1167
    """
1168
    return lib.TCOD_path_compute(p.cdata, ox, oy, dx, dy)
1169
1170
def path_get_origin(p):
1171
    """Get the current origin position.
1172
1173
    This point moves when :any:`path_walk` returns the next x,y step.
1174
1175
    Args:
1176
        p (AStar): An AStar instance.
1177
    Returns:
1178
        Tuple[int, int]: An (x, y) point.
1179
    """
1180
    x = ffi.new('int *')
1181
    y = ffi.new('int *')
1182
    lib.TCOD_path_get_origin(p.cdata, x, y)
1183
    return x[0], y[0]
1184
1185
def path_get_destination(p):
1186
    """Get the current destination position.
1187
1188
    Args:
1189
        p (AStar): An AStar instance.
1190
    Returns:
1191
        Tuple[int, int]: An (x, y) point.
1192
    """
1193
    x = ffi.new('int *')
1194
    y = ffi.new('int *')
1195
    lib.TCOD_path_get_destination(p.cdata, x, y)
1196
    return x[0], y[0]
1197
1198
def path_size(p):
1199
    """Return the current length of the computed path.
1200
1201
    Args:
1202
        p (AStar): An AStar instance.
1203
    Returns:
1204
        int: Length of the path.
1205
    """
1206
    return lib.TCOD_path_size(p.cdata)
1207
1208
def path_reverse(p):
1209
    """Reverse the direction of a path.
1210
1211
    This effectively swaps the origin and destination points.
1212
1213
    Args:
1214
        p (AStar): An AStar instance.
1215
    """
1216
    lib.TCOD_path_reverse(p.cdata)
1217
1218
def path_get(p, idx):
1219
    """Get a point on a path.
1220
1221
    Args:
1222
        p (AStar): An AStar instance.
1223
        idx (int): Should be in range: 0 <= inx < :any:`path_size`
1224
    """
1225
    x = ffi.new('int *')
1226
    y = ffi.new('int *')
1227
    lib.TCOD_path_get(p.cdata, idx, x, y)
1228
    return x[0], y[0]
1229
1230
def path_is_empty(p):
1231
    """Return True if a path is empty.
1232
1233
    Args:
1234
        p (AStar): An AStar instance.
1235
    Returns:
1236
        bool: True if a path is empty.  Otherwise False.
1237
    """
1238
    return lib.TCOD_path_is_empty(p.cdata)
1239
1240
def path_walk(p, recompute):
1241
    """Return the next (x, y) point in a path, or (None, None) if it's empty.
1242
1243
    When ``recompute`` is True and a previously valid path reaches a point
1244
    where it is now blocked, a new path will automatically be found.
1245
1246
    Args:
1247
        p (AStar): An AStar instance.
1248
        recompute (bool): Recompute the path automatically.
1249
    Returns:
1250
        Union[Tuple[int, int], Tuple[None, None]]:
1251
            A single (x, y) point, or (None, None)
1252
    """
1253
    x = ffi.new('int *')
1254
    y = ffi.new('int *')
1255
    if lib.TCOD_path_walk(p.cdata, x, y, recompute):
1256
        return x[0], y[0]
1257
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1258
1259
def path_delete(p):
0 ignored issues
show
Unused Code introduced by
The argument p seems to be unused.
Loading history...
1260
    """Does nothing."""
1261
    pass
1262
1263
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...
1264
    return tcod.path.Dijkstra(m, dcost)
1265
1266
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...
1267
    return tcod.path.Dijkstra((func, userData), dcost, w, h)
1268
1269
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...
1270
    lib.TCOD_dijkstra_compute(p.cdata, ox, oy)
1271
1272
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...
1273
    return lib.TCOD_dijkstra_path_set(p.cdata, x, y)
1274
1275
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...
1276
    return lib.TCOD_dijkstra_get_distance(p.cdata, x, y)
1277
1278
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...
1279
    return lib.TCOD_dijkstra_size(p.cdata)
1280
1281
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...
1282
    lib.TCOD_dijkstra_reverse(p.cdata)
1283
1284
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...
1285
    x = ffi.new('int *')
1286
    y = ffi.new('int *')
1287
    lib.TCOD_dijkstra_get(p.cdata, idx, x, y)
1288
    return x[0], y[0]
1289
1290
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...
1291
    return lib.TCOD_dijkstra_is_empty(p.cdata)
1292
1293
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...
1294
    x = ffi.new('int *')
1295
    y = ffi.new('int *')
1296
    if lib.TCOD_dijkstra_path_walk(p.cdata, x, y):
1297
        return x[0], y[0]
1298
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1299
1300
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...
1301
    pass
1302
1303
def _heightmap_cdata(array):
1304
    """Return a new TCOD_heightmap_t instance using an array.
1305
1306
    Formatting is verified during this function.
1307
    """
1308
    if not array.flags['C_CONTIGUOUS']:
1309
        raise ValueError('array must be a C-style contiguous segment.')
1310
    if array.dtype != _np.float32:
1311
        raise ValueError('array dtype must be float32, not %r' % array.dtype)
1312
    width, height = array.shape
1313
    pointer = ffi.cast('float *', array.ctypes.data)
1314
    return ffi.new('TCOD_heightmap_t *', (width, height, pointer))
1315
1316
def heightmap_new(w, h):
1317
    """Return a new numpy.ndarray formatted for use with heightmap functions.
1318
1319
    You can pass a numpy array to any heightmap function as long as all the
1320
    following are true::
1321
    * The array is 2 dimentional.
1322
    * The array has the C_CONTIGUOUS flag.
1323
    * The array's dtype is :any:`dtype.float32`.
1324
1325
    Args:
1326
        w (int): The width of the new HeightMap.
1327
        h (int): The height of the new HeightMap.
1328
1329
    Returns:
1330
        numpy.ndarray: A C-contiguous mapping of float32 values.
1331
    """
1332
    return _np.ndarray((h, w), _np.float32)
1333
1334
def heightmap_set_value(hm, x, y, value):
1335
    """Set the value of a point on a heightmap.
1336
1337
    Args:
1338
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1339
        x (int): The x position to change.
1340
        y (int): The y position to change.
1341
        value (float): The value to set.
1342
1343
    .. deprecated:: 2.0
1344
        Do ``hm[y, x] = value`` instead.
1345
    """
1346
    hm[y, x] = value
1347
1348
def heightmap_add(hm, value):
1349
    """Add value to all values on this heightmap.
1350
1351
    Args:
1352
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1353
        value (float): A number to add to this heightmap.
1354
1355
    .. deprecated:: 2.0
1356
        Do ``hm[:] += value`` instead.
1357
    """
1358
    hm[:] += value
1359
1360
def heightmap_scale(hm, value):
1361
    """Multiply all items on this heightmap by value.
1362
1363
    Args:
1364
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1365
        value (float): A number to scale this heightmap by.
1366
1367
    .. deprecated:: 2.0
1368
        Do ``hm[:] *= value`` instead.
1369
    """
1370
    hm[:] *= value
1371
1372
def heightmap_clear(hm):
1373
    """Add value to all values on this heightmap.
1374
1375
    Args:
1376
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1377
1378
    .. deprecated:: 2.0
1379
        Do ``hm.array[:] = 0`` instead.
1380
    """
1381
    hm[:] = 0
1382
1383
def heightmap_clamp(hm, mi, ma):
1384
    """Clamp all values on this heightmap between ``mi`` and ``ma``
1385
1386
    Args:
1387
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1388
        mi (float): The lower bound to clamp to.
1389
        ma (float): The upper bound to clamp to.
1390
1391
    .. deprecated:: 2.0
1392
        Do ``hm.clip(mi, ma)`` instead.
1393
    """
1394
    hm.clip(mi, ma)
1395
1396
def heightmap_copy(hm1, hm2):
1397
    """Copy the heightmap ``hm1`` to ``hm2``.
1398
1399
    Args:
1400
        hm1 (numpy.ndarray): The source heightmap.
1401
        hm2 (numpy.ndarray): The destination heightmap.
1402
1403
    .. deprecated:: 2.0
1404
        Do ``hm2[:] = hm1[:]`` instead.
1405
    """
1406
    hm2[:] = hm1[:]
1407
1408
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...
1409
    """Normalize heightmap values between ``mi`` and ``ma``.
1410
1411
    Args:
1412
        mi (float): The lowest value after normalization.
1413
        ma (float): The highest value after normalization.
1414
    """
1415
    lib.TCOD_heightmap_normalize(_heightmap_cdata(hm), mi, ma)
1416
1417
def heightmap_lerp_hm(hm1, hm2, hm3, coef):
1418
    """Perform linear interpolation between two heightmaps storing the result
1419
    in ``hm3``.
1420
1421
    This is the same as doing ``hm3[:] = hm1[:] + (hm2[:] - hm1[:]) * coef``
1422
1423
    Args:
1424
        hm1 (numpy.ndarray): The first heightmap.
1425
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1426
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1427
        coef (float): The linear interpolation coefficient.
1428
    """
1429
    lib.TCOD_heightmap_lerp_hm(_heightmap_cdata(hm1), _heightmap_cdata(hm2),
1430
                               _heightmap_cdata(hm3), coef)
1431
1432
def heightmap_add_hm(hm1, hm2, hm3):
1433
    """Add two heightmaps together and stores the result in ``hm3``.
1434
1435
    Args:
1436
        hm1 (numpy.ndarray): The first heightmap.
1437
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1438
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1439
1440
    .. deprecated:: 2.0
1441
        Do ``hm3[:] = hm1[:] + hm2[:]`` instead.
1442
    """
1443
    hm3[:] = hm1[:] + hm2[:]
1444
1445
def heightmap_multiply_hm(hm1, hm2, hm3):
1446
    """Multiplies two heightmap's together and stores the result in ``hm3``.
1447
1448
    Args:
1449
        hm1 (numpy.ndarray): The first heightmap.
1450
        hm2 (numpy.ndarray): The second heightmap to multiply with the first.
1451
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1452
1453
    .. deprecated:: 2.0
1454
        Do ``hm3[:] = hm1[:] * hm2[:]`` instead.
1455
        Alternatively you can do ``HeightMap(hm1.array[:] * hm2.array[:])``.
1456
    """
1457
    hm3[:] = hm1[:] * hm2[:]
1458
1459
def heightmap_add_hill(hm, x, y, radius, height):
1460
    """Add a hill (a half spheroid) at given position.
1461
1462
    If height == radius or -radius, the hill is a half-sphere.
1463
1464
    Args:
1465
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1466
        x (float): The x position at the center of the new hill.
1467
        y (float): The y position at the center of the new hill.
1468
        radius (float): The size of the new hill.
1469
        height (float): The height or depth of the new hill.
1470
    """
1471
    lib.TCOD_heightmap_add_hill(_heightmap_cdata(hm), x, y, radius, height)
1472
1473
def heightmap_dig_hill(hm, x, y, radius, height):
1474
    """
1475
1476
    This function takes the highest value (if height > 0) or the lowest
1477
    (if height < 0) between the map and the hill.
1478
1479
    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...
1480
1481
    Args:
1482
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1483
        x (float): The x position at the center of the new carving.
1484
        y (float): The y position at the center of the new carving.
1485
        radius (float): The size of the carving.
1486
        height (float): The height or depth of the hill to dig out.
1487
    """
1488
    lib.TCOD_heightmap_dig_hill(_heightmap_cdata(hm), x, y, radius, height)
1489
1490
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...
1491
    """Simulate the effect of rain drops on the terrain, resulting in erosion.
1492
1493
    ``nbDrops`` should be at least hm.size.
1494
1495
    Args:
1496
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1497
        nbDrops (int): Number of rain drops to simulate.
1498
        erosionCoef (float): Amount of ground eroded on the drop's path.
1499
        sedimentationCoef (float): Amount of ground deposited when the drops
1500
                                   stops to flow.
1501
        rnd (Optional[Random]): A tcod.Random instance, or None.
1502
    """
1503
    lib.TCOD_heightmap_rain_erosion(_heightmap_cdata(hm), nbDrops, erosionCoef,
1504
                                    sedimentationCoef, _cdata(rnd))
1505
1506
def heightmap_kernel_transform(hm, kernelsize, dx, dy, weight, minLevel,
1507
                               maxLevel):
1508
    """Apply a generic transformation on the map, so that each resulting cell
1509
    value is the weighted sum of several neighbour cells.
1510
1511
    This can be used to smooth/sharpen the map.
1512
1513
    Args:
1514
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1515
        kernelsize (int): Should be set to the length of the parameters::
1516
                          dx, dy, and weight.
1517
        dx (Sequence[int]): A sequence of x coorinates.
1518
        dy (Sequence[int]): A sequence of y coorinates.
1519
        weight (Sequence[float]): A sequence of kernelSize cells weight.
1520
                                  The value of each neighbour cell is scaled by
1521
                                  its corresponding weight
1522
        minLevel (float): No transformation will apply to cells
1523
                          below this value.
1524
        maxLevel (float): No transformation will apply to cells
1525
                          above this value.
1526
1527
    See examples below for a simple horizontal smoothing kernel :
1528
    replace value(x,y) with
1529
    0.33*value(x-1,y) + 0.33*value(x,y) + 0.33*value(x+1,y).
1530
    To do this, you need a kernel of size 3
1531
    (the sum involves 3 surrounding cells).
1532
    The dx,dy array will contain
1533
    * dx=-1, dy=0 for cell (x-1, y)
1534
    * dx=1, dy=0 for cell (x+1, y)
1535
    * dx=0, dy=0 for cell (x, y)
1536
    * The weight array will contain 0.33 for each cell.
1537
1538
    Example:
1539
        >>> dx = [-1, 1, 0]
1540
        >>> dy = [0, 0, 0]
1541
        >>> weight = [0.33, 0.33, 0.33]
1542
        >>> tcod.heightMap_kernel_transform(heightmap,3,dx,dy,weight,0.0,1.0)
1543
    """
1544
    cdx = ffi.new('int[]', dx)
1545
    cdy = ffi.new('int[]', dy)
1546
    cweight = ffi.new('float[]', weight)
1547
    lib.TCOD_heightmap_kernel_transform(_heightmap_cdata(hm), kernelsize,
1548
                                        cdx, cdy, cweight, minLevel, maxLevel)
1549
1550
def heightmap_add_voronoi(hm, nbPoints, nbCoef, coef, rnd=None):
1551
    """Add values from a Voronoi diagram to the heightmap.
1552
1553
    Args:
1554
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1555
        nbPoints (Any): Number of Voronoi sites.
1556
        nbCoef (int): The diagram value is calculated from the nbCoef
1557
                      closest sites.
1558
        coef (Sequence[float]): The distance to each site is scaled by the
1559
                                corresponding coef.
1560
                                Closest site : coef[0],
1561
                                second closest site : coef[1], ...
1562
        rnd (Optional[Random]): A Random instance, or None.
1563
    """
1564
    nbPoints = len(coef)
1565
    ccoef = ffi.new('float[]', coef)
1566
    lib.TCOD_heightmap_add_voronoi(_heightmap_cdata(hm), nbPoints,
1567
                                   nbCoef, ccoef, _cdata(rnd))
1568
1569
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...
1570
    """Add FBM noise to the heightmap.
1571
1572
    The noise coordinate for each map cell is
1573
    `((x + addx) * mulx / width, (y + addy) * muly / height)`.
1574
1575
    The value added to the heightmap is `delta + noise * scale`.
1576
1577
    Args:
1578
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1579
        noise (Noise): A Noise instance.
1580
        mulx (float): Scaling of each x coordinate.
1581
        muly (float): Scaling of each y coordinate.
1582
        addx (float): Translation of each x coordinate.
1583
        addy (float): Translation of each y coordinate.
1584
        octaves (float): Number of octaves in the FBM sum.
1585
        delta (float): The value added to all heightmap cells.
1586
        scale (float): The noise value is scaled with this parameter.
1587
    """
1588
    noise = noise.noise_c if noise is not None else ffi.NULL
1589
    lib.TCOD_heightmap_add_fbm(_heightmap_cdata(hm), noise,
1590
                               mulx, muly, addx, addy, octaves, delta, scale)
1591
1592
def heightmap_scale_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta,
1593
                        scale):
1594
    """Multiply the heighmap values with FBM noise.
1595
1596
    Args:
1597
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1598
        noise (Noise): A Noise instance.
1599
        mulx (float): Scaling of each x coordinate.
1600
        muly (float): Scaling of each y coordinate.
1601
        addx (float): Translation of each x coordinate.
1602
        addy (float): Translation of each y coordinate.
1603
        octaves (float): Number of octaves in the FBM sum.
1604
        delta (float): The value added to all heightmap cells.
1605
        scale (float): The noise value is scaled with this parameter.
1606
    """
1607
    noise = noise.noise_c if noise is not None else ffi.NULL
1608
    lib.TCOD_heightmap_scale_fbm(_heightmap_cdata(hm), noise,
1609
                                 mulx, muly, addx, addy, octaves, delta, scale)
1610
1611
def heightmap_dig_bezier(hm, px, py, startRadius, startDepth, endRadius,
1612
                         endDepth):
1613
    """Carve a path along a cubic Bezier curve.
1614
1615
    Both radius and depth can vary linearly along the path.
1616
1617
    Args:
1618
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1619
        px (Sequence[int]): The 4 `x` coordinates of the Bezier curve.
1620
        py (Sequence[int]): The 4 `y` coordinates of the Bezier curve.
1621
        startRadius (float): The starting radius size.
1622
        startDepth (float): The starting depth.
1623
        endRadius (float): The ending radius size.
1624
        endDepth (float): The ending depth.
1625
    """
1626
    lib.TCOD_heightmap_dig_bezier(_heightmap_cdata(hm), px, py, startRadius,
1627
                                   startDepth, endRadius,
1628
                                   endDepth)
1629
1630
def heightmap_get_value(hm, x, y):
1631
    """Return the value at ``x``, ``y`` in a heightmap.
1632
1633
    Args:
1634
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1635
        x (int): The x position to pick.
1636
        y (int): The y position to pick.
1637
1638
    Returns:
1639
        float: The value at ``x``, ``y``.
1640
1641
    .. deprecated:: 2.0
1642
        Do ``value = hm[y, x]`` instead.
1643
    """
1644
    # explicit type conversion to pass test, (test should have been better.)
1645
    return float(hm[y, x])
1646
1647
def heightmap_get_interpolated_value(hm, x, y):
1648
    """Return the interpolated height at non integer coordinates.
1649
1650
    Args:
1651
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1652
        x (float): A floating point x coordinate.
1653
        y (float): A floating point y coordinate.
1654
1655
    Returns:
1656
        float: The value at ``x``, ``y``.
1657
    """
1658
    return lib.TCOD_heightmap_get_interpolated_value(_heightmap_cdata(hm),
1659
                                                     x, y)
1660
1661
def heightmap_get_slope(hm, x, y):
1662
    """Return the slope between 0 and (pi / 2) at given coordinates.
1663
1664
    Args:
1665
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1666
        x (int): The x coordinate.
1667
        y (int): The y coordinate.
1668
1669
    Returns:
1670
        float: The steepness at ``x``, ``y``.  From 0 to (pi / 2)
1671
    """
1672
    return lib.TCOD_heightmap_get_slope(_heightmap_cdata(hm), x, y)
1673
1674
def heightmap_get_normal(hm, x, y, waterLevel):
1675
    """Return the map normal at given coordinates.
1676
1677
    Args:
1678
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1679
        x (float): The x coordinate.
1680
        y (float): The y coordinate.
1681
        waterLevel (float): The heightmap is considered flat below this value.
1682
1683
    Returns:
1684
        Tuple[float, float, float]: An (x, y, z) vector normal.
1685
    """
1686
    cn = ffi.new('float[3]')
1687
    lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)
1688
    return tuple(cn)
1689
1690
def heightmap_count_cells(hm, mi, ma):
1691
    """Return the number of map cells which value is between ``mi`` and ``ma``.
1692
1693
    Args:
1694
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1695
        mi (float): The lower bound.
1696
        ma (float): The upper bound.
1697
1698
    Returns:
1699
        int: The count of values which fall between ``mi`` and ``ma``.
1700
    """
1701
    return lib.TCOD_heightmap_count_cells(_heightmap_cdata(hm), mi, ma)
1702
1703
def heightmap_has_land_on_border(hm, waterlevel):
1704
    """Returns True if the map edges are below ``waterlevel``, otherwise False.
1705
1706
    Args:
1707
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1708
        waterLevel (float): The water level to use.
1709
1710
    Returns:
1711
        bool: True if the map edges are below ``waterlevel``, otherwise False.
1712
    """
1713
    return lib.TCOD_heightmap_has_land_on_border(_heightmap_cdata(hm),
1714
                                                 waterlevel)
1715
1716
def heightmap_get_minmax(hm):
1717
    """Return the min and max values of this heightmap.
1718
1719
    Args:
1720
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1721
1722
    Returns:
1723
        Tuple[float, float]: The (min, max) values.
1724
1725
    .. deprecated:: 2.0
1726
        Do ``hm.min()`` or ``hm.max()`` instead.
1727
    """
1728
    mi = ffi.new('float *')
1729
    ma = ffi.new('float *')
1730
    lib.TCOD_heightmap_get_minmax(_heightmap_cdata(hm), mi, ma)
1731
    return mi[0], ma[0]
1732
1733
def heightmap_delete(hm):
0 ignored issues
show
Unused Code introduced by
The argument hm seems to be unused.
Loading history...
1734
    """Does nothing.
1735
1736
    .. deprecated:: 2.0
1737
        libtcod-cffi deletes heightmaps automatically.
1738
    """
1739
    pass
1740
1741
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...
1742
    return tcod.image.Image(width, height)
1743
1744
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...
1745
    image.clear(col)
1746
1747
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...
1748
    image.invert()
1749
1750
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...
1751
    image.hflip()
1752
1753
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...
1754
    image.rotate90(num)
1755
1756
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...
1757
    image.vflip()
1758
1759
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...
1760
    image.scale(neww, newh)
1761
1762
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...
1763
    image.set_key_color(col)
1764
1765
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...
1766
    image.get_alpha(x, y)
1767
1768
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...
1769
    lib.TCOD_image_is_pixel_transparent(image.image_c, x, y)
1770
1771
def image_load(filename):
1772
    """Load an image file into an Image instance and return it.
1773
1774
    Args:
1775
        filename (AnyStr): Path to a .bmp or .png image file.
1776
    """
1777
    return tcod.image.Image._from_cdata(
1778
        ffi.gc(lib.TCOD_image_load(_bytes(filename)),
1779
               lib.TCOD_image_delete)
1780
        )
1781
1782
def image_from_console(console):
1783
    """Return an Image with a Consoles pixel data.
1784
1785
    This effectively takes a screen-shot of the Console.
1786
1787
    Args:
1788
        console (Console): Any Console instance.
1789
    """
1790
    return tcod.image.Image._from_cdata(
1791
        ffi.gc(lib.TCOD_image_from_console(_cdata(console)),
1792
               lib.TCOD_image_delete)
1793
        )
1794
1795
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...
1796
    image.refresh_console(console)
1797
1798
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...
1799
    return image.width, image.height
1800
1801
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...
1802
    return image.get_pixel(x, y)
1803
1804
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...
1805
    return image.get_mipmap_pixel(x0, y0, x1, y1)
1806
1807
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...
1808
    image.put_pixel(x, y, col)
1809
1810
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...
1811
    image.blit(console, x, y, bkgnd_flag, scalex, scaley, angle)
1812
1813
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...
1814
    image.blit_rect(console, x, y, w, h, bkgnd_flag)
1815
1816
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...
1817
    image.blit_2x(console, dx, dy, sx, sy, w, h)
1818
1819
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...
1820
    image.save_as(filename)
1821
1822
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...
1823
    pass
1824
1825
def line_init(xo, yo, xd, yd):
1826
    """Initilize a line whose points will be returned by `line_step`.
1827
1828
    This function does not return anything on its own.
1829
1830
    Does not include the origin point.
1831
1832
    Args:
1833
        xo (int): X starting point.
1834
        yo (int): Y starting point.
1835
        xd (int): X destination point.
1836
        yd (int): Y destination point.
1837
1838
    .. deprecated:: 2.0
1839
       Use `line_iter` instead.
1840
    """
1841
    lib.TCOD_line_init(xo, yo, xd, yd)
1842
1843
def line_step():
1844
    """After calling line_init returns (x, y) points of the line.
1845
1846
    Once all points are exhausted this function will return (None, None)
1847
1848
    Returns:
1849
        Union[Tuple[int, int], Tuple[None, None]]:
1850
            The next (x, y) point of the line setup by line_init,
1851
            or (None, None) if there are no more points.
1852
1853
    .. deprecated:: 2.0
1854
       Use `line_iter` instead.
1855
    """
1856
    x = ffi.new('int *')
1857
    y = ffi.new('int *')
1858
    ret = lib.TCOD_line_step(x, y)
1859
    if not ret:
1860
        return x[0], y[0]
1861
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1862
1863
_line_listener_lock = _threading.Lock()
1864
1865
def line(xo, yo, xd, yd, py_callback):
1866
    """ Iterate over a line using a callback function.
1867
1868
    Your callback function will take x and y parameters and return True to
1869
    continue iteration or False to stop iteration and return.
1870
1871
    This function includes both the start and end points.
1872
1873
    Args:
1874
        xo (int): X starting point.
1875
        yo (int): Y starting point.
1876
        xd (int): X destination point.
1877
        yd (int): Y destination point.
1878
        py_callback (Callable[[int, int], bool]):
1879
            A callback which takes x and y parameters and returns bool.
1880
1881
    Returns:
1882
        bool: False if the callback cancels the line interation by
1883
              returning False or None, otherwise True.
1884
1885
    .. deprecated:: 2.0
1886
       Use `line_iter` instead.
1887
    """
1888
    with _PropagateException() as propagate:
1889
        with _line_listener_lock:
1890
            @ffi.def_extern(onerror=propagate)
1891
            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...
1892
                return py_callback(x, y)
1893
            return bool(lib.TCOD_line(xo, yo, xd, yd,
1894
                                       lib._pycall_line_listener))
1895
1896
def line_iter(xo, yo, xd, yd):
1897
    """ returns an iterator
1898
1899
    This iterator does not include the origin point.
1900
1901
    Args:
1902
        xo (int): X starting point.
1903
        yo (int): Y starting point.
1904
        xd (int): X destination point.
1905
        yd (int): Y destination point.
1906
1907
    Returns:
1908
        Iterator[Tuple[int,int]]: An iterator of (x,y) points.
1909
    """
1910
    data = ffi.new('TCOD_bresenham_data_t *')
1911
    lib.TCOD_line_init_mt(xo, yo, xd, yd, data)
1912
    x = ffi.new('int *')
1913
    y = ffi.new('int *')
1914
    yield xo, yo
1915
    while not lib.TCOD_line_step_mt(x, y, data):
1916
        yield (x[0], y[0])
1917
1918
FOV_BASIC = 0
1919
FOV_DIAMOND = 1
1920
FOV_SHADOW = 2
1921
FOV_PERMISSIVE_0 = 3
1922
FOV_PERMISSIVE_1 = 4
1923
FOV_PERMISSIVE_2 = 5
1924
FOV_PERMISSIVE_3 = 6
1925
FOV_PERMISSIVE_4 = 7
1926
FOV_PERMISSIVE_5 = 8
1927
FOV_PERMISSIVE_6 = 9
1928
FOV_PERMISSIVE_7 = 10
1929
FOV_PERMISSIVE_8 = 11
1930
FOV_RESTRICTIVE = 12
1931
NB_FOV_ALGORITHMS = 13
1932
1933
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...
1934
    return tcod.map.Map(w, h)
1935
1936
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...
1937
    return lib.TCOD_map_copy(source.cdata, dest.cdata)
1938
1939
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...
1940
    lib.TCOD_map_set_properties(m.cdata, x, y, isTrans, isWalk)
1941
1942
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...
1943
    # walkable/transparent looks incorrectly ordered here.
1944
    # TODO: needs test.
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1945
    lib.TCOD_map_clear(m.cdata, walkable, transparent)
1946
1947
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...
1948
    lib.TCOD_map_compute_fov(m.cdata, x, y, radius, light_walls, algo)
1949
1950
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...
1951
    return lib.TCOD_map_is_in_fov(m.cdata, x, y)
1952
1953
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...
1954
    return lib.TCOD_map_is_transparent(m.cdata, x, y)
1955
1956
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...
1957
    return lib.TCOD_map_is_walkable(m.cdata, x, y)
1958
1959
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...
1960
    pass
1961
1962
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...
1963
    return map.width
1964
1965
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...
1966
    return map.height
1967
1968
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...
1969
    lib.TCOD_mouse_show_cursor(visible)
1970
1971
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...
1972
    return lib.TCOD_mouse_is_cursor_visible()
1973
1974
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...
1975
    lib.TCOD_mouse_move(x, y)
1976
1977
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...
1978
    return Mouse(lib.TCOD_mouse_get_status())
1979
1980
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...
1981
    lib.TCOD_namegen_parse(_bytes(filename), random or ffi.NULL)
1982
1983
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...
1984
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name), False))
1985
1986
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...
1987
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name),
1988
                                                     _bytes(rule), False))
1989
1990
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...
1991
    sets = lib.TCOD_namegen_get_sets()
1992
    try:
1993
        lst = []
1994
        while not lib.TCOD_list_is_empty(sets):
1995
            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...
1996
    finally:
1997
        lib.TCOD_list_delete(sets)
1998
    return lst
1999
2000
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...
2001
    lib.TCOD_namegen_destroy()
2002
2003
def noise_new(dim, h=NOISE_DEFAULT_HURST, l=NOISE_DEFAULT_LACUNARITY,
2004
        random=None):
2005
    """Return a new Noise instance.
2006
2007
    Args:
2008
        dim (int): Number of dimensions.  From 1 to 4.
2009
        h (float): The hurst exponent.  Should be in the 0.0-1.0 range.
2010
        l (float): The noise lacunarity.
2011
        random (Optional[Random]): A Random instance, or None.
2012
2013
    Returns:
2014
        Noise: The new Noise instance.
2015
    """
2016
    return tcod.noise.Noise(dim, hurst=h, lacunarity=l, rand=random)
2017
2018
def noise_set_type(n, typ):
2019
    """Set a Noise objects default noise algorithm.
2020
2021
    Args:
2022
        typ (int): Any NOISE_* constant.
2023
    """
2024
    n.algorithm = typ
2025
2026
def noise_get(n, f, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
2027
    """Return the noise value sampled from the ``f`` coordinate.
2028
2029
    ``f`` should be a tuple or list with a length matching
2030
    :any:`Noise.dimensions`.
2031
    If ``f`` is shoerter than :any:`Noise.dimensions` the missing coordinates
2032
    will be filled with zeros.
2033
2034
    Args:
2035
        n (Noise): A Noise instance.
2036
        f (Sequence[float]): The point to sample the noise from.
2037
        typ (int): The noise algorithm to use.
2038
2039
    Returns:
2040
        float: The sampled noise value.
2041
    """
2042
    return lib.TCOD_noise_get_ex(n.noise_c, ffi.new('float[4]', f), typ)
2043
2044
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...
2045
    """Return the fractal Brownian motion sampled from the ``f`` coordinate.
2046
2047
    Args:
2048
        n (Noise): A Noise instance.
2049
        f (Sequence[float]): The point to sample the noise from.
2050
        typ (int): The noise algorithm to use.
2051
        octaves (float): The level of level.  Should be more than 1.
2052
2053
    Returns:
2054
        float: The sampled noise value.
2055
    """
2056
    return lib.TCOD_noise_get_fbm_ex(n.noise_c, ffi.new('float[4]', f),
2057
                                     oc, typ)
2058
2059
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...
2060
    """Return the turbulence noise sampled from the ``f`` coordinate.
2061
2062
    Args:
2063
        n (Noise): A Noise instance.
2064
        f (Sequence[float]): The point to sample the noise from.
2065
        typ (int): The noise algorithm to use.
2066
        octaves (float): The level of level.  Should be more than 1.
2067
2068
    Returns:
2069
        float: The sampled noise value.
2070
    """
2071
    return lib.TCOD_noise_get_turbulence_ex(n.noise_c, ffi.new('float[4]', f),
2072
                                            oc, typ)
2073
2074
def noise_delete(n):
0 ignored issues
show
Unused Code introduced by
The argument n seems to be unused.
Loading history...
2075
    """Does nothing."""
2076
    pass
2077
2078
_chr = chr
2079
try:
2080
    _chr = unichr # Python 2
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unichr'
Loading history...
2081
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...
2082
    pass
2083
2084
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...
2085
    '''
2086
        unpack items from parser new_property (value_converter)
2087
    '''
2088
    if type == lib.TCOD_TYPE_BOOL:
2089
        return bool(union.b)
2090
    elif type == lib.TCOD_TYPE_CHAR:
2091
        return _unicode(union.c)
2092
    elif type == lib.TCOD_TYPE_INT:
2093
        return union.i
2094
    elif type == lib.TCOD_TYPE_FLOAT:
2095
        return union.f
2096
    elif (type == lib.TCOD_TYPE_STRING or
2097
         lib.TCOD_TYPE_VALUELIST15 >= type >= lib.TCOD_TYPE_VALUELIST00):
2098
         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...
2099
    elif type == lib.TCOD_TYPE_COLOR:
2100
        return Color._new_from_cdata(union.col)
2101
    elif type == lib.TCOD_TYPE_DICE:
2102
        return Dice(union.dice)
2103
    elif type & lib.TCOD_TYPE_LIST:
2104
        return _convert_TCODList(union.list, type & 0xFF)
2105
    else:
2106
        raise RuntimeError('Unknown libtcod type: %i' % type)
2107
2108
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...
2109
    return [_unpack_union(type, lib.TDL_list_get_union(clist, i))
2110
            for i in range(lib.TCOD_list_size(clist))]
2111
2112
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...
2113
    return ffi.gc(lib.TCOD_parser_new(), lib.TCOD_parser_delete)
2114
2115
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...
2116
    return lib.TCOD_parser_new_struct(parser, name)
2117
2118
# prevent multiple threads from messing with def_extern callbacks
2119
_parser_callback_lock = _threading.Lock()
2120
2121
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...
2122
    if not listener:
2123
        lib.TCOD_parser_run(parser, _bytes(filename), ffi.NULL)
2124
        return
2125
2126
    propagate_manager = _PropagateException()
2127
    propagate = propagate_manager.propagate
2128
2129
    with _parser_callback_lock:
2130
        clistener = ffi.new('TCOD_parser_listener_t *')
2131
2132
        @ffi.def_extern(onerror=propagate)
2133
        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...
2134
            return listener.end_struct(struct, _unpack_char_p(name))
2135
2136
        @ffi.def_extern(onerror=propagate)
2137
        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...
2138
            return listener.new_flag(_unpack_char_p(name))
2139
2140
        @ffi.def_extern(onerror=propagate)
2141
        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...
2142
            return listener.new_property(_unpack_char_p(propname), type,
2143
                                         _unpack_union(type, value))
2144
2145
        @ffi.def_extern(onerror=propagate)
2146
        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...
2147
            return listener.end_struct(struct, _unpack_char_p(name))
2148
2149
        @ffi.def_extern(onerror=propagate)
2150
        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...
2151
            listener.error(_unpack_char_p(msg))
2152
2153
        clistener.new_struct = lib.pycall_parser_new_struct
2154
        clistener.new_flag = lib.pycall_parser_new_flag
2155
        clistener.new_property = lib.pycall_parser_new_property
2156
        clistener.end_struct = lib.pycall_parser_end_struct
2157
        clistener.error = lib.pycall_parser_error
2158
2159
        with propagate_manager:
2160
            lib.TCOD_parser_run(parser, _bytes(filename), clistener)
2161
2162
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...
2163
    pass
2164
2165
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...
2166
    return bool(lib.TCOD_parser_get_bool_property(parser, _bytes(name)))
2167
2168
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...
2169
    return lib.TCOD_parser_get_int_property(parser, _bytes(name))
2170
2171
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...
2172
    return _chr(lib.TCOD_parser_get_char_property(parser, _bytes(name)))
2173
2174
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...
2175
    return lib.TCOD_parser_get_float_property(parser, _bytes(name))
2176
2177
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...
2178
    return _unpack_char_p(
2179
        lib.TCOD_parser_get_string_property(parser, _bytes(name)))
2180
2181
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...
2182
    return Color._new_from_cdata(
2183
        lib.TCOD_parser_get_color_property(parser, _bytes(name)))
2184
2185
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...
2186
    d = ffi.new('TCOD_dice_t *')
2187
    lib.TCOD_parser_get_dice_property_py(parser, _bytes(name), d)
2188
    return Dice(d)
2189
2190
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...
2191
    clist = lib.TCOD_parser_get_list_property(parser, _bytes(name), type)
2192
    return _convert_TCODList(clist, type)
2193
2194
RNG_MT = 0
2195
RNG_CMWC = 1
2196
2197
DISTRIBUTION_LINEAR = 0
2198
DISTRIBUTION_GAUSSIAN = 1
2199
DISTRIBUTION_GAUSSIAN_RANGE = 2
2200
DISTRIBUTION_GAUSSIAN_INVERSE = 3
2201
DISTRIBUTION_GAUSSIAN_RANGE_INVERSE = 4
2202
2203
def random_get_instance():
2204
    """Return the default Random instance.
2205
2206
    Returns:
2207
        Random: A Random instance using the default random number generator.
2208
    """
2209
    return tcod.random.Random._new_from_cdata(
2210
        ffi.cast('mersenne_data_t*', lib.TCOD_random_get_instance()))
2211
2212
def random_new(algo=RNG_CMWC):
2213
    """Return a new Random instance.  Using ``algo``.
2214
2215
    Args:
2216
        algo (int): The random number algorithm to use.
2217
2218
    Returns:
2219
        Random: A new Random instance using the given algorithm.
2220
    """
2221
    return tcod.random.Random(algo)
2222
2223
def random_new_from_seed(seed, algo=RNG_CMWC):
2224
    """Return a new Random instance.  Using the given ``seed`` and ``algo``.
2225
2226
    Args:
2227
        seed (Hashable): The RNG seed.  Should be a 32-bit integer, but any
2228
                         hashable object is accepted.
2229
        algo (int): The random number algorithm to use.
2230
2231
    Returns:
2232
        Random: A new Random instance using the given algorithm.
2233
    """
2234
    return tcod.random.Random(algo, seed)
2235
2236
def random_set_distribution(rnd, dist):
2237
    """Change the distribution mode of a random number generator.
2238
2239
    Args:
2240
        rnd (Optional[Random]): A Random instance, or None to use the default.
2241
        dist (int): The distribution mode to use.  Should be DISTRIBUTION_*.
2242
    """
2243
    lib.TCOD_random_set_distribution(_cdata(rnd), dist)
2244
2245
def random_get_int(rnd, mi, ma):
2246
    """Return a random integer in the range: ``mi`` <= n <= ``ma``.
2247
2248
    The result is affacted by calls to :any:`random_set_distribution`.
2249
2250
    Args:
2251
        rnd (Optional[Random]): A Random instance, or None to use the default.
2252
        low (int): The lower bound of the random range, inclusive.
2253
        high (int): The upper bound of the random range, inclusive.
2254
2255
    Returns:
2256
        int: A random integer in the range ``mi`` <= n <= ``ma``.
2257
    """
2258
    return lib.TCOD_random_get_int(_cdata(rnd), mi, ma)
2259
2260
def random_get_float(rnd, mi, ma):
2261
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2262
2263
    The result is affacted by calls to :any:`random_set_distribution`.
2264
2265
    Args:
2266
        rnd (Optional[Random]): A Random instance, or None to use the default.
2267
        low (float): The lower bound of the random range, inclusive.
2268
        high (float): The upper bound of the random range, inclusive.
2269
2270
    Returns:
2271
        float: A random double precision float
2272
               in the range ``mi`` <= n <= ``ma``.
2273
    """
2274
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2275
2276
def random_get_double(rnd, mi, ma):
2277
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2278
2279
    .. deprecated:: 2.0
2280
        Use :any:`random_get_float` instead.
2281
        Both funtions return a double precision float.
2282
    """
2283
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2284
2285
def random_get_int_mean(rnd, mi, ma, mean):
2286
    """Return a random weighted integer in the range: ``mi`` <= n <= ``ma``.
2287
2288
    The result is affacted by calls to :any:`random_set_distribution`.
2289
2290
    Args:
2291
        rnd (Optional[Random]): A Random instance, or None to use the default.
2292
        low (int): The lower bound of the random range, inclusive.
2293
        high (int): The upper bound of the random range, inclusive.
2294
        mean (int): The mean return value.
2295
2296
    Returns:
2297
        int: A random weighted integer in the range ``mi`` <= n <= ``ma``.
2298
    """
2299
    return lib.TCOD_random_get_int_mean(_cdata(rnd), mi, ma, mean)
2300
2301
def random_get_float_mean(rnd, mi, ma, mean):
2302
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2303
2304
    The result is affacted by calls to :any:`random_set_distribution`.
2305
2306
    Args:
2307
        rnd (Optional[Random]): A Random instance, or None to use the default.
2308
        low (float): The lower bound of the random range, inclusive.
2309
        high (float): The upper bound of the random range, inclusive.
2310
        mean (float): The mean return value.
2311
2312
    Returns:
2313
        float: A random weighted double precision float
2314
               in the range ``mi`` <= n <= ``ma``.
2315
    """
2316
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2317
2318
def random_get_double_mean(rnd, mi, ma, mean):
2319
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2320
2321
    .. deprecated:: 2.0
2322
        Use :any:`random_get_float_mean` instead.
2323
        Both funtions return a double precision float.
2324
    """
2325
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2326
2327
def random_save(rnd):
2328
    """Return a copy of a random number generator.
2329
2330
    Args:
2331
        rnd (Optional[Random]): A Random instance, or None to use the default.
2332
2333
    Returns:
2334
        Random: A Random instance with a copy of the random generator.
2335
    """
2336
    return tcod.random.Random._new_from_cdata(
2337
        ffi.gc(ffi.cast('mersenne_data_t*', lib.TCOD_random_save(rnd.cdata)),
2338
               lib.TCOD_random_delete))
2339
2340
def random_restore(rnd, backup):
2341
    """Restore a random number generator from a backed up copy.
2342
2343
    Args:
2344
        rnd (Optional[Random]): A Random instance, or None to use the default.
2345
        backup (Random): The Random instance which was used as a backup.
2346
    """
2347
    lib.TCOD_random_restore(_cdata(rnd), backup.cdata)
2348
2349
def random_delete(rnd):
0 ignored issues
show
Unused Code introduced by
The argument rnd seems to be unused.
Loading history...
2350
    """Does nothing."""
2351
    pass
2352
2353
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...
2354
    lib.TCOD_struct_add_flag(struct, name)
2355
2356
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...
2357
    lib.TCOD_struct_add_property(struct, name, typ, mandatory)
2358
2359
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...
2360
    CARRAY = c_char_p * (len(value_list) + 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'c_char_p'
Loading history...
2361
    cvalue_list = CARRAY()
2362
    for i in range(len(value_list)):
2363
        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...
2364
    cvalue_list[len(value_list)] = 0
2365
    lib.TCOD_struct_add_value_list(struct, name, cvalue_list, mandatory)
2366
2367
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...
2368
    lib.TCOD_struct_add_list_property(struct, name, typ, mandatory)
2369
2370
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...
2371
    lib.TCOD_struct_add_structure(struct, sub_struct)
2372
2373
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...
2374
    return _unpack_char_p(lib.TCOD_struct_get_name(struct))
2375
2376
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...
2377
    return lib.TCOD_struct_is_mandatory(struct, name)
2378
2379
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...
2380
    return lib.TCOD_struct_get_type(struct, name)
2381
2382
# high precision time functions
2383
def sys_set_fps(fps):
2384
    """Set the maximum frame rate.
2385
2386
    You can disable the frame limit again by setting fps to 0.
2387
2388
    Args:
2389
        fps (int): A frame rate limit (i.e. 60)
2390
    """
2391
    lib.TCOD_sys_set_fps(fps)
2392
2393
def sys_get_fps():
2394
    """Return the current frames per second.
2395
2396
    This the actual frame rate, not the frame limit set by
2397
    :any:`tcod.sys_set_fps`.
2398
2399
    This number is updated every second.
2400
2401
    Returns:
2402
        int: The currently measured frame rate.
2403
    """
2404
    return lib.TCOD_sys_get_fps()
2405
2406
def sys_get_last_frame_length():
2407
    """Return the delta time of the last rendered frame in seconds.
2408
2409
    Returns:
2410
        float: The delta time of the last rendered frame.
2411
    """
2412
    return lib.TCOD_sys_get_last_frame_length()
2413
2414
def sys_sleep_milli(val):
2415
    """Sleep for 'val' milliseconds.
2416
2417
    Args:
2418
        val (int): Time to sleep for in milliseconds.
2419
2420
    .. deprecated:: 2.0
2421
       Use :any:`time.sleep` instead.
2422
    """
2423
    lib.TCOD_sys_sleep_milli(val)
2424
2425
def sys_elapsed_milli():
2426
    """Get number of milliseconds since the start of the program.
2427
2428
    Returns:
2429
        int: Time since the progeam has started in milliseconds.
2430
2431
    .. deprecated:: 2.0
2432
       Use :any:`time.clock` instead.
2433
    """
2434
    return lib.TCOD_sys_elapsed_milli()
2435
2436
def sys_elapsed_seconds():
2437
    """Get number of seconds since the start of the program.
2438
2439
    Returns:
2440
        float: Time since the progeam has started in seconds.
2441
2442
    .. deprecated:: 2.0
2443
       Use :any:`time.clock` instead.
2444
    """
2445
    return lib.TCOD_sys_elapsed_seconds()
2446
2447
def sys_set_renderer(renderer):
2448
    """Change the current rendering mode to renderer.
2449
2450
    .. deprecated:: 2.0
2451
       RENDERER_GLSL and RENDERER_OPENGL are not currently available.
2452
    """
2453
    lib.TCOD_sys_set_renderer(renderer)
2454
2455
def sys_get_renderer():
2456
    """Return the current rendering mode.
2457
2458
    """
2459
    return lib.TCOD_sys_get_renderer()
2460
2461
# easy screenshots
2462
def sys_save_screenshot(name=None):
2463
    """Save a screenshot to a file.
2464
2465
    By default this will automatically save screenshots in the working
2466
    directory.
2467
2468
    The automatic names are formatted as screenshotNNN.png.  For example:
2469
    screenshot000.png, screenshot001.png, etc.  Whichever is available first.
2470
2471
    Args:
2472
        file Optional[AnyStr]: File path to save screenshot.
2473
    """
2474
    if name is not None:
2475
        name = _bytes(name)
2476
    lib.TCOD_sys_save_screenshot(name or ffi.NULL)
2477
2478
# custom fullscreen resolution
2479
def sys_force_fullscreen_resolution(width, height):
2480
    """Force a specific resolution in fullscreen.
2481
2482
    Will use the smallest available resolution so that:
2483
2484
    * resolution width >= width and
2485
      resolution width >= root console width * font char width
2486
    * resolution height >= height and
2487
      resolution height >= root console height * font char height
2488
2489
    Args:
2490
        width (int): The desired resolution width.
2491
        height (int): The desired resolution height.
2492
    """
2493
    lib.TCOD_sys_force_fullscreen_resolution(width, height)
2494
2495
def sys_get_current_resolution():
2496
    """Return the current resolution as (width, height)
2497
2498
    Returns:
2499
        Tuple[int,int]: The current resolution.
2500
    """
2501
    w = ffi.new('int *')
2502
    h = ffi.new('int *')
2503
    lib.TCOD_sys_get_current_resolution(w, h)
2504
    return w[0], h[0]
2505
2506
def sys_get_char_size():
2507
    """Return the current fonts character size as (width, height)
2508
2509
    Returns:
2510
        Tuple[int,int]: The current font glyph size in (width, height)
2511
    """
2512
    w = ffi.new('int *')
2513
    h = ffi.new('int *')
2514
    lib.TCOD_sys_get_char_size(w, h)
2515
    return w[0], h[0]
2516
2517
# update font bitmap
2518
def sys_update_char(asciiCode, fontx, fonty, img, x, y):
2519
    """Dynamically update the current frot with img.
2520
2521
    All cells using this asciiCode will be updated
2522
    at the next call to :any:`tcod.console_flush`.
2523
2524
    Args:
2525
        asciiCode (int): Ascii code corresponding to the character to update.
2526
        fontx (int): Left coordinate of the character
2527
                     in the bitmap font (in tiles)
2528
        fonty (int): Top coordinate of the character
2529
                     in the bitmap font (in tiles)
2530
        img (Image): An image containing the new character bitmap.
2531
        x (int): Left pixel of the character in the image.
2532
        y (int): Top pixel of the character in the image.
2533
    """
2534
    lib.TCOD_sys_update_char(_int(asciiCode), fontx, fonty, img, x, y)
2535
2536
def sys_register_SDL_renderer(callback):
2537
    """Register a custom randering function with libtcod.
2538
2539
    Note:
2540
        This callback will only be called by the SDL renderer.
2541
2542
    The callack will receive a :any:`CData <ffi-cdata>` void* to an
2543
    SDL_Surface* struct.
2544
2545
    The callback is called on every call to :any:`tcod.console_flush`.
2546
2547
    Args:
2548
        callback Callable[[CData], None]:
2549
            A function which takes a single argument.
2550
    """
2551
    with _PropagateException() as propagate:
2552
        @ffi.def_extern(onerror=propagate)
2553
        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...
2554
            callback(sdl_surface)
2555
        lib.TCOD_sys_register_SDL_renderer(lib._pycall_sdl_hook)
2556
2557
def sys_check_for_event(mask, k, m):
2558
    """Check for and return an event.
2559
2560
    Args:
2561
        mask (int): :any:`Event types` to wait for.
2562
        k (Optional[Key]): A tcod.Key instance which might be updated with
2563
                           an event.  Can be None.
2564
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2565
                             with an event.  Can be None.
2566
    """
2567
    return lib.TCOD_sys_check_for_event(mask, _cdata(k), _cdata(m))
2568
2569
def sys_wait_for_event(mask, k, m, flush):
2570
    """Wait for an event then return.
2571
2572
    If flush is True then the buffer will be cleared before waiting. Otherwise
2573
    each available event will be returned in the order they're recieved.
2574
2575
    Args:
2576
        mask (int): :any:`Event types` to wait for.
2577
        k (Optional[Key]): A tcod.Key instance which might be updated with
2578
                           an event.  Can be None.
2579
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2580
                             with an event.  Can be None.
2581
        flush (bool): Clear the event buffer before waiting.
2582
    """
2583
    return lib.TCOD_sys_wait_for_event(mask, _cdata(k), _cdata(m), flush)
2584
2585
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...
2586
    return lib.TCOD_sys_clipboard_set(text.encode('utf-8'))
2587
2588
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...
2589
    return ffi.string(lib.TCOD_sys_clipboard_get()).decode('utf-8')
2590