Skip to content

Commit b5746c8

Browse files
committed
Create a Color object extending the Attribute dict with hex and string representations to wrap up color functionalities
1 parent 4a9f129 commit b5746c8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sc2reader/objects.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
from sc2reader.constants import *
55
from sc2reader.data import GameObject, ABILITIES
6-
from sc2reader.utils import PersonDict, Selection, read_header
6+
from sc2reader.utils import PersonDict, Selection, read_header, AttributeDict
7+
8+
class Color(AttributeDict):
9+
@property
10+
def hex():
11+
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
12+
13+
def __str__(self):
14+
if not hasattr(self,'name'):
15+
self.name = COLOR_CODES[self.hex]
16+
return self.name
717

818
class Replay(object):
919

0 commit comments

Comments
 (0)