signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
---|---|---|---|
def ev_mousebuttonup(self, event: MouseButtonUp) -> None: | Called when a mouse button is released. | f3117:c16:m8 |
|
def ev_mousewheel(self, event: MouseWheel) -> None: | Called when the mouse wheel is scrolled. | f3117:c16:m9 |
|
def ev_textinput(self, event: TextInput) -> None: | Called to handle Unicode input. | f3117:c16:m10 |
|
def ev_windowshown(self, event: WindowEvent) -> None: | Called when the window is shown. | f3117:c16:m11 |
|
def ev_windowhidden(self, event: WindowEvent) -> None: | Called when the window is hidden. | f3117:c16:m12 |
|
def ev_windowexposed(self, event: WindowEvent) -> None: | Called when a window is exposed, and needs to be refreshed.
This usually means a call to :any:`tcod.console_flush` is necessary. | f3117:c16:m13 |
|
def ev_windowmoved(self, event: WindowMoved) -> None: | Called when the window is moved. | f3117:c16:m14 |
|
def ev_windowresized(self, event: WindowResized) -> None: | Called when the window is resized. | f3117:c16:m15 |
|
def ev_windowsizechanged(self, event: WindowResized) -> None: | Called when the system or user changes the size of the window. | f3117:c16:m16 |
|
def ev_windowminimized(self, event: WindowEvent) -> None: | Called when the window is minimized. | f3117:c16:m17 |
|
def ev_windowmaximized(self, event: WindowEvent) -> None: | Called when the window is maximized. | f3117:c16:m18 |
|
def ev_windowrestored(self, event: WindowEvent) -> None: | Called when the window is restored. | f3117:c16:m19 |
|
def ev_windowenter(self, event: WindowEvent) -> None: | Called when the window gains mouse focus. | f3117:c16:m20 |
|
def ev_windowleave(self, event: WindowEvent) -> None: | Called when the window loses mouse focus. | f3117:c16:m21 |
|
def ev_windowfocusgained(self, event: WindowEvent) -> None: | Called when the window gains keyboard focus. | f3117:c16:m22 |
|
def ev_windowfocuslost(self, event: WindowEvent) -> None: | Called when the window loses keyboard focus. | f3117:c16:m23 |
|
def ev_windowclose(self, event: WindowEvent) -> None: | Called when the window manager requests the window to be closed. | f3117:c16:m24 |
|
def __init__(<EOL>self,<EOL>algorithm: int = MERSENNE_TWISTER,<EOL>seed: Optional[Hashable] = None,<EOL>): | if seed is None:<EOL><INDENT>seed = random.getrandbits(<NUM_LIT:32>)<EOL><DEDENT>self.random_c = ffi.gc(<EOL>ffi.cast(<EOL>"<STR_LIT>",<EOL>lib.TCOD_random_new_from_seed(<EOL>algorithm, hash(seed) % (<NUM_LIT:1> << <NUM_LIT:32>)<EOL>),<EOL>),<EOL>lib.TCOD_random_delete,<EOL>)<EOL> | Create a new instance using this algorithm and seed. | f3118:c0:m0 |
@classmethod<EOL><INDENT>def _new_from_cdata(cls, cdata: Any) -> "<STR_LIT>":<DEDENT> | self = object.__new__(cls) <EOL>self.random_c = cdata<EOL>return self<EOL> | Return a new instance encapsulating this cdata. | f3118:c0:m1 |
def randint(self, low: int, high: int) -> int: | return int(lib.TCOD_random_get_i(self.random_c, low, high))<EOL> | Return a random integer within the linear range: low <= n <= high.
Args:
low (int): The lower bound of the random range.
high (int): The upper bound of the random range.
Returns:
int: A random integer. | f3118:c0:m2 |
def uniform(self, low: float, high: float) -> float: | return float(lib.TCOD_random_get_double(self.random_c, low, high))<EOL> | Return a random floating number in the range: low <= n <= high.
Args:
low (float): The lower bound of the random range.
high (float): The upper bound of the random range.
Returns:
float: A random float. | f3118:c0:m3 |
def guass(self, mu: float, sigma: float) -> float: | return float(<EOL>lib.TCOD_random_get_gaussian_double(self.random_c, mu, sigma)<EOL>)<EOL> | Return a random number using Gaussian distribution.
Args:
mu (float): The median returned value.
sigma (float): The standard deviation.
Returns:
float: A random float. | f3118:c0:m4 |
def inverse_guass(self, mu: float, sigma: float) -> float: | return float(<EOL>lib.TCOD_random_get_gaussian_double_inv(self.random_c, mu, sigma)<EOL>)<EOL> | Return a random Gaussian number using the Box-Muller transform.
Args:
mu (float): The median returned value.
sigma (float): The standard deviation.
Returns:
float: A random float. | f3118:c0:m5 |
def __getstate__(self) -> Any: | state = self.__dict__.copy()<EOL>state["<STR_LIT>"] = {<EOL>"<STR_LIT>": self.random_c.algo,<EOL>"<STR_LIT>": self.random_c.distribution,<EOL>"<STR_LIT>": list(self.random_c.mt),<EOL>"<STR_LIT>": self.random_c.cur_mt,<EOL>"<STR_LIT>": list(self.random_c.Q),<EOL>"<STR_LIT:c>": self.random_c.c,<EOL>"<STR_LIT>": self.random_c.cur,<EOL>}<EOL>return state<EOL> | Pack the self.random_c attribute into a portable state. | f3118:c0:m6 |
def __setstate__(self, state: Any) -> None: | try:<EOL><INDENT>cdata = state["<STR_LIT>"]<EOL><DEDENT>except KeyError: <EOL><INDENT>cdata = state["<STR_LIT>"]<EOL>del state["<STR_LIT>"]<EOL><DEDENT>state["<STR_LIT>"] = ffi.new("<STR_LIT>", cdata)<EOL>self.__dict__.update(state)<EOL> | Create a new cdata object with the stored paramaters. | f3118:c0:m7 |
def deprecate(<EOL>message: str, category: Any = DeprecationWarning, stacklevel: int = <NUM_LIT:0><EOL>) -> Callable[[F], F]: | def decorator(func: F) -> F:<EOL><INDENT>if not __debug__:<EOL><INDENT>return func<EOL><DEDENT>@functools.wraps(func)<EOL>def wrapper(*args, **kargs): <EOL><INDENT>warnings.warn(message, category, stacklevel=stacklevel + <NUM_LIT:2>)<EOL>return func(*args, **kargs)<EOL><DEDENT>return cast(F, wrapper)<EOL><DEDENT>return decorator<EOL> | Return a decorator which adds a warning to functions. | f3119:m0 |
def pending_deprecate(<EOL>message: str = "<STR_LIT>"<EOL>"<STR_LIT>",<EOL>category: Any = PendingDeprecationWarning,<EOL>stacklevel: int = <NUM_LIT:0>,<EOL>) -> Callable[[F], F]: | return deprecate(message, category, stacklevel)<EOL> | Like deprecate, but the default parameters are filled out for a generic
pending deprecation warning. | f3119:m1 |
def get_default() -> Tileset: | return Tileset._claim(lib.TCOD_get_default_tileset())<EOL> | Return a reference to the default Tileset.
This function is provisional. The API may change. | f3120:m0 |
def set_default(tileset: Tileset) -> None: | lib.TCOD_set_default_tileset(tileset._tileset_p)<EOL> | Set the default tileset.
The display will use this new tileset immediately.
This function only affects the `SDL2` and `OPENGL2` renderers.
This function is provisional. The API may change. | f3120:m1 |
def load_truetype_font(<EOL>path: str, tile_width: int, tile_height: int<EOL>) -> Tileset: | if not os.path.exists(path):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % (os.path.realpath(path),))<EOL><DEDENT>return Tileset._claim(<EOL>lib.TCOD_load_truetype_font_(path.encode(), tile_width, tile_height)<EOL>)<EOL> | Return a new Tileset from a `.ttf` or `.otf` file.
Same as :any:`set_truetype_font`, but returns a :any:`Tileset` instead.
You can send this Tileset to :any:`set_default`.
This function is provisional. The API may change. | f3120:m2 |
def set_truetype_font(path: str, tile_width: int, tile_height: int) -> None: | if not os.path.exists(path):<EOL><INDENT>raise RuntimeError("<STR_LIT>" % (os.path.realpath(path),))<EOL><DEDENT>lib.TCOD_tileset_load_truetype_(path.encode(), tile_width, tile_height)<EOL> | Set the default tileset from a `.ttf` or `.otf` file.
`path` is the file path for the font file.
`tile_width` and `tile_height` are the desired size of the tiles in the new
tileset. The font will be scaled to fit the given `tile_height` and
`tile_width`.
This function will only affect the `SDL2` and `OPENGL2` renderers.
This function must be called before :any:`tcod.console_init_root`. Once
the root console is setup you may call this funtion again to change the
font. The tileset can be changed but the window will not be resized
automatically.
.. versionadded:: 9.2 | f3120:m3 |
@classmethod<EOL><INDENT>def _claim(cls, cdata: Any) -> "<STR_LIT>":<DEDENT> | self = object.__new__(cls) <EOL>if cdata == ffi.NULL:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>self._tileset_p = ffi.gc(cdata, lib.TCOD_tileset_delete)<EOL>return self<EOL> | Return a new Tileset that owns the provided TCOD_Tileset* object. | f3120:c0:m1 |
@property<EOL><INDENT>def tile_width(self) -> int:<DEDENT> | return int(lib.TCOD_tileset_get_tile_width_(self._tileset_p))<EOL> | The width of the tile in pixels. | f3120:c0:m2 |
@property<EOL><INDENT>def tile_height(self) -> int:<DEDENT> | return int(lib.TCOD_tileset_get_tile_height_(self._tileset_p))<EOL> | The height of the tile in pixels. | f3120:c0:m3 |
@property<EOL><INDENT>def tile_shape(self) -> Tuple[int, int]:<DEDENT> | return self.tile_height, self.tile_width<EOL> | The shape (height, width) of the tile in pixels. | f3120:c0:m4 |
def __contains__(self, codepoint: int) -> bool: | return bool(<EOL>lib.TCOD_tileset_get_tile_(self._tileset_p, codepoint, ffi.NULL)<EOL>== <NUM_LIT:0><EOL>)<EOL> | Test if a tileset has a codepoint with ``n in tileset``. | f3120:c0:m5 |
def get_tile(self, codepoint: int) -> np.array: | tile = np.zeros(self.tile_shape + (<NUM_LIT:4>,), dtype=np.uint8)<EOL>lib.TCOD_tileset_get_tile_(<EOL>self._tileset_p,<EOL>codepoint,<EOL>ffi.cast("<STR_LIT>", tile.ctypes.data),<EOL>)<EOL>return tile<EOL> | Return a copy of a tile for the given codepoint.
If the tile does not exist yet then a blank array will be returned.
The tile will have a shape of (height, width, rgba) and a dtype of
uint8. Note that most grey-scale tiles will only use the alpha
channel and will usually have a solid white color channel. | f3120:c0:m6 |
def set_tile(self, codepoint: int, tile: np.array) -> None: | tile = np.ascontiguousarray(tile, dtype=np.uint8)<EOL>if tile.shape == self.tile_shape:<EOL><INDENT>full_tile = np.empty(self.tile_shape + (<NUM_LIT:4>,), dtype=np.uint8)<EOL>full_tile[:, :, :<NUM_LIT:3>] = <NUM_LIT:255><EOL>full_tile[:, :, <NUM_LIT:3>] = tile<EOL>return self.set_tile(codepoint, full_tile)<EOL><DEDENT>required = self.tile_shape + (<NUM_LIT:4>,)<EOL>if tile.shape != required:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>% (required, self.tile_shape, tile.shape)<EOL>)<EOL><DEDENT>lib.TCOD_tileset_set_tile_(<EOL>self._tileset_p,<EOL>codepoint,<EOL>ffi.cast("<STR_LIT>", tile.ctypes.data),<EOL>)<EOL> | Upload a tile into this array.
The tile can be in 32-bit color (height, width, rgba), or grey-scale
(height, width). The tile should have a dtype of ``np.uint8``.
This data may need to be sent to graphics card memory, this is a slow
operation. | f3120:c0:m7 |
def get_architecture() -> str: | return "<STR_LIT>" if platform.architecture()[<NUM_LIT:0>] == "<STR_LIT>" else "<STR_LIT>"<EOL> | Return the Windows architecture, one of "x86" or "x64". | f3121:m0 |
@staticmethod<EOL><INDENT>def def_extern() -> Any:<DEDENT> | return lambda func: func<EOL> | Pass def_extern call silently. | f3121:c0:m0 |
def __getattr__(self, attr: Any) -> Any: | return self<EOL> | This object pretends to have everything. | f3121:c0:m1 |
def __call__(self, *args: Any, **kargs: Any) -> Any: | return self<EOL> | Suppress any other calls | f3121:c0:m2 |
def __str__(self) -> Any: | return "<STR_LIT:?>"<EOL> | Just have ? in case anything leaks as a parameter default. | f3121:c0:m3 |
@property<EOL><INDENT>def r(self) -> int:<DEDENT> | return self[<NUM_LIT:0>]<EOL> | int: Red value, always normalised to 0-255.
.. deprecated:: 9.2
Color attributes will not be mutable in the future. | f3122:c0:m1 |
@property<EOL><INDENT>def g(self) -> int:<DEDENT> | return self[<NUM_LIT:1>]<EOL> | int: Green value, always normalised to 0-255.
.. deprecated:: 9.2
Color attributes will not be mutable in the future. | f3122:c0:m3 |
@property<EOL><INDENT>def b(self) -> int:<DEDENT> | return self[<NUM_LIT:2>]<EOL> | int: Blue value, always normalised to 0-255.
.. deprecated:: 9.2
Color attributes will not be mutable in the future. | f3122:c0:m5 |
@classmethod<EOL><INDENT>def _new_from_cdata(cls, cdata: Any) -> "<STR_LIT>":<DEDENT> | return cls(cdata.r, cdata.g, cdata.b)<EOL> | new in libtcod-cffi | f3122:c0:m7 |
def __getitem__(self, index: Any) -> int: | try:<EOL><INDENT>return super().__getitem__(index)<EOL><DEDENT>except TypeError:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>",<EOL>DeprecationWarning,<EOL>stacklevel=<NUM_LIT:2>,<EOL>)<EOL>return super().__getitem__("<STR_LIT>".index(index))<EOL><DEDENT> | .. deprecated:: 9.2
Accessing colors via a letter index is deprecated. | f3122:c0:m8 |
def __eq__(self, other: Any) -> bool: | try:<EOL><INDENT>return bool(lib.TCOD_color_equals(self, other))<EOL><DEDENT>except TypeError:<EOL><INDENT>return False<EOL><DEDENT> | Compare equality between colors.
Also compares with standard sequences such as 3-item tuples or lists. | f3122:c0:m10 |
@deprecate("<STR_LIT>")<EOL><INDENT>def __add__(self, other: Any) -> "<STR_LIT>":<DEDENT> | return Color._new_from_cdata(lib.TCOD_color_add(self, other))<EOL> | Add two colors together.
.. deprecated:: 9.2
Use NumPy instead for color math operations. | f3122:c0:m11 |
@deprecate("<STR_LIT>")<EOL><INDENT>def __sub__(self, other: Any) -> "<STR_LIT>":<DEDENT> | return Color._new_from_cdata(lib.TCOD_color_subtract(self, other))<EOL> | Subtract one color from another.
.. deprecated:: 9.2
Use NumPy instead for color math operations. | f3122:c0:m12 |
@deprecate("<STR_LIT>")<EOL><INDENT>def __mul__(self, other: Any) -> "<STR_LIT>":<DEDENT> | if isinstance(other, (Color, list, tuple)):<EOL><INDENT>return Color._new_from_cdata(lib.TCOD_color_multiply(self, other))<EOL><DEDENT>else:<EOL><INDENT>return Color._new_from_cdata(<EOL>lib.TCOD_color_multiply_scalar(self, other)<EOL>)<EOL><DEDENT> | Multiply with a scaler or another color.
.. deprecated:: 9.2
Use NumPy instead for color math operations. | f3122:c0:m13 |
def __repr__(self) -> str: | return "<STR_LIT>" % (<EOL>self.__class__.__name__,<EOL>self.r,<EOL>self.g,<EOL>self.b,<EOL>)<EOL> | Return a printable representation of the current color. | f3122:c0:m14 |
def in_window(self, x, y): | return <NUM_LIT:0> <= x < WINWIDTH and <NUM_LIT:0> <= y < WINHEIGHT<EOL> | returns True if this point is in the Window | f3133:c0:m3 |
def randomize_console(self): | noise = [((x, y), self.get_random_character()) for x,y in self.get_drawables()]<EOL>for (x, y), graphic in noise:<EOL><INDENT>self.console.draw_char(x, y, *graphic)<EOL><DEDENT>return noise<EOL> | Randomize the console returning the random data | f3133:c0:m4 |
def flush(self): | <EOL>tdl.flush()<EOL> | Pump events and refresh screen so show progress | f3133:c0:m5 |
def get_random_character(self): | return (random.getrandbits(<NUM_LIT:8>), self.get_random_color(), self.get_random_color())<EOL> | returns a tuple with a random character and colors (ch, fg, bg) | f3133:c0:m6 |
def get_random_color(self): | return (random.getrandbits(<NUM_LIT:8>), random.getrandbits(<NUM_LIT:8>), random.getrandbits(<NUM_LIT:8>))<EOL> | returns a single random color | f3133:c0:m7 |
def get_drawables(self, console=None): | if console is None:<EOL><INDENT>console = self.console<EOL><DEDENT>w, h = console.get_size()<EOL>return itertools.product(range(w), range(h))<EOL> | return a list of all drawable (x,y) positions
defaults to self.console | f3133:c0:m8 |
def get_undrawables(self, console=None): | if console is None:<EOL><INDENT>console = self.console<EOL><DEDENT>w, h = console.get_size()<EOL>for y in range(-<NUM_LIT:1>, h+<NUM_LIT:1>):<EOL><INDENT>yield -w-<NUM_LIT:1>, y<EOL>yield w, y<EOL><DEDENT>for x in range(<NUM_LIT:0>, w):<EOL><INDENT>yield x, h<EOL>yield x, -h-<NUM_LIT:1><EOL><DEDENT> | return a list of (x,y) positions that should raise errors when used
positions are mostly random and will have at least one over the bounds of each side and each corner | f3133:c0:m9 |
def compare_consoles(self, consoleA, consoleB, errorMsg='<STR_LIT>'): | self.assertEqual(consoleA.get_size(), consoleB.get_size(), '<STR_LIT>')<EOL>for x, y in self.get_drawables(consoleA):<EOL><INDENT>self.assertEqual(consoleA.get_char(x, y),<EOL>consoleB.get_char(x, y), '<STR_LIT>' % (errorMsg, x, y))<EOL><DEDENT> | Compare two console assuming they match and failing if they don't | f3133:c0:m10 |
def rule(self, is_alive, neighbours): | if is_alive:<EOL><INDENT>return <NUM_LIT:2> <= neighbours <= <NUM_LIT:3><EOL><DEDENT>else:<EOL><INDENT>return neighbours == <NUM_LIT:3><EOL><DEDENT> | 1. Any live cell with fewer than two live neighbours dies, as if caused
by under-population.
2. Any live cell with two or three live neighbours lives on to the next
generation.
3. Any live cell with more than three live neighbours dies, as if by
overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live
cell, as if by reproduction. | f3146:c0:m8 |
def main(): | WIDTH, HEIGHT = <NUM_LIT>, <NUM_LIT><EOL>TITLE = None<EOL>with tcod.console_init_root(WIDTH, HEIGHT, TITLE, order="<STR_LIT:F>",<EOL>renderer=tcod.RENDERER_SDL) as console:<EOL><INDENT>tcod.sys_set_fps(<NUM_LIT>)<EOL>while True:<EOL><INDENT>tcod.console_flush()<EOL>for event in tcod.event.wait():<EOL><INDENT>print(event)<EOL>if event.type == "<STR_LIT>":<EOL><INDENT>raise SystemExit()<EOL><DEDENT>elif event.type == "<STR_LIT>":<EOL><INDENT>console.ch[:, -<NUM_LIT:1>] = <NUM_LIT:0><EOL>console.print_(<NUM_LIT:0>, HEIGHT - <NUM_LIT:1>, str(event))<EOL><DEDENT>else:<EOL><INDENT>console.blit(console, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, WIDTH, HEIGHT - <NUM_LIT:2>)<EOL>console.ch[:, -<NUM_LIT:3>] = <NUM_LIT:0><EOL>console.print_(<NUM_LIT:0>, HEIGHT - <NUM_LIT:3>, str(event))<EOL><DEDENT><DEDENT><DEDENT><DEDENT> | Example program for tcod.event | f3147:m0 |
def present(self): | tdl.flush()<EOL> | Sync state of the internal cell buffer with the terminal. | f3150:c2:m5 |
def change_cell(self, x, y, ch, fg, bg): | self.console.draw_char(x, y, ch, fg, bg)<EOL> | Change cell in position (x;y). | f3150:c2:m6 |
def width(self): | return self.console.width<EOL> | Returns width of the terminal screen. | f3150:c2:m7 |
def height(self): | return self.console.height<EOL> | Return height of the terminal screen. | f3150:c2:m8 |
def clear(self): | self.console.clear()<EOL> | Clear the internal cell buffer. | f3150:c2:m9 |
def set_cursor(self, x, y): | tb_set_cursor(x, y)<EOL> | Set cursor position to (x;y).
Set both arguments to HIDE_CURSOR or use 'hide_cursor' function to
hide it. | f3150:c2:m10 |
def hide_cursor(self): | tb_set_cursor(-<NUM_LIT:1>, -<NUM_LIT:1>)<EOL> | Hide cursor. | f3150:c2:m11 |
def select_input_mode(self, mode): | return int(tb_select_input_mode(mode))<EOL> | Select preferred input mode: INPUT_ESC or INPUT_ALT.
INPUT_CURRENT returns the selected mode without changing anything. | f3150:c2:m12 |
def select_output_mode(self, mode): | return int(tb_select_output_mode(mode))<EOL> | Select preferred output mode: one of OUTPUT_* constants.
OUTPUT_CURRENT returns the selected mode without changing anything. | f3150:c2:m13 |
def peek_event(self, timeout=<NUM_LIT:0>): | """<STR_LIT>"""<EOL>pass<EOL> | Wait for an event up to 'timeout' milliseconds and return it.
Returns None if there was no event and timeout is expired.
Returns a tuple otherwise: (type, unicode character, key, mod,
width, height, mousex, mousey). | f3150:c2:m14 |
def poll_event(self): | """<STR_LIT>"""<EOL>for e in tdl.event.get():<EOL><INDENT>self.e.type = e.type<EOL>if e.type == '<STR_LIT>':<EOL><INDENT>self.e.key = e.key<EOL>return self.e.gettuple()<EOL><DEDENT><DEDENT> | Wait for an event and return it.
Returns a tuple: (type, unicode character, key, mod, width, height,
mousex, mousey). | f3150:c2:m15 |
def fix_header(filepath): | with open(filepath, "<STR_LIT>") as f:<EOL><INDENT>current = f.read()<EOL>fixed = "<STR_LIT:\n>".join(line.strip() for line in current.split("<STR_LIT:\n>"))<EOL>if current == fixed:<EOL><INDENT>return<EOL><DEDENT>f.seek(<NUM_LIT:0>)<EOL>f.truncate()<EOL>f.write(fixed)<EOL><DEDENT> | Removes leading whitespace from a MacOS header file.
This whitespace is causing issues with directives on some platforms. | f3153:m4 |
def find_sdl_attrs(prefix: str) -> Iterator[Tuple[str, Any]]: | from tcod._libtcod import lib<EOL>if prefix.startswith("<STR_LIT>"):<EOL><INDENT>name_starts_at = <NUM_LIT:4><EOL><DEDENT>elif prefix.startswith("<STR_LIT>"):<EOL><INDENT>name_starts_at = <NUM_LIT:3><EOL><DEDENT>else:<EOL><INDENT>name_starts_at = <NUM_LIT:0><EOL><DEDENT>for attr in dir(lib):<EOL><INDENT>if attr.startswith(prefix):<EOL><INDENT>yield attr[name_starts_at:], getattr(lib, attr)<EOL><DEDENT><DEDENT> | Return names and values from `tcod.lib`.
`prefix` is used to filter out which names to copy. | f3153:m7 |
def parse_sdl_attrs(prefix: str, all_names: List[str]) -> Tuple[str, str]: | names = []<EOL>lookup = []<EOL>for name, value in sorted(<EOL>find_sdl_attrs(prefix), key=lambda item: item[<NUM_LIT:1>]<EOL>):<EOL><INDENT>all_names.append(name)<EOL>names.append("<STR_LIT>" % (name, value))<EOL>lookup.append('<STR_LIT>' % (value, name))<EOL><DEDENT>names = "<STR_LIT:\n>".join(names)<EOL>lookup = "<STR_LIT>" % ("<STR_LIT>".join(lookup),)<EOL>return names, lookup<EOL> | Return the name/value pairs, and the final dictionary string for the
library attributes with `prefix`.
Append matching names to the `all_names` list. | f3153:m8 |
def write_library_constants(): | from tcod._libtcod import lib, ffi<EOL>import tcod.color<EOL>with open("<STR_LIT>", "<STR_LIT:w>") as f:<EOL><INDENT>all_names = []<EOL>f.write(CONSTANT_MODULE_HEADER)<EOL>for name in dir(lib):<EOL><INDENT>value = getattr(lib, name)<EOL>if name[:<NUM_LIT:5>] == "<STR_LIT>":<EOL><INDENT>if name.isupper(): <EOL><INDENT>f.write("<STR_LIT>" % (name[<NUM_LIT:5>:], value))<EOL>all_names.append(name[<NUM_LIT:5>:])<EOL><DEDENT><DEDENT>elif name.startswith("<STR_LIT>"): <EOL><INDENT>f.write("<STR_LIT>" % (name, value))<EOL>all_names.append(name)<EOL><DEDENT>elif name[:<NUM_LIT:6>] == "<STR_LIT>": <EOL><INDENT>f.write("<STR_LIT>" % (name[<NUM_LIT:6>:], value))<EOL>all_names.append("<STR_LIT>" % name[<NUM_LIT:6>:])<EOL><DEDENT><DEDENT>f.write("<STR_LIT>")<EOL>for name in dir(lib):<EOL><INDENT>if name[:<NUM_LIT:5>] != "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>value = getattr(lib, name)<EOL>if not isinstance(value, ffi.CData):<EOL><INDENT>continue<EOL><DEDENT>if ffi.typeof(value) != ffi.typeof("<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>color = tcod.color.Color._new_from_cdata(value)<EOL>f.write("<STR_LIT>" % (name[<NUM_LIT:5>:], color))<EOL>all_names.append(name[<NUM_LIT:5>:])<EOL><DEDENT>all_names = "<STR_LIT>".join('<STR_LIT>' % name for name in all_names)<EOL>f.write("<STR_LIT>" % (all_names,))<EOL><DEDENT>with open("<STR_LIT>", "<STR_LIT:w>") as f:<EOL><INDENT>all_names = []<EOL>f.write(EVENT_CONSTANT_MODULE_HEADER)<EOL>f.write("<STR_LIT>")<EOL>f.write(<EOL>"<STR_LIT>"<EOL>% parse_sdl_attrs("<STR_LIT>", all_names)<EOL>)<EOL>f.write("<STR_LIT>")<EOL>f.write(<EOL>"<STR_LIT>"<EOL>% parse_sdl_attrs("<STR_LIT>", all_names)<EOL>)<EOL>f.write("<STR_LIT>")<EOL>f.write(<EOL>"<STR_LIT>"<EOL>% parse_sdl_attrs("<STR_LIT>", all_names)<EOL>)<EOL>f.write("<STR_LIT>")<EOL>f.write(<EOL>"<STR_LIT>"<EOL>% parse_sdl_attrs("<STR_LIT>", all_names)<EOL>)<EOL>all_names = "<STR_LIT>".join('<STR_LIT>' % name for name in all_names)<EOL>f.write("<STR_LIT>" % (all_names,))<EOL><DEDENT> | Write libtcod constants into the tcod.constants module. | f3153:m9 |
def visit_EnumeratorList(self, node): | for type, enum in node.children():<EOL><INDENT>if enum.value is None:<EOL><INDENT>pass<EOL><DEDENT>elif isinstance(enum.value, (c_ast.BinaryOp, c_ast.UnaryOp)):<EOL><INDENT>enum.value = c_ast.Constant("<STR_LIT:int>", "<STR_LIT>")<EOL><DEDENT>elif hasattr(enum.value, "<STR_LIT:type>"):<EOL><INDENT>enum.value = c_ast.Constant(enum.value.type, "<STR_LIT>")<EOL><DEDENT><DEDENT> | Replace enumerator expressions with '...' stubs. | f3153:c0:m3 |
def visit_FuncDef(self, node): | self.funcdefs.append(node)<EOL> | Exclude function definitions. Should be declarations only. | f3153:c0:m6 |
def get_version(): | try:<EOL><INDENT>tag = check_output(<EOL>["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"], universal_newlines=True<EOL>).strip()<EOL>assert not tag.startswith("<STR_LIT:v>")<EOL>version = tag<EOL>log = check_output(<EOL>["<STR_LIT>", "<STR_LIT>", "<STR_LIT>" % tag, "<STR_LIT>"],<EOL>universal_newlines=True,<EOL>)<EOL>commits_since_tag = log.count("<STR_LIT:\n>")<EOL>if commits_since_tag:<EOL><INDENT>version += "<STR_LIT>" % commits_since_tag<EOL><DEDENT>open("<STR_LIT>", "<STR_LIT:w>").write('<STR_LIT>' % version)<EOL>return version<EOL><DEDENT>except:<EOL><INDENT>exec(open("<STR_LIT>").read(), globals())<EOL>return __version__<EOL><DEDENT> | Get the current version from a git tag, or by reading tcod/version.py | f3159:m1 |
def get_package_data(): | BITSIZE, LINKAGE = platform.architecture()<EOL>files = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]<EOL>if "<STR_LIT:win32>" in sys.platform:<EOL><INDENT>if BITSIZE == "<STR_LIT>":<EOL><INDENT>files += ["<STR_LIT>"]<EOL><DEDENT>else:<EOL><INDENT>files += ["<STR_LIT>"]<EOL><DEDENT><DEDENT>if sys.platform == "<STR_LIT>":<EOL><INDENT>files += ["<STR_LIT>"]<EOL><DEDENT>return files<EOL> | get data files which will be included in the main tcod/ directory | f3159:m2 |
def get_long_description(): | with open("<STR_LIT>", "<STR_LIT:r>") as f:<EOL><INDENT>readme = f.read()<EOL><DEDENT>with open("<STR_LIT>", "<STR_LIT:r>") as f:<EOL><INDENT>changelog = f.read()<EOL>changelog = changelog.replace("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return "<STR_LIT:\n>".join([readme, changelog])<EOL> | Return this projects description. | f3159:m3 |
def parse_changelog(args: Any) -> Tuple[str, str]: | with open("<STR_LIT>", "<STR_LIT:r>") as file:<EOL><INDENT>match = re.match(<EOL>pattern=r"<STR_LIT>",<EOL>string=file.read(),<EOL>flags=re.DOTALL,<EOL>)<EOL><DEDENT>assert match<EOL>header, changes, tail = match.groups()<EOL>tag = "<STR_LIT>" % (args.tag, datetime.date.today().isoformat())<EOL>tagged = "<STR_LIT>" % (tag, "<STR_LIT:->" * len(tag), changes)<EOL>if args.verbose:<EOL><INDENT>print(tagged)<EOL><DEDENT>return "<STR_LIT>".join((header, tagged, tail)), changes<EOL> | Return an updated changelog and and the list of changes. | f3160:m0 |
def backport(func): | if not __debug__:<EOL><INDENT>return func<EOL><DEDENT>@_functools.wraps(func)<EOL>def deprecated_function(*args, **kargs):<EOL><INDENT>_warnings.warn('<STR_LIT>',<EOL>DeprecationWarning, <NUM_LIT:2>)<EOL>return func(*args, **kargs)<EOL><DEDENT>deprecated_function.__doc__ = None<EOL>return deprecated_function<EOL> | Backport a function name into an old style for compatibility.
The docstring is updated to reflect that the new function returned is
deprecated and that the other function is preferred.
A DeprecationWarning is also raised for using this function.
If the script is run with an optimization flag then the real function
will be returned without being wrapped. | f3162:m0 |
def _get_fov_type(fov): | oldFOV = fov<EOL>fov = str(fov).upper()<EOL>if fov in _FOVTYPES:<EOL><INDENT>return _FOVTYPES[fov]<EOL><DEDENT>if fov[:<NUM_LIT:10>] == '<STR_LIT>' and fov[<NUM_LIT:10>].isdigit() and fov[<NUM_LIT:10>] != '<STR_LIT>':<EOL><INDENT>return <NUM_LIT:4> + int(fov[<NUM_LIT:10>])<EOL><DEDENT>raise _tdl.TDLError('<STR_LIT>' % oldFOV)<EOL> | Return a FOV from a string | f3163:m0 |
@deprecate("<STR_LIT>")<EOL>def quick_fov(x, y, callback, fov='<STR_LIT>', radius=<NUM_LIT>, lightWalls=True,<EOL>sphere=True): | trueRadius = radius<EOL>radius = int(_math.ceil(radius))<EOL>mapSize = radius * <NUM_LIT:2> + <NUM_LIT:1><EOL>fov = _get_fov_type(fov)<EOL>setProp = _lib.TCOD_map_set_properties <EOL>inFOV = _lib.TCOD_map_is_in_fov<EOL>tcodMap = _lib.TCOD_map_new(mapSize, mapSize)<EOL>try:<EOL><INDENT>for x_, y_ in _itertools.product(range(mapSize), range(mapSize)):<EOL><INDENT>pos = (x_ + x - radius,<EOL>y_ + y - radius)<EOL>transparent = bool(callback(*pos))<EOL>setProp(tcodMap, x_, y_, transparent, False)<EOL><DEDENT>_lib.TCOD_map_compute_fov(tcodMap, radius, radius, radius, lightWalls, fov)<EOL>touched = set() <EOL>for x_, y_ in _itertools.product(range(mapSize), range(mapSize)):<EOL><INDENT>if sphere and _math.hypot(x_ - radius, y_ - radius) > trueRadius:<EOL><INDENT>continue<EOL><DEDENT>if inFOV(tcodMap, x_, y_):<EOL><INDENT>touched.add((x_ + x - radius, y_ + y - radius))<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>_lib.TCOD_map_delete(tcodMap)<EOL><DEDENT>return touched<EOL> | All field-of-view functionality in one call.
Before using this call be sure to make a function, lambda, or method that takes 2
positional parameters and returns True if light can pass through the tile or False
for light-blocking tiles and for indexes that are out of bounds of the
dungeon.
This function is 'quick' as in no hassle but can quickly become a very slow
function call if a large radius is used or the callback provided itself
isn't optimized.
Always check if the index is in bounds both in the callback and in the
returned values. These values can go into the negatives as well.
Args:
x (int): x center of the field-of-view
y (int): y center of the field-of-view
callback (Callable[[int, int], bool]):
This should be a function that takes two positional arguments x,y
and returns True if the tile at that position is transparent
or False if the tile blocks light or is out of bounds.
fov (Text): The type of field-of-view to be used.
Available types are:
'BASIC', 'DIAMOND', 'SHADOW', 'RESTRICTIVE', 'PERMISSIVE',
'PERMISSIVE0', 'PERMISSIVE1', ..., 'PERMISSIVE8'
radius (float) Radius of the field-of-view.
When sphere is True a floating point can be used to fine-tune
the range. Otherwise the radius is just rounded up.
Be careful as a large radius has an exponential affect on
how long this function takes.
lightWalls (bool): Include or exclude wall tiles in the field-of-view.
sphere (bool): True for a spherical field-of-view.
False for a square one.
Returns:
Set[Tuple[int, int]]: A set of (x, y) points that are within the
field-of-view. | f3163:m1 |
def bresenham(x1, y1, x2, y2): | points = []<EOL>issteep = abs(y2-y1) > abs(x2-x1)<EOL>if issteep:<EOL><INDENT>x1, y1 = y1, x1<EOL>x2, y2 = y2, x2<EOL><DEDENT>rev = False<EOL>if x1 > x2:<EOL><INDENT>x1, x2 = x2, x1<EOL>y1, y2 = y2, y1<EOL>rev = True<EOL><DEDENT>deltax = x2 - x1<EOL>deltay = abs(y2-y1)<EOL>error = int(deltax / <NUM_LIT:2>)<EOL>y = y1<EOL>ystep = None<EOL>if y1 < y2:<EOL><INDENT>ystep = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>ystep = -<NUM_LIT:1><EOL><DEDENT>for x in range(x1, x2 + <NUM_LIT:1>):<EOL><INDENT>if issteep:<EOL><INDENT>points.append((y, x))<EOL><DEDENT>else:<EOL><INDENT>points.append((x, y))<EOL><DEDENT>error -= deltay<EOL>if error < <NUM_LIT:0>:<EOL><INDENT>y += ystep<EOL>error += deltax<EOL><DEDENT><DEDENT>if rev:<EOL><INDENT>points.reverse()<EOL><DEDENT>return points<EOL> | Return a list of points in a bresenham line.
Implementation hastily copied from RogueBasin.
Returns:
List[Tuple[int, int]]: A list of (x, y) points,
including both the start and end-points. | f3163:m2 |
def compute_fov(self, x, y, fov='<STR_LIT>', radius=None,<EOL>light_walls=True, sphere=True, cumulative=False): | <EOL>if radius is None: <EOL><INDENT>radius = <NUM_LIT:0><EOL><DEDENT>if cumulative:<EOL><INDENT>fov_copy = self.fov.copy()<EOL><DEDENT>lib.TCOD_map_compute_fov(<EOL>self.map_c, x, y, radius, light_walls, _get_fov_type(fov))<EOL>if cumulative:<EOL><INDENT>self.fov[:] |= fov_copy<EOL><DEDENT>return zip(*np.where(self.fov))<EOL> | Compute the field-of-view of this Map and return an iterator of the
points touched.
Args:
x (int): Point of view, x-coordinate.
y (int): Point of view, y-coordinate.
fov (Text): The type of field-of-view to be used.
Available types are:
'BASIC', 'DIAMOND', 'SHADOW', 'RESTRICTIVE', 'PERMISSIVE',
'PERMISSIVE0', 'PERMISSIVE1', ..., 'PERMISSIVE8'
radius (Optional[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.
sphere (bool): If True the lit area will be round instead of
square.
cumulative (bool): If True the lit cells will accumulate instead
of being cleared before the computation.
Returns:
Iterator[Tuple[int, int]]: An iterator of (x, y) points of tiles
touched by the field-of-view. | f3163:c0:m1 |
def compute_path(self, start_x, start_y, dest_x, dest_y,<EOL>diagonal_cost=_math.sqrt(<NUM_LIT:2>)): | return tcod.path.AStar(self, diagonal_cost).get_path(start_x, start_y,<EOL>dest_x, dest_y)<EOL> | Get the shortest path between two points.
Args:
start_x (int): Starting x-position.
start_y (int): Starting y-position.
dest_x (int): Destination x-position.
dest_y (int): Destination y-position.
diagonal_cost (float): Multiplier for diagonal movement.
Can be set to zero to disable diagonal movement entirely.
Returns:
List[Tuple[int, int]]: The shortest list of points to the
destination position from the starting position.
The start point is not included in this list. | f3163:c0:m2 |
def get_path(self, origX, origY, destX, destY): | return super(AStar, self).get_path(origX, origY, destX, destY)<EOL> | Get the shortest path from origXY to destXY.
Returns:
List[Tuple[int, int]]: Returns a list walking the path from orig
to dest.
This excludes the starting point and includes the destination.
If no path is found then an empty list is returned. | f3163:c1:m1 |
def _encodeString(string): | if isinstance(string, _STRTYPES):<EOL><INDENT>return string.encode()<EOL><DEDENT>return string<EOL> | changes string into bytes if running in python 3, for sending to ctypes | f3164:m0 |
def _format_char(char): | if char is None:<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>if isinstance(char, _STRTYPES) and len(char) == <NUM_LIT:1>:<EOL><INDENT>return ord(char)<EOL><DEDENT>try:<EOL><INDENT>return int(char) <EOL><DEDENT>except:<EOL><INDENT>raise TypeError('<STR_LIT>' + repr(char))<EOL><DEDENT> | Prepares a single character for passing to ctypes calls, needs to return
an integer but can also pass None which will keep the current character
instead of overwriting it.
This is called often and needs to be optimized whenever possible. | f3164:m1 |
def _format_str(string): | if isinstance(string, _STRTYPES):<EOL><INDENT>if _IS_PYTHON3:<EOL><INDENT>array = _array.array('<STR_LIT:I>')<EOL>array.frombytes(string.encode(_utf32_codec))<EOL><DEDENT>else: <EOL><INDENT>if isinstance(string, unicode):<EOL><INDENT>array = _array.array(b'<STR_LIT:I>')<EOL>array.fromstring(string.encode(_utf32_codec))<EOL><DEDENT>else:<EOL><INDENT>array = _array.array(b'<STR_LIT:B>')<EOL>array.fromstring(string)<EOL><DEDENT><DEDENT>return array<EOL><DEDENT>return string<EOL> | Attempt fast string handing by decoding directly into an array. | f3164:m2 |
def _getImageSize(filename): | result = None<EOL>file = open(filename, '<STR_LIT:rb>')<EOL>if file.read(<NUM_LIT:8>) == b'<STR_LIT>': <EOL><INDENT>while <NUM_LIT:1>:<EOL><INDENT>length, = _struct.unpack('<STR_LIT>', file.read(<NUM_LIT:4>))<EOL>chunkID = file.read(<NUM_LIT:4>)<EOL>if chunkID == '<STR_LIT>': <EOL><INDENT>break<EOL><DEDENT>if chunkID == b'<STR_LIT>':<EOL><INDENT>result = _struct.unpack('<STR_LIT>', file.read(<NUM_LIT:8>))<EOL>break<EOL><DEDENT>file.seek(<NUM_LIT:4> + length, <NUM_LIT:1>)<EOL><DEDENT>file.close()<EOL>return result<EOL><DEDENT>file.seek(<NUM_LIT:0>)<EOL>if file.read(<NUM_LIT:8>) == b'<STR_LIT>': <EOL><INDENT>file.seek(<NUM_LIT>, <NUM_LIT:0>) <EOL>result = _struct.unpack('<STR_LIT>', file.read(<NUM_LIT:8>))<EOL><DEDENT>file.close()<EOL>return result<EOL> | Try to get the width and height of a bmp of png image file | f3164:m5 |
def init(width, height, title=None, fullscreen=False, renderer='<STR_LIT>'): | RENDERERS = {'<STR_LIT>': <NUM_LIT:0>, '<STR_LIT>': <NUM_LIT:1>, '<STR_LIT>': <NUM_LIT:2>}<EOL>global _rootinitialized, _rootConsoleRef<EOL>if not _fontinitialized: <EOL><INDENT>set_font(_os.path.join(__path__[<NUM_LIT:0>], '<STR_LIT>'),<EOL>None, None, True, True)<EOL><DEDENT>if renderer.upper() not in RENDERERS:<EOL><INDENT>raise TDLError('<STR_LIT>' % (renderer, '<STR_LIT>'.join(RENDERERS)))<EOL><DEDENT>renderer = RENDERERS[renderer.upper()]<EOL>if _rootConsoleRef and _rootConsoleRef():<EOL><INDENT>_rootConsoleRef()._root_unhook()<EOL><DEDENT>if title is None: <EOL><INDENT>if _sys.argv:<EOL><INDENT>title = _os.path.basename(_sys.argv[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>title = '<STR_LIT>'<EOL><DEDENT><DEDENT>_lib.TCOD_console_init_root(width, height, _encodeString(title), fullscreen, renderer)<EOL>event._eventsflushed = False<EOL>_rootinitialized = True<EOL>rootconsole = Console._newConsole(_ffi.NULL)<EOL>_rootConsoleRef = _weakref.ref(rootconsole)<EOL>return rootconsole<EOL> | Start the main console with the given width and height and return the
root console.
Call the consoles drawing functions. Then remember to use L{tdl.flush} to
make what's drawn visible on the console.
Args:
width (int): width of the root console (in tiles)
height (int): height of the root console (in tiles)
title (Optiona[Text]):
Text to display as the window title.
If left None it defaults to the running scripts filename.
fullscreen (bool): Can be set to True to start in fullscreen mode.
renderer (Text): Can be one of 'GLSL', 'OPENGL', or 'SDL'.
Due to way Python works you're unlikely to see much of an
improvement by using 'GLSL' over 'OPENGL' as most of the
time Python is slow interacting with the console and the
rendering itself is pretty fast even on 'SDL'.
Returns:
tdl.Console: The root console.
Only what is drawn on the root console is
what's visible after a call to :any:`tdl.flush`.
After the root console is garbage collected, the window made by
this function will close.
.. seealso::
:any:`Console` :any:`set_font` | f3164:m6 |
def flush(): | if not _rootinitialized:<EOL><INDENT>raise TDLError('<STR_LIT>')<EOL><DEDENT>event.get()<EOL>_lib.TCOD_console_flush()<EOL> | Make all changes visible and update the screen.
Remember to call this function after drawing operations.
Calls to flush will enfore the frame rate limit set by :any:`tdl.set_fps`.
This function can only be called after :any:`tdl.init` | f3164:m7 |
def set_font(path, columns=None, rows=None, columnFirst=False,<EOL>greyscale=False, altLayout=False): | <EOL>FONT_LAYOUT_ASCII_INCOL = <NUM_LIT:1><EOL>FONT_LAYOUT_ASCII_INROW = <NUM_LIT:2><EOL>FONT_TYPE_GREYSCALE = <NUM_LIT:4><EOL>FONT_LAYOUT_TCOD = <NUM_LIT:8><EOL>global _fontinitialized<EOL>_fontinitialized = True<EOL>flags = <NUM_LIT:0><EOL>if altLayout:<EOL><INDENT>flags |= FONT_LAYOUT_TCOD<EOL><DEDENT>elif columnFirst:<EOL><INDENT>flags |= FONT_LAYOUT_ASCII_INCOL<EOL><DEDENT>else:<EOL><INDENT>flags |= FONT_LAYOUT_ASCII_INROW<EOL><DEDENT>if greyscale:<EOL><INDENT>flags |= FONT_TYPE_GREYSCALE<EOL><DEDENT>if not _os.path.exists(path):<EOL><INDENT>raise TDLError('<STR_LIT>' % _os.path.abspath(path))<EOL><DEDENT>path = _os.path.abspath(path)<EOL>imgSize = _getImageSize(path) <EOL>if imgSize:<EOL><INDENT>fontWidth, fontHeight = None, None<EOL>imgWidth, imgHeight = imgSize<EOL>match = _re.match('<STR_LIT>', _os.path.basename(path))<EOL>if match:<EOL><INDENT>fontWidth, fontHeight = match.groups()<EOL>fontWidth, fontHeight = int(fontWidth), int(fontHeight)<EOL>estColumns, remC = divmod(imgWidth, fontWidth)<EOL>estRows, remR = divmod(imgHeight, fontHeight)<EOL>if remC or remR:<EOL><INDENT>_warnings.warn("<STR_LIT>")<EOL><DEDENT>if not columns:<EOL><INDENT>columns = estColumns<EOL><DEDENT>if not rows:<EOL><INDENT>rows = estRows<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if columns and rows:<EOL><INDENT>fontWidth, remC = divmod(imgWidth, columns)<EOL>fontHeight, remR = divmod(imgHeight, rows)<EOL>if remC or remR:<EOL><INDENT>_warnings.warn("<STR_LIT>")<EOL><DEDENT><DEDENT>if not (columns and rows):<EOL><INDENT>raise TDLError('<STR_LIT>' % _os.path.basename(path))<EOL><DEDENT><DEDENT>if columns and rows:<EOL><INDENT>if (fontWidth * columns != imgWidth or<EOL>fontHeight * rows != imgHeight):<EOL><INDENT>_warnings.warn("<STR_LIT>"<EOL>% (fontWidth * columns, fontHeight * rows,<EOL>imgWidth, imgHeight))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>_warnings.warn("<STR_LIT>" % _os.path.basename(path))<EOL><DEDENT>if not (columns and rows):<EOL><INDENT>raise TDLError('<STR_LIT>' % _os.path.basename(path))<EOL><DEDENT>_lib.TCOD_console_set_custom_font(_encodeString(path), flags, columns, rows)<EOL> | Changes the font to be used for this session.
This should be called before :any:`tdl.init`
If the font specifies its size in its filename (i.e. font_NxN.png) then this
function can auto-detect the tileset formatting and the parameters columns
and rows can be left None.
While it's possible you can change the font mid program it can sometimes
break in rare circumstances. So use caution when doing this.
Args:
path (Text): A file path to a `.bmp` or `.png` file.
columns (int):
Number of columns in the tileset.
Can be left None for auto-detection.
rows (int):
Number of rows in the tileset.
Can be left None for auto-detection.
columnFirst (bool):
Defines if the characer order goes along the rows or colomns.
It should be True if the charater codes 0-15 are in the
first column, and should be False if the characters 0-15
are in the first row.
greyscale (bool):
Creates an anti-aliased font from a greyscale bitmap.
Otherwise it uses the alpha channel for anti-aliasing.
Unless you actually need anti-aliasing from a font you
know uses a smooth greyscale channel you should leave
this on False.
altLayout (bool)
An alternative layout with space in the upper left corner.
The colomn parameter is ignored if this is True,
find examples of this layout in the `font/libtcod/`
directory included with the python-tdl source.
Raises:
TDLError: Will be raised if no file is found at path or if auto-
detection fails. | f3164:m8 |
def get_fullscreen(): | if not _rootinitialized:<EOL><INDENT>raise TDLError('<STR_LIT>')<EOL><DEDENT>return _lib.TCOD_console_is_fullscreen()<EOL> | Returns True if program is fullscreen.
Returns:
bool: Returns True if the application is in full-screen mode.
Otherwise returns False. | f3164:m9 |
def set_fullscreen(fullscreen): | if not _rootinitialized:<EOL><INDENT>raise TDLError('<STR_LIT>')<EOL><DEDENT>_lib.TCOD_console_set_fullscreen(fullscreen)<EOL> | Changes the fullscreen state.
Args:
fullscreen (bool): True for full-screen, False for windowed mode. | f3164:m10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.