def from_json(cls, json_world): point_index = {} points = set() json_points = json_world[cls.JSON_KEY_POINTS] for point_type_key, point_class in [ (cls.JSON_KEY_FOOD_POINTS, FoodPoint), (cls.JSON_KEY_ANTHILL_POINTS, AnthillPoint), (cls.JSON_KEY_ORDINARY_POINTS, Point), ]: for json_point in json_points[point_type_key]: p = point_class.from_json(json_point) point_index[p.coordinates] = p points.add(p) edges = set() for json_edge in json_world[cls.JSON_KEY_EDGES]: e = Edge.from_json(json_edge, point_index) e.register_with_points() edges.add(e) return cls(points, edges)