55import sys
66from datetime import timedelta
77
8+ from sc2reader .log_utils import loggable
89from sc2reader .exceptions import MPQError
910from sc2reader .constants import COLOR_CODES , COLOR_CODES_INV
1011
@@ -102,6 +103,7 @@ def __setattr__(self, name, value):
102103 def copy (self ):
103104 return AttributeDict (self .items ())
104105
106+ @loggable
105107class Color (object ):
106108 """
107109 Stores a color name and rgba representation of a color. Individual
@@ -120,22 +122,22 @@ class Color(object):
120122 def __init__ (self , name = None , r = 0 , g = 0 , b = 0 , a = 255 ):
121123 if name :
122124 if name not in COLOR_CODES_INV :
123- raise ValueError ("Invalid color name: " + name )
124- hexstr = COLOR_CODES_INV [ name ]
125- self .r = int (hexstr [0 :2 ],16 )
126- self .g = int (hexstr [2 :4 ],16 )
127- self .b = int (hexstr [4 :6 ],16 )
125+ self . logger . warn ("Invalid color name: " + name )
126+ hexstr = COLOR_CODES_INV . get ( name , '000000' )
127+ self .r = int (hexstr [0 :2 ], 16 )
128+ self .g = int (hexstr [2 :4 ], 16 )
129+ self .b = int (hexstr [4 :6 ], 16 )
128130 self .a = 255
129131 self .name = name
130132 else :
131133 self .r = r
132134 self .g = g
133135 self .b = b
134136 self .a = a
135- if self .hex in COLOR_CODES :
136- self .name = COLOR_CODES [ self .hex ]
137- else :
138- raise ValueError ( "Invalid color hex code: " + self . hex )
137+ if self .hex not in COLOR_CODES :
138+ self .logger . warn ( "Invalid color hex value: " + self .hex )
139+ self . name = COLOR_CODES . get ( self . hex , self . hex )
140+
139141
140142 @property
141143 def rgba (self ):
0 commit comments