Skip to content

Commit 3c12baa

Browse files
committed
Add autodoc strings to Team, Person, Player, and Observer classes.
1 parent f1e2f80 commit 3c12baa

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

sc2reader/objects.py

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ def __str__(self):
2424
return self.name
2525

2626
class Team(object):
27+
"""
28+
The team object primarily a container object for organizing :class:`Player`
29+
objects with some metadata. As such, it implements iterable and can be
30+
looped over like a list::
31+
32+
for player in team:
33+
print player
34+
35+
:param interger number: The team number as recorded in the replay
36+
"""
37+
38+
#: The team number as recorded in the replay
39+
number = int()
40+
41+
#: A list of the :class:`Player` objects on the team
42+
players = list()
43+
44+
#: The result of the game for this team.
45+
#: One of "Win", "Loss", or "Unknown"
46+
result = str()
47+
2748
def __init__(self,number):
2849
self.number = number
2950
self.players = list()
@@ -73,9 +94,41 @@ def __repr__(self):
7394
return str(self)
7495

7596
def __str__(self):
76-
return "%s: %s" % (self.name, self.value)
97+
return "[%s] %s: %s" % (self.player, self.name, self.value)
7798

7899
class Person(object):
100+
"""
101+
The person object is never actually instanciated but instead acts as a
102+
parent class for the :class:`Observer` and :class:`Player` classes.
103+
104+
:param integer pid: The person's unique id in this game.
105+
:param string name: The person's battle.net name
106+
"""
107+
108+
#: The person's unique in this game
109+
pid = int()
110+
111+
#: The person's battle.net name
112+
name = str()
113+
114+
#: A flag indicating the player's observer status.
115+
#: Really just a shortcut for isinstance(obj, Observer).
116+
is_observer = bool()
117+
118+
#: A list of :class:`ChatEvent` objects representing all of the chat
119+
#: messages the person sent during the game
120+
messages = list()
121+
122+
#: A list of :class:`Event` objects representing all the game events
123+
#: generated by the person over the course of the game
124+
events = list()
125+
126+
#: A flag indicating if this person was the one who recorded the game.
127+
recorder = bool()
128+
129+
#: A flag indicating if the person is a computer or human
130+
is_human = bool()
131+
79132
def __init__(self, pid, name):
80133
self.pid = pid
81134
self.name = name
@@ -87,35 +140,46 @@ def __init__(self, pid, name):
87140
self.recorder = False # Actual recorder will be determined using the replay.message.events file
88141

89142
class Observer(Person):
143+
"""
144+
A subclass of the :class:`Person` class for observers. Fewer attributes
145+
are made available for observers in the replay file.
146+
147+
All Observers are human.
148+
"""
90149
def __init__(self, pid, name):
91150
super(Observer,self).__init__(pid, name)
92151
self.is_observer = True
93152
self.is_human = True
94153

95154
class Player(Person):
155+
"""
156+
A subclass of the :class:`Person` class for players.
157+
"""
96158

97159
URL_TEMPLATE = "http://%s.battle.net/sc2/en/profile/%s/%s/%s/"
98160

161+
#: A reference to the player's :class:`Team` object
162+
team = None
163+
99164
def __init__(self, pid, name):
100165
super(Player,self).__init__(pid, name)
101166
self.is_observer = False
102-
# self.result = "Win","Loss","Unknown"
103-
# self.team = Team()
104-
# TODO: set default external interface variables?
105167

106168
@property
107169
def url(self):
170+
"""The player's battle.net profile url"""
108171
return self.URL_TEMPLATE % (self.gateway, self.uid, self.subregion, self.name)
109172

110173
def __str__(self):
111174
return "Player %s - %s (%s)" % (self.pid, self.name, self.play_race)
112175

113-
def __repr__(self):
114-
return str(self)
115-
116176
@property
117177
def result(self):
178+
"""The game result for this player"""
118179
return self.team.result
119180

120181
def format(self, format_string):
121-
return format_string.format(**self.__dict__)
182+
return format_string.format(**self.__dict__)
183+
184+
def __repr__(self):
185+
return str(self)

0 commit comments

Comments
 (0)