Skip to content

Commit c6d16bd

Browse files
committed
Add DocumentInfo support, closes #142.
1 parent e802365 commit c6d16bd

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

sc2reader/resources.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,36 @@ def __init__(self, map_file, filename=None, gateway=None, map_hash=None, **optio
624624
game_strings = self.archive.read_file('enUS.SC2Data\LocalizedData\GameStrings.txt')
625625
if game_strings:
626626
for line in game_strings.split('\r\n'):
627-
parts = line.split('=')
628-
if parts[0] == 'DocInfo/Name':
629-
self.name = parts[1]
630-
elif parts[0] == 'DocInfo/Author':
631-
self.author = parts[1]
632-
elif parts[0] == 'DocInfo/DescLong':
633-
self.description = parts[1]
627+
if len(line) == 0:
628+
continue
629+
630+
key, value = line.split('=')
631+
if key == 'DocInfo/Name':
632+
self.name = value
633+
elif key == 'DocInfo/Author':
634+
self.author = value
635+
elif key == 'DocInfo/DescLong':
636+
self.description = value
637+
elif key == 'DocInfo/Website':
638+
self.website = value
634639

635640
#: A reference to the map's :class:`~sc2reader.objects.MapInfo` object
636641
self.map_info = MapInfo(self.archive.read_file('MapInfo'))
637642

643+
doc_info = ElementTree.fromstring(self.archive.read_file('DocumentInfo'))
644+
645+
icon_path_node = doc_info.find('Icon/Value')
646+
#: (Optional) The path to the icon for the map, relative to the archive root
647+
self.icon_path = icon_path_node.text if icon_path_node is not None else None
648+
649+
#: (Optional) The icon image for the map in tga format
650+
self.icon = self.archive.read_file(self.icon_path) if self.icon_path is not None else None
651+
652+
#: A list of module names this map depends on
653+
self.dependencies = list()
654+
for dependency_node in doc_info.findall('Dependencies/Value'):
655+
self.dependencies.append(dependency_node.text)
656+
638657
@classmethod
639658
def get_url(cls, gateway, map_hash):
640659
"""Builds a download URL for the map from its components."""

0 commit comments

Comments
 (0)