def load_game(self, slot): self.slot = slot with open('save%d.json' % slot) as f: d = json.loads(f.read()) self.party_gold = d['gold'] self.pc_position = GameTile.from_string(d['pc_position']) self.level = d['level'] self.party_food = d['food'] self.map.level = self.level for key in d['inventory_dump']: item_class = items.ITEMS[key][0] item_args = items.ITEMS[key][1] self.inventory.append(item_class(*item_args)) self.pc_list = [ Creature.dict_load(pc, self.inventory) for pc in d['pcs'] ] self.map.load_dict(d['map']) self.map.board[self.pc_position].on_step(self)
def load_dict(self, d): for k, v in d.items(): tile = GameTile.from_string(k) self.board[tile] = MapTile.from_list(v, tile)