Skip to content

Commit b5e7e36

Browse files
committed
color asserts no longer needed
1 parent 67a6d55 commit b5e7e36

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

tdl/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,14 @@ def _iscolor(color):
165165
def _formatColor(color, default=Ellipsis):
166166
if color is Ellipsis:
167167
return default
168-
if color is None or color is False:
168+
if color is None:
169169
return -1
170-
#if (isinstance(color, _ffi.CData) and
171-
# _ffi.typeof(color) is _ffi.typeof('TCOD_color_t *')):
172-
# return color
173170
if isinstance(color, int_types):
174171
# format a web style color with the format 0xRRGGBB
175172
return color
176-
#return _ffi.new('TCOD_color_t *', (color >> 16 & 0xff,
177-
# color >> 8 & 0xff,
178-
# color & 0xff))
179-
return (color[0] << 16) + (color[1] << 8) + color[2]
173+
if isinstance(color, (tuple, list)) and len(color) == 3:
174+
return (color[0] << 16) + (color[1] << 8) + color[2]
175+
raise TDLError('color must be a 3 item tuple, integer, Ellipsis, or None\nReceived: %r' % (color,))
180176
#return _ffi.new('TCOD_color_t *', color)
181177

182178
def _to_tcod_color(color):
@@ -422,7 +418,7 @@ def draw_char(self, x, y, char, fg=Ellipsis, bg=Ellipsis):
422418
@see: L{get_char}
423419
"""
424420

425-
assert _verify_colors(fg, bg)
421+
#assert _verify_colors(fg, bg)
426422
#x, y = self._normalizePoint(x, y)
427423
#x, y = _ctypes.c_int(x), _ctypes.c_int(y)
428424
_lib.set_char(self._as_parameter_, x, y, _formatChar(char),
@@ -468,7 +464,7 @@ def draw_str(self, x, y, string, fg=Ellipsis, bg=Ellipsis):
468464
"""
469465

470466
x, y = self._normalizePoint(x, y)
471-
assert _verify_colors(fg, bg)
467+
#assert _verify_colors(fg, bg)
472468
fg, bg = _formatColor(fg, self._fg), _formatColor(bg, self._bg)
473469
width, height = self.get_size()
474470
batch = [] # prepare a batch operation
@@ -527,7 +523,7 @@ def draw_rect(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis):
527523
@see: L{clear}, L{draw_frame}
528524
"""
529525
x, y, width, height = self._normalizeRect(x, y, width, height)
530-
assert _verify_colors(fg, bg)
526+
#assert _verify_colors(fg, bg)
531527
fg, bg = _formatColor(fg, self._fg), _formatColor(bg, self._bg)
532528
char = _formatChar(string)
533529
# use itertools to make an x,y grid
@@ -576,7 +572,7 @@ def draw_frame(self, x, y, width, height, string, fg=Ellipsis, bg=Ellipsis):
576572
@see: L{draw_rect}, L{Window}
577573
"""
578574
x, y, width, height = self._normalizeRect(x, y, width, height)
579-
assert _verify_colors(fg, bg)
575+
#assert _verify_colors(fg, bg)
580576
fg, bg = _formatColor(fg, self._fg), _formatColor(bg, self._bg)
581577
char = _formatChar(string)
582578
if width == 1 or height == 1: # it's just a single width line here
@@ -904,7 +900,7 @@ def clear(self, fg=Ellipsis, bg=Ellipsis):
904900
@param bg: Background color. See fg.
905901
@see: L{draw_rect}
906902
"""
907-
assert _verify_colors(fg, bg)
903+
#assert _verify_colors(fg, bg)
908904
assert fg is not None and bg is not None, 'Can not use None with clear'
909905
self._typewriter = None
910906
fg = _formatColor(fg, self._fg)
@@ -1085,7 +1081,7 @@ def clear(self, fg=Ellipsis, bg=Ellipsis):
10851081
@param bg: See fg
10861082
@see: L{draw_rect}
10871083
"""
1088-
assert _verify_colors(fg, bg)
1084+
#assert _verify_colors(fg, bg)
10891085
assert fg is not None and bg is not None, 'Can not use None with clear'
10901086
if fg is Ellipsis:
10911087
fg = self._fg

0 commit comments

Comments
 (0)