2
####################################################################################
3
# copyright 2008 Gabriel Pettier <gabriel.pettier@gmail.com>
5
# This file is part of UltimateSmashFriends
7
# UltimateSmashFriends is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# UltimateSmashFriends is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with UltimateSmashFriends. If not, see <http://www.gnu.org/licenses/>.
19
##################################################################################
29
from pygame.locals import BLEND_MAX
31
from debug_utils import LOG
33
def memoize(function):
35
def decorated_function(*args, **kwargs):
36
params = (args)+tuple(zip(kwargs.keys(),kwargs.values()))
40
val = function(*args, **kwargs)
43
return decorated_function
46
def image(name, *args, **kwargs):
48
A function to load an image, shamelessly picked from pygame
49
tutorial, and grossly adjusted for native transparency support of png.
50
Can scale and reverse horizontaly an image, can produce a lightened version
53
keywords arguments accepted are the followings:
54
zoom=None, colorkey=None, server=False, lighten=False, reversed=False,
56
# FIXME: should not have to load the image in server mode, we just want
58
if 'reversed' in kwargs and kwargs['reversed'] == True:
59
kwargs['reversed'] = False
60
#LOG().log("reverse "+name)
61
image = pygame.transform.flip(
62
loaders.image(name,*args, **kwargs)[0],
63
True, #flip horizontaly
67
elif 'lighten' in kwargs and kwargs['lighten'] == True:
68
#LOG().log('lightened: '+name)
69
kwargs['lighten'] = False
70
image = loaders.image(name, *args, **kwargs)[0].copy()
72
pygame.Color('lightgrey'),
77
elif 'zoom' in kwargs and kwargs['zoom'] not in (None, 1):
80
#LOG().log('scaling image '+name+' :'+str(zoom))
81
image = pygame.transform.scale(
82
loaders.image(name, **kwargs)[0],
84
int(loaders.image(name, *args, **kwargs)[1][2]*zoom*
85
config.config['SIZE'][0]/800),
86
int(loaders.image(name, *args, **kwargs)[1][3]*zoom*
87
config.config['SIZE'][1]/480)
92
image = pygame.image.load(name)
93
except pygame.error, message:
94
LOG().log('Cannot load image:'+str(name), 2)
95
raise# SystemExit, message
96
if 'colorkey' not in kwargs or kwargs['colorkey'] is None:
97
image = image.convert_alpha()
98
if 'colorkey' in kwargs and kwargs['colorkey'] is not None:
99
image = image.convert()
101
colorkey = image.get_at((0,0))
102
image.set_colorkey(colorkey, RLEACCEL)
103
return image, image.get_rect()
107
return pygame.mixer.Sound(name)