5
5
import sys
6
6
from datetime import timedelta
7
7
8
+ from sc2reader .log_utils import loggable
8
9
from sc2reader .exceptions import MPQError
9
10
from sc2reader .constants import COLOR_CODES , COLOR_CODES_INV
10
11
@@ -102,6 +103,7 @@ def __setattr__(self, name, value):
102
103
def copy (self ):
103
104
return AttributeDict (self .items ())
104
105
106
+ @loggable
105
107
class Color (object ):
106
108
"""
107
109
Stores a color name and rgba representation of a color. Individual
@@ -120,22 +122,22 @@ class Color(object):
120
122
def __init__ (self , name = None , r = 0 , g = 0 , b = 0 , a = 255 ):
121
123
if name :
122
124
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 )
128
130
self .a = 255
129
131
self .name = name
130
132
else :
131
133
self .r = r
132
134
self .g = g
133
135
self .b = b
134
136
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
+
139
141
140
142
@property
141
143
def rgba (self ):
0 commit comments