idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
241,100 | 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 . | 61 | 14 |
241,101 | 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 . | 63 | 17 |
241,102 | 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 . | 111 | 14 |
241,103 | 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 . | 143 | 22 |
241,104 | 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 . | 139 | 13 |
241,105 | 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 . | 127 | 9 |
241,106 | 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 . | 119 | 12 |
241,107 | 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 . | 67 | 10 |
241,108 | 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 . | 94 | 8 |
241,109 | 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 . | 59 | 14 |
241,110 | 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 . | 63 | 13 |
241,111 | 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 . | 89 | 11 |
241,112 | 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 . | 63 | 12 |
241,113 | 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 . | 73 | 10 |
241,114 | 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 . | 47 | 15 |
241,115 | 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 . | 80 | 10 |
241,116 | 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 | 144 | 5 |
241,117 | 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 . | 173 | 14 |
241,118 | def map_copy ( source : tcod . map . Map , dest : tcod . map . Map ) -> None : if source . width != dest . width or source . height != dest . height : dest . __init__ ( # type: ignore source . width , source . height , source . _order ) dest . _Map__buffer [ : ] = source . _Map__buffer [ : ] | Copy map data from source to dest . | 85 | 8 |
241,119 | 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 . | 64 | 8 |
241,120 | 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 . | 48 | 9 |
241,121 | 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 . | 79 | 13 |
241,122 | 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 . | 58 | 20 |
241,123 | def noise_new ( dim : int , h : float = NOISE_DEFAULT_HURST , l : float = NOISE_DEFAULT_LACUNARITY , # noqa: E741 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 . | 94 | 6 |
241,124 | def noise_set_type ( n : tcod . noise . Noise , typ : int ) -> None : n . algorithm = typ | Set a Noise objects default noise algorithm . | 28 | 8 |
241,125 | 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 . | 72 | 10 |
241,126 | 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 . | 87 | 13 |
241,127 | 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 . | 89 | 10 |
241,128 | 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 . | 61 | 6 |
241,129 | def random_new ( algo : int = RNG_CMWC ) -> tcod . random . Random : return tcod . random . Random ( algo ) | Return a new Random instance . Using algo . | 36 | 10 |
241,130 | 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 . | 47 | 14 |
241,131 | 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 . | 57 | 10 |
241,132 | 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 . | 101 | 9 |
241,133 | 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 . | 62 | 12 |
241,134 | 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 . | 58 | 9 |
241,135 | 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 . | 48 | 7 |
241,136 | 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 . | 77 | 10 |
241,137 | def sys_register_SDL_renderer ( callback : Callable [ [ Any ] , None ] ) -> None : with _PropagateException ( ) as propagate : @ ffi . def_extern ( onerror = propagate ) # type: ignore 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 . | 107 | 11 |
241,138 | 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 . | 75 | 7 |
241,139 | 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 . | 82 | 7 |
241,140 | 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 . | 87 | 14 |
241,141 | 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 . | 163 | 19 |
241,142 | def copy ( self ) -> "ConsoleBuffer" : other = ConsoleBuffer ( 0 , 0 ) # type: "ConsoleBuffer" other . width = self . width other . height = self . height other . back_r = list ( self . back_r ) # make explicit copies of all lists 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 . | 144 | 8 |
241,143 | 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 . | 84 | 10 |
241,144 | 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 . | 69 | 8 |
241,145 | 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 . | 149 | 12 |
241,146 | 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 . | 231 | 15 |
241,147 | def clear ( self , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_clear ( self . image_c , color ) | Fill this entire Image with color . | 37 | 7 |
241,148 | 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 . | 46 | 10 |
241,149 | 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 . | 45 | 11 |
241,150 | 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 . | 40 | 11 |
241,151 | 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 . | 61 | 10 |
241,152 | 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 . | 83 | 11 |
241,153 | 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 | 7 |
241,154 | 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 . | 94 | 10 |
241,155 | 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 . | 83 | 10 |
241,156 | 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 . | 118 | 9 |
241,157 | 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 . | 40 | 17 |
241,158 | 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 | 211 | 7 |
241,159 | 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 . | 193 | 13 |
241,160 | 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 . | 61 | 9 |
241,161 | 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 . | 136 | 8 |
241,162 | 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 . | 56 | 11 |
241,163 | def level_order ( self ) -> Iterator [ "BSP" ] : next = [ self ] # type: List['BSP'] while next : level = next # type: List['BSP'] next = [ ] yield from level for node in level : next . extend ( node . children ) | Iterate over this BSP s hierarchy in level order . | 64 | 12 |
241,164 | def inverted_level_order ( self ) -> Iterator [ "BSP" ] : levels = [ ] # type: List[List['BSP']] next = [ self ] # type: List['BSP'] while next : levels . append ( next ) level = next # type: List['BSP'] 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 . | 94 | 13 |
241,165 | 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 . | 46 | 9 |
241,166 | 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 ) # type: Optional["BSP"] if found : return found return self | Return the deepest node which contains these coordinates . | 71 | 9 |
241,167 | 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 . | 84 | 12 |
241,168 | def _get_fov_type ( fov ) : 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 | 125 | 7 |
241,169 | 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 # make local inFOV = _lib . TCOD_map_is_in_fov tcodMap = _lib . TCOD_map_new ( mapSize , mapSize ) try : # pass no.1, write callback data to the tcodMap 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 ) # pass no.2, compute fov and build a list of points _lib . TCOD_map_compute_fov ( tcodMap , radius , radius , radius , lightWalls , fov ) touched = set ( ) # points touched by field of view 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 . | 384 | 11 |
241,170 | 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 # Reverse the list if the coordinates were reversed if rev : points . reverse ( ) return points | Return a list of points in a bresenham line . | 239 | 13 |
241,171 | def compute_fov ( self , x , y , fov = 'PERMISSIVE' , radius = None , light_walls = True , sphere = True , cumulative = False ) : # refresh cdata if radius is None : # infinite radius 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 . | 145 | 20 |
241,172 | 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 . | 73 | 8 |
241,173 | 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 . | 45 | 11 |
241,174 | 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 . | 102 | 5 |
241,175 | def get_height_rect ( width : int , string : str ) -> int : string_ = string . encode ( "utf-8" ) # type: bytes return int ( lib . get_height_rect2 ( width , string_ , len ( string_ ) ) ) | Return the number of lines which would be printed from these parameters . | 59 | 13 |
241,176 | 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 # type: 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 . | 100 | 10 |
241,177 | 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 . | 175 | 11 |
241,178 | def tiles ( self ) -> np . array : return self . _tiles . T if self . _order == "F" else self . _tiles | An array of this consoles tile data . | 33 | 8 |
241,179 | 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 . | 74 | 13 |
241,180 | def __deprecate_defaults ( self , new_func : str , bg_blend : Any , alignment : Any = ... , clear : Any = ... , ) -> None : if not __debug__ : return fg = self . default_fg # type: Any bg = self . default_bg # type: Any 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 . | 504 | 11 |
241,181 | 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 . | 80 | 13 |
241,182 | 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 . | 132 | 8 |
241,183 | 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 : # The old syntax is easy to detect and correct. if hasattr ( src_y , "console_c" ) : ( src_x , # type: ignore src_y , width , height , dest , # type: ignore 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 . | 368 | 10 |
241,184 | def print ( self , x : int , y : int , string : str , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , alignment : int = tcod . constants . LEFT , ) -> None : x , y = self . _pythonic_index ( x , y ) string_ = string . encode ( "utf-8" ) # type: bytes lib . console_print ( self . console_c , x , y , string_ , len ( string_ ) , ( fg , ) if fg is not None else ffi . NULL , ( bg , ) if bg is not None else ffi . NULL , bg_blend , alignment , ) | Print a string on a console with manual line breaks . | 190 | 11 |
241,185 | def draw_frame ( self , x : int , y : int , width : int , height : int , title : str = "" , clear : bool = True , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , ) -> None : x , y = self . _pythonic_index ( x , y ) title_ = title . encode ( "utf-8" ) # type: bytes lib . print_frame ( self . console_c , x , y , width , height , title_ , len ( title_ ) , ( fg , ) if fg is not None else ffi . NULL , ( bg , ) if bg is not None else ffi . NULL , bg_blend , clear , ) | Draw a framed rectangle with an optional title . | 200 | 9 |
241,186 | def draw_rect ( self , x : int , y : int , width : int , height : int , ch : int , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , ) -> None : x , y = self . _pythonic_index ( x , y ) lib . draw_rect ( self . console_c , x , y , width , height , ch , ( fg , ) if fg is not None else ffi . NULL , ( bg , ) if bg is not None else ffi . NULL , bg_blend , ) | Draw characters and colors over a rectangular region . | 166 | 9 |
241,187 | def blit ( self , image , x , y ) : # adjust the position with the local bbox x += self . font_bbox [ 2 ] - self . bbox [ 2 ] y += self . font_bbox [ 3 ] - self . bbox [ 3 ] x += self . font_bbox [ 0 ] - self . bbox [ 0 ] y += self . font_bbox [ 1 ] - self . bbox [ 1 ] image [ y : y + self . height , x : x + self . width ] = self . bitmap * 255 | blit to the image array | 123 | 6 |
241,188 | def parseBits ( self , hexcode , width ) : bitarray = [ ] for byte in hexcode [ : : - 1 ] : bits = int ( byte , 16 ) for x in range ( 4 ) : bitarray . append ( bool ( ( 2 ** x ) & bits ) ) bitarray = bitarray [ : : - 1 ] return enumerate ( bitarray [ : width ] ) | enumerate over bits in a line of data | 84 | 10 |
241,189 | def memory_warning ( config , context ) : used = psutil . Process ( os . getpid ( ) ) . memory_info ( ) . rss / 1048576 limit = float ( context . memory_limit_in_mb ) p = used / limit memory_threshold = config . get ( 'memory_warning_threshold' ) if p >= memory_threshold : config [ 'raven_client' ] . captureMessage ( 'Memory Usage Warning' , level = 'warning' , extra = { 'MemoryLimitInMB' : context . memory_limit_in_mb , 'MemoryUsedInMB' : math . floor ( used ) } ) else : # nothing to do check back later Timer ( .5 , memory_warning , ( config , context ) ) . start ( ) | Determines when memory usage is nearing it s max . | 171 | 12 |
241,190 | def install_timers ( config , context ) : timers = [ ] if config . get ( 'capture_timeout_warnings' ) : timeout_threshold = config . get ( 'timeout_warning_threshold' ) # Schedule the warning at the user specified threshold given in percent. # ie: 0.50 of 30000 ms = 15000ms # Schedule the error a few milliseconds before the actual timeout happens. time_remaining = context . get_remaining_time_in_millis ( ) / 1000 timers . append ( Timer ( time_remaining * timeout_threshold , timeout_warning , ( config , context ) ) ) timers . append ( Timer ( max ( time_remaining - .5 , 0 ) , timeout_error , [ config ] ) ) if config . get ( 'capture_memory_warnings' ) : # Schedule the memory watch dog interval. Warning will re-schedule itself if necessary. timers . append ( Timer ( .5 , memory_warning , ( config , context ) ) ) for t in timers : t . start ( ) return timers | Create the timers as specified by the plugin configuration . | 235 | 10 |
241,191 | def recurseforumcontents ( parser , token ) : bits = token . contents . split ( ) forums_contents_var = template . Variable ( bits [ 1 ] ) template_nodes = parser . parse ( ( 'endrecurseforumcontents' , ) ) parser . delete_first_token ( ) return RecurseTreeForumVisibilityContentNode ( template_nodes , forums_contents_var ) | Iterates over the content nodes and renders the contained forum block for each node . | 90 | 16 |
241,192 | def forum_list ( context , forum_visibility_contents ) : request = context . get ( 'request' ) tracking_handler = TrackingHandler ( request = request ) data_dict = { 'forum_contents' : forum_visibility_contents , 'unread_forums' : tracking_handler . get_unread_forums_from_list ( request . user , forum_visibility_contents . forums ) , 'user' : request . user , 'request' : request , } root_level = forum_visibility_contents . root_level if root_level is not None : data_dict [ 'root_level' ] = root_level data_dict [ 'root_level_middle' ] = root_level + 1 data_dict [ 'root_level_sub' ] = root_level + 2 return data_dict | Renders the considered forum list . | 186 | 7 |
241,193 | def get_object ( self , request , * args , * * kwargs ) : forum_pk = kwargs . get ( 'forum_pk' , None ) descendants = kwargs . get ( 'descendants' , None ) self . user = request . user if forum_pk : forum = get_object_or_404 ( Forum , pk = forum_pk ) forums_qs = ( forum . get_descendants ( include_self = True ) if descendants else Forum . objects . filter ( pk = forum_pk ) ) self . forums = request . forum_permission_handler . get_readable_forums ( forums_qs , request . user , ) else : self . forums = request . forum_permission_handler . get_readable_forums ( Forum . objects . all ( ) , request . user , ) | Handles the considered object . | 185 | 6 |
241,194 | def items ( self ) : return Topic . objects . filter ( forum__in = self . forums , approved = True ) . order_by ( '-last_post_on' ) | Returns the items to include into the feed . | 39 | 9 |
241,195 | def item_link ( self , item ) : return reverse_lazy ( 'forum_conversation:topic' , kwargs = { 'forum_slug' : item . forum . slug , 'forum_pk' : item . forum . pk , 'slug' : item . slug , 'pk' : item . id , } , ) | Generates a link for a specific item of the feed . | 79 | 12 |
241,196 | def topic_pages_inline_list ( topic ) : data_dict = { 'topic' : topic , } pages_number = ( ( topic . posts_count - 1 ) // machina_settings . TOPIC_POSTS_NUMBER_PER_PAGE ) + 1 if pages_number > 5 : data_dict [ 'first_pages' ] = range ( 1 , 5 ) data_dict [ 'last_page' ] = pages_number elif pages_number > 1 : data_dict [ 'first_pages' ] = range ( 1 , pages_number + 1 ) return data_dict | This will render an inline pagination for the posts related to the given topic . | 131 | 16 |
241,197 | def get_urls ( self ) : urls = super ( ) . get_urls ( ) forum_admin_urls = [ url ( r'^(?P<forum_id>[0-9]+)/move-forum/(?P<direction>up|down)/$' , self . admin_site . admin_view ( self . moveforum_view ) , name = 'forum_forum_move' , ) , url ( r'^edit-global-permissions/$' , self . admin_site . admin_view ( self . editpermissions_index_view ) , name = 'forum_forum_editpermission_index' , ) , url ( r'^edit-global-permissions/user/(?P<user_id>[0-9]+)/$' , self . admin_site . admin_view ( self . editpermissions_user_view ) , name = 'forum_forum_editpermission_user' , ) , url ( r'^edit-global-permissions/user/anonymous/$' , self . admin_site . admin_view ( self . editpermissions_anonymous_user_view ) , name = 'forum_forum_editpermission_anonymous_user' , ) , url ( r'^edit-global-permissions/group/(?P<group_id>[0-9]+)/$' , self . admin_site . admin_view ( self . editpermissions_group_view ) , name = 'forum_forum_editpermission_group' , ) , url ( r'^(?P<forum_id>[0-9]+)/edit-permissions/$' , self . admin_site . admin_view ( self . editpermissions_index_view ) , name = 'forum_forum_editpermission_index' , ) , url ( r'^(?P<forum_id>[0-9]+)/edit-permissions/user/(?P<user_id>[0-9]+)/$' , self . admin_site . admin_view ( self . editpermissions_user_view ) , name = 'forum_forum_editpermission_user' , ) , url ( r'^(?P<forum_id>[0-9]+)/edit-permissions/user/anonymous/$' , self . admin_site . admin_view ( self . editpermissions_anonymous_user_view ) , name = 'forum_forum_editpermission_anonymous_user' , ) , url ( r'^(?P<forum_id>[0-9]+)/edit-permissions/group/(?P<group_id>[0-9]+)/$' , self . admin_site . admin_view ( self . editpermissions_group_view ) , name = 'forum_forum_editpermission_group' , ) , ] return forum_admin_urls + urls | Returns the URLs associated with the admin abstraction . | 639 | 9 |
241,198 | def get_forum_perms_base_context ( self , request , obj = None ) : context = { 'adminform' : { 'model_admin' : self } , 'media' : self . media , 'object' : obj , 'app_label' : self . model . _meta . app_label , 'opts' : self . model . _meta , 'has_change_permission' : self . has_change_permission ( request , obj ) , } try : context . update ( self . admin_site . each_context ( request ) ) except TypeError : # pragma: no cover # Django 1.7 compatibility context . update ( self . admin_site . each_context ( ) ) except AttributeError : # pragma: no cover pass return context | Returns the context to provide to the template for permissions contents . | 171 | 12 |
241,199 | def moveforum_view ( self , request , forum_id , direction ) : forum = get_object_or_404 ( Forum , pk = forum_id ) # Fetch the target target , position = None , None if direction == 'up' : target , position = forum . get_previous_sibling ( ) , 'left' elif direction == 'down' : target , position = forum . get_next_sibling ( ) , 'right' # Do the move try : assert target is not None forum . move_to ( target , position ) except ( InvalidMove , AssertionError ) : pass self . message_user ( request , _ ( "'{}' forum successfully moved" ) . format ( forum . name ) ) return HttpResponseRedirect ( reverse ( 'admin:forum_forum_changelist' ) ) | Moves the given forum toward the requested direction . | 182 | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.