"""Return a pygame surface of the requested image."""
fn = self.full_path("images", *parts)
transform = kwargs.pop("transform", self.NULL_TRANSFORM)
- img = self._cache.get((fn, transform.hash), None)
+ 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())
img = transform.apply(img)
- self._cache[(fn, transform.hash)] = img
+ self._cache[(fn, transform)] = img
return img
def load_font(self, *parts, **kwargs):
for k in self.ARGS:
setattr(self, k, kw.pop(k))
assert not kw
- self.hash = "%s: <%s>" % (
+ self._repr = "%s: <%s>" % (
self.__class__.__name__,
", ".join("%s=%s" % (k, getattr(self, k)) for k in self.ARGS))
return
+ def __repr__(self):
+ return self._repr
+
+ def __hash__(self):
+ return hash(self._repr)
+
+ def __eq__(self, other):
+ if not isinstance(other, Transform):
+ return NotImplemented
+ return self._repr == other._repr
+
def apply(self, surface):
raise NotImplementedError("Transforms should implement .apply")