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,000 | def _normalizeRect ( self , x , y , width , height ) : x , y = self . _normalizePoint ( x , y ) # inherit _normalizePoint logic assert width is None or isinstance ( width , _INTTYPES ) , 'width must be an integer or None, got %s' % repr ( width ) assert height is None or isinstance ( height , _INTTYPES ) , 'height must be an integer or None, got %s' % repr ( height ) # if width or height are None then extend them to the edge if width is None : width = self . width - x elif width < 0 : # handle negative numbers width += self . width width = max ( 0 , width ) # a 'too big' negative is clamped zero if height is None : height = self . height - y height = max ( 0 , height ) elif height < 0 : height += self . height # reduce rect size to bounds width = min ( width , self . width - x ) height = min ( height , self . height - y ) return x , y , width , height | Check if the rectangle is in bounds and make minor adjustments . raise AssertionError s for any problems | 237 | 21 |
241,001 | def _normalizeCursor ( self , x , y ) : width , height = self . get_size ( ) assert width != 0 and height != 0 , 'can not print on a console with a width or height of zero' while x >= width : x -= width y += 1 while y >= height : if self . _scrollMode == 'scroll' : y -= 1 self . scroll ( 0 , - 1 ) elif self . _scrollMode == 'error' : # reset the cursor on error self . _cursor = ( 0 , 0 ) raise TDLError ( 'Cursor has reached the end of the console' ) return ( x , y ) | return the normalized the cursor position . | 141 | 7 |
241,002 | def set_mode ( self , mode ) : MODES = [ 'error' , 'scroll' ] if mode . lower ( ) not in MODES : raise TDLError ( 'mode must be one of %s, got %s' % ( MODES , repr ( mode ) ) ) self . _scrollMode = mode . lower ( ) | Configure how this console will react to the cursor writing past the end if the console . | 74 | 18 |
241,003 | def print_str ( self , string ) : x , y = self . _cursor for char in string : if char == '\n' : # line break x = 0 y += 1 continue if char == '\r' : # return x = 0 continue x , y = self . _normalizeCursor ( x , y ) self . draw_char ( x , y , char , self . _fg , self . _bg ) x += 1 self . _cursor = ( x , y ) | Print a string at the virtual cursor . | 108 | 8 |
241,004 | def write ( self , string ) : # some 'basic' line buffer stuff. # there must be an easier way to do this. The textwrap module didn't # help much. x , y = self . _normalizeCursor ( * self . _cursor ) width , height = self . get_size ( ) wrapper = _textwrap . TextWrapper ( initial_indent = ( ' ' * x ) , width = width ) writeLines = [ ] for line in string . split ( '\n' ) : if line : writeLines += wrapper . wrap ( line ) wrapper . initial_indent = '' else : writeLines . append ( [ ] ) for line in writeLines : x , y = self . _normalizeCursor ( x , y ) self . draw_str ( x , y , line [ x : ] , self . _fg , self . _bg ) y += 1 x = 0 y -= 1 self . _cursor = ( x , y ) | This method mimics basic file - like behaviour . | 214 | 10 |
241,005 | def draw_char ( self , x , y , char , fg = Ellipsis , bg = Ellipsis ) : #x, y = self._normalizePoint(x, y) _put_char_ex ( self . console_c , x , y , _format_char ( char ) , _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) , 1 ) | Draws a single character . | 98 | 6 |
241,006 | def draw_str ( self , x , y , string , fg = Ellipsis , bg = Ellipsis ) : x , y = self . _normalizePoint ( x , y ) fg , bg = _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) width , height = self . get_size ( ) def _drawStrGen ( x = x , y = y , string = string , width = width , height = height ) : """Generator for draw_str Iterates over ((x, y), ch) data for _set_batch, raising an error if the end of the console is reached. """ for char in _format_str ( string ) : if y == height : raise TDLError ( 'End of console reached.' ) yield ( ( x , y ) , char ) x += 1 # advance cursor if x == width : # line break x = 0 y += 1 self . _set_batch ( _drawStrGen ( ) , fg , bg ) | Draws a string starting at x and y . | 230 | 10 |
241,007 | def draw_rect ( self , x , y , width , height , string , fg = Ellipsis , bg = Ellipsis ) : x , y , width , height = self . _normalizeRect ( x , y , width , height ) fg , bg = _format_color ( fg , self . _fg ) , _format_color ( bg , self . _bg ) char = _format_char ( string ) # use itertools to make an x,y grid # using ctypes here reduces type converstions later #grid = _itertools.product((_ctypes.c_int(x) for x in range(x, x + width)), # (_ctypes.c_int(y) for y in range(y, y + height))) grid = _itertools . product ( ( x for x in range ( x , x + width ) ) , ( y for y in range ( y , y + height ) ) ) # zip the single character in a batch variable batch = zip ( grid , _itertools . repeat ( char , width * height ) ) self . _set_batch ( batch , fg , bg , nullChar = ( char is None ) ) | Draws a rectangle starting from x and y and extending to width and height . | 265 | 16 |
241,008 | def blit ( self , source , x = 0 , y = 0 , width = None , height = None , srcX = 0 , srcY = 0 , fg_alpha = 1.0 , bg_alpha = 1.0 ) : assert isinstance ( source , ( Console , Window ) ) , "source muse be a Window or Console instance" # handle negative indexes and rects # negative width and height will be set realtive to the destination # and will also be clamped to the smallest Console x , y , width , height = self . _normalizeRect ( x , y , width , height ) srcX , srcY , width , height = source . _normalizeRect ( srcX , srcY , width , height ) # translate source and self if any of them are Window instances srcX , srcY = source . _translate ( srcX , srcY ) source = source . console x , y = self . _translate ( x , y ) self = self . console if self == source : # if we are the same console then we need a third console to hold # onto the data, otherwise it tries to copy into itself and # starts destroying everything tmp = Console ( width , height ) _lib . TCOD_console_blit ( source . console_c , srcX , srcY , width , height , tmp . console_c , 0 , 0 , fg_alpha , bg_alpha ) _lib . TCOD_console_blit ( tmp . console_c , 0 , 0 , width , height , self . console_c , x , y , fg_alpha , bg_alpha ) else : _lib . TCOD_console_blit ( source . console_c , srcX , srcY , width , height , self . console_c , x , y , fg_alpha , bg_alpha ) | Blit another console or Window onto the current console . | 398 | 11 |
241,009 | def get_cursor ( self ) : x , y = self . _cursor width , height = self . parent . get_size ( ) while x >= width : x -= width y += 1 if y >= height and self . scrollMode == 'scroll' : y = height - 1 return x , y | Return the virtual cursor position . | 65 | 6 |
241,010 | def move ( self , x , y ) : self . _cursor = self . _normalizePoint ( x , y ) | Move the virtual cursor . | 27 | 5 |
241,011 | def scroll ( self , x , y ) : assert isinstance ( x , _INTTYPES ) , "x must be an integer, got %s" % repr ( x ) assert isinstance ( y , _INTTYPES ) , "y must be an integer, got %s" % repr ( x ) def getSlide ( x , length ) : """get the parameters needed to scroll the console in the given direction with x returns (x, length, srcx) """ if x > 0 : srcx = 0 length -= x elif x < 0 : srcx = abs ( x ) x = 0 length -= srcx else : srcx = 0 return x , length , srcx def getCover ( x , length ) : """return the (x, width) ranges of what is covered and uncovered""" cover = ( 0 , length ) # everything covered uncover = None # nothing uncovered if x > 0 : # left side uncovered cover = ( x , length - x ) uncover = ( 0 , x ) elif x < 0 : # right side uncovered x = abs ( x ) cover = ( 0 , length - x ) uncover = ( length - x , x ) return cover , uncover width , height = self . get_size ( ) if abs ( x ) >= width or abs ( y ) >= height : return self . clear ( ) # just clear the console normally # get the ranges of the areas that will be uncovered coverX , uncoverX = getCover ( x , width ) coverY , uncoverY = getCover ( y , height ) # so at this point we know that coverX and coverY makes a rect that # encases the area that we end up blitting to. uncoverX/Y makes a # rect in the corner of the uncovered area. So we need to combine # the uncoverX/Y with coverY/X to make what's left of the uncovered # area. Explaining it makes it mush easier to do now. # But first we need to blit. x , width , srcx = getSlide ( x , width ) y , height , srcy = getSlide ( y , height ) self . blit ( self , x , y , width , height , srcx , srcy ) if uncoverX : # clear sides (0x20 is space) self . draw_rect ( uncoverX [ 0 ] , coverY [ 0 ] , uncoverX [ 1 ] , coverY [ 1 ] , 0x20 , self . _fg , self . _bg ) if uncoverY : # clear top/bottom self . draw_rect ( coverX [ 0 ] , uncoverY [ 0 ] , coverX [ 1 ] , uncoverY [ 1 ] , 0x20 , self . _fg , self . _bg ) if uncoverX and uncoverY : # clear corner self . draw_rect ( uncoverX [ 0 ] , uncoverY [ 0 ] , uncoverX [ 1 ] , uncoverY [ 1 ] , 0x20 , self . _fg , self . _bg ) | Scroll the contents of the console in the direction of x y . | 636 | 13 |
241,012 | def _newConsole ( cls , console ) : self = cls . __new__ ( cls ) _BaseConsole . __init__ ( self ) self . console_c = console self . console = self self . width = _lib . TCOD_console_get_width ( console ) self . height = _lib . TCOD_console_get_height ( console ) return self | Make a Console instance from a console ctype | 83 | 9 |
241,013 | def _root_unhook ( self ) : global _rootinitialized , _rootConsoleRef # do we recognise this as the root console? # if not then assume the console has already been taken care of if ( _rootConsoleRef and _rootConsoleRef ( ) is self ) : # turn this console into a regular console unhooked = _lib . TCOD_console_new ( self . width , self . height ) _lib . TCOD_console_blit ( self . console_c , 0 , 0 , self . width , self . height , unhooked , 0 , 0 , 1 , 1 ) # delete root console from TDL and TCOD _rootinitialized = False _rootConsoleRef = None _lib . TCOD_console_delete ( self . console_c ) # this Console object is now a regular console self . console_c = unhooked | Change this root console into a normal Console object and delete the root console from TCOD | 182 | 17 |
241,014 | def _set_char ( self , x , y , char , fg = None , bg = None , bgblend = _lib . TCOD_BKGND_SET ) : # values are already formatted, honestly this function is redundant return _put_char_ex ( self . console_c , x , y , char , fg , bg , bgblend ) | Sets a character . This is called often and is designed to be as fast as possible . | 85 | 19 |
241,015 | def _set_batch ( self , batch , fg , bg , bgblend = 1 , nullChar = False ) : for ( x , y ) , char in batch : self . _set_char ( x , y , char , fg , bg , bgblend ) | Try to perform a batch operation otherwise fall back to _set_char . If fg and bg are defined then this is faster but not by very much . | 64 | 33 |
241,016 | def _translate ( self , x , y ) : # we add our position relative to our parent and then call then next parent up return self . parent . _translate ( ( x + self . x ) , ( y + self . y ) ) | Convertion x and y to their position on the root Console | 53 | 13 |
241,017 | def _pycall_path_old ( x1 : int , y1 : int , x2 : int , y2 : int , handle : Any ) -> float : func , userData = ffi . from_handle ( handle ) return func ( x1 , y1 , x2 , y2 , userData ) | libtcodpy style callback needs to preserve the old userData issue . | 68 | 15 |
241,018 | def _pycall_path_simple ( x1 : int , y1 : int , x2 : int , y2 : int , handle : Any ) -> float : return ffi . from_handle ( handle ) ( x1 , y1 , x2 , y2 ) | Does less and should run faster just calls the handle function . | 59 | 12 |
241,019 | def _get_pathcost_func ( name : str ) -> Callable [ [ int , int , int , int , Any ] , float ] : return ffi . cast ( # type: ignore "TCOD_path_func_t" , ffi . addressof ( lib , name ) ) | Return a properly cast PathCostArray callback . | 65 | 9 |
241,020 | def set_goal ( self , x : int , y : int ) -> None : lib . TCOD_dijkstra_compute ( self . _path_c , x , y ) | Set the goal point and recompute the Dijkstra path - finder . | 41 | 16 |
241,021 | def poll_event ( self ) : """ cdef tb_event e with self._poll_lock: with nogil: result = tb_poll_event(&e) assert(result >= 0) if e.ch: uch = unichr(e.ch) else: uch = None """ for e in tdl . event . get ( ) : # [ ] not all events are passed thru self . e . type = e . type if e . type == 'KEYDOWN' : self . e . key = e . key return self . e . gettuple ( ) | Wait for an event and return it . | 127 | 8 |
241,022 | def _new_from_cdata ( cls , cdata : Any ) -> "Random" : self = object . __new__ ( cls ) # type: "Random" self . random_c = cdata return self | Return a new instance encapsulating this cdata . | 49 | 10 |
241,023 | def guass ( self , mu : float , sigma : float ) -> float : return float ( lib . TCOD_random_get_gaussian_double ( self . random_c , mu , sigma ) ) | Return a random number using Gaussian distribution . | 47 | 9 |
241,024 | def inverse_guass ( self , mu : float , sigma : float ) -> float : return float ( lib . TCOD_random_get_gaussian_double_inv ( self . random_c , mu , sigma ) ) | Return a random Gaussian number using the Box - Muller transform . | 51 | 13 |
241,025 | def get_point ( self , * position ) : #array = self._array #for d, pos in enumerate(position): # array[d] = pos #array = self._cFloatArray(*position) array = _ffi . new ( self . _arrayType , position ) if self . _useOctaves : return ( self . _noiseFunc ( self . _noise , array , self . _octaves ) + 1 ) * 0.5 return ( self . _noiseFunc ( self . _noise , array ) + 1 ) * 0.5 | Return the noise value of a specific position . | 126 | 9 |
241,026 | def compute_fov ( transparency : np . array , x : int , y : int , radius : int = 0 , light_walls : bool = True , algorithm : int = tcod . constants . FOV_RESTRICTIVE , ) -> np . array : if len ( transparency . shape ) != 2 : raise TypeError ( "transparency must be an array of 2 dimensions" " (shape is %r)" % transparency . shape ) map_ = Map ( transparency . shape [ 1 ] , transparency . shape [ 0 ] ) map_ . transparent [ ... ] = transparency map_ . compute_fov ( x , y , radius , light_walls , algorithm ) return map_ . fov | Return the visible area of a field - of - view computation . | 150 | 13 |
241,027 | def compute_fov ( self , x : int , y : int , radius : int = 0 , light_walls : bool = True , algorithm : int = tcod . constants . FOV_RESTRICTIVE , ) -> None : lib . TCOD_map_compute_fov ( self . map_c , x , y , radius , light_walls , algorithm ) | Compute a field - of - view on the current instance . | 84 | 13 |
241,028 | def sample_mgrid ( self , mgrid : np . array ) -> np . array : mgrid = np . ascontiguousarray ( mgrid , np . float32 ) if mgrid . shape [ 0 ] != self . dimensions : raise ValueError ( "mgrid.shape[0] must equal self.dimensions, " "%r[0] != %r" % ( mgrid . shape , self . dimensions ) ) out = np . ndarray ( mgrid . shape [ 1 : ] , np . float32 ) if mgrid . shape [ 1 : ] != out . shape : raise ValueError ( "mgrid.shape[1:] must equal out.shape, " "%r[1:] != %r" % ( mgrid . shape , out . shape ) ) lib . NoiseSampleMeshGrid ( self . _tdl_noise_c , out . size , ffi . cast ( "float*" , mgrid . ctypes . data ) , ffi . cast ( "float*" , out . ctypes . data ) , ) return out | Sample a mesh - grid array and return the result . | 230 | 11 |
241,029 | def sample_ogrid ( self , ogrid : np . array ) -> np . array : if len ( ogrid ) != self . dimensions : raise ValueError ( "len(ogrid) must equal self.dimensions, " "%r != %r" % ( len ( ogrid ) , self . dimensions ) ) ogrids = [ np . ascontiguousarray ( array , np . float32 ) for array in ogrid ] out = np . ndarray ( [ array . size for array in ogrids ] , np . float32 ) lib . NoiseSampleOpenMeshGrid ( self . _tdl_noise_c , len ( ogrids ) , out . shape , [ ffi . cast ( "float*" , array . ctypes . data ) for array in ogrids ] , ffi . cast ( "float*" , out . ctypes . data ) , ) return out | Sample an open mesh - grid array and return the result . | 195 | 12 |
241,030 | def _processEvents ( ) : global _mousel , _mousem , _mouser , _eventsflushed , _pushedEvents _eventsflushed = True events = _pushedEvents # get events from event.push _pushedEvents = [ ] # then clear the pushed events queue mouse = _ffi . new ( 'TCOD_mouse_t *' ) libkey = _ffi . new ( 'TCOD_key_t *' ) while 1 : libevent = _lib . TCOD_sys_check_for_event ( _lib . TCOD_EVENT_ANY , libkey , mouse ) if not libevent : # no more events from libtcod break #if mouse.dx or mouse.dy: if libevent & _lib . TCOD_EVENT_MOUSE_MOVE : events . append ( MouseMotion ( ( mouse . x , mouse . y ) , ( mouse . cx , mouse . cy ) , ( mouse . dx , mouse . dy ) , ( mouse . dcx , mouse . dcy ) ) ) mousepos = ( ( mouse . x , mouse . y ) , ( mouse . cx , mouse . cy ) ) for oldstate , newstate , released , button in zip ( ( _mousel , _mousem , _mouser ) , ( mouse . lbutton , mouse . mbutton , mouse . rbutton ) , ( mouse . lbutton_pressed , mouse . mbutton_pressed , mouse . rbutton_pressed ) , ( 1 , 2 , 3 ) ) : if released : if not oldstate : events . append ( MouseDown ( button , * mousepos ) ) events . append ( MouseUp ( button , * mousepos ) ) if newstate : events . append ( MouseDown ( button , * mousepos ) ) elif newstate and not oldstate : events . append ( MouseDown ( button , * mousepos ) ) if mouse . wheel_up : events . append ( MouseDown ( 4 , * mousepos ) ) if mouse . wheel_down : events . append ( MouseDown ( 5 , * mousepos ) ) _mousel = mouse . lbutton _mousem = mouse . mbutton _mouser = mouse . rbutton if libkey . vk == _lib . TCODK_NONE : break if libkey . pressed : keyevent = KeyDown else : keyevent = KeyUp events . append ( keyevent ( libkey . vk , libkey . c . decode ( 'ascii' , errors = 'ignore' ) , _ffi . string ( libkey . text ) . decode ( 'utf-8' ) , libkey . shift , libkey . lalt , libkey . ralt , libkey . lctrl , libkey . rctrl , libkey . lmeta , libkey . rmeta , ) ) if _lib . TCOD_console_is_window_closed ( ) : events . append ( Quit ( ) ) _eventQueue . extend ( events ) | Flushes the event queue from libtcod into the global list _eventQueue | 641 | 16 |
241,031 | def wait ( timeout = None , flush = True ) : if timeout is not None : timeout = timeout + _time . clock ( ) # timeout at this time while True : if _eventQueue : return _eventQueue . pop ( 0 ) if flush : # a full 'round' of events need to be processed before flushing _tdl . flush ( ) if timeout and _time . clock ( ) >= timeout : return None # return None on timeout _time . sleep ( 0.001 ) # sleep 1ms _processEvents ( ) | Wait for an event . | 112 | 5 |
241,032 | def run_once ( self ) : if not hasattr ( self , '_App__prevTime' ) : self . __prevTime = _time . clock ( ) # initiate __prevTime for event in get ( ) : if event . type : # exclude custom events with a blank type variable # call the ev_* methods method = 'ev_%s' % event . type # ev_TYPE getattr ( self , method ) ( event ) if event . type == 'KEYDOWN' : # call the key_* methods method = 'key_%s' % event . key # key_KEYNAME if hasattr ( self , method ) : # silently exclude undefined methods getattr ( self , method ) ( event ) newTime = _time . clock ( ) self . update ( newTime - self . __prevTime ) self . __prevTime = newTime | Pump events to this App instance and then return . | 183 | 11 |
241,033 | def load_truetype_font ( path : str , tile_width : int , tile_height : int ) -> Tileset : if not os . path . exists ( path ) : raise RuntimeError ( "File not found:\n\t%s" % ( os . path . realpath ( path ) , ) ) return Tileset . _claim ( lib . TCOD_load_truetype_font_ ( path . encode ( ) , tile_width , tile_height ) ) | Return a new Tileset from a . ttf or . otf file . | 109 | 17 |
241,034 | def set_truetype_font ( path : str , tile_width : int , tile_height : int ) -> None : if not os . path . exists ( path ) : raise RuntimeError ( "File not found:\n\t%s" % ( os . path . realpath ( path ) , ) ) lib . TCOD_tileset_load_truetype_ ( path . encode ( ) , tile_width , tile_height ) | Set the default tileset from a . ttf or . otf file . | 100 | 16 |
241,035 | def get_tile ( self , codepoint : int ) -> np . array : tile = np . zeros ( self . tile_shape + ( 4 , ) , dtype = np . uint8 ) lib . TCOD_tileset_get_tile_ ( self . _tileset_p , codepoint , ffi . cast ( "struct TCOD_ColorRGBA*" , tile . ctypes . data ) , ) return tile | Return a copy of a tile for the given codepoint . | 98 | 13 |
241,036 | def set_tile ( self , codepoint : int , tile : np . array ) -> None : tile = np . ascontiguousarray ( tile , dtype = np . uint8 ) if tile . shape == self . tile_shape : full_tile = np . empty ( self . tile_shape + ( 4 , ) , dtype = np . uint8 ) full_tile [ : , : , : 3 ] = 255 full_tile [ : , : , 3 ] = tile return self . set_tile ( codepoint , full_tile ) required = self . tile_shape + ( 4 , ) if tile . shape != required : raise ValueError ( "Tile shape must be %r or %r, got %r." % ( required , self . tile_shape , tile . shape ) ) lib . TCOD_tileset_set_tile_ ( self . _tileset_p , codepoint , ffi . cast ( "struct TCOD_ColorRGBA*" , tile . ctypes . data ) , ) | Upload a tile into this array . | 224 | 7 |
241,037 | def fix_header ( filepath ) : with open ( filepath , "r+" ) as f : current = f . read ( ) fixed = "\n" . join ( line . strip ( ) for line in current . split ( "\n" ) ) if current == fixed : return f . seek ( 0 ) f . truncate ( ) f . write ( fixed ) | Removes leading whitespace from a MacOS header file . | 79 | 12 |
241,038 | def find_sdl_attrs ( prefix : str ) -> Iterator [ Tuple [ str , Any ] ] : from tcod . _libtcod import lib if prefix . startswith ( "SDL_" ) : name_starts_at = 4 elif prefix . startswith ( "SDL" ) : name_starts_at = 3 else : name_starts_at = 0 for attr in dir ( lib ) : if attr . startswith ( prefix ) : yield attr [ name_starts_at : ] , getattr ( lib , attr ) | Return names and values from tcod . lib . | 131 | 10 |
241,039 | def write_library_constants ( ) : from tcod . _libtcod import lib , ffi import tcod . color with open ( "tcod/constants.py" , "w" ) as f : all_names = [ ] f . write ( CONSTANT_MODULE_HEADER ) for name in dir ( lib ) : value = getattr ( lib , name ) if name [ : 5 ] == "TCOD_" : if name . isupper ( ) : # const names f . write ( "%s = %r\n" % ( name [ 5 : ] , value ) ) all_names . append ( name [ 5 : ] ) elif name . startswith ( "FOV" ) : # fov const names f . write ( "%s = %r\n" % ( name , value ) ) all_names . append ( name ) elif name [ : 6 ] == "TCODK_" : # key name f . write ( "KEY_%s = %r\n" % ( name [ 6 : ] , value ) ) all_names . append ( "KEY_%s" % name [ 6 : ] ) f . write ( "\n# --- colors ---\n" ) for name in dir ( lib ) : if name [ : 5 ] != "TCOD_" : continue value = getattr ( lib , name ) if not isinstance ( value , ffi . CData ) : continue if ffi . typeof ( value ) != ffi . typeof ( "TCOD_color_t" ) : continue color = tcod . color . Color . _new_from_cdata ( value ) f . write ( "%s = %r\n" % ( name [ 5 : ] , color ) ) all_names . append ( name [ 5 : ] ) all_names = ",\n " . join ( '"%s"' % name for name in all_names ) f . write ( "\n__all__ = [\n %s,\n]\n" % ( all_names , ) ) with open ( "tcod/event_constants.py" , "w" ) as f : all_names = [ ] f . write ( EVENT_CONSTANT_MODULE_HEADER ) f . write ( "# --- SDL scancodes ---\n" ) f . write ( "%s\n_REVERSE_SCANCODE_TABLE = %s\n" % parse_sdl_attrs ( "SDL_SCANCODE" , all_names ) ) f . write ( "\n# --- SDL keyboard symbols ---\n" ) f . write ( "%s\n_REVERSE_SYM_TABLE = %s\n" % parse_sdl_attrs ( "SDLK" , all_names ) ) f . write ( "\n# --- SDL keyboard modifiers ---\n" ) f . write ( "%s\n_REVERSE_MOD_TABLE = %s\n" % parse_sdl_attrs ( "KMOD" , all_names ) ) f . write ( "\n# --- SDL wheel ---\n" ) f . write ( "%s\n_REVERSE_WHEEL_TABLE = %s\n" % parse_sdl_attrs ( "SDL_MOUSEWHEEL" , all_names ) ) all_names = ",\n " . join ( '"%s"' % name for name in all_names ) f . write ( "\n__all__ = [\n %s,\n]\n" % ( all_names , ) ) | Write libtcod constants into the tcod . constants module . | 791 | 13 |
241,040 | def visit_EnumeratorList ( self , node ) : for type , enum in node . children ( ) : if enum . value is None : pass elif isinstance ( enum . value , ( c_ast . BinaryOp , c_ast . UnaryOp ) ) : enum . value = c_ast . Constant ( "int" , "..." ) elif hasattr ( enum . value , "type" ) : enum . value = c_ast . Constant ( enum . value . type , "..." ) | Replace enumerator expressions with ... stubs . | 109 | 10 |
241,041 | def bsp_new_with_size ( x : int , y : int , w : int , h : int ) -> tcod . bsp . BSP : return Bsp ( x , y , w , h ) | Create a new BSP instance with the given rectangle . | 48 | 11 |
241,042 | def _bsp_traverse ( node_iter : Iterable [ tcod . bsp . BSP ] , callback : Callable [ [ tcod . bsp . BSP , Any ] , None ] , userData : Any , ) -> None : for node in node_iter : callback ( node , userData ) | pack callback into a handle for use with the callback _pycall_bsp_callback | 68 | 17 |
241,043 | def color_lerp ( c1 : Tuple [ int , int , int ] , c2 : Tuple [ int , int , int ] , a : float ) -> Color : return Color . _new_from_cdata ( lib . TCOD_color_lerp ( c1 , c2 , a ) ) | Return the linear interpolation between two colors . | 69 | 9 |
241,044 | def color_scale_HSV ( c : Color , scoef : float , vcoef : float ) -> None : color_p = ffi . new ( "TCOD_color_t*" ) color_p . r , color_p . g , color_p . b = c . r , c . g , c . b lib . TCOD_color_scale_HSV ( color_p , scoef , vcoef ) c [ : ] = color_p . r , color_p . g , color_p . b | Scale a color s saturation and value . | 121 | 8 |
241,045 | def color_gen_map ( colors : Iterable [ Tuple [ int , int , int ] ] , indexes : Iterable [ int ] ) -> List [ Color ] : ccolors = ffi . new ( "TCOD_color_t[]" , colors ) cindexes = ffi . new ( "int[]" , indexes ) cres = ffi . new ( "TCOD_color_t[]" , max ( indexes ) + 1 ) lib . TCOD_color_gen_map ( cres , len ( ccolors ) , ccolors , cindexes ) return [ Color . _new_from_cdata ( cdata ) for cdata in cres ] | Return a smoothly defined scale of colors . | 150 | 8 |
241,046 | def console_init_root ( w : int , h : int , title : Optional [ str ] = None , fullscreen : bool = False , renderer : Optional [ int ] = None , order : str = "C" , ) -> tcod . console . Console : if title is None : # Use the scripts filename as the title. title = os . path . basename ( sys . argv [ 0 ] ) if renderer is None : warnings . warn ( "A renderer should be given, see the online documentation." , DeprecationWarning , stacklevel = 2 , ) renderer = tcod . constants . RENDERER_SDL elif renderer in ( tcod . constants . RENDERER_SDL , tcod . constants . RENDERER_OPENGL , tcod . constants . RENDERER_GLSL , ) : warnings . warn ( "The SDL, OPENGL, and GLSL renderers are deprecated." , DeprecationWarning , stacklevel = 2 , ) lib . TCOD_console_init_root ( w , h , _bytes ( title ) , fullscreen , renderer ) console = tcod . console . Console . _get_root ( order ) console . clear ( ) return console | Set up the primary display and return the root console . | 270 | 11 |
241,047 | def console_set_custom_font ( fontFile : AnyStr , flags : int = FONT_LAYOUT_ASCII_INCOL , nb_char_horiz : int = 0 , nb_char_vertic : int = 0 , ) -> None : if not os . path . exists ( fontFile ) : raise RuntimeError ( "File not found:\n\t%s" % ( os . path . realpath ( fontFile ) , ) ) lib . TCOD_console_set_custom_font ( _bytes ( fontFile ) , flags , nb_char_horiz , nb_char_vertic ) | Load the custom font file at fontFile . | 140 | 9 |
241,048 | def console_get_width ( con : tcod . console . Console ) -> int : return int ( lib . TCOD_console_get_width ( _console ( con ) ) ) | Return the width of a console . | 40 | 7 |
241,049 | def console_get_height ( con : tcod . console . Console ) -> int : return int ( lib . TCOD_console_get_height ( _console ( con ) ) ) | Return the height of a console . | 40 | 7 |
241,050 | def console_map_ascii_code_to_font ( asciiCode : int , fontCharX : int , fontCharY : int ) -> None : lib . TCOD_console_map_ascii_code_to_font ( _int ( asciiCode ) , fontCharX , fontCharY ) | Set a character code to new coordinates on the tile - set . | 73 | 13 |
241,051 | def console_map_ascii_codes_to_font ( firstAsciiCode : int , nbCodes : int , fontCharX : int , fontCharY : int ) -> None : lib . TCOD_console_map_ascii_codes_to_font ( _int ( firstAsciiCode ) , nbCodes , fontCharX , fontCharY ) | Remap a contiguous set of codes to a contiguous set of tiles . | 87 | 14 |
241,052 | def console_map_string_to_font ( s : str , fontCharX : int , fontCharY : int ) -> None : lib . TCOD_console_map_string_to_font_utf ( _unicode ( s ) , fontCharX , fontCharY ) | Remap a string of codes to a contiguous set of tiles . | 62 | 13 |
241,053 | def console_set_default_background ( con : tcod . console . Console , col : Tuple [ int , int , int ] ) -> None : lib . TCOD_console_set_default_background ( _console ( con ) , col ) | Change the default background color for a console . | 54 | 9 |
241,054 | def console_set_default_foreground ( con : tcod . console . Console , col : Tuple [ int , int , int ] ) -> None : lib . TCOD_console_set_default_foreground ( _console ( con ) , col ) | Change the default foreground color for a console . | 56 | 9 |
241,055 | def console_put_char_ex ( con : tcod . console . Console , x : int , y : int , c : Union [ int , str ] , fore : Tuple [ int , int , int ] , back : Tuple [ int , int , int ] , ) -> None : lib . TCOD_console_put_char_ex ( _console ( con ) , x , y , _int ( c ) , fore , back ) | Draw the character c at x y using the colors fore and back . | 96 | 14 |
241,056 | def console_set_char_background ( con : tcod . console . Console , x : int , y : int , col : Tuple [ int , int , int ] , flag : int = BKGND_SET , ) -> None : lib . TCOD_console_set_char_background ( _console ( con ) , x , y , col , flag ) | Change the background color of x y to col using a blend mode . | 80 | 14 |
241,057 | def console_set_char_foreground ( con : tcod . console . Console , x : int , y : int , col : Tuple [ int , int , int ] ) -> None : lib . TCOD_console_set_char_foreground ( _console ( con ) , x , y , col ) | Change the foreground color of x y to col . | 68 | 10 |
241,058 | def console_set_char ( con : tcod . console . Console , x : int , y : int , c : Union [ int , str ] ) -> None : lib . TCOD_console_set_char ( _console ( con ) , x , y , _int ( c ) ) | Change the character at x y to c keeping the current colors . | 63 | 13 |
241,059 | def console_set_background_flag ( con : tcod . console . Console , flag : int ) -> None : lib . TCOD_console_set_background_flag ( _console ( con ) , flag ) | Change the default blend mode for this console . | 46 | 9 |
241,060 | def console_get_background_flag ( con : tcod . console . Console ) -> int : return int ( lib . TCOD_console_get_background_flag ( _console ( con ) ) ) | Return this consoles current blend mode . | 44 | 7 |
241,061 | def console_set_alignment ( con : tcod . console . Console , alignment : int ) -> None : lib . TCOD_console_set_alignment ( _console ( con ) , alignment ) | Change this consoles current alignment mode . | 44 | 7 |
241,062 | def console_get_alignment ( con : tcod . console . Console ) -> int : return int ( lib . TCOD_console_get_alignment ( _console ( con ) ) ) | Return this consoles current alignment mode . | 42 | 7 |
241,063 | def console_print_ex ( con : tcod . console . Console , x : int , y : int , flag : int , alignment : int , fmt : str , ) -> None : lib . TCOD_console_printf_ex ( _console ( con ) , x , y , flag , alignment , _fmt ( fmt ) ) | Print a string on a console using a blend mode and alignment mode . | 72 | 14 |
241,064 | def console_print_rect_ex ( con : tcod . console . Console , x : int , y : int , w : int , h : int , flag : int , alignment : int , fmt : str , ) -> int : return int ( lib . TCOD_console_printf_rect_ex ( _console ( con ) , x , y , w , h , flag , alignment , _fmt ( fmt ) ) ) | Print a string constrained to a rectangle with blend and alignment . | 92 | 12 |
241,065 | def console_get_height_rect ( con : tcod . console . Console , x : int , y : int , w : int , h : int , fmt : str ) -> int : return int ( lib . TCOD_console_get_height_rect_fmt ( _console ( con ) , x , y , w , h , _fmt ( fmt ) ) ) | Return the height of this text once word - wrapped into this rectangle . | 82 | 14 |
241,066 | def console_print_frame ( con : tcod . console . Console , x : int , y : int , w : int , h : int , clear : bool = True , flag : int = BKGND_DEFAULT , fmt : str = "" , ) -> None : fmt = _fmt ( fmt ) if fmt else ffi . NULL lib . TCOD_console_printf_frame ( _console ( con ) , x , y , w , h , clear , flag , fmt ) | Draw a framed rectangle with optinal text . | 106 | 9 |
241,067 | def console_get_default_background ( con : tcod . console . Console ) -> Color : return Color . _new_from_cdata ( lib . TCOD_console_get_default_background ( _console ( con ) ) ) | Return this consoles default background color . | 52 | 7 |
241,068 | def console_get_default_foreground ( con : tcod . console . Console ) -> Color : return Color . _new_from_cdata ( lib . TCOD_console_get_default_foreground ( _console ( con ) ) ) | Return this consoles default foreground color . | 54 | 7 |
241,069 | def console_get_char_background ( con : tcod . console . Console , x : int , y : int ) -> Color : return Color . _new_from_cdata ( lib . TCOD_console_get_char_background ( _console ( con ) , x , y ) ) | Return the background color at the x y of this console . | 64 | 12 |
241,070 | def console_get_char_foreground ( con : tcod . console . Console , x : int , y : int ) -> Color : return Color . _new_from_cdata ( lib . TCOD_console_get_char_foreground ( _console ( con ) , x , y ) ) | Return the foreground color at the x y of this console . | 66 | 12 |
241,071 | def console_get_char ( con : tcod . console . Console , x : int , y : int ) -> int : return lib . TCOD_console_get_char ( _console ( con ) , x , y ) | Return the character at the x y of this console . | 49 | 11 |
241,072 | def console_wait_for_keypress ( flush : bool ) -> Key : key = Key ( ) lib . TCOD_console_wait_for_keypress_wrapper ( key . key_p , flush ) return key | Block until the user presses a key then returns a new Key . | 48 | 13 |
241,073 | def console_from_file ( filename : str ) -> tcod . console . Console : return tcod . console . Console . _from_cdata ( lib . TCOD_console_from_file ( filename . encode ( "utf-8" ) ) ) | Return a new console object from a filename . | 56 | 9 |
241,074 | def console_blit ( src : tcod . console . Console , x : int , y : int , w : int , h : int , dst : tcod . console . Console , xdst : int , ydst : int , ffade : float = 1.0 , bfade : float = 1.0 , ) -> None : lib . TCOD_console_blit ( _console ( src ) , x , y , w , h , _console ( dst ) , xdst , ydst , ffade , bfade ) | Blit the console src from x y w h to console dst at xdst ydst . | 120 | 21 |
241,075 | def console_delete ( con : tcod . console . Console ) -> None : con = _console ( con ) if con == ffi . NULL : lib . TCOD_console_delete ( con ) warnings . warn ( "Instead of this call you should use a with statement to ensure" " the root console closes, for example:" "\n with tcod.console_init_root(...) as root_console:" "\n ..." , DeprecationWarning , stacklevel = 2 , ) else : warnings . warn ( "You no longer need to make this call, " "Console's are deleted when they go out of scope." , DeprecationWarning , stacklevel = 2 , ) | Closes the window if con is the root console . | 144 | 11 |
241,076 | def console_fill_foreground ( con : tcod . console . Console , r : Sequence [ int ] , g : Sequence [ int ] , b : Sequence [ int ] , ) -> None : if len ( r ) != len ( g ) or len ( r ) != len ( b ) : raise TypeError ( "R, G and B must all have the same size." ) if ( isinstance ( r , np . ndarray ) and isinstance ( g , np . ndarray ) and isinstance ( b , np . ndarray ) ) : # numpy arrays, use numpy's ctypes functions r_ = np . ascontiguousarray ( r , dtype = np . intc ) g_ = np . ascontiguousarray ( g , dtype = np . intc ) b_ = np . ascontiguousarray ( b , dtype = np . intc ) cr = ffi . cast ( "int *" , r_ . ctypes . data ) cg = ffi . cast ( "int *" , g_ . ctypes . data ) cb = ffi . cast ( "int *" , b_ . ctypes . data ) else : # otherwise convert using ffi arrays cr = ffi . new ( "int[]" , r ) cg = ffi . new ( "int[]" , g ) cb = ffi . new ( "int[]" , b ) lib . TCOD_console_fill_foreground ( _console ( con ) , cr , cg , cb ) | Fill the foregound of a console with r g b . | 333 | 13 |
241,077 | def console_fill_char ( con : tcod . console . Console , arr : Sequence [ int ] ) -> None : if isinstance ( arr , np . ndarray ) : # numpy arrays, use numpy's ctypes functions np_array = np . ascontiguousarray ( arr , dtype = np . intc ) carr = ffi . cast ( "int *" , np_array . ctypes . data ) else : # otherwise convert using the ffi module carr = ffi . new ( "int[]" , arr ) lib . TCOD_console_fill_char ( _console ( con ) , carr ) | Fill the character tiles of a console with an array . | 139 | 11 |
241,078 | def console_load_asc ( con : tcod . console . Console , filename : str ) -> bool : return bool ( lib . TCOD_console_load_asc ( _console ( con ) , filename . encode ( "utf-8" ) ) ) | Update a console from a non - delimited ASCII . asc file . | 55 | 14 |
241,079 | def console_save_asc ( con : tcod . console . Console , filename : str ) -> bool : return bool ( lib . TCOD_console_save_asc ( _console ( con ) , filename . encode ( "utf-8" ) ) ) | Save a console to a non - delimited ASCII . asc file . | 55 | 14 |
241,080 | def console_load_apf ( con : tcod . console . Console , filename : str ) -> bool : return bool ( lib . TCOD_console_load_apf ( _console ( con ) , filename . encode ( "utf-8" ) ) ) | Update a console from an ASCII Paint . apf file . | 57 | 12 |
241,081 | def console_save_apf ( con : tcod . console . Console , filename : str ) -> bool : return bool ( lib . TCOD_console_save_apf ( _console ( con ) , filename . encode ( "utf-8" ) ) ) | Save a console to an ASCII Paint . apf file . | 57 | 12 |
241,082 | def console_load_xp ( con : tcod . console . Console , filename : str ) -> bool : return bool ( lib . TCOD_console_load_xp ( _console ( con ) , filename . encode ( "utf-8" ) ) ) | Update a console from a REXPaint . xp file . | 55 | 12 |
241,083 | def console_save_xp ( con : tcod . console . Console , filename : str , compress_level : int = 9 ) -> bool : return bool ( lib . TCOD_console_save_xp ( _console ( con ) , filename . encode ( "utf-8" ) , compress_level ) ) | Save a console to a REXPaint . xp file . | 67 | 12 |
241,084 | 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 . | 56 | 13 |
241,085 | 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 . | 165 | 14 |
241,086 | 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 . | 136 | 14 |
241,087 | 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 . | 50 | 10 |
241,088 | 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 . | 100 | 12 |
241,089 | 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 . | 82 | 6 |
241,090 | 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 . | 84 | 6 |
241,091 | 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 . | 38 | 9 |
241,092 | 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 . | 86 | 7 |
241,093 | 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 . | 42 | 8 |
241,094 | 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 . | 160 | 15 |
241,095 | 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 . | 111 | 17 |
241,096 | 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 . | 174 | 11 |
241,097 | 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 | 36 | 12 |
241,098 | 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 . | 61 | 10 |
241,099 | 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 . | 100 | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.