Skip to content

Commit 5cf0bd7

Browse files
committed
Add full color support for summary players.
1 parent 434d1cd commit 5cf0bd7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

sc2reader/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155
'E55BB0': 'Pink'
156156
}
157157

158+
COLOR_CODES_INV = dict(zip(COLOR_CODES.values(),COLOR_CODES.keys()))
159+
158160
## Names of the different properties found in the s2gs files lobby part
159161
LOBBY_PROPERTY_NAMES = {
160162
1 : 'unknown1', #0001/0002

sc2reader/resources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from sc2reader import readers, data
1818
from sc2reader.objects import Player, Observer, Team, PlayerSummary, Graph, DepotFile
1919
from sc2reader.constants import REGIONS, LOCALIZED_RACES, GAME_SPEED_FACTOR, GAME_SPEED_CODES, RACE_CODES, PLAYER_TYPE_CODES, TEAM_COLOR_CODES, GAME_FORMAT_CODES, GAME_TYPE_CODES, DIFFICULTY_CODES
20+
from sc2reader.utils import Color
2021

2122

2223
def real_type(teams):
@@ -980,7 +981,7 @@ def load_players(self):
980981

981982
# We can just copy these settings right over
982983
# TODO: Get the hex from the color string?
983-
player.color = settings.get('Color', None)
984+
player.color = Color(name=settings.get('Color', None))
984985
player.pick_race = settings.get('Race', None)
985986
player.handicap = settings.get('Handicap', None)
986987

sc2reader/utils.py

Lines changed: 11 additions & 2 deletions
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
from sc2reader.data import build22612 as Data
1919

2020
LITTLE_ENDIAN,BIG_ENDIAN = '<','>'
@@ -416,12 +416,21 @@ class Color(AttributeDict):
416416
@property
417417
def rgba(self):
418418
"""Tuple containing the (r,g,b,a) representation of the color"""
419+
if 'r' not in self or 'g' not in self or 'b' not in self:
420+
hexstr = self.hex
421+
self.r = int(hexstr[0:2],16)
422+
self.g = int(hexstr[2:4],16)
423+
self.b = int(hexstr[4:6],16)
424+
self.a = 255
419425
return (self.r,self.g,self.b,self.a)
420426

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

426435
def __str__(self):
427436
if not hasattr(self,'name'):

0 commit comments

Comments
 (0)