From: Christian Heller Date: Thu, 24 Jan 2019 01:52:34 +0000 (+0100) Subject: Add coloring to map in ncurses client. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/ledger?a=commitdiff_plain;h=05aae1b6380c5bea2d69ee001f64f93dbff2b0c1;p=plomrogue2-experiments Add coloring to map in ncurses client. --- diff --git a/client-curses.py b/client-curses.py index a79afa0..a18d8af 100755 --- a/client-curses.py +++ b/client-curses.py @@ -205,9 +205,9 @@ class MapWidget(Widget): for t in self.tui.game.world.things: pos_i = self.tui.game.world.map_.get_position_index(t.position) terrain_as_list[pos_i] = self.tui.game.symbol_for_type(t.type_) - text = self.tui.game.world.map_.list_terrain_to_lines(terrain_as_list) + lines = self.tui.game.world.map_.list_terrain_to_lines(terrain_as_list) line_width = self.size[1] - for line in text: + for line in lines: if line_width > len(line): to_pad = line_width - (len(line) % line_width) to_join += [line + '0' * to_pad] @@ -216,7 +216,19 @@ class MapWidget(Widget): if len(to_join) < self.size[0]: to_pad = self.size[0] - len(to_join) to_join += to_pad * ['0' * self.size[1]] - self.safe_write(''.join(to_join)) + text = ''.join(to_join) + text_as_list = [] + for c in text: + if c in {'@', 'm'}: + text_as_list += [(c, curses.color_pair(1))] + elif c == '.': + text_as_list += [(c, curses.color_pair(2))] + elif c in {'x', 'X', '#'}: + text_as_list += [(c, curses.color_pair(3))] + else: + text_as_list += [c] + #self.safe_write(''.join(to_join)) + self.safe_write(text_as_list) class TurnWidget(Widget):