Skip to content

Commit d36642e

Browse files
committed
Move the Color class to the utils module.
1 parent 2df3e47 commit d36642e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

sc2reader/objects.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
ColorData = namedtuple('ColorData',['a','r','g','b'])
1414
BnetData = namedtuple('BnetData',['unknown1','unknown2','subregion','uid'])
1515

16-
class Color(AttributeDict):
17-
@property
18-
def hex(self):
19-
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
20-
21-
def __str__(self):
22-
if not hasattr(self,'name'):
23-
self.name = COLOR_CODES[self.hex]
24-
return self.name
25-
2616
class Team(object):
2717
"""
2818
The team object primarily a container object for organizing :class:`Player`

sc2reader/replay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
from collections import defaultdict
55
from sc2reader.constants import REGIONS, LOCALIZED_RACES
6-
from sc2reader.objects import Player, Color, Observer, Team
6+
from sc2reader.objects import Player, Observer, Team
77

88
from sc2reader import utils
99

@@ -250,7 +250,7 @@ def load_players(self):
250250
# color_rgba is the color object itself
251251
# color_hex is color.hex
252252
# color is str(color)
253-
player.color = Color(**pdata.color._asdict())
253+
player.color = utils.Color(**pdata.color._asdict())
254254

255255
# Each player can be referenced in a number of different ways,
256256
# primarily for convenience of access in any given situation.

sc2reader/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,16 @@ def __setattr__(self, name, value):
543543
def copy(self):
544544
return AttributeDict(super(AttributeDict,self).copy())
545545

546+
class Color(AttributeDict):
547+
@property
548+
def hex(self):
549+
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
550+
551+
def __str__(self):
552+
if not hasattr(self,'name'):
553+
self.name = COLOR_CODES[self.hex]
554+
return self.name
555+
546556
def open_archive(replay_file):
547557
# Don't read the listfile because some replays have corrupted listfiles
548558
# due to tampering by 3rd parties.

0 commit comments

Comments
 (0)