projects
/
tabakrolletjie.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
explained spotlight rotation
[tabakrolletjie.git]
/
tabakrolletjie
/
loader.py
diff --git
a/tabakrolletjie/loader.py
b/tabakrolletjie/loader.py
index 252960b42b90e9850206dc215d3a8a8e551c24b4..4ad1d585787be3cc944575c723708056db76eb8b 100644
(file)
--- a/
tabakrolletjie/loader.py
+++ b/
tabakrolletjie/loader.py
@@
-6,13
+6,17
@@
import os
import pygame.image
import pygame.font
import pygame.display
import pygame.image
import pygame.font
import pygame.display
+import pygame.mixer
from .constants import DEBUG
from .constants import DEBUG
+from .transforms import NullTransform
class Loader(object):
""" Load data files from beneath a prefix. """
class Loader(object):
""" Load data files from beneath a prefix. """
+ NULL_TRANSFORM = NullTransform()
+
def __init__(self, prefix):
self._prefix = prefix
self._cache = {}
def __init__(self, prefix):
self._prefix = prefix
self._cache = {}
@@
-32,16
+36,18
@@
class Loader(object):
with self.open_file("stations", *parts) as f:
return json.load(f)
with self.open_file("stations", *parts) as f:
return json.load(f)
- def load_image(self, *parts):
+ def load_image(self, *parts
, **kwargs
):
"""Return a pygame surface of the requested image."""
fn = self.full_path("images", *parts)
"""Return a pygame surface of the requested image."""
fn = self.full_path("images", *parts)
- img = self._cache.get(fn, None)
+ transform = kwargs.pop("transform", self.NULL_TRANSFORM)
+ img = self._cache.get((fn, transform), None)
if img is None:
img = pygame.image.load(fn)
# We assume pygame.display has been initialised
# Fix this if that changes
img.convert_alpha(pygame.display.get_surface())
if img is None:
img = pygame.image.load(fn)
# We assume pygame.display has been initialised
# Fix this if that changes
img.convert_alpha(pygame.display.get_surface())
- self._cache[fn] = img
+ img = transform.apply(img)
+ self._cache[(fn, transform)] = img
return img
def load_font(self, *parts, **kwargs):
return img
def load_font(self, *parts, **kwargs):
@@
-52,6
+58,15
@@
class Loader(object):
# Do we need to cache this?
return font
# Do we need to cache this?
return font
+ def load_sound(self, *parts):
+ """Return a pygame sound"""
+ fn = self.full_path("sounds", *parts)
+ sound = self._cache.get(fn, None)
+ if not sound:
+ sound = pygame.mixer.Sound(fn)
+ self._cache[fn] = sound
+ return sound
+
_DATA_PREFIX = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "data"))
_DATA_PREFIX = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "data"))