|
| 1 | +sc2reader Documentation |
| 2 | +===================================== |
| 3 | + |
| 4 | +sc2reader is a library for extracting game information from Starcraft II |
| 5 | +replay files into a structured replay object. sc2reader aims to give anyone |
| 6 | +and everyone the power to construct their own tools and hack on their own |
| 7 | +Starcraft II projects under the open MIT license. |
| 8 | + |
| 9 | +This document is a work in progress and an attempt to document the use and |
| 10 | +configuration of sc2reader as well as the data that it makes available. I'll |
| 11 | +try to keep it up to date and fill out some of the missing sections as time |
| 12 | +goes on. While this document will hopefully give you an idea how sc2reader works |
| 13 | +there is no substitute for reading the source code. If you plan on seriously |
| 14 | +using the library please feel welcome to ask questions in #sc2reader on FreeNode |
| 15 | +(IRC) or on the `mailing list`_. I'd be happy to help you out. |
| 16 | + |
| 17 | +.. _mailing list: http://groups.google.com/group/sc2reader |
| 18 | + |
| 19 | +Use and Configuration |
| 20 | +======================= |
| 21 | + |
| 22 | +Basic Use |
| 23 | +------------- |
| 24 | + |
| 25 | +The sc2reader package itself can be configured and used to read replay files |
| 26 | +right out of the box! This lightweight approach to usage provides default |
| 27 | +options for full replay parsing so no configuration is necessary for normal use. |
| 28 | + |
| 29 | +read |
| 30 | +~~~~~~~~ |
| 31 | + |
| 32 | +:: |
| 33 | + |
| 34 | + >>> import sc2reader |
| 35 | + >>> sc2reader.read('test_replays/1.4.0.19679/36663.SC2Replay') |
| 36 | + [<sc2reader.objects.Replay object at 0x944822c>] |
| 37 | + |
| 38 | +Notice that a list of Replay_ objects was returned. That is because the read |
| 39 | +function is always plural and will return a list regardless of how many replays |
| 40 | +it finds at the path that you send it. |
| 41 | + |
| 42 | +It works by (optionally) recursing through the specified path (if its a directory) |
| 43 | +and grabbing all files of the .SC2Replay file type and parsing them. Because of |
| 44 | +this, while the path you send it must always exist it is possible for the read_ |
| 45 | +function to return an empty array of not files are found. This scanning process |
| 46 | +is fairly configurable by several of the available Options_. |
| 47 | + |
| 48 | +Because frequently you will be parsing only a single file or will be in an |
| 49 | +environment where you only have access to file or file-like objects, a read_file_ |
| 50 | +function is available as well. |
| 51 | + |
| 52 | +read_file |
| 53 | +~~~~~~~~~~~~ |
| 54 | + |
| 55 | +:: |
| 56 | + |
| 57 | + >>> import sc2reader |
| 58 | + >>> replay = sc2reader.read_file('test_replays/1.4.0.19679/36663.SC2Replay') |
| 59 | + >>> print "{0} on {1}, played on {2}".format(replay.type, replay.map, replay.date) |
| 60 | + 1v1 on Xel'Naga Caverns, played on 2011-09-21 02:49:47 |
| 61 | + |
| 62 | +The read file function can accept either a path to a single file or a reference |
| 63 | +to a file-like object. A file-like object must implement the ``seek`` and |
| 64 | +``read`` methods to be valid. These two functions read_file_ and read_ provide |
| 65 | +the interface for constructing replays from file objects. |
| 66 | + |
| 67 | + |
| 68 | +configure |
| 69 | +~~~~~~~~~~~ |
| 70 | + |
| 71 | +:: |
| 72 | + |
| 73 | + >>> import sc2reader |
| 74 | + >>> sc2reader.configure(files=sc2reader.config.files.partial) |
| 75 | + >>> replay = sc2reader.read_file('CustomMap.SC2Replay') |
| 76 | + |
| 77 | +The configure_ function can be used to change the default configuration of the |
| 78 | +replay parser and processor. This can be used to effect scanning of the file |
| 79 | +tree, the output and logging destination, and the fullness of the parsing. In |
| 80 | +the example above, we have restricted the file set to a partial parse and |
| 81 | +excluded the replay.game.events file from the parsing process. While sc2reader |
| 82 | +doesn't support custom games, by restricting the file set it can successfully |
| 83 | +read custom games to get non-event related information including summary game |
| 84 | +information as well as a general profile of the players. |
| 85 | + |
| 86 | +For one off configuration jobs though, sometimes its easier to pass the options |
| 87 | +in as keyword arguments to the read_ and read_file_ functions. This will leave |
| 88 | +the current sc2reader options untouched and won't affect future calls. |
| 89 | + |
| 90 | +:: |
| 91 | + |
| 92 | + >>> import sc2reader |
| 93 | + >>> sc2reader.read(path, **options) |
| 94 | + >>> sc2reader.read_file(fileobj, **options) |
| 95 | + |
| 96 | + |
| 97 | +Advanced Use |
| 98 | +-------------- |
| 99 | + |
| 100 | +In addition to making the read_, read_file_, and configure_ methods available on |
| 101 | +the module, they are also available as part of an SC2Reader class with the same |
| 102 | +call signature. This can let you move easily between several different |
| 103 | +configurations as needed for different tasks. |
| 104 | + |
| 105 | +:: |
| 106 | + |
| 107 | + >>> from sc2reader import SC2Reader |
| 108 | + >>> reader = SC2Reader(**options) |
| 109 | + >>> reader.read_file('test_replays/1.4.0.19679/36663.SC2Replay') |
| 110 | + <sc2reader.objects.Replay object at 0x944822c> |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +Indices and tables |
| 115 | +================== |
| 116 | + |
| 117 | +* :ref:`genindex` |
0 commit comments