def load_player(path): player_attributes = {} xml = ET.parse(path) root = xml.getroot() player_attributes['coords'] = (int(root.attrib['x']), int(root.attrib['y']), int(root.attrib['z']), int(root.attrib['a'])) player_attributes['prev_coords'] = (int(root.attrib['prev_x']), int(root.attrib['prev_y']), int(root.attrib['prev_z']), int(root.attrib['prev_a'])) player_attributes['fih'] = int(root.attrib['fih']) player_attributes['name'] = root.attrib['name'] player_attributes['items'] = [] player_attributes['affiliation'] = {} player_attributes['sense_effects'] = {} player_attributes['vote_history'] = {} affiliation_people = ['Obama', 'Kanye', 'OReilly', 'Gottfried', 'Burbiglia'] for node in root: if node.tag == 'item': for i in range(int(node.attrib['quantity'])): player_attributes['items'].append(node.text) elif node.tag in affiliation_people: player_attributes['affiliation'][node.tag] = int(node.text) elif node.tag == 'vote_history': player_attributes['vote_history'] = load_vote_history(node) else: player_attributes['sense_effects'][node.tag] = int(node.text) return engine_classes.Player(**player_attributes)
def load_objects(path): xml = ET.parse(path) root = xml.getroot() objects = {} for node in root: if node.tag == 'item': item = load_item(node) objects[item.name] = item elif node.tag == 'portal': portal = load_portal(node) objects[portal.name] = portal return objects
def load_room(path): room_attributes = {} room_attributes['items'] = [] room_attributes['portals'] = [] room_attributes['npcs'] = [] room_attributes['players'] = [] xml = ET.parse(path) root = xml.getroot() room_attributes['desc'] = root.attrib['desc'] room_attributes['id'] = root.attrib['id'] room_attributes['up_votes'] = int(root.attrib['up_votes']) room_attributes['down_votes'] = int(root.attrib['down_votes']) for node in root: if node.tag == 'item': room_attributes['items'].append(node.text) elif node.tag == 'portal': room_attributes['portals'].append(node.text) return engine_classes.Room(**room_attributes)