idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
53,200
def console_from_xp ( filename : str ) -> tcod . console . Console : return tcod . console . Console . _from_cdata ( lib . TCOD_console_from_xp ( filename . encode ( "utf-8" ) ) )
Return a single console from a REXPaint . xp file .
53,201
def console_list_load_xp ( filename : str ) -> Optional [ List [ tcod . console . Console ] ] : tcod_list = lib . TCOD_console_list_from_xp ( filename . encode ( "utf-8" ) ) if tcod_list == ffi . NULL : return None try : python_list = [ ] lib . TCOD_list_reverse ( tcod_list ) while not lib . TCOD_list_is_empty ( tcod_list ) : python_list . append ( tcod . console . Console . _from_cdata ( lib . TCOD_list_pop ( tcod_list ) ) ) return python_list finally : lib . TCOD_list_delete ( tcod_list )
Return a list of consoles from a REXPaint . xp file .
53,202
def console_list_save_xp ( console_list : Sequence [ tcod . console . Console ] , filename : str , compress_level : int = 9 , ) -> bool : tcod_list = lib . TCOD_list_new ( ) try : for console in console_list : lib . TCOD_list_push ( tcod_list , _console ( console ) ) return bool ( lib . TCOD_console_list_save_xp ( tcod_list , filename . encode ( "utf-8" ) , compress_level ) ) finally : lib . TCOD_list_delete ( tcod_list )
Save a list of consoles to a REXPaint . xp file .
53,203
def path_new_using_map ( m : tcod . map . Map , dcost : float = 1.41 ) -> tcod . path . AStar : return tcod . path . AStar ( m , dcost )
Return a new AStar using the given Map .
53,204
def path_new_using_function ( w : int , h : int , func : Callable [ [ int , int , int , int , Any ] , float ] , userData : Any = 0 , dcost : float = 1.41 , ) -> tcod . path . AStar : return tcod . path . AStar ( tcod . path . _EdgeCostFunc ( ( func , userData ) , ( w , h ) ) , dcost )
Return a new AStar using the given callable function .
53,205
def path_get_origin ( p : tcod . path . AStar ) -> Tuple [ int , int ] : x = ffi . new ( "int *" ) y = ffi . new ( "int *" ) lib . TCOD_path_get_origin ( p . _path_c , x , y ) return x [ 0 ] , y [ 0 ]
Get the current origin position .
53,206
def path_get_destination ( p : tcod . path . AStar ) -> Tuple [ int , int ] : x = ffi . new ( "int *" ) y = ffi . new ( "int *" ) lib . TCOD_path_get_destination ( p . _path_c , x , y ) return x [ 0 ] , y [ 0 ]
Get the current destination position .
53,207
def path_size ( p : tcod . path . AStar ) -> int : return int ( lib . TCOD_path_size ( p . _path_c ) )
Return the current length of the computed path .
53,208
def path_get ( p : tcod . path . AStar , idx : int ) -> Tuple [ int , int ] : x = ffi . new ( "int *" ) y = ffi . new ( "int *" ) lib . TCOD_path_get ( p . _path_c , idx , x , y ) return x [ 0 ] , y [ 0 ]
Get a point on a path .
53,209
def path_is_empty ( p : tcod . path . AStar ) -> bool : return bool ( lib . TCOD_path_is_empty ( p . _path_c ) )
Return True if a path is empty .
53,210
def _heightmap_cdata ( array : np . ndarray ) -> ffi . CData : if array . flags [ "F_CONTIGUOUS" ] : array = array . transpose ( ) if not array . flags [ "C_CONTIGUOUS" ] : raise ValueError ( "array must be a contiguous segment." ) if array . dtype != np . float32 : raise ValueError ( "array dtype must be float32, not %r" % array . dtype ) width , height = array . shape pointer = ffi . cast ( "float *" , array . ctypes . data ) return ffi . new ( "TCOD_heightmap_t *" , ( width , height , pointer ) )
Return a new TCOD_heightmap_t instance using an array .
53,211
def heightmap_new ( w : int , h : int , order : str = "C" ) -> np . ndarray : if order == "C" : return np . zeros ( ( h , w ) , np . float32 , order = "C" ) elif order == "F" : return np . zeros ( ( w , h ) , np . float32 , order = "F" ) else : raise ValueError ( "Invalid order parameter, should be 'C' or 'F'." )
Return a new numpy . ndarray formatted for use with heightmap functions .
53,212
def heightmap_set_value ( hm : np . ndarray , x : int , y : int , value : float ) -> None : if hm . flags [ "C_CONTIGUOUS" ] : warnings . warn ( "Assign to this heightmap with hm[i,j] = value\n" "consider using order='F'" , DeprecationWarning , stacklevel = 2 , ) hm [ y , x ] = value elif hm . flags [ "F_CONTIGUOUS" ] : warnings . warn ( "Assign to this heightmap with hm[x,y] = value" , DeprecationWarning , stacklevel = 2 , ) hm [ x , y ] = value else : raise ValueError ( "This array is not contiguous." )
Set the value of a point on a heightmap .
53,213
def heightmap_clamp ( hm : np . ndarray , mi : float , ma : float ) -> None : hm . clip ( mi , ma )
Clamp all values on this heightmap between mi and ma
53,214
def heightmap_normalize ( hm : np . ndarray , mi : float = 0.0 , ma : float = 1.0 ) -> None : lib . TCOD_heightmap_normalize ( _heightmap_cdata ( hm ) , mi , ma )
Normalize heightmap values between mi and ma .
53,215
def heightmap_lerp_hm ( hm1 : np . ndarray , hm2 : np . ndarray , hm3 : np . ndarray , coef : float ) -> None : lib . TCOD_heightmap_lerp_hm ( _heightmap_cdata ( hm1 ) , _heightmap_cdata ( hm2 ) , _heightmap_cdata ( hm3 ) , coef , )
Perform linear interpolation between two heightmaps storing the result in hm3 .
53,216
def heightmap_add_hm ( hm1 : np . ndarray , hm2 : np . ndarray , hm3 : np . ndarray ) -> None : hm3 [ : ] = hm1 [ : ] + hm2 [ : ]
Add two heightmaps together and stores the result in hm3 .
53,217
def heightmap_multiply_hm ( hm1 : np . ndarray , hm2 : np . ndarray , hm3 : np . ndarray ) -> None : hm3 [ : ] = hm1 [ : ] * hm2 [ : ]
Multiplies two heightmap s together and stores the result in hm3 .
53,218
def heightmap_rain_erosion ( hm : np . ndarray , nbDrops : int , erosionCoef : float , sedimentationCoef : float , rnd : Optional [ tcod . random . Random ] = None , ) -> None : lib . TCOD_heightmap_rain_erosion ( _heightmap_cdata ( hm ) , nbDrops , erosionCoef , sedimentationCoef , rnd . random_c if rnd else ffi . NULL , )
Simulate the effect of rain drops on the terrain resulting in erosion .
53,219
def heightmap_kernel_transform ( hm : np . ndarray , kernelsize : int , dx : Sequence [ int ] , dy : Sequence [ int ] , weight : Sequence [ float ] , minLevel : float , maxLevel : float , ) -> None : cdx = ffi . new ( "int[]" , dx ) cdy = ffi . new ( "int[]" , dy ) cweight = ffi . new ( "float[]" , weight ) lib . TCOD_heightmap_kernel_transform ( _heightmap_cdata ( hm ) , kernelsize , cdx , cdy , cweight , minLevel , maxLevel )
Apply a generic transformation on the map so that each resulting cell value is the weighted sum of several neighbour cells .
53,220
def heightmap_add_voronoi ( hm : np . ndarray , nbPoints : Any , nbCoef : int , coef : Sequence [ float ] , rnd : Optional [ tcod . random . Random ] = None , ) -> None : nbPoints = len ( coef ) ccoef = ffi . new ( "float[]" , coef ) lib . TCOD_heightmap_add_voronoi ( _heightmap_cdata ( hm ) , nbPoints , nbCoef , ccoef , rnd . random_c if rnd else ffi . NULL , )
Add values from a Voronoi diagram to the heightmap .
53,221
def heightmap_add_fbm ( hm : np . ndarray , noise : tcod . noise . Noise , mulx : float , muly : float , addx : float , addy : float , octaves : float , delta : float , scale : float , ) -> None : noise = noise . noise_c if noise is not None else ffi . NULL lib . TCOD_heightmap_add_fbm ( _heightmap_cdata ( hm ) , noise , mulx , muly , addx , addy , octaves , delta , scale , )
Add FBM noise to the heightmap .
53,222
def heightmap_dig_bezier ( hm : np . ndarray , px : Tuple [ int , int , int , int ] , py : Tuple [ int , int , int , int ] , startRadius : float , startDepth : float , endRadius : float , endDepth : float , ) -> None : lib . TCOD_heightmap_dig_bezier ( _heightmap_cdata ( hm ) , px , py , startRadius , startDepth , endRadius , endDepth , )
Carve a path along a cubic Bezier curve .
53,223
def heightmap_get_interpolated_value ( hm : np . ndarray , x : float , y : float ) -> float : return float ( lib . TCOD_heightmap_get_interpolated_value ( _heightmap_cdata ( hm ) , x , y ) )
Return the interpolated height at non integer coordinates .
53,224
def heightmap_get_normal ( hm : np . ndarray , x : float , y : float , waterLevel : float ) -> Tuple [ float , float , float ] : cn = ffi . new ( "float[3]" ) lib . TCOD_heightmap_get_normal ( _heightmap_cdata ( hm ) , x , y , cn , waterLevel ) return tuple ( cn )
Return the map normal at given coordinates .
53,225
def heightmap_count_cells ( hm : np . ndarray , mi : float , ma : float ) -> int : return int ( lib . TCOD_heightmap_count_cells ( _heightmap_cdata ( hm ) , mi , ma ) )
Return the number of map cells which value is between mi and ma .
53,226
def heightmap_has_land_on_border ( hm : np . ndarray , waterlevel : float ) -> bool : return bool ( lib . TCOD_heightmap_has_land_on_border ( _heightmap_cdata ( hm ) , waterlevel ) )
Returns True if the map edges are below waterlevel otherwise False .
53,227
def heightmap_get_minmax ( hm : np . ndarray ) -> Tuple [ float , float ] : mi = ffi . new ( "float *" ) ma = ffi . new ( "float *" ) lib . TCOD_heightmap_get_minmax ( _heightmap_cdata ( hm ) , mi , ma ) return mi [ 0 ] , ma [ 0 ]
Return the min and max values of this heightmap .
53,228
def image_load ( filename : str ) -> tcod . image . Image : return tcod . image . Image . _from_cdata ( ffi . gc ( lib . TCOD_image_load ( _bytes ( filename ) ) , lib . TCOD_image_delete ) )
Load an image file into an Image instance and return it .
53,229
def image_from_console ( console : tcod . console . Console ) -> tcod . image . Image : return tcod . image . Image . _from_cdata ( ffi . gc ( lib . TCOD_image_from_console ( _console ( console ) ) , lib . TCOD_image_delete , ) )
Return an Image with a Consoles pixel data .
53,230
def line_init ( xo : int , yo : int , xd : int , yd : int ) -> None : lib . TCOD_line_init ( xo , yo , xd , yd )
Initilize a line whose points will be returned by line_step .
53,231
def line ( xo : int , yo : int , xd : int , yd : int , py_callback : Callable [ [ int , int ] , bool ] ) -> bool : for x , y in line_iter ( xo , yo , xd , yd ) : if not py_callback ( x , y ) : break else : return True return False
Iterate over a line using a callback function .
53,232
def line_iter ( xo : int , yo : int , xd : int , yd : int ) -> Iterator [ Tuple [ int , int ] ] : data = ffi . new ( "TCOD_bresenham_data_t *" ) lib . TCOD_line_init_mt ( xo , yo , xd , yd , data ) x = ffi . new ( "int *" ) y = ffi . new ( "int *" ) yield xo , yo while not lib . TCOD_line_step_mt ( x , y , data ) : yield ( x [ 0 ] , y [ 0 ] )
returns an Iterable
53,233
def line_where ( x1 : int , y1 : int , x2 : int , y2 : int , inclusive : bool = True ) -> Tuple [ np . array , np . array ] : length = max ( abs ( x1 - x2 ) , abs ( y1 - y2 ) ) + 1 array = np . ndarray ( ( 2 , length ) , dtype = np . intc ) x = ffi . cast ( "int*" , array [ 0 ] . ctypes . data ) y = ffi . cast ( "int*" , array [ 1 ] . ctypes . data ) lib . LineWhere ( x1 , y1 , x2 , y2 , x , y ) if not inclusive : array = array [ : , 1 : ] return tuple ( array )
Return a NumPy index array following a Bresenham line .
53,234
def map_copy ( source : tcod . map . Map , dest : tcod . map . Map ) -> None : if source . width != dest . width or source . height != dest . height : dest . __init__ ( source . width , source . height , source . _order ) dest . _Map__buffer [ : ] = source . _Map__buffer [ : ]
Copy map data from source to dest .
53,235
def map_set_properties ( m : tcod . map . Map , x : int , y : int , isTrans : bool , isWalk : bool ) -> None : lib . TCOD_map_set_properties ( m . map_c , x , y , isTrans , isWalk )
Set the properties of a single cell .
53,236
def map_clear ( m : tcod . map . Map , transparent : bool = False , walkable : bool = False ) -> None : m . transparent [ : ] = transparent m . walkable [ : ] = walkable
Change all map cells to a specific value .
53,237
def map_compute_fov ( m : tcod . map . Map , x : int , y : int , radius : int = 0 , light_walls : bool = True , algo : int = FOV_RESTRICTIVE , ) -> None : m . compute_fov ( x , y , radius , light_walls , algo )
Compute the field - of - view for a map instance .
53,238
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 ) )
Return True if the cell at x y is lit by the last field - of - view algorithm .
53,239
def noise_new ( dim : int , h : float = NOISE_DEFAULT_HURST , l : float = NOISE_DEFAULT_LACUNARITY , random : Optional [ tcod . random . Random ] = None , ) -> tcod . noise . Noise : return tcod . noise . Noise ( dim , hurst = h , lacunarity = l , seed = random )
Return a new Noise instance .
53,240
def noise_set_type ( n : tcod . noise . Noise , typ : int ) -> None : n . algorithm = typ
Set a Noise objects default noise algorithm .
53,241
def noise_get ( n : tcod . noise . Noise , f : Sequence [ float ] , typ : int = NOISE_DEFAULT ) -> float : return float ( lib . TCOD_noise_get_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , typ ) )
Return the noise value sampled from the f coordinate .
53,242
def noise_get_fbm ( n : tcod . noise . Noise , f : Sequence [ float ] , oc : float , typ : int = NOISE_DEFAULT , ) -> float : return float ( lib . TCOD_noise_get_fbm_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , oc , typ ) )
Return the fractal Brownian motion sampled from the f coordinate .
53,243
def noise_get_turbulence ( n : tcod . noise . Noise , f : Sequence [ float ] , oc : float , typ : int = NOISE_DEFAULT , ) -> float : return float ( lib . TCOD_noise_get_turbulence_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , oc , typ ) )
Return the turbulence noise sampled from the f coordinate .
53,244
def random_get_instance ( ) -> tcod . random . Random : return tcod . random . Random . _new_from_cdata ( ffi . cast ( "mersenne_data_t*" , lib . TCOD_random_get_instance ( ) ) )
Return the default Random instance .
53,245
def random_new ( algo : int = RNG_CMWC ) -> tcod . random . Random : return tcod . random . Random ( algo )
Return a new Random instance . Using algo .
53,246
def random_new_from_seed ( seed : Hashable , algo : int = RNG_CMWC ) -> tcod . random . Random : return tcod . random . Random ( algo , seed )
Return a new Random instance . Using the given seed and algo .
53,247
def random_set_distribution ( rnd : Optional [ tcod . random . Random ] , dist : int ) -> None : lib . TCOD_random_set_distribution ( rnd . random_c if rnd else ffi . NULL , dist )
Change the distribution mode of a random number generator .
53,248
def random_save ( rnd : Optional [ tcod . random . Random ] ) -> tcod . random . Random : return tcod . random . Random . _new_from_cdata ( ffi . gc ( ffi . cast ( "mersenne_data_t*" , lib . TCOD_random_save ( rnd . random_c if rnd else ffi . NULL ) , ) , lib . TCOD_random_delete , ) )
Return a copy of a random number generator .
53,249
def random_restore ( rnd : Optional [ tcod . random . Random ] , backup : tcod . random . Random ) -> None : lib . TCOD_random_restore ( rnd . random_c if rnd else ffi . NULL , backup . random_c )
Restore a random number generator from a backed up copy .
53,250
def sys_set_renderer ( renderer : int ) -> None : lib . TCOD_sys_set_renderer ( renderer ) if tcod . console . _root_console is not None : tcod . console . Console . _get_root ( )
Change the current rendering mode to renderer .
53,251
def sys_save_screenshot ( name : Optional [ str ] = None ) -> None : lib . TCOD_sys_save_screenshot ( _bytes ( name ) if name is not None else ffi . NULL )
Save a screenshot to a file .
53,252
def sys_update_char ( asciiCode : int , fontx : int , fonty : int , img : tcod . image . Image , x : int , y : int , ) -> None : lib . TCOD_sys_update_char ( _int ( asciiCode ) , fontx , fonty , img , x , y )
Dynamically update the current font with img .
53,253
def sys_register_SDL_renderer ( callback : Callable [ [ Any ] , None ] ) -> None : with _PropagateException ( ) as propagate : @ ffi . def_extern ( onerror = propagate ) def _pycall_sdl_hook ( sdl_surface : Any ) -> None : callback ( sdl_surface ) lib . TCOD_sys_register_SDL_renderer ( lib . _pycall_sdl_hook )
Register a custom randering function with libtcod .
53,254
def sys_check_for_event ( mask : int , k : Optional [ Key ] , m : Optional [ Mouse ] ) -> int : return int ( lib . TCOD_sys_check_for_event ( mask , k . key_p if k else ffi . NULL , m . mouse_p if m else ffi . NULL ) )
Check for and return an event .
53,255
def sys_wait_for_event ( mask : int , k : Optional [ Key ] , m : Optional [ Mouse ] , flush : bool ) -> int : return int ( lib . TCOD_sys_wait_for_event ( mask , k . key_p if k else ffi . NULL , m . mouse_p if m else ffi . NULL , flush , ) )
Wait for an event then return .
53,256
def _atexit_verify ( ) -> None : if lib . TCOD_ctx . root : warnings . warn ( "The libtcod root console was implicitly deleted.\n" "Make sure the 'with' statement is used with the root console to" " ensure that it closes properly." , ResourceWarning , stacklevel = 2 , ) lib . TCOD_console_delete ( ffi . NULL )
Warns if the libtcod root console is implicitly deleted .
53,257
def clear ( self , back_r : int = 0 , back_g : int = 0 , back_b : int = 0 , fore_r : int = 0 , fore_g : int = 0 , fore_b : int = 0 , char : str = " " , ) -> None : n = self . width * self . height self . back_r = [ back_r ] * n self . back_g = [ back_g ] * n self . back_b = [ back_b ] * n self . fore_r = [ fore_r ] * n self . fore_g = [ fore_g ] * n self . fore_b = [ fore_b ] * n self . char = [ ord ( char ) ] * n
Clears the console . Values to fill it with are optional defaults to black with no characters .
53,258
def copy ( self ) -> "ConsoleBuffer" : other = ConsoleBuffer ( 0 , 0 ) other . width = self . width other . height = self . height other . back_r = list ( self . back_r ) other . back_g = list ( self . back_g ) other . back_b = list ( self . back_b ) other . fore_r = list ( self . fore_r ) other . fore_g = list ( self . fore_g ) other . fore_b = list ( self . fore_b ) other . char = list ( self . char ) return other
Returns a copy of this ConsoleBuffer .
53,259
def set_fore ( self , x : int , y : int , r : int , g : int , b : int , char : str ) -> None : i = self . width * y + x self . fore_r [ i ] = r self . fore_g [ i ] = g self . fore_b [ i ] = b self . char [ i ] = ord ( char )
Set the character and foreground color of one cell .
53,260
def set_back ( self , x : int , y : int , r : int , g : int , b : int ) -> None : i = self . width * y + x self . back_r [ i ] = r self . back_g [ i ] = g self . back_b [ i ] = b
Set the background color of one cell .
53,261
def set ( self , x : int , y : int , back_r : int , back_g : int , back_b : int , fore_r : int , fore_g : int , fore_b : int , char : str , ) -> None : i = self . width * y + x self . back_r [ i ] = back_r self . back_g [ i ] = back_g self . back_b [ i ] = back_b self . fore_r [ i ] = fore_r self . fore_g [ i ] = fore_g self . fore_b [ i ] = fore_b self . char [ i ] = ord ( char )
Set the background color foreground color and character of one cell .
53,262
def blit ( self , dest : tcod . console . Console , fill_fore : bool = True , fill_back : bool = True , ) -> None : if not dest : dest = tcod . console . Console . _from_cdata ( ffi . NULL ) if dest . width != self . width or dest . height != self . height : raise ValueError ( "ConsoleBuffer.blit: " "Destination console has an incorrect size." ) if fill_back : bg = dest . bg . ravel ( ) bg [ 0 : : 3 ] = self . back_r bg [ 1 : : 3 ] = self . back_g bg [ 2 : : 3 ] = self . back_b if fill_fore : fg = dest . fg . ravel ( ) fg [ 0 : : 3 ] = self . fore_r fg [ 1 : : 3 ] = self . fore_g fg [ 2 : : 3 ] = self . fore_b dest . ch . ravel ( ) [ : ] = self . char
Use libtcod s fill functions to write the buffer to a console .
53,263
def clear ( self , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_clear ( self . image_c , color )
Fill this entire Image with color .
53,264
def scale ( self , width : int , height : int ) -> None : lib . TCOD_image_scale ( self . image_c , width , height ) self . width , self . height = width , height
Scale this Image to the new width and height .
53,265
def set_key_color ( self , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_set_key_color ( self . image_c , color )
Set a color to be transparent during blitting functions .
53,266
def get_alpha ( self , x : int , y : int ) -> int : return lib . TCOD_image_get_alpha ( self . image_c , x , y )
Get the Image alpha of the pixel at x y .
53,267
def get_pixel ( self , x : int , y : int ) -> Tuple [ int , int , int ] : color = lib . TCOD_image_get_pixel ( self . image_c , x , y ) return color . r , color . g , color . b
Get the color of a pixel in this Image .
53,268
def get_mipmap_pixel ( self , left : float , top : float , right : float , bottom : float ) -> Tuple [ int , int , int ] : color = lib . TCOD_image_get_mipmap_pixel ( self . image_c , left , top , right , bottom ) return ( color . r , color . g , color . b )
Get the average color of a rectangle in this Image .
53,269
def put_pixel ( self , x : int , y : int , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_put_pixel ( self . image_c , x , y , color )
Change a pixel on this Image .
53,270
def blit ( self , console : tcod . console . Console , x : float , y : float , bg_blend : int , scale_x : float , scale_y : float , angle : float , ) -> None : lib . TCOD_image_blit ( self . image_c , _console ( console ) , x , y , bg_blend , scale_x , scale_y , angle , )
Blit onto a Console using scaling and rotation .
53,271
def blit_rect ( self , console : tcod . console . Console , x : int , y : int , width : int , height : int , bg_blend : int , ) -> None : lib . TCOD_image_blit_rect ( self . image_c , _console ( console ) , x , y , width , height , bg_blend )
Blit onto a Console without scaling or rotation .
53,272
def blit_2x ( self , console : tcod . console . Console , dest_x : int , dest_y : int , img_x : int = 0 , img_y : int = 0 , img_width : int = - 1 , img_height : int = - 1 , ) -> None : lib . TCOD_image_blit_2x ( self . image_c , _console ( console ) , dest_x , dest_y , img_x , img_y , img_width , img_height , )
Blit onto a Console with double resolution .
53,273
def save_as ( self , filename : str ) -> None : lib . TCOD_image_save ( self . image_c , filename . encode ( "utf-8" ) )
Save the Image to a 32 - bit . bmp or . png file .
53,274
def main ( ) : WIDTH , HEIGHT = 120 , 60 TITLE = None with tcod . console_init_root ( WIDTH , HEIGHT , TITLE , order = "F" , renderer = tcod . RENDERER_SDL ) as console : tcod . sys_set_fps ( 24 ) while True : tcod . console_flush ( ) for event in tcod . event . wait ( ) : print ( event ) if event . type == "QUIT" : raise SystemExit ( ) elif event . type == "MOUSEMOTION" : console . ch [ : , - 1 ] = 0 console . print_ ( 0 , HEIGHT - 1 , str ( event ) ) else : console . blit ( console , 0 , 0 , 0 , 1 , WIDTH , HEIGHT - 2 ) console . ch [ : , - 3 ] = 0 console . print_ ( 0 , HEIGHT - 3 , str ( event ) )
Example program for tcod . event
53,275
def parse_changelog ( args : Any ) -> Tuple [ str , str ] : with open ( "CHANGELOG.rst" , "r" ) as file : match = re . match ( pattern = r"(.*?Unreleased\n---+\n)(.+?)(\n*[^\n]+\n---+\n.*)" , string = file . read ( ) , flags = re . DOTALL , ) assert match header , changes , tail = match . groups ( ) tag = "%s - %s" % ( args . tag , datetime . date . today ( ) . isoformat ( ) ) tagged = "\n%s\n%s\n%s" % ( tag , "-" * len ( tag ) , changes ) if args . verbose : print ( tagged ) return "" . join ( ( header , tagged , tail ) ) , changes
Return an updated changelog and and the list of changes .
53,276
def split_once ( self , horizontal : bool , position : int ) -> None : cdata = self . _as_cdata ( ) lib . TCOD_bsp_split_once ( cdata , horizontal , position ) self . _unpack_bsp_tree ( cdata )
Split this partition into 2 sub - partitions .
53,277
def split_recursive ( self , depth : int , min_width : int , min_height : int , max_horizontal_ratio : float , max_vertical_ratio : float , seed : Optional [ tcod . random . Random ] = None , ) -> None : cdata = self . _as_cdata ( ) lib . TCOD_bsp_split_recursive ( cdata , seed or ffi . NULL , depth , min_width , min_height , max_horizontal_ratio , max_vertical_ratio , ) self . _unpack_bsp_tree ( cdata )
Divide this partition recursively .
53,278
def in_order ( self ) -> Iterator [ "BSP" ] : if self . children : yield from self . children [ 0 ] . in_order ( ) yield self yield from self . children [ 1 ] . in_order ( ) else : yield self
Iterate over this BSP s hierarchy in order .
53,279
def level_order ( self ) -> Iterator [ "BSP" ] : next = [ self ] while next : level = next next = [ ] yield from level for node in level : next . extend ( node . children )
Iterate over this BSP s hierarchy in level order .
53,280
def inverted_level_order ( self ) -> Iterator [ "BSP" ] : levels = [ ] next = [ self ] while next : levels . append ( next ) level = next next = [ ] for node in level : next . extend ( node . children ) while levels : yield from levels . pop ( )
Iterate over this BSP s hierarchy in inverse level order .
53,281
def contains ( self , x : int , y : int ) -> bool : return ( self . x <= x < self . x + self . width and self . y <= y < self . y + self . height )
Returns True if this node contains these coordinates .
53,282
def find_node ( self , x : int , y : int ) -> Optional [ "BSP" ] : if not self . contains ( x , y ) : return None for child in self . children : found = child . find_node ( x , y ) if found : return found return self
Return the deepest node which contains these coordinates .
53,283
def backport ( func ) : if not __debug__ : return func @ _functools . wraps ( func ) def deprecated_function ( * args , ** kargs ) : _warnings . warn ( 'This function name is deprecated' , DeprecationWarning , 2 ) return func ( * args , ** kargs ) deprecated_function . __doc__ = None return deprecated_function
Backport a function name into an old style for compatibility .
53,284
def _get_fov_type ( fov ) : "Return a FOV from a string" oldFOV = fov fov = str ( fov ) . upper ( ) if fov in _FOVTYPES : return _FOVTYPES [ fov ] if fov [ : 10 ] == 'PERMISSIVE' and fov [ 10 ] . isdigit ( ) and fov [ 10 ] != '9' : return 4 + int ( fov [ 10 ] ) raise _tdl . TDLError ( 'No such fov option as %s' % oldFOV )
Return a FOV from a string
53,285
def quick_fov ( x , y , callback , fov = 'PERMISSIVE' , radius = 7.5 , lightWalls = True , sphere = True ) : trueRadius = radius radius = int ( _math . ceil ( radius ) ) mapSize = radius * 2 + 1 fov = _get_fov_type ( fov ) setProp = _lib . TCOD_map_set_properties inFOV = _lib . TCOD_map_is_in_fov tcodMap = _lib . TCOD_map_new ( mapSize , mapSize ) try : for x_ , y_ in _itertools . product ( range ( mapSize ) , range ( mapSize ) ) : pos = ( x_ + x - radius , y_ + y - radius ) transparent = bool ( callback ( * pos ) ) setProp ( tcodMap , x_ , y_ , transparent , False ) _lib . TCOD_map_compute_fov ( tcodMap , radius , radius , radius , lightWalls , fov ) touched = set ( ) for x_ , y_ in _itertools . product ( range ( mapSize ) , range ( mapSize ) ) : if sphere and _math . hypot ( x_ - radius , y_ - radius ) > trueRadius : continue if inFOV ( tcodMap , x_ , y_ ) : touched . add ( ( x_ + x - radius , y_ + y - radius ) ) finally : _lib . TCOD_map_delete ( tcodMap ) return touched
All field - of - view functionality in one call .
53,286
def bresenham ( x1 , y1 , x2 , y2 ) : points = [ ] issteep = abs ( y2 - y1 ) > abs ( x2 - x1 ) if issteep : x1 , y1 = y1 , x1 x2 , y2 = y2 , x2 rev = False if x1 > x2 : x1 , x2 = x2 , x1 y1 , y2 = y2 , y1 rev = True deltax = x2 - x1 deltay = abs ( y2 - y1 ) error = int ( deltax / 2 ) y = y1 ystep = None if y1 < y2 : ystep = 1 else : ystep = - 1 for x in range ( x1 , x2 + 1 ) : if issteep : points . append ( ( y , x ) ) else : points . append ( ( x , y ) ) error -= deltay if error < 0 : y += ystep error += deltax if rev : points . reverse ( ) return points
Return a list of points in a bresenham line .
53,287
def compute_fov ( self , x , y , fov = 'PERMISSIVE' , radius = None , light_walls = True , sphere = True , cumulative = False ) : if radius is None : radius = 0 if cumulative : fov_copy = self . fov . copy ( ) lib . TCOD_map_compute_fov ( self . map_c , x , y , radius , light_walls , _get_fov_type ( fov ) ) if cumulative : self . fov [ : ] |= fov_copy return zip ( * np . where ( self . fov ) )
Compute the field - of - view of this Map and return an iterator of the points touched .
53,288
def compute_path ( self , start_x , start_y , dest_x , dest_y , diagonal_cost = _math . sqrt ( 2 ) ) : return tcod . path . AStar ( self , diagonal_cost ) . get_path ( start_x , start_y , dest_x , dest_y )
Get the shortest path between two points .
53,289
def get_path ( self , origX , origY , destX , destY ) : return super ( AStar , self ) . get_path ( origX , origY , destX , destY )
Get the shortest path from origXY to destXY .
53,290
def get_long_description ( ) : with open ( "README.rst" , "r" ) as f : readme = f . read ( ) with open ( "CHANGELOG.rst" , "r" ) as f : changelog = f . read ( ) changelog = changelog . replace ( "\nUnreleased\n------------------" , "" ) return "\n" . join ( [ readme , changelog ] )
Return this projects description .
53,291
def get_height_rect ( width : int , string : str ) -> int : string_ = string . encode ( "utf-8" ) return int ( lib . get_height_rect2 ( width , string_ , len ( string_ ) ) )
Return the number of lines which would be printed from these parameters .
53,292
def _get_root ( cls , order : Optional [ str ] = None ) -> "Console" : global _root_console if _root_console is None : _root_console = object . __new__ ( cls ) self = _root_console if order is not None : self . _order = order self . console_c = ffi . NULL self . _init_setup_console_data ( self . _order ) return self
Return a root console singleton with valid buffers .
53,293
def _init_setup_console_data ( self , order : str = "C" ) -> None : global _root_console self . _key_color = None if self . console_c == ffi . NULL : _root_console = self self . _console_data = lib . TCOD_ctx . root else : self . _console_data = ffi . cast ( "struct TCOD_Console*" , self . console_c ) self . _tiles = np . frombuffer ( ffi . buffer ( self . _console_data . tiles [ 0 : self . width * self . height ] ) , dtype = self . DTYPE , ) . reshape ( ( self . height , self . width ) ) self . _order = tcod . _internal . verify_order ( order )
Setup numpy arrays over libtcod data buffers .
53,294
def tiles ( self ) -> np . array : return self . _tiles . T if self . _order == "F" else self . _tiles
An array of this consoles tile data .
53,295
def __clear_warning ( self , name : str , value : Tuple [ int , int , int ] ) -> None : warnings . warn ( "Clearing with the console default values is deprecated.\n" "Add %s=%r to this call." % ( name , value ) , DeprecationWarning , stacklevel = 3 , )
Raise a warning for bad default values during calls to clear .
53,296
def __deprecate_defaults ( self , new_func : str , bg_blend : Any , alignment : Any = ... , clear : Any = ... , ) -> None : if not __debug__ : return fg = self . default_fg bg = self . default_bg if bg_blend == tcod . constants . BKGND_NONE : bg = None if bg_blend == tcod . constants . BKGND_DEFAULT : bg_blend = self . default_bg_blend else : bg_blend = None if bg_blend == tcod . constants . BKGND_NONE : bg = None bg_blend = None if bg_blend == tcod . constants . BKGND_SET : bg_blend = None if alignment is None : alignment = self . default_alignment if alignment == tcod . constants . LEFT : alignment = None else : alignment = None if clear is not ... : fg = None params = [ ] if clear is True : params . append ( 'ch=ord(" ")' ) if clear is False : params . append ( "ch=0" ) if fg is not None : params . append ( "fg=%s" % ( fg , ) ) if bg is not None : params . append ( "bg=%s" % ( bg , ) ) if bg_blend is not None : params . append ( "bg_blend=%s" % ( self . __BG_BLEND_LOOKUP [ bg_blend ] , ) ) if alignment is not None : params . append ( "alignment=%s" % ( self . __ALIGNMENT_LOOKUP [ alignment ] , ) ) param_str = ", " . join ( params ) if not param_str : param_str = "." else : param_str = " and add the following parameters:\n%s" % ( param_str , ) warnings . warn ( "Console functions using default values have been deprecated.\n" "Replace this method with `Console.%s`%s" % ( new_func , param_str ) , DeprecationWarning , stacklevel = 3 , )
Return the parameters needed to recreate the current default state .
53,297
def get_height_rect ( self , x : int , y : int , width : int , height : int , string : str ) -> int : string_ = string . encode ( "utf-8" ) return int ( lib . get_height_rect ( self . console_c , x , y , width , height , string_ , len ( string_ ) ) )
Return the height of this text word - wrapped into this rectangle .
53,298
def print_frame ( self , x : int , y : int , width : int , height : int , string : str = "" , clear : bool = True , bg_blend : int = tcod . constants . BKGND_DEFAULT , ) -> None : self . __deprecate_defaults ( "draw_frame" , bg_blend ) string = _fmt ( string ) if string else ffi . NULL lib . TCOD_console_printf_frame ( self . console_c , x , y , width , height , clear , bg_blend , string )
Draw a framed rectangle with optional text .
53,299
def blit ( self , dest : "Console" , dest_x : int = 0 , dest_y : int = 0 , src_x : int = 0 , src_y : int = 0 , width : int = 0 , height : int = 0 , fg_alpha : float = 1.0 , bg_alpha : float = 1.0 , key_color : Optional [ Tuple [ int , int , int ] ] = None , ) -> None : if hasattr ( src_y , "console_c" ) : ( src_x , src_y , width , height , dest , dest_x , dest_y , ) = ( dest , dest_x , dest_y , src_x , src_y , width , height ) warnings . warn ( "Parameter names have been moved around, see documentation." , DeprecationWarning , stacklevel = 2 , ) key_color = key_color or self . _key_color if key_color : key_color = ffi . new ( "TCOD_color_t*" , key_color ) lib . TCOD_console_blit_key_color ( self . console_c , src_x , src_y , width , height , dest . console_c , dest_x , dest_y , fg_alpha , bg_alpha , key_color , ) else : lib . TCOD_console_blit ( self . console_c , src_x , src_y , width , height , dest . console_c , dest_x , dest_y , fg_alpha , bg_alpha , )
Blit from this console onto the dest console .