Skip to content

Commit 98320af

Browse files
committed
Add full color support for summary players.
1 parent 3540b47 commit 98320af

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

sc2reader/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
'E55BB0': 'Pink'
9393
}
9494

95+
COLOR_CODES_INV = dict(zip(COLOR_CODES.values(),COLOR_CODES.keys()))
96+
9597
## Names of the different properties found in the s2gs files lobby part
9698
LOBBY_PROPERTY_NAMES = {
9799
1 : 'unknown1', #0001/0002

sc2reader/resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ def load_players(self):
10111011

10121012
# We can just copy these settings right over
10131013
# TODO: Get the hex from the color string?
1014-
player.color = settings.get('Color', None)
1014+
player.color = utils.Color(name=settings.get('Color', None)
10151015
player.pick_race = settings.get('Race', None)
10161016
player.handicap = settings.get('Handicap', None)
10171017

sc2reader/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from collections import deque
1515

1616
from sc2reader import exceptions
17-
from sc2reader.constants import COLOR_CODES, BUILD_ORDER_UPGRADES
17+
from sc2reader.constants import COLOR_CODES, COLOR_CODES_INV, BUILD_ORDER_UPGRADES
1818

1919
LITTLE_ENDIAN,BIG_ENDIAN = '<','>'
2020

@@ -415,11 +415,21 @@ class Color(AttributeDict):
415415
@property
416416
def rgba(self):
417417
"""Tuple containing the (r,g,b,a) representation of the color"""
418+
if 'r' not in self or 'g' not in self or 'b' not in self:
419+
hexstr = self.hex
420+
self.r = int(hexstr[0:2],16)
421+
self.g = int(hexstr[2:4],16)
422+
self.b = int(hexstr[4:6],16)
423+
self.a = 255
418424
return (self.r,self.g,self.b,self.a)
419425

420426
@property
421427
def hex(self):
422428
"""The hexadecimal representation of the color"""
429+
if 'name' in self:
430+
return COLOR_CODES_INV.get(self.name)
431+
else:
432+
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
423433
return "{0.r:02X}{0.g:02X}{0.b:02X}".format(self)
424434

425435
def __str__(self):

0 commit comments

Comments
 (0)