class World(object): cell_class = Cell def __init__(self): self.cells = {} self.leaderboard_names = [] self.leaderboard_groups = [] self.top_left = Vec(0, 0) self.bottom_right = Vec(0, 0) self.reset() def reset(self): """ Clears the `cells` and leaderboards, and sets all corners to `0,0`. """ self.cells.clear() del self.leaderboard_names[:] del self.leaderboard_groups[:] self.top_left.set(0, 0) self.bottom_right.set(0, 0) def create_cell(self, cid): """ Creates a new cell in the world. Override to use a custom cell class. """ self.cells[cid] = self.cell_class() @property def center(self): return Vec(self.size.x/2,self.size.y/2) @property def size(self): return self.top_left.abs() + self.bottom_right.abs() def __eq__(self, other): """Compares two worlds by comparing their leaderboards.""" for ls, lo in zip(self.leaderboard_names, other.leaderboard_names): if ls != lo: return False for ls, lo in zip(self.leaderboard_groups, other.leaderboard_groups): if ls != lo: return False if self.top_left != other.top_left: return False if self.bottom_right != other.bottom_right: return False return True