@@ -231,6 +231,33 @@ def __repr__(self):
231
231
def __int__ (self ):
232
232
return _lib .TDL_color_RGB (self ._r , self ._g , self ._b )
233
233
234
+ def __getitem__ (self , key ):
235
+ if key == 0 :
236
+ return self ._r
237
+ if key == 1 :
238
+ return self ._g
239
+ if key == 2 :
240
+ return self ._b
241
+ return list (self )[key ] # fallback to list-like behaviour
242
+
243
+ def __setitem__ (self , key , value ):
244
+ if key == 0 :
245
+ self ._r = value & 0xFF
246
+ return
247
+ if key == 1 :
248
+ self ._g = value & 0xFF
249
+ return
250
+ if key == 2 :
251
+ self ._b = value & 0xFF
252
+ return
253
+ # fallback to list-like behaviour
254
+ color = [self ._r , self ._g , self ._b ]
255
+ color [key ] = value
256
+ self .r , self .g , self .b = color
257
+
258
+ def __iter__ (self ):
259
+ return iter ((self ._r , self ._g , self ._b ))
260
+
234
261
235
262
class _BaseConsole (object ):
236
263
"""
@@ -878,7 +905,7 @@ def get_char(self, x, y):
878
905
This method runs very slowly as is not recommended to be called
879
906
frequently.
880
907
881
- @rtype: (int, (r, g, b), (r, g, b) )
908
+ @rtype: (int, L{Color}, L{Color} )
882
909
@returns: Returns a 3-item tuple. The first item is an integer of the
883
910
character at the position (x, y) the second and third are the
884
911
foreground and background colors respectfully.
@@ -1059,11 +1086,13 @@ def _set_batch(self, batch, fg, bg, bgblend=1, nullChar=False):
1059
1086
1060
1087
def get_char (self , x , y ):
1061
1088
# inherit docstring
1062
- x , y = self ._normalizePoint (x , y )
1063
- char = _lib .TCOD_console_get_char (self .tcod_console , x , y )
1064
- bg = _lib .TCOD_console_get_char_background (self .tcod_console , x , y )
1065
- fg = _lib .TCOD_console_get_char_foreground (self .tcod_console , x , y )
1066
- return char , (fg .r , fg .g , fg .b ), (bg .r , bg .g , bg .b )
1089
+ x = self ._range_x [x ]
1090
+ y = self ._range_y [y ]
1091
+ return (
1092
+ _lib .TCOD_console_get_char (self .tcod_console , x , y ),
1093
+ Color .from_int (_lib .TDL_console_get_bg (self .tcod_console , x , y )),
1094
+ Color .from_int (_lib .TDL_console_get_fg (self .tcod_console , x , y ))
1095
+ )
1067
1096
1068
1097
def __getitem__ (self , key ):
1069
1098
x , y = key
0 commit comments