Back to index

freevial  1.2
Classes | Functions | Variables
common.freevialglob Namespace Reference

Classes

class  Equip
class  helpOnScreen
class  frameRate

Functions

def bitCategoria
def loadImage
def loadSound
def set_default_font
def render_text
def screenshot
def count_not_empty
def maxPunts
def puntsTotals
def teamsActius
def teamsTancat
def teamsGuanyador
def seguentEquipActiu
def anteriorEquipActiu
def list2string
def createTextSurface
def replaceKeywoards
def readLocalizedHelpFile
def createHelpScreen
def initTextos
def valorText
def colorsCategories
def firstExistingDirectory

Variables

list textos = []
string default_font = '/usr/share/fonts/truetype/unfonts/UnBatangBold.ttf'
tuple i_colors_cat = ( (0,0,255), (255,128,0), (0,255,0),(255,0,0),(255,0,255), (255,255,0) )
int HOS_SCORE_MODE0 = 0
int HOS_SCORE_MODE1 = 1
int HOS_SCORE_MODE2 = 2
int HOS_QUIT = 3
int HOS_YES = 4
int HOS_NO = 5
int HOS_PREGUNTADOR_RUN = 6
int HOS_PREGUNTADOR_END = 7
int HOS_SCORE_MODEW = 8
int HOS_RODA_ATURA = 9
int HOS_NEW_GAME = 10

Function Documentation

def common.freevialglob.anteriorEquipActiu (   teams,
  actual 
)

Definition at line 339 of file freevialglob.py.

00339 
00340 def anteriorEquipActiu( teams, actual ):
00341 
00342        actual -= 1
00343 
00344        for num in range( 0, Global.game.max_teams ):
00345               if teams[ (actual - num ) % Global.game.max_teams ].actiu: 
00346                      return (actual - num ) % Global.game.max_teams
00347        
00348        return -1
00349 

Here is the caller graph for this function:

def common.freevialglob.bitCategoria (   categoria)

Definition at line 76 of file freevialglob.py.

00076 
00077 def bitCategoria ( categoria ):
00078        return (0x4,0x8,0x20,0x10,0x2,0x1)[ categoria ]
00079 

Here is the caller graph for this function:

Definition at line 465 of file freevialglob.py.

00465 
00466 def colorsCategories():
00467 
00468        return i_colors_cat
00469 

Here is the caller graph for this function:

def common.freevialglob.count_not_empty (   list,
  attr = None 
)
Returns the amount of non-empty elements in a list. Optionally,
if the attr option is set, it will count the amount of elements in
the list that have an attribute named like that which is not empty.

Definition at line 224 of file freevialglob.py.

00224 
00225 def count_not_empty( list, attr = None ):
00226        """ Returns the amount of non-empty elements in a list. Optionally,
00227        if the attr option is set, it will count the amount of elements in
00228        the list that have an attribute named like that which is not empty."""
00229        
00230        count = 0
00231        
00232        for element in list:
00233               if element:
00234                      if not attr or (hasattr(element, attr) and getattr(element, attr)):
00235                             count += 1
00236        
00237        return count
00238 

Here is the caller graph for this function:

def common.freevialglob.createHelpScreen (   help_section,
  alternate_text = False 
)
Creates a help overlay surface based on a help file. 

Definition at line 447 of file freevialglob.py.

00447 
00448 def createHelpScreen( help_section, alternate_text = False ):
00449        """ Creates a help overlay surface based on a help file. """
00450        
00451        return createTextSurface( readLocalizedHelpFile( help_section ), (0, 255, 255) if alternate_text else (255, 255, 0) )

Here is the call graph for this function:

Here is the caller graph for this function:

def common.freevialglob.createTextSurface (   frases,
  color,
  intensitat = 25 
)
Creates a help overlay surface and prints the passed text on it. 

Definition at line 378 of file freevialglob.py.

00378 
00379 def createTextSurface( frases, color, intensitat = 25 ):
00380        """ Creates a help overlay surface and prints the passed text on it. """
00381        
00382        font_step = (768 - (315)) / len(frases) 
00383        font_step = min( font_step, 25 )
00384 
00385        font_size = font_step - (font_step * 10) / 100
00386        if font_size < 10: font_size = 10
00387  
00388        help_overlay = pygame.Surface( ( 1024, 768), pygame.SRCALPHA, 32 )
00389        
00390        for num in range( 0, 10):
00391               help_overlay.fill( (0, 0, 16, num * intensitat), ( 100 + (num * 2), 100 + (num * 2), 1024 - 100 * 2 - (num * 4), 768 - 150 - (num * 4)) )
00392        
00393        nline = 0
00394 
00395        pos = 0
00396        for line in frases:
00397               if line != "":       
00398                      text_pregunta = render_text( line, (0,0,0), font_size, 1, '', 700 )
00399                      help_overlay.blit( text_pregunta, (150 + 2, pos + 142))
00400                      
00401                      text_pregunta = render_text( line, color, font_size, 1, '', 700 )
00402                      help_overlay.blit( text_pregunta, (150, pos + 140))
00403                      
00404                      pos += text_pregunta.get_height()
00405               else:
00406                      pos += font_size     
00407 
00408               nline += 1
00409        
00410        return help_overlay
00411 

Here is the call graph for this function:

Here is the caller graph for this function:

def common.freevialglob.firstExistingDirectory (   name,
  dirs 
)
Searches for a directory called by the given name inside all given
directories, and returns the full path to the first one which exists. 

Definition at line 470 of file freevialglob.py.

00470 
00471 def firstExistingDirectory(name, *dirs):
00472        """ Searches for a directory called by the given name inside all given
00473        directories, and returns the full path to the first one which exists. """
00474        
00475        for directory in dirs:
00476               if os.path.isdir( os.path.join(directory, name) ):
00477                      return os.path.join(directory, name)
00478        
00479        return False
00480 

Here is the caller graph for this function:

Definition at line 455 of file freevialglob.py.

00455 
00456 def initTextos():
00457        global textos
00458 
00459        textos = readLocalizedHelpFile( "textos" )
00460 

Here is the call graph for this function:

Here is the caller graph for this function:

def common.freevialglob.list2string (   list,
  wordsEachLine = 5,
  lineEnd = ' 
)
Converts a list of words into a list of comma-separated string with 'wordsEachLine' words. 

Definition at line 350 of file freevialglob.py.

00350 
00351 def list2string( list, wordsEachLine = 5, lineEnd = ',' ):
00352        """ Converts a list of words into a list of comma-separated string with 'wordsEachLine' words. """
00353        
00354        lines = []
00355        string = ''
00356        i = 0
00357        
00358        for author in list:
00359               
00360               if string != '':
00361                      string += ', '
00362               
00363               string += author
00364               
00365               if (wordsEachLine - 1) == (i % wordsEachLine):
00366                      lines.append( str(string + lineEnd) )
00367                      string = ''
00368 
00369               i += 1
00370               
00371        if string != '':
00372               lines.append( str(string + lineEnd) )
00373        
00374        lines[-1] = lines[-1][:-len(lineEnd)]
00375        
00376        return lines
00377 

def common.freevialglob.loadImage (   name,
  colorkey = None,
  rotate = 0 
)
Returns a Surface of the indicated image, which is expected to be in the images folder. 

Definition at line 80 of file freevialglob.py.

00080 
00081 def loadImage( name, colorkey = None, rotate = 0 ):
00082        """ Returns a Surface of the indicated image, which is expected to be in the images folder. """
00083        
00084        fullname = os.path.join(Global.folders['images'], str(name))
00085        
00086        try:
00087               image = pygame.image.load(fullname)
00088        except pygame.error, message:
00089               print _('Failed loading image: %s' % fullname)
00090               raise SystemExit, message
00091        
00092        if colorkey is not None:
00093               if colorkey is -1:
00094                      colorkey = image.get_at((0,0))
00095               image = image.convert()
00096               image.set_colorkey(colorkey, pygame.RLEACCEL)
00097        else:
00098               image = image.convert_alpha()
00099        
00100        if rotate != 0:
00101               image = rotateImage(image, rotate)
00102        
00103        return image  # [ image, image.get_rect() ]
00104 

Here is the caller graph for this function:

def common.freevialglob.loadSound (   name,
  volume = 1.0,
  music = False 
)
Returns a sound object of the indicated audio file, which is expected to be in the sounds folder. 

Definition at line 105 of file freevialglob.py.

00105 
00106 def loadSound( name, volume = 1.0, music = False ):
00107        """ Returns a sound object of the indicated audio file, which is expected to be in the sounds folder. """
00108        
00109        if ( Global.MUSIC_MUTE and music ) or ( Global.SOUND_MUTE and not music ) or not pygame.mixer or not pygame.mixer.get_init():
00110        
00111               class NoneSound:
00112                      def load( *args ): pass
00113                      def play( *args ): pass
00114                      def stop( *args ): pass
00115                      def set_volume( *args ): pass
00116               
00117               return NoneSound()
00118        
00119        fullname = os.path.join(Global.folders['sounds'], name)
00120        
00121        try:
00122               if not music:
00123                      obj = pygame.mixer.Sound(fullname)
00124               else:
00125                      obj = pygame.mixer.music
00126                      obj.load(fullname)
00127        except pygame.error, message:
00128               
00129               print _('Failed loading sound: %s' % fullname)
00130               
00131               if not music:
00132                      raise SystemExit, message
00133        
00134        obj.set_volume(float(volume))
00135        
00136        return obj

Here is the caller graph for this function:

Definition at line 239 of file freevialglob.py.

00239 
00240 def maxPunts( teams ):
00241 
00242        puntsmax = 0
00243 
00244        for num in range( 0, Global.game.max_teams ):
00245               if teams[num].actiu:
00246                      puntsmax = max( puntsmax, teams[num].punts )
00247        
00248        return puntsmax
00249 

Here is the caller graph for this function:

Definition at line 250 of file freevialglob.py.

00250 
00251 def puntsTotals( teams ):
00252 
00253        punts = 0
00254 
00255        for num in range( 0, Global.game.max_teams ):
00256               punts += teams[num].punts
00257        
00258        return punts
00259 

Reads a localized file into an unicoded array. 

Definition at line 425 of file freevialglob.py.

00425 
00426 def readLocalizedHelpFile( help_section ):
00427        """ Reads a localized file into an unicoded array. """
00428        
00429        # FIXME/TODO: Delete help files and use gettext strings instead.
00430        
00431        filename = os.path.join(Global.folders['help'], (help_section + "_"+ locale.getdefaultlocale()[0][:2] +'.txt'))
00432        
00433        if not os.path.exists (filename):
00434               filename = os.path.join(Global.folders['help'], (help_section + '.txt'))
00435        
00436        lines = []
00437        
00438        for line in replaceKeywoards(open( filename, 'r' ).readlines()):
00439               
00440               if not line[-1:].isalnum():
00441                      line = line[:-1]
00442               
00443               lines.append ( line )
00444        
00445        return lines
00446 

Here is the call graph for this function:

Here is the caller graph for this function:

def common.freevialglob.render_text (   cadena,
  color,
  mida,
  antialias = 0,
  nomfont = '',
  maxwidth = 0 
)
Function for easier text rendering. 

Definition at line 146 of file freevialglob.py.

00146 
00147 def render_text( cadena, color, mida, antialias = 0, nomfont = '', maxwidth = 0 ):
00148        """ Function for easier text rendering. """
00149 
00150        global default_font
00151 
00152        if os.path.exists( nomfont ):
00153               font1 = pygame.font.Font( nomfont, mida )
00154        else:
00155               tnomfont = os.path.join(Global.folders['fonts'], default_font if nomfont == '' else nomfont)
00156               if os.path.exists( tnomfont ):
00157                      font1 = pygame.font.Font( tnomfont, mida )
00158               else:
00159                      # NOT WORKING IN PYGAME
00160                      font1 = pygame.font.SysFont( nomfont, mida )
00161               
00162        
00163        text_restant = cadena
00164        sfc = None
00165 
00166        if maxwidth:
00167               sfcs = []
00168 
00169               while text_restant != "":
00170 
00171                      ample = maxwidth + 1
00172                      escriure = text_restant
00173 
00174                      while ample > maxwidth:
00175 
00176                             sfc = font1.render( escriure, antialias, color )
00177                             ample = sfc.get_width()            
00178                      
00179                             if ample > maxwidth:
00180                                    tpos = escriure.rfind( ' ' )
00181                                    if tpos == -1:
00182                                           ample = maxwidth
00183                                    else:
00184                                           escriure = escriure[0:tpos]        
00185 
00186                      sfcs.append( sfc )
00187 
00188                      text_restant = text_restant[ len( escriure )+1:]
00189 
00190               if len(sfcs) > 1:
00191                      iample = 0
00192                      ialt = 0
00193                      for compta in range( 0, len(sfcs) ):
00194                             ialt += max(sfcs[compta].get_height(), mida)
00195                             iample = min(maxwidth, max( iample, sfcs[compta].get_width() ))
00196 
00197                      sfc = pygame.Surface( ( iample, ialt), pygame.SRCALPHA, 32 )
00198 
00199                      pos = 0
00200                      for compta in range( 0, len(sfcs) ):
00201                             sfc.blit( sfcs[compta], (0, pos) )
00202                             pos += max(sfcs[compta].get_height(), mida)
00203 
00204               else:
00205                      sfc = sfcs[0] if len(sfcs) == 1 else None
00206        else:
00207               sfc = font1.render( cadena, antialias, color )
00208 
00209        return sfc

Here is the caller graph for this function:

Replaces keywoards found in the content a help file. 

Definition at line 412 of file freevialglob.py.

00412 
00413 def replaceKeywoards( content ):
00414        """ Replaces keywoards found in the content a help file. """
00415        
00416        for num in range(0, len(content)):
00417               content[num] = unicode(content[num], 'utf-8')
00418        
00419        for (i, line) in enumerate(content):
00420               if line.startswith( '##replace:question-authors' ):
00421                      content[ i : (i + 1) ] = sorted(["%s: %s" % (category.name, category.authors) for category in get_databases()])
00422        
00423        return content
00424 

Here is the call graph for this function:

Here is the caller graph for this function:

def common.freevialglob.screenshot (   surface,
  destination = os.path.join( os.path.expanduser('~'), 'Freevial/Screenshots/' 
)
Saves a screenshot of the indicated surface. 

Definition at line 210 of file freevialglob.py.

00210 
00211 def screenshot( surface, destination = os.path.join( os.path.expanduser('~'), 'Freevial/Screenshots/' ) ):
00212        """ Saves a screenshot of the indicated surface. """
00213        
00214        destination = os.path.normpath( destination )
00215        
00216        if not os.path.exists( destination ):
00217               os.makedirs( destination )
00218        
00219        # PNG and JPEG saving is new in pygame 1.8.
00220        destination = os.path.join( destination, str( time.time() ) + '.tga' )
00221        
00222        pygame.image.save( surface, destination )
00223 

Here is the caller graph for this function:

def common.freevialglob.seguentEquipActiu (   teams,
  actual 
)

Definition at line 328 of file freevialglob.py.

00328 
00329 def seguentEquipActiu( teams, actual ):
00330 
00331        actual += 1
00332 
00333        for num in range(0, Global.game.max_teams ):
00334               if teams[ (actual + num) % Global.game.max_teams ].actiu: 
00335                      return (actual + num) % Global.game.max_teams
00336        
00337        return -1
00338 

Here is the caller graph for this function:

Definition at line 140 of file freevialglob.py.

00140 
00141 def set_default_font( nomfont ):
00142 
00143        if os.path.exists( nomfont ):
00144               default_font = nomfont
00145               

Definition at line 260 of file freevialglob.py.

00260 
00261 def teamsActius( teams ):
00262 
00263        actius = 0
00264 
00265        for num in range( 0, Global.game.max_teams ):
00266               if teams[num].actiu: actius += 1
00267        
00268        return actius
00269 

Here is the caller graph for this function:

def common.freevialglob.teamsGuanyador (   teams,
  mode,
  extra 
)

Definition at line 279 of file freevialglob.py.

00279 
00280 def teamsGuanyador( teams, mode, extra ):
00281 
00282        # Mode 0 - Figureta de 6 peces completa i una diferència de més de 2 punts respecte a l'equip anterior. Guanyador a punts
00283        # Mode 1 - Aconseguir un nombre determinat de punts
00284        # Mode 2 - Ser el darrer equip en fer X cagades
00285        # Mode 3 - Omplir la figureta de 6 peces
00286 
00287        guanyador = -1
00288 
00289        if mode == 0:
00290               puntsmax = 0
00291               equipmax = -1
00292 
00293               if teamsTancat( teams ):
00294 
00295                      for num in range( 0, Global.game.max_teams ):
00296                             if teams[num].actiu:
00297                                    if teams[num].punts == puntsmax:
00298                                           # empat a punts
00299                                           equipmax = -1 
00300 
00301                                    if teams[num].punts > puntsmax:
00302                                           equipmax = num
00303                                           puntsmax = teams[num].punts
00304        
00305               guanyador = equipmax
00306        
00307        elif mode == 1:
00308               
00309               for num in range( 0, Global.game.max_teams ):
00310                      if teams[num].punts >=  extra:
00311                             guanyador = num
00312        
00313        elif mode == 2:
00314               nocagats = []
00315               for num in range( 0, Global.game.max_teams ):
00316                      if teams[num].errors <  extra:
00317                             nocagats.append( num )
00318               if len(nocagats) == 1:
00319                      guanyador = nogacats[0]
00320        
00321        elif mode == 3:
00322               for num in range( 0, Global.game.max_teams ):
00323                      if teams[num].figureta == 63:
00324                             guanyador = num
00325        
00326        return guanyador
00327 

Here is the call graph for this function:

Definition at line 270 of file freevialglob.py.

00270 
00271 def teamsTancat( teams ):
00272 
00273        for num in range( 0, Global.game.max_teams ):
00274               if teams[num].figureta == 63:
00275                      return True
00276        
00277        return False
00278 

Here is the caller graph for this function:

Definition at line 461 of file freevialglob.py.

00461 
00462 def valorText( ntext ):
00463        return textos[ ntext ]
00464 

Here is the caller graph for this function:


Variable Documentation

string common.freevialglob.default_font = '/usr/share/fonts/truetype/unfonts/UnBatangBold.ttf'

Definition at line 137 of file freevialglob.py.

Definition at line 491 of file freevialglob.py.

Definition at line 486 of file freevialglob.py.

Definition at line 488 of file freevialglob.py.

Definition at line 487 of file freevialglob.py.

Definition at line 484 of file freevialglob.py.

Definition at line 490 of file freevialglob.py.

Definition at line 481 of file freevialglob.py.

Definition at line 482 of file freevialglob.py.

Definition at line 483 of file freevialglob.py.

Definition at line 489 of file freevialglob.py.

Definition at line 485 of file freevialglob.py.

tuple common.freevialglob.i_colors_cat = ( (0,0,255), (255,128,0), (0,255,0),(255,0,0),(255,0,255), (255,255,0) )

Definition at line 452 of file freevialglob.py.

Definition at line 39 of file freevialglob.py.