signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
@pending_deprecate()<EOL>def heightmap_kernel_transform(<EOL>hm: np.ndarray,<EOL>kernelsize: int,<EOL>dx: Sequence[int],<EOL>dy: Sequence[int],<EOL>weight: Sequence[float],<EOL>minLevel: float,<EOL>maxLevel: float,<EOL>) -> None:
cdx = ffi.new("<STR_LIT>", dx)<EOL>cdy = ffi.new("<STR_LIT>", dy)<EOL>cweight = ffi.new("<STR_LIT>", weight)<EOL>lib.TCOD_heightmap_kernel_transform(<EOL>_heightmap_cdata(hm), kernelsize, cdx, cdy, cweight, minLevel, maxLevel<EOL>)<EOL>
Apply a generic transformation on the map, so that each resulting cell value is the weighted sum of several neighbour cells. This can be used to smooth/sharpen the map. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. kernelsize (int): Should be set to the length of the parameters:: dx, dy, and weight. dx (Sequence[int]): A sequence of x coorinates. dy (Sequence[int]): A sequence of y coorinates. weight (Sequence[float]): A sequence of kernelSize cells weight. The value of each neighbour cell is scaled by its corresponding weight minLevel (float): No transformation will apply to cells below this value. maxLevel (float): No transformation will apply to cells above this value. See examples below for a simple horizontal smoothing kernel : replace value(x,y) with 0.33*value(x-1,y) + 0.33*value(x,y) + 0.33*value(x+1,y). To do this, you need a kernel of size 3 (the sum involves 3 surrounding cells). The dx,dy array will contain: * dx=-1, dy=0 for cell (x-1, y) * dx=1, dy=0 for cell (x+1, y) * dx=0, dy=0 for cell (x, y) * The weight array will contain 0.33 for each cell. Example: >>> import numpy as np >>> heightmap = np.zeros((3, 3), dtype=np.float32) >>> heightmap[:,1] = 1 >>> dx = [-1, 1, 0] >>> dy = [0, 0, 0] >>> weight = [0.33, 0.33, 0.33] >>> tcod.heightmap_kernel_transform(heightmap, 3, dx, dy, weight, ... 0.0, 1.0)
f3112:m130
@pending_deprecate()<EOL>def heightmap_add_voronoi(<EOL>hm: np.ndarray,<EOL>nbPoints: Any,<EOL>nbCoef: int,<EOL>coef: Sequence[float],<EOL>rnd: Optional[tcod.random.Random] = None,<EOL>) -> None:
nbPoints = len(coef)<EOL>ccoef = ffi.new("<STR_LIT>", coef)<EOL>lib.TCOD_heightmap_add_voronoi(<EOL>_heightmap_cdata(hm),<EOL>nbPoints,<EOL>nbCoef,<EOL>ccoef,<EOL>rnd.random_c if rnd else ffi.NULL,<EOL>)<EOL>
Add values from a Voronoi diagram to the heightmap. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. nbPoints (Any): Number of Voronoi sites. nbCoef (int): The diagram value is calculated from the nbCoef closest sites. coef (Sequence[float]): The distance to each site is scaled by the corresponding coef. Closest site : coef[0], second closest site : coef[1], ... rnd (Optional[Random]): A Random instance, or None.
f3112:m131
@deprecate("<STR_LIT>")<EOL>def heightmap_add_fbm(<EOL>hm: np.ndarray,<EOL>noise: tcod.noise.Noise,<EOL>mulx: float,<EOL>muly: float,<EOL>addx: float,<EOL>addy: float,<EOL>octaves: float,<EOL>delta: float,<EOL>scale: float,<EOL>) -> None:
noise = noise.noise_c if noise is not None else ffi.NULL<EOL>lib.TCOD_heightmap_add_fbm(<EOL>_heightmap_cdata(hm),<EOL>noise,<EOL>mulx,<EOL>muly,<EOL>addx,<EOL>addy,<EOL>octaves,<EOL>delta,<EOL>scale,<EOL>)<EOL>
Add FBM noise to the heightmap. The noise coordinate for each map cell is `((x + addx) * mulx / width, (y + addy) * muly / height)`. The value added to the heightmap is `delta + noise * scale`. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. noise (Noise): A Noise instance. mulx (float): Scaling of each x coordinate. muly (float): Scaling of each y coordinate. addx (float): Translation of each x coordinate. addy (float): Translation of each y coordinate. octaves (float): Number of octaves in the FBM sum. delta (float): The value added to all heightmap cells. scale (float): The noise value is scaled with this parameter. .. deprecated:: 8.1 An equivalent array of noise samples can be taken using a method such as :any:`Noise.sample_ogrid`.
f3112:m132
@deprecate("<STR_LIT>")<EOL>def heightmap_scale_fbm(<EOL>hm: np.ndarray,<EOL>noise: tcod.noise.Noise,<EOL>mulx: float,<EOL>muly: float,<EOL>addx: float,<EOL>addy: float,<EOL>octaves: float,<EOL>delta: float,<EOL>scale: float,<EOL>) -> None:
noise = noise.noise_c if noise is not None else ffi.NULL<EOL>lib.TCOD_heightmap_scale_fbm(<EOL>_heightmap_cdata(hm),<EOL>noise,<EOL>mulx,<EOL>muly,<EOL>addx,<EOL>addy,<EOL>octaves,<EOL>delta,<EOL>scale,<EOL>)<EOL>
Multiply the heighmap values with FBM noise. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. noise (Noise): A Noise instance. mulx (float): Scaling of each x coordinate. muly (float): Scaling of each y coordinate. addx (float): Translation of each x coordinate. addy (float): Translation of each y coordinate. octaves (float): Number of octaves in the FBM sum. delta (float): The value added to all heightmap cells. scale (float): The noise value is scaled with this parameter. .. deprecated:: 8.1 An equivalent array of noise samples can be taken using a method such as :any:`Noise.sample_ogrid`.
f3112:m133
@pending_deprecate()<EOL>def heightmap_dig_bezier(<EOL>hm: np.ndarray,<EOL>px: Tuple[int, int, int, int],<EOL>py: Tuple[int, int, int, int],<EOL>startRadius: float,<EOL>startDepth: float,<EOL>endRadius: float,<EOL>endDepth: float,<EOL>) -> None:
lib.TCOD_heightmap_dig_bezier(<EOL>_heightmap_cdata(hm),<EOL>px,<EOL>py,<EOL>startRadius,<EOL>startDepth,<EOL>endRadius,<EOL>endDepth,<EOL>)<EOL>
Carve a path along a cubic Bezier curve. Both radius and depth can vary linearly along the path. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. px (Sequence[int]): The 4 `x` coordinates of the Bezier curve. py (Sequence[int]): The 4 `y` coordinates of the Bezier curve. startRadius (float): The starting radius size. startDepth (float): The starting depth. endRadius (float): The ending radius size. endDepth (float): The ending depth.
f3112:m134
@deprecate("<STR_LIT>")<EOL>def heightmap_get_value(hm: np.ndarray, x: int, y: int) -> float:
if hm.flags["<STR_LIT>"]:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>DeprecationWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>return hm[y, x] <EOL><DEDENT>elif hm.flags["<STR_LIT>"]:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>",<EOL>DeprecationWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>return hm[x, y] <EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>
Return the value at ``x``, ``y`` in a heightmap. .. deprecated:: 2.0 Access `hm` as a NumPy array instead.
f3112:m135
@pending_deprecate()<EOL>def heightmap_get_interpolated_value(<EOL>hm: np.ndarray, x: float, y: float<EOL>) -> float:
return float(<EOL>lib.TCOD_heightmap_get_interpolated_value(_heightmap_cdata(hm), x, y)<EOL>)<EOL>
Return the interpolated height at non integer coordinates. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. x (float): A floating point x coordinate. y (float): A floating point y coordinate. Returns: float: The value at ``x``, ``y``.
f3112:m136
@pending_deprecate()<EOL>def heightmap_get_slope(hm: np.ndarray, x: int, y: int) -> float:
return float(lib.TCOD_heightmap_get_slope(_heightmap_cdata(hm), x, y))<EOL>
Return the slope between 0 and (pi / 2) at given coordinates. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. x (int): The x coordinate. y (int): The y coordinate. Returns: float: The steepness at ``x``, ``y``. From 0 to (pi / 2)
f3112:m137
@pending_deprecate()<EOL>def heightmap_get_normal(<EOL>hm: np.ndarray, x: float, y: float, waterLevel: float<EOL>) -> Tuple[float, float, float]:
cn = ffi.new("<STR_LIT>")<EOL>lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)<EOL>return tuple(cn)<EOL>
Return the map normal at given coordinates. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. x (float): The x coordinate. y (float): The y coordinate. waterLevel (float): The heightmap is considered flat below this value. Returns: Tuple[float, float, float]: An (x, y, z) vector normal.
f3112:m138
@deprecate("<STR_LIT>")<EOL>def heightmap_count_cells(hm: np.ndarray, mi: float, ma: float) -> int:
return int(lib.TCOD_heightmap_count_cells(_heightmap_cdata(hm), mi, ma))<EOL>
Return the number of map cells which value is between ``mi`` and ``ma``. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. mi (float): The lower bound. ma (float): The upper bound. Returns: int: The count of values which fall between ``mi`` and ``ma``. .. deprecated:: 8.1 Can be replaced by an equivalent NumPy function such as: ``numpy.count_nonzero((mi <= hm) & (hm < ma))``
f3112:m139
@pending_deprecate()<EOL>def heightmap_has_land_on_border(hm: np.ndarray, waterlevel: float) -> bool:
return bool(<EOL>lib.TCOD_heightmap_has_land_on_border(_heightmap_cdata(hm), waterlevel)<EOL>)<EOL>
Returns True if the map edges are below ``waterlevel``, otherwise False. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. waterLevel (float): The water level to use. Returns: bool: True if the map edges are below ``waterlevel``, otherwise False.
f3112:m140
@deprecate("<STR_LIT>")<EOL>def heightmap_get_minmax(hm: np.ndarray) -> Tuple[float, float]:
mi = ffi.new("<STR_LIT>")<EOL>ma = ffi.new("<STR_LIT>")<EOL>lib.TCOD_heightmap_get_minmax(_heightmap_cdata(hm), mi, ma)<EOL>return mi[<NUM_LIT:0>], ma[<NUM_LIT:0>]<EOL>
Return the min and max values of this heightmap. Args: hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions. Returns: Tuple[float, float]: The (min, max) values. .. deprecated:: 2.0 Use ``hm.min()`` or ``hm.max()`` instead.
f3112:m141
@deprecate("<STR_LIT>")<EOL>def heightmap_delete(hm: Any) -> None:
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy. .. deprecated:: 2.0 libtcod-cffi deletes heightmaps automatically.
f3112:m142
@pending_deprecate()<EOL>def image_load(filename: str) -> tcod.image.Image:
return tcod.image.Image._from_cdata(<EOL>ffi.gc(lib.TCOD_image_load(_bytes(filename)), lib.TCOD_image_delete)<EOL>)<EOL>
Load an image file into an Image instance and return it. Args: filename (AnyStr): Path to a .bmp or .png image file.
f3112:m153
@pending_deprecate()<EOL>def image_from_console(console: tcod.console.Console) -> tcod.image.Image:
return tcod.image.Image._from_cdata(<EOL>ffi.gc(<EOL>lib.TCOD_image_from_console(_console(console)),<EOL>lib.TCOD_image_delete,<EOL>)<EOL>)<EOL>
Return an Image with a Consoles pixel data. This effectively takes a screen-shot of the Console. Args: console (Console): Any Console instance.
f3112:m154
@deprecate("<STR_LIT>")<EOL>def image_delete(image: tcod.image.Image) -> None:
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy.
f3112:m164
@deprecate("<STR_LIT>")<EOL>def line_init(xo: int, yo: int, xd: int, yd: int) -> None:
lib.TCOD_line_init(xo, yo, xd, yd)<EOL>
Initilize a line whose points will be returned by `line_step`. This function does not return anything on its own. Does not include the origin point. Args: xo (int): X starting point. yo (int): Y starting point. xd (int): X destination point. yd (int): Y destination point. .. deprecated:: 2.0 Use `line_iter` instead.
f3112:m165
@deprecate("<STR_LIT>")<EOL>def line_step() -> Union[Tuple[int, int], Tuple[None, None]]:
x = ffi.new("<STR_LIT>")<EOL>y = ffi.new("<STR_LIT>")<EOL>ret = lib.TCOD_line_step(x, y)<EOL>if not ret:<EOL><INDENT>return x[<NUM_LIT:0>], y[<NUM_LIT:0>]<EOL><DEDENT>return None, None<EOL>
After calling line_init returns (x, y) points of the line. Once all points are exhausted this function will return (None, None) Returns: Union[Tuple[int, int], Tuple[None, None]]: The next (x, y) point of the line setup by line_init, or (None, None) if there are no more points. .. deprecated:: 2.0 Use `line_iter` instead.
f3112:m166
@deprecate("<STR_LIT>")<EOL>def line(<EOL>xo: int, yo: int, xd: int, yd: int, py_callback: Callable[[int, int], bool]<EOL>) -> bool:
for x, y in line_iter(xo, yo, xd, yd):<EOL><INDENT>if not py_callback(x, y):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Iterate over a line using a callback function. Your callback function will take x and y parameters and return True to continue iteration or False to stop iteration and return. This function includes both the start and end points. Args: xo (int): X starting point. yo (int): Y starting point. xd (int): X destination point. yd (int): Y destination point. py_callback (Callable[[int, int], bool]): A callback which takes x and y parameters and returns bool. Returns: bool: False if the callback cancels the line interation by returning False or None, otherwise True. .. deprecated:: 2.0 Use `line_iter` instead.
f3112:m167
def line_iter(xo: int, yo: int, xd: int, yd: int) -> Iterator[Tuple[int, int]]:
data = ffi.new("<STR_LIT>")<EOL>lib.TCOD_line_init_mt(xo, yo, xd, yd, data)<EOL>x = ffi.new("<STR_LIT>")<EOL>y = ffi.new("<STR_LIT>")<EOL>yield xo, yo<EOL>while not lib.TCOD_line_step_mt(x, y, data):<EOL><INDENT>yield (x[<NUM_LIT:0>], y[<NUM_LIT:0>])<EOL><DEDENT>
returns an Iterable This Iterable does not include the origin point. Args: xo (int): X starting point. yo (int): Y starting point. xd (int): X destination point. yd (int): Y destination point. Returns: Iterable[Tuple[int,int]]: An Iterable of (x,y) points.
f3112:m168
def line_where(<EOL>x1: int, y1: int, x2: int, y2: int, inclusive: bool = True<EOL>) -> Tuple[np.array, np.array]:
length = max(abs(x1 - x2), abs(y1 - y2)) + <NUM_LIT:1><EOL>array = np.ndarray((<NUM_LIT:2>, length), dtype=np.intc)<EOL>x = ffi.cast("<STR_LIT>", array[<NUM_LIT:0>].ctypes.data)<EOL>y = ffi.cast("<STR_LIT>", array[<NUM_LIT:1>].ctypes.data)<EOL>lib.LineWhere(x1, y1, x2, y2, x, y)<EOL>if not inclusive:<EOL><INDENT>array = array[:, <NUM_LIT:1>:]<EOL><DEDENT>return tuple(array)<EOL>
Return a NumPy index array following a Bresenham line. If `inclusive` is true then the start point is included in the result. Example: >>> where = tcod.line_where(1, 0, 3, 4) >>> where (array([1, 1, 2, 2, 3]...), array([0, 1, 2, 3, 4]...)) >>> array = np.zeros((5, 5), dtype=np.int32) >>> array[where] = np.arange(len(where[0])) + 1 >>> array array([[0, 0, 0, 0, 0], [1, 2, 0, 0, 0], [0, 0, 3, 4, 0], [0, 0, 0, 0, 5], [0, 0, 0, 0, 0]]...) .. versionadded:: 4.6
f3112:m169
@deprecate("<STR_LIT>")<EOL>def map_new(w: int, h: int) -> tcod.map.Map:
return tcod.map.Map(w, h)<EOL>
Return a :any:`tcod.map.Map` with a width and height. .. deprecated:: 4.5 Use the :any:`tcod.map` module for working with field-of-view, or :any:`tcod.path` for working with path-finding.
f3112:m170
@deprecate("<STR_LIT>")<EOL>def map_copy(source: tcod.map.Map, dest: tcod.map.Map) -> None:
if source.width != dest.width or source.height != dest.height:<EOL><INDENT>dest.__init__( <EOL>source.width, source.height, source._order<EOL>)<EOL><DEDENT>dest._Map__buffer[:] = source._Map__buffer[:]<EOL>
Copy map data from `source` to `dest`. .. deprecated:: 4.5 Use Python's copy module, or see :any:`tcod.map.Map` and assign between array attributes manually.
f3112:m171
@deprecate("<STR_LIT>")<EOL>def map_set_properties(<EOL>m: tcod.map.Map, x: int, y: int, isTrans: bool, isWalk: bool<EOL>) -> None:
lib.TCOD_map_set_properties(m.map_c, x, y, isTrans, isWalk)<EOL>
Set the properties of a single cell. .. note:: This function is slow. .. deprecated:: 4.5 Use :any:`tcod.map.Map.transparent` and :any:`tcod.map.Map.walkable` arrays to set these properties.
f3112:m172
@deprecate("<STR_LIT>")<EOL>def map_clear(<EOL>m: tcod.map.Map, transparent: bool = False, walkable: bool = False<EOL>) -> None:
m.transparent[:] = transparent<EOL>m.walkable[:] = walkable<EOL>
Change all map cells to a specific value. .. deprecated:: 4.5 Use :any:`tcod.map.Map.transparent` and :any:`tcod.map.Map.walkable` arrays to set these properties.
f3112:m173
@deprecate("<STR_LIT>")<EOL>def map_compute_fov(<EOL>m: tcod.map.Map,<EOL>x: int,<EOL>y: int,<EOL>radius: int = <NUM_LIT:0>,<EOL>light_walls: bool = True,<EOL>algo: int = FOV_RESTRICTIVE,<EOL>) -> None:
m.compute_fov(x, y, radius, light_walls, algo)<EOL>
Compute the field-of-view for a map instance. .. deprecated:: 4.5 Use :any:`tcod.map.Map.compute_fov` instead.
f3112:m174
@deprecate("<STR_LIT>")<EOL>def map_is_in_fov(m: tcod.map.Map, x: int, y: int) -> bool:
return bool(lib.TCOD_map_is_in_fov(m.map_c, x, y))<EOL>
Return True if the cell at x,y is lit by the last field-of-view algorithm. .. note:: This function is slow. .. deprecated:: 4.5 Use :any:`tcod.map.Map.fov` to check this property.
f3112:m175
@deprecate("<STR_LIT>")<EOL>def map_is_transparent(m: tcod.map.Map, x: int, y: int) -> bool:
return bool(lib.TCOD_map_is_transparent(m.map_c, x, y))<EOL>
.. note:: This function is slow. .. deprecated:: 4.5 Use :any:`tcod.map.Map.transparent` to check this property.
f3112:m176
@deprecate("<STR_LIT>")<EOL>def map_is_walkable(m: tcod.map.Map, x: int, y: int) -> bool:
return bool(lib.TCOD_map_is_walkable(m.map_c, x, y))<EOL>
.. note:: This function is slow. .. deprecated:: 4.5 Use :any:`tcod.map.Map.walkable` to check this property.
f3112:m177
@deprecate("<STR_LIT>")<EOL>def map_delete(m: tcod.map.Map) -> None:
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy.
f3112:m178
@deprecate("<STR_LIT>")<EOL>def map_get_width(map: tcod.map.Map) -> int:
return map.width<EOL>
Return the width of a map. .. deprecated:: 4.5 Check the :any:`tcod.map.Map.width` attribute instead.
f3112:m179
@deprecate("<STR_LIT>")<EOL>def map_get_height(map: tcod.map.Map) -> int:
return map.height<EOL>
Return the height of a map. .. deprecated:: 4.5 Check the :any:`tcod.map.Map.height` attribute instead.
f3112:m180
@pending_deprecate()<EOL>def mouse_show_cursor(visible: bool) -> None:
lib.TCOD_mouse_show_cursor(visible)<EOL>
Change the visibility of the mouse cursor.
f3112:m181
@pending_deprecate()<EOL>def mouse_is_cursor_visible() -> bool:
return bool(lib.TCOD_mouse_is_cursor_visible())<EOL>
Return True if the mouse cursor is visible.
f3112:m182
@pending_deprecate()<EOL>def noise_new(<EOL>dim: int,<EOL>h: float = NOISE_DEFAULT_HURST,<EOL>l: float = NOISE_DEFAULT_LACUNARITY, <EOL>random: Optional[tcod.random.Random] = None,<EOL>) -> tcod.noise.Noise:
return tcod.noise.Noise(dim, hurst=h, lacunarity=l, seed=random)<EOL>
Return a new Noise instance. Args: dim (int): Number of dimensions. From 1 to 4. h (float): The hurst exponent. Should be in the 0.0-1.0 range. l (float): The noise lacunarity. random (Optional[Random]): A Random instance, or None. Returns: Noise: The new Noise instance.
f3112:m190
@pending_deprecate()<EOL>def noise_set_type(n: tcod.noise.Noise, typ: int) -> None:
n.algorithm = typ<EOL>
Set a Noise objects default noise algorithm. Args: typ (int): Any NOISE_* constant.
f3112:m191
@pending_deprecate()<EOL>def noise_get(<EOL>n: tcod.noise.Noise, f: Sequence[float], typ: int = NOISE_DEFAULT<EOL>) -> float:
return float(lib.TCOD_noise_get_ex(n.noise_c, ffi.new("<STR_LIT>", f), typ))<EOL>
Return the noise value sampled from the ``f`` coordinate. ``f`` should be a tuple or list with a length matching :any:`Noise.dimensions`. If ``f`` is shoerter than :any:`Noise.dimensions` the missing coordinates will be filled with zeros. Args: n (Noise): A Noise instance. f (Sequence[float]): The point to sample the noise from. typ (int): The noise algorithm to use. Returns: float: The sampled noise value.
f3112:m192
@pending_deprecate()<EOL>def noise_get_fbm(<EOL>n: tcod.noise.Noise,<EOL>f: Sequence[float],<EOL>oc: float,<EOL>typ: int = NOISE_DEFAULT,<EOL>) -> float:
return float(<EOL>lib.TCOD_noise_get_fbm_ex(n.noise_c, ffi.new("<STR_LIT>", f), oc, typ)<EOL>)<EOL>
Return the fractal Brownian motion sampled from the ``f`` coordinate. Args: n (Noise): A Noise instance. f (Sequence[float]): The point to sample the noise from. typ (int): The noise algorithm to use. octaves (float): The level of level. Should be more than 1. Returns: float: The sampled noise value.
f3112:m193
@pending_deprecate()<EOL>def noise_get_turbulence(<EOL>n: tcod.noise.Noise,<EOL>f: Sequence[float],<EOL>oc: float,<EOL>typ: int = NOISE_DEFAULT,<EOL>) -> float:
return float(<EOL>lib.TCOD_noise_get_turbulence_ex(<EOL>n.noise_c, ffi.new("<STR_LIT>", f), oc, typ<EOL>)<EOL>)<EOL>
Return the turbulence noise sampled from the ``f`` coordinate. Args: n (Noise): A Noise instance. f (Sequence[float]): The point to sample the noise from. typ (int): The noise algorithm to use. octaves (float): The level of level. Should be more than 1. Returns: float: The sampled noise value.
f3112:m194
@deprecate("<STR_LIT>")<EOL>def noise_delete(n: tcod.noise.Noise) -> None:<EOL>
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy.
f3112:m195
def _unpack_union(type_: int, union: Any) -> Any:
if type_ == lib.TCOD_TYPE_BOOL:<EOL><INDENT>return bool(union.b)<EOL><DEDENT>elif type_ == lib.TCOD_TYPE_CHAR:<EOL><INDENT>return union.c.decode("<STR_LIT>")<EOL><DEDENT>elif type_ == lib.TCOD_TYPE_INT:<EOL><INDENT>return union.i<EOL><DEDENT>elif type_ == lib.TCOD_TYPE_FLOAT:<EOL><INDENT>return union.f<EOL><DEDENT>elif (<EOL>type_ == lib.TCOD_TYPE_STRING<EOL>or lib.TCOD_TYPE_VALUELIST15 >= type_ >= lib.TCOD_TYPE_VALUELIST00<EOL>):<EOL><INDENT>return _unpack_char_p(union.s)<EOL><DEDENT>elif type_ == lib.TCOD_TYPE_COLOR:<EOL><INDENT>return Color._new_from_cdata(union.col)<EOL><DEDENT>elif type_ == lib.TCOD_TYPE_DICE:<EOL><INDENT>return Dice(union.dice)<EOL><DEDENT>elif type_ & lib.TCOD_TYPE_LIST:<EOL><INDENT>return _convert_TCODList(union.list, type_ & <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % type_)<EOL><DEDENT>
unpack items from parser new_property (value_converter)
f3112:m196
@deprecate("<STR_LIT>")<EOL>def parser_delete(parser: Any) -> None:<EOL>
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy.
f3112:m206
@pending_deprecate()<EOL>def random_get_instance() -> tcod.random.Random:
return tcod.random.Random._new_from_cdata(<EOL>ffi.cast("<STR_LIT>", lib.TCOD_random_get_instance())<EOL>)<EOL>
Return the default Random instance. Returns: Random: A Random instance using the default random number generator.
f3112:m215
@pending_deprecate()<EOL>def random_new(algo: int = RNG_CMWC) -> tcod.random.Random:
return tcod.random.Random(algo)<EOL>
Return a new Random instance. Using ``algo``. Args: algo (int): The random number algorithm to use. Returns: Random: A new Random instance using the given algorithm.
f3112:m216
@pending_deprecate()<EOL>def random_new_from_seed(<EOL>seed: Hashable, algo: int = RNG_CMWC<EOL>) -> tcod.random.Random:
return tcod.random.Random(algo, seed)<EOL>
Return a new Random instance. Using the given ``seed`` and ``algo``. Args: seed (Hashable): The RNG seed. Should be a 32-bit integer, but any hashable object is accepted. algo (int): The random number algorithm to use. Returns: Random: A new Random instance using the given algorithm.
f3112:m217
@pending_deprecate()<EOL>def random_set_distribution(<EOL>rnd: Optional[tcod.random.Random], dist: int<EOL>) -> None:
lib.TCOD_random_set_distribution(rnd.random_c if rnd else ffi.NULL, dist)<EOL>
Change the distribution mode of a random number generator. Args: rnd (Optional[Random]): A Random instance, or None to use the default. dist (int): The distribution mode to use. Should be DISTRIBUTION_*.
f3112:m218
@pending_deprecate()<EOL>def random_get_int(rnd: Optional[tcod.random.Random], mi: int, ma: int) -> int:
return int(<EOL>lib.TCOD_random_get_int(rnd.random_c if rnd else ffi.NULL, mi, ma)<EOL>)<EOL>
Return a random integer in the range: ``mi`` <= n <= ``ma``. The result is affected by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (int): The lower bound of the random range, inclusive. high (int): The upper bound of the random range, inclusive. Returns: int: A random integer in the range ``mi`` <= n <= ``ma``.
f3112:m219
@pending_deprecate()<EOL>def random_get_float(<EOL>rnd: Optional[tcod.random.Random], mi: float, ma: float<EOL>) -> float:
return float(<EOL>lib.TCOD_random_get_double(rnd.random_c if rnd else ffi.NULL, mi, ma)<EOL>)<EOL>
Return a random float in the range: ``mi`` <= n <= ``ma``. The result is affected by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (float): The lower bound of the random range, inclusive. high (float): The upper bound of the random range, inclusive. Returns: float: A random double precision float in the range ``mi`` <= n <= ``ma``.
f3112:m220
@deprecate("<STR_LIT>")<EOL>def random_get_double(<EOL>rnd: Optional[tcod.random.Random], mi: float, ma: float<EOL>) -> float:
return float(<EOL>lib.TCOD_random_get_double(rnd.random_c if rnd else ffi.NULL, mi, ma)<EOL>)<EOL>
Return a random float in the range: ``mi`` <= n <= ``ma``. .. deprecated:: 2.0 Use :any:`random_get_float` instead. Both funtions return a double precision float.
f3112:m221
@pending_deprecate()<EOL>def random_get_int_mean(<EOL>rnd: Optional[tcod.random.Random], mi: int, ma: int, mean: int<EOL>) -> int:
return int(<EOL>lib.TCOD_random_get_int_mean(<EOL>rnd.random_c if rnd else ffi.NULL, mi, ma, mean<EOL>)<EOL>)<EOL>
Return a random weighted integer in the range: ``mi`` <= n <= ``ma``. The result is affacted by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (int): The lower bound of the random range, inclusive. high (int): The upper bound of the random range, inclusive. mean (int): The mean return value. Returns: int: A random weighted integer in the range ``mi`` <= n <= ``ma``.
f3112:m222
@pending_deprecate()<EOL>def random_get_float_mean(<EOL>rnd: Optional[tcod.random.Random], mi: float, ma: float, mean: float<EOL>) -> float:
return float(<EOL>lib.TCOD_random_get_double_mean(<EOL>rnd.random_c if rnd else ffi.NULL, mi, ma, mean<EOL>)<EOL>)<EOL>
Return a random weighted float in the range: ``mi`` <= n <= ``ma``. The result is affacted by calls to :any:`random_set_distribution`. Args: rnd (Optional[Random]): A Random instance, or None to use the default. low (float): The lower bound of the random range, inclusive. high (float): The upper bound of the random range, inclusive. mean (float): The mean return value. Returns: float: A random weighted double precision float in the range ``mi`` <= n <= ``ma``.
f3112:m223
@deprecate("<STR_LIT>")<EOL>def random_get_double_mean(<EOL>rnd: Optional[tcod.random.Random], mi: float, ma: float, mean: float<EOL>) -> float:
return float(<EOL>lib.TCOD_random_get_double_mean(<EOL>rnd.random_c if rnd else ffi.NULL, mi, ma, mean<EOL>)<EOL>)<EOL>
Return a random weighted float in the range: ``mi`` <= n <= ``ma``. .. deprecated:: 2.0 Use :any:`random_get_float_mean` instead. Both funtions return a double precision float.
f3112:m224
@deprecate("<STR_LIT>")<EOL>def random_save(rnd: Optional[tcod.random.Random]) -> tcod.random.Random:
return tcod.random.Random._new_from_cdata(<EOL>ffi.gc(<EOL>ffi.cast(<EOL>"<STR_LIT>",<EOL>lib.TCOD_random_save(rnd.random_c if rnd else ffi.NULL),<EOL>),<EOL>lib.TCOD_random_delete,<EOL>)<EOL>)<EOL>
Return a copy of a random number generator. .. deprecated:: 8.4 You can use the standard library copy and pickle modules to save a random state.
f3112:m225
@deprecate("<STR_LIT>")<EOL>def random_restore(<EOL>rnd: Optional[tcod.random.Random], backup: tcod.random.Random<EOL>) -> None:
lib.TCOD_random_restore(rnd.random_c if rnd else ffi.NULL, backup.random_c)<EOL>
Restore a random number generator from a backed up copy. Args: rnd (Optional[Random]): A Random instance, or None to use the default. backup (Random): The Random instance which was used as a backup. .. deprecated:: 8.4 You can use the standard library copy and pickle modules to save a random state.
f3112:m226
@deprecate("<STR_LIT>")<EOL>def random_delete(rnd: tcod.random.Random) -> None:
Does nothing. libtcod objects are managed by Python's garbage collector. This function exists for backwards compatibility with libtcodpy.
f3112:m227
def sys_set_fps(fps: int) -> None:
lib.TCOD_sys_set_fps(fps)<EOL>
Set the maximum frame rate. You can disable the frame limit again by setting fps to 0. Args: fps (int): A frame rate limit (i.e. 60)
f3112:m236
def sys_get_fps() -> int:
return int(lib.TCOD_sys_get_fps())<EOL>
Return the current frames per second. This the actual frame rate, not the frame limit set by :any:`tcod.sys_set_fps`. This number is updated every second. Returns: int: The currently measured frame rate.
f3112:m237
def sys_get_last_frame_length() -> float:
return float(lib.TCOD_sys_get_last_frame_length())<EOL>
Return the delta time of the last rendered frame in seconds. Returns: float: The delta time of the last rendered frame.
f3112:m238
@deprecate("<STR_LIT>")<EOL>def sys_sleep_milli(val: int) -> None:
lib.TCOD_sys_sleep_milli(val)<EOL>
Sleep for 'val' milliseconds. Args: val (int): Time to sleep for in milliseconds. .. deprecated:: 2.0 Use :any:`time.sleep` instead.
f3112:m239
@deprecate("<STR_LIT>")<EOL>def sys_elapsed_milli() -> int:
return int(lib.TCOD_sys_elapsed_milli())<EOL>
Get number of milliseconds since the start of the program. Returns: int: Time since the progeam has started in milliseconds. .. deprecated:: 2.0 Use :any:`time.clock` instead.
f3112:m240
@deprecate("<STR_LIT>")<EOL>def sys_elapsed_seconds() -> float:
return float(lib.TCOD_sys_elapsed_seconds())<EOL>
Get number of seconds since the start of the program. Returns: float: Time since the progeam has started in seconds. .. deprecated:: 2.0 Use :any:`time.clock` instead.
f3112:m241
def sys_set_renderer(renderer: int) -> None:
lib.TCOD_sys_set_renderer(renderer)<EOL>if tcod.console._root_console is not None:<EOL><INDENT>tcod.console.Console._get_root()<EOL><DEDENT>
Change the current rendering mode to renderer. .. deprecated:: 2.0 RENDERER_GLSL and RENDERER_OPENGL are not currently available.
f3112:m242
def sys_get_renderer() -> int:
return int(lib.TCOD_sys_get_renderer())<EOL>
Return the current rendering mode.
f3112:m243
def sys_save_screenshot(name: Optional[str] = None) -> None:
lib.TCOD_sys_save_screenshot(<EOL>_bytes(name) if name is not None else ffi.NULL<EOL>)<EOL>
Save a screenshot to a file. By default this will automatically save screenshots in the working directory. The automatic names are formatted as screenshotNNN.png. For example: screenshot000.png, screenshot001.png, etc. Whichever is available first. Args: file Optional[AnyStr]: File path to save screenshot.
f3112:m244
@pending_deprecate()<EOL>def sys_force_fullscreen_resolution(width: int, height: int) -> None:
lib.TCOD_sys_force_fullscreen_resolution(width, height)<EOL>
Force a specific resolution in fullscreen. Will use the smallest available resolution so that: * resolution width >= width and resolution width >= root console width * font char width * resolution height >= height and resolution height >= root console height * font char height Args: width (int): The desired resolution width. height (int): The desired resolution height.
f3112:m245
def sys_get_current_resolution() -> Tuple[int, int]:
w = ffi.new("<STR_LIT>")<EOL>h = ffi.new("<STR_LIT>")<EOL>lib.TCOD_sys_get_current_resolution(w, h)<EOL>return w[<NUM_LIT:0>], h[<NUM_LIT:0>]<EOL>
Return the current resolution as (width, height) Returns: Tuple[int,int]: The current resolution.
f3112:m246
def sys_get_char_size() -> Tuple[int, int]:
w = ffi.new("<STR_LIT>")<EOL>h = ffi.new("<STR_LIT>")<EOL>lib.TCOD_sys_get_char_size(w, h)<EOL>return w[<NUM_LIT:0>], h[<NUM_LIT:0>]<EOL>
Return the current fonts character size as (width, height) Returns: Tuple[int,int]: The current font glyph size in (width, height)
f3112:m247
@pending_deprecate()<EOL>def sys_update_char(<EOL>asciiCode: int,<EOL>fontx: int,<EOL>fonty: int,<EOL>img: tcod.image.Image,<EOL>x: int,<EOL>y: int,<EOL>) -> None:
lib.TCOD_sys_update_char(_int(asciiCode), fontx, fonty, img, x, y)<EOL>
Dynamically update the current font with img. All cells using this asciiCode will be updated at the next call to :any:`tcod.console_flush`. Args: asciiCode (int): Ascii code corresponding to the character to update. fontx (int): Left coordinate of the character in the bitmap font (in tiles) fonty (int): Top coordinate of the character in the bitmap font (in tiles) img (Image): An image containing the new character bitmap. x (int): Left pixel of the character in the image. y (int): Top pixel of the character in the image.
f3112:m248
@pending_deprecate()<EOL>def sys_register_SDL_renderer(callback: Callable[[Any], None]) -> None:
with _PropagateException() as propagate:<EOL><INDENT>@ffi.def_extern(onerror=propagate) <EOL>def _pycall_sdl_hook(sdl_surface: Any) -> None:<EOL><INDENT>callback(sdl_surface)<EOL><DEDENT>lib.TCOD_sys_register_SDL_renderer(lib._pycall_sdl_hook)<EOL><DEDENT>
Register a custom randering function with libtcod. Note: This callback will only be called by the SDL renderer. The callack will receive a :any:`CData <ffi-cdata>` void* to an SDL_Surface* struct. The callback is called on every call to :any:`tcod.console_flush`. Args: callback Callable[[CData], None]: A function which takes a single argument.
f3112:m249
@deprecate("<STR_LIT>")<EOL>def sys_check_for_event(<EOL>mask: int, k: Optional[Key], m: Optional[Mouse]<EOL>) -> int:
return int(<EOL>lib.TCOD_sys_check_for_event(<EOL>mask, k.key_p if k else ffi.NULL, m.mouse_p if m else ffi.NULL<EOL>)<EOL>)<EOL>
Check for and return an event. Args: mask (int): :any:`Event types` to wait for. k (Optional[Key]): A tcod.Key instance which might be updated with an event. Can be None. m (Optional[Mouse]): A tcod.Mouse instance which might be updated with an event. Can be None. .. deprecated:: 9.3 Use the :any:`tcod.event.get` function to check for events.
f3112:m250
@deprecate("<STR_LIT>")<EOL>def sys_wait_for_event(<EOL>mask: int, k: Optional[Key], m: Optional[Mouse], flush: bool<EOL>) -> int:
return int(<EOL>lib.TCOD_sys_wait_for_event(<EOL>mask,<EOL>k.key_p if k else ffi.NULL,<EOL>m.mouse_p if m else ffi.NULL,<EOL>flush,<EOL>)<EOL>)<EOL>
Wait for an event then return. If flush is True then the buffer will be cleared before waiting. Otherwise each available event will be returned in the order they're recieved. Args: mask (int): :any:`Event types` to wait for. k (Optional[Key]): A tcod.Key instance which might be updated with an event. Can be None. m (Optional[Mouse]): A tcod.Mouse instance which might be updated with an event. Can be None. flush (bool): Clear the event buffer before waiting. .. deprecated:: 9.3 Use the :any:`tcod.event.wait` function to wait for events.
f3112:m251
@deprecate("<STR_LIT>")<EOL>def sys_clipboard_set(text: str) -> bool:
return bool(lib.TCOD_sys_clipboard_set(text.encode("<STR_LIT:utf-8>")))<EOL>
Sets the clipboard to `text`. .. deprecated:: 6.0 This function does not provide reliable access to the clipboard.
f3112:m252
@deprecate("<STR_LIT>")<EOL>def sys_clipboard_get() -> str:
return str(ffi.string(lib.TCOD_sys_clipboard_get()).decode("<STR_LIT:utf-8>"))<EOL>
Return the current value of the clipboard. .. deprecated:: 6.0 This function does not provide reliable access to the clipboard.
f3112:m253
@atexit.register<EOL>def _atexit_verify() -> None:
if lib.TCOD_ctx.root:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>ResourceWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>lib.TCOD_console_delete(ffi.NULL)<EOL><DEDENT>
Warns if the libtcod root console is implicitly deleted.
f3112:m254
def __init__(<EOL>self,<EOL>width: int,<EOL>height: int,<EOL>back_r: int = <NUM_LIT:0>,<EOL>back_g: int = <NUM_LIT:0>,<EOL>back_b: int = <NUM_LIT:0>,<EOL>fore_r: int = <NUM_LIT:0>,<EOL>fore_g: int = <NUM_LIT:0>,<EOL>fore_b: int = <NUM_LIT:0>,<EOL>char: str = "<STR_LIT:U+0020>",<EOL>) -> None:
warnings.warn(<EOL>"<STR_LIT>",<EOL>DeprecationWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>self.width = width<EOL>self.height = height<EOL>self.clear(back_r, back_g, back_b, fore_r, fore_g, fore_b, char)<EOL>
initialize with given width and height. values to fill the buffer are optional, defaults to black with no characters.
f3112:c0:m0
def clear(<EOL>self,<EOL>back_r: int = <NUM_LIT:0>,<EOL>back_g: int = <NUM_LIT:0>,<EOL>back_b: int = <NUM_LIT:0>,<EOL>fore_r: int = <NUM_LIT:0>,<EOL>fore_g: int = <NUM_LIT:0>,<EOL>fore_b: int = <NUM_LIT:0>,<EOL>char: str = "<STR_LIT:U+0020>",<EOL>) -> None:
n = self.width * self.height<EOL>self.back_r = [back_r] * n<EOL>self.back_g = [back_g] * n<EOL>self.back_b = [back_b] * n<EOL>self.fore_r = [fore_r] * n<EOL>self.fore_g = [fore_g] * n<EOL>self.fore_b = [fore_b] * n<EOL>self.char = [ord(char)] * n<EOL>
Clears the console. Values to fill it with are optional, defaults to black with no characters. Args: back_r (int): Red background color, from 0 to 255. back_g (int): Green background color, from 0 to 255. back_b (int): Blue background color, from 0 to 255. fore_r (int): Red foreground color, from 0 to 255. fore_g (int): Green foreground color, from 0 to 255. fore_b (int): Blue foreground color, from 0 to 255. char (AnyStr): A single character str or bytes object.
f3112:c0:m1
def copy(self) -> "<STR_LIT>":
other = ConsoleBuffer(<NUM_LIT:0>, <NUM_LIT:0>) <EOL>other.width = self.width<EOL>other.height = self.height<EOL>other.back_r = list(self.back_r) <EOL>other.back_g = list(self.back_g)<EOL>other.back_b = list(self.back_b)<EOL>other.fore_r = list(self.fore_r)<EOL>other.fore_g = list(self.fore_g)<EOL>other.fore_b = list(self.fore_b)<EOL>other.char = list(self.char)<EOL>return other<EOL>
Returns a copy of this ConsoleBuffer. Returns: ConsoleBuffer: A new ConsoleBuffer copy.
f3112:c0:m2
def set_fore(<EOL>self, x: int, y: int, r: int, g: int, b: int, char: str<EOL>) -> None:
i = self.width * y + x<EOL>self.fore_r[i] = r<EOL>self.fore_g[i] = g<EOL>self.fore_b[i] = b<EOL>self.char[i] = ord(char)<EOL>
Set the character and foreground color of one cell. Args: x (int): X position to change. y (int): Y position to change. r (int): Red foreground color, from 0 to 255. g (int): Green foreground color, from 0 to 255. b (int): Blue foreground color, from 0 to 255. char (AnyStr): A single character str or bytes object.
f3112:c0:m3
def set_back(self, x: int, y: int, r: int, g: int, b: int) -> None:
i = self.width * y + x<EOL>self.back_r[i] = r<EOL>self.back_g[i] = g<EOL>self.back_b[i] = b<EOL>
Set the background color of one cell. Args: x (int): X position to change. y (int): Y position to change. r (int): Red background color, from 0 to 255. g (int): Green background color, from 0 to 255. b (int): Blue background color, from 0 to 255.
f3112:c0:m4
def set(<EOL>self,<EOL>x: int,<EOL>y: int,<EOL>back_r: int,<EOL>back_g: int,<EOL>back_b: int,<EOL>fore_r: int,<EOL>fore_g: int,<EOL>fore_b: int,<EOL>char: str,<EOL>) -> None:
i = self.width * y + x<EOL>self.back_r[i] = back_r<EOL>self.back_g[i] = back_g<EOL>self.back_b[i] = back_b<EOL>self.fore_r[i] = fore_r<EOL>self.fore_g[i] = fore_g<EOL>self.fore_b[i] = fore_b<EOL>self.char[i] = ord(char)<EOL>
Set the background color, foreground color and character of one cell. Args: x (int): X position to change. y (int): Y position to change. back_r (int): Red background color, from 0 to 255. back_g (int): Green background color, from 0 to 255. back_b (int): Blue background color, from 0 to 255. fore_r (int): Red foreground color, from 0 to 255. fore_g (int): Green foreground color, from 0 to 255. fore_b (int): Blue foreground color, from 0 to 255. char (AnyStr): A single character str or bytes object.
f3112:c0:m5
def blit(<EOL>self,<EOL>dest: tcod.console.Console,<EOL>fill_fore: bool = True,<EOL>fill_back: bool = True,<EOL>) -> None:
if not dest:<EOL><INDENT>dest = tcod.console.Console._from_cdata(ffi.NULL)<EOL><DEDENT>if dest.width != self.width or dest.height != self.height:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if fill_back:<EOL><INDENT>bg = dest.bg.ravel()<EOL>bg[<NUM_LIT:0>::<NUM_LIT:3>] = self.back_r<EOL>bg[<NUM_LIT:1>::<NUM_LIT:3>] = self.back_g<EOL>bg[<NUM_LIT:2>::<NUM_LIT:3>] = self.back_b<EOL><DEDENT>if fill_fore:<EOL><INDENT>fg = dest.fg.ravel()<EOL>fg[<NUM_LIT:0>::<NUM_LIT:3>] = self.fore_r<EOL>fg[<NUM_LIT:1>::<NUM_LIT:3>] = self.fore_g<EOL>fg[<NUM_LIT:2>::<NUM_LIT:3>] = self.fore_b<EOL>dest.ch.ravel()[:] = self.char<EOL><DEDENT>
Use libtcod's "fill" functions to write the buffer to a console. Args: dest (Console): Console object to modify. fill_fore (bool): If True, fill the foreground color and characters. fill_back (bool): If True, fill the background color.
f3112:c0:m6
def __repr__(self) -> str:
params = []<EOL>params.append(<EOL>"<STR_LIT>" % (self.pressed, _LOOKUP_VK[self.vk])<EOL>)<EOL>if self.c:<EOL><INDENT>params.append("<STR_LIT>" % chr(self.c))<EOL><DEDENT>if self.text:<EOL><INDENT>params.append("<STR_LIT>" % self.text)<EOL><DEDENT>for attr in [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]:<EOL><INDENT>if getattr(self, attr):<EOL><INDENT>params.append("<STR_LIT>" % (attr, getattr(self, attr)))<EOL><DEDENT><DEDENT>return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(params)<EOL>
Return a representation of this Key object.
f3112:c2:m3
def __repr__(self) -> str:
params = []<EOL>for attr in ["<STR_LIT:x>", "<STR_LIT:y>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if getattr(self, attr) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>params.append("<STR_LIT>" % (attr, getattr(self, attr)))<EOL><DEDENT>for attr in [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]:<EOL><INDENT>if getattr(self, attr):<EOL><INDENT>params.append("<STR_LIT>" % (attr, getattr(self, attr)))<EOL><DEDENT><DEDENT>return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>".join(params)<EOL>
Return a representation of this Mouse object.
f3112:c3:m1
def compute_fov(<EOL>transparency: np.array,<EOL>x: int,<EOL>y: int,<EOL>radius: int = <NUM_LIT:0>,<EOL>light_walls: bool = True,<EOL>algorithm: int = tcod.constants.FOV_RESTRICTIVE,<EOL>) -> np.array:
if len(transparency.shape) != <NUM_LIT:2>:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % transparency.shape<EOL>)<EOL><DEDENT>map_ = Map(transparency.shape[<NUM_LIT:1>], transparency.shape[<NUM_LIT:0>])<EOL>map_.transparent[...] = transparency<EOL>map_.compute_fov(x, y, radius, light_walls, algorithm)<EOL>return map_.fov<EOL>
Return the visible area of a field-of-view computation. `transparency` is a 2 dimensional array where all non-zero values are considered transparent. The returned array will match the shape of this array. `x` and `y` are the 1st and 2nd coordinates of the origin point. Areas are visible when they can be seen from this point-of-view. `radius` is the maximum view distance from `x`/`y`. If this is zero then the maximum distance is used. If `light_walls` is True then visible obstacles will be returned, otherwise only transparent areas will be. `algorithm` is the field-of-view algorithm to run. The default value is `tcod.FOV_RESTRICTIVE`. The options are: * `tcod.FOV_BASIC`: Simple ray-cast implementation. * `tcod.FOV_DIAMOND` * `tcod.FOV_SHADOW`: Recursive shadow caster. * `tcod.FOV_PERMISSIVE(n)`: `n` starts at 0 (most restrictive) and goes up to 8 (most permissive.) * `tcod.FOV_RESTRICTIVE` .. versionadded:: 9.3 Example:: >>> explored = np.zeros((3, 5), dtype=bool, order="F") >>> transparency = np.ones((3, 5), dtype=bool, order="F") >>> transparency[:2, 2] = False >>> transparency # Transparent area. array([[ True, True, False, True, True], [ True, True, False, True, True], [ True, True, True, True, True]]...) >>> visible = tcod.map.compute_fov(transparency, 0, 0) >>> visible # Visible area. array([[ True, True, True, False, False], [ True, True, True, False, False], [ True, True, True, True, False]]...) >>> explored |= visible # Keep track of an explored area.
f3114:m0
def compute_fov(<EOL>self,<EOL>x: int,<EOL>y: int,<EOL>radius: int = <NUM_LIT:0>,<EOL>light_walls: bool = True,<EOL>algorithm: int = tcod.constants.FOV_RESTRICTIVE,<EOL>) -> None:
lib.TCOD_map_compute_fov(<EOL>self.map_c, x, y, radius, light_walls, algorithm<EOL>)<EOL>
Compute a field-of-view on the current instance. Args: x (int): Point of view, x-coordinate. y (int): Point of view, y-coordinate. radius (int): Maximum view distance from the point of view. A value of `0` will give an infinite distance. light_walls (bool): Light up walls, or only the floor. algorithm (int): Defaults to tcod.FOV_RESTRICTIVE If you already have transparency in a NumPy array then you could use :any:`tcod.map_compute_fov` instead.
f3114:c0:m5
def get_point(<EOL>self, x: float = <NUM_LIT:0>, y: float = <NUM_LIT:0>, z: float = <NUM_LIT:0>, w: float = <NUM_LIT:0><EOL>) -> float:
return float(lib.NoiseGetSample(self._tdl_noise_c, (x, y, z, w)))<EOL>
Return the noise value at the (x, y, z, w) point. Args: x (float): The position on the 1st axis. y (float): The position on the 2nd axis. z (float): The position on the 3rd axis. w (float): The position on the 4th axis.
f3116:c0:m11
def sample_mgrid(self, mgrid: np.array) -> np.array:
mgrid = np.ascontiguousarray(mgrid, np.float32)<EOL>if mgrid.shape[<NUM_LIT:0>] != self.dimensions:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (mgrid.shape, self.dimensions)<EOL>)<EOL><DEDENT>out = np.ndarray(mgrid.shape[<NUM_LIT:1>:], np.float32)<EOL>if mgrid.shape[<NUM_LIT:1>:] != out.shape:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (mgrid.shape, out.shape)<EOL>)<EOL><DEDENT>lib.NoiseSampleMeshGrid(<EOL>self._tdl_noise_c,<EOL>out.size,<EOL>ffi.cast("<STR_LIT>", mgrid.ctypes.data),<EOL>ffi.cast("<STR_LIT>", out.ctypes.data),<EOL>)<EOL>return out<EOL>
Sample a mesh-grid array and return the result. The :any:`sample_ogrid` method performs better as there is a lot of overhead when working with large mesh-grids. Args: mgrid (numpy.ndarray): A mesh-grid array of points to sample. A contiguous array of type `numpy.float32` is preferred. Returns: numpy.ndarray: An array of sampled points. This array has the shape: ``mgrid.shape[:-1]``. The ``dtype`` is `numpy.float32`.
f3116:c0:m12
def sample_ogrid(self, ogrid: np.array) -> np.array:
if len(ogrid) != self.dimensions:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (len(ogrid), self.dimensions)<EOL>)<EOL><DEDENT>ogrids = [np.ascontiguousarray(array, np.float32) for array in ogrid]<EOL>out = np.ndarray([array.size for array in ogrids], np.float32)<EOL>lib.NoiseSampleOpenMeshGrid(<EOL>self._tdl_noise_c,<EOL>len(ogrids),<EOL>out.shape,<EOL>[ffi.cast("<STR_LIT>", array.ctypes.data) for array in ogrids],<EOL>ffi.cast("<STR_LIT>", out.ctypes.data),<EOL>)<EOL>return out<EOL>
Sample an open mesh-grid array and return the result. Args ogrid (Sequence[Sequence[float]]): An open mesh-grid. Returns: numpy.ndarray: An array of sampled points. The ``shape`` is based on the lengths of the open mesh-grid arrays. The ``dtype`` is `numpy.float32`.
f3116:c0:m13
def _describe_bitmask(<EOL>bits: int, table: Dict[Any, str], default: str = "<STR_LIT:0>"<EOL>) -> str:
result = []<EOL>for bit, name in table.items():<EOL><INDENT>if bit & bits:<EOL><INDENT>result.append(name)<EOL><DEDENT><DEDENT>if not result:<EOL><INDENT>return default<EOL><DEDENT>return "<STR_LIT:|>".join(result)<EOL>
Returns a bitmask in human readable form. This is a private function, used internally. Args: bits (int): The bitmask to be represented. table (Dict[Any,str]): A reverse lookup table. default (Any): A default return value when bits is 0. Returns: str: A printable version of the bits variable.
f3117:m0
def _pixel_to_tile(x: float, y: float) -> Tuple[float, float]:
xy = tcod.ffi.new("<STR_LIT>", (x, y))<EOL>tcod.lib.TCOD_sys_pixel_to_tile(xy, xy + <NUM_LIT:1>)<EOL>return xy[<NUM_LIT:0>], xy[<NUM_LIT:1>]<EOL>
Convert pixel coordinates to tile coordinates.
f3117:m1
def get() -> Iterator[Any]:
sdl_event = tcod.ffi.new("<STR_LIT>")<EOL>while tcod.lib.SDL_PollEvent(sdl_event):<EOL><INDENT>if sdl_event.type in _SDL_TO_CLASS_TABLE:<EOL><INDENT>yield _SDL_TO_CLASS_TABLE[sdl_event.type].from_sdl_event(sdl_event)<EOL><DEDENT>else:<EOL><INDENT>yield Undefined.from_sdl_event(sdl_event)<EOL><DEDENT><DEDENT>
Return an iterator for all pending events. Events are processed as the iterator is consumed. Breaking out of, or discarding the iterator will leave the remaining events on the event queue. Example:: for event in tcod.event.get(): if event.type == "QUIT": print(event) raise SystemExit() elif event.type == "KEYDOWN": print(event) elif event.type == "MOUSEBUTTONDOWN": print(event) elif event.type == "MOUSEMOTION": print(event) else: print(event)
f3117:m2
def wait(timeout: Optional[float] = None) -> Iterator[Any]:
if timeout is not None:<EOL><INDENT>tcod.lib.SDL_WaitEventTimeout(tcod.ffi.NULL, int(timeout * <NUM_LIT:1000>))<EOL><DEDENT>else:<EOL><INDENT>tcod.lib.SDL_WaitEvent(tcod.ffi.NULL)<EOL><DEDENT>return get()<EOL>
Block until events exist, then return an event iterator. `timeout` is the maximum number of seconds to wait as a floating point number with millisecond precision, or it can be None to wait forever. Returns the same iterator as a call to :any:`tcod.event.get`. Example:: for event in tcod.event.wait(): if event.type == "QUIT": print(event) raise SystemExit() elif event.type == "KEYDOWN": print(event) elif event.type == "MOUSEBUTTONDOWN": print(event) elif event.type == "MOUSEMOTION": print(event) else: print(event)
f3117:m3
def get_mouse_state() -> MouseState:
xy = tcod.ffi.new("<STR_LIT>")<EOL>buttons = tcod.lib.SDL_GetMouseState(xy, xy + <NUM_LIT:1>)<EOL>x, y = _pixel_to_tile(*xy)<EOL>return MouseState((xy[<NUM_LIT:0>], xy[<NUM_LIT:1>]), (int(x), int(y)), buttons)<EOL>
Return the current state of the mouse. .. addedversion:: 9.3
f3117:m4
@classmethod<EOL><INDENT>def from_sdl_event(cls, sdl_event: Any) -> Any:<DEDENT>
raise NotImplementedError()<EOL>
Return a class instance from a python-cffi 'SDL_Event*' pointer.
f3117:c0:m1
def dispatch(self, event: Any) -> None:
if event.type:<EOL><INDENT>getattr(self, "<STR_LIT>" % (event.type.lower(),))(event)<EOL><DEDENT>
Send an event to an `ev_*` method. `*` will be the events type converted to lower-case. If `event.type` is an empty string or None then it will be ignored.
f3117:c16:m0
def ev_quit(self, event: Quit) -> None:
Called when the termination of the program is requested.
f3117:c16:m3
def ev_keydown(self, event: KeyDown) -> None:
Called when a keyboard key is pressed or repeated.
f3117:c16:m4
def ev_keyup(self, event: KeyUp) -> None:
Called when a keyboard key is released.
f3117:c16:m5
def ev_mousemotion(self, event: MouseMotion) -> None:
Called when the mouse is moved.
f3117:c16:m6
def ev_mousebuttondown(self, event: MouseButtonDown) -> None:
Called when a mouse button is pressed.
f3117:c16:m7