Mercurial > mamba
changeset 65:ca2206efeeb1
Add mutators concept to image loader.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 17:23:59 +0200 |
parents | fbb5cc655b47 |
children | 855bc20b9900 |
files | mamba/data.py mamba/mutators.py |
diffstat | 2 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/data.py Sun Sep 11 17:23:42 2011 +0200 +++ b/mamba/data.py Sun Sep 11 17:23:59 2011 +0200 @@ -33,12 +33,20 @@ IMAGES = {} +MUTATED_IMAGES = {} -def load_image(filename): - if filename not in IMAGES: - IMAGES[filename] = pygame.image.load(filepath(filename)) - if pygame.display.get_init(): - IMAGES[filename] = IMAGES[filename].convert_alpha( - pygame.display.get_surface()) - return IMAGES[filename] +def load_image(filename, mutators=()): + key = (filename, mutators) + if key in MUTATED_IMAGES: + return MUTATED_IMAGES[key] + if filename in IMAGES: + image = IMAGES[filename] + else: + image = pygame.image.load(filepath(filename)) + image = image.convert_alpha(pygame.display.get_surface()) + IMAGES[filename] = image + for mutator in mutators: + image = mutator(image) + MUTATED_IMAGES[key] = image + return image