def onOpen(self, filename): with open(filename) as levelfile: self.level.clear() data = levelformat.load(levelfile) if data.version != 2: print('Too high version:', data.version) return for rect in data.rects: self._addrect(rect.x + rect.dx, rect.y + rect.dy, rect.w, rect.h)
def load(filename): '''Returns a list of hitboxes - the rects stored in the file. Raises IOError if file doesn't exist; LevelFormatError if format is unsupported.''' with open(filename) as levelfile: data = levelformat.load(levelfile) if data.version != 2: raise levelformat.LevelFormatError('Too high version: {0}'.format(data.version)) # And return a list of all rects with their positions in world coordinates return [components.hitbox((r.x + r.dx, r.y + r.dy), (r.w, r.h)) for r in data.rects]