From: Christian Heller Date: Tue, 30 Apr 2019 21:37:47 +0000 (+0200) Subject: Only send to client whether map starts indented, not whole offset. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/index.html?a=commitdiff_plain;h=1fbd3687acb5edcdf043abfed92ec022d342f807;p=plomrogue2-experiments Only send to client whether map starts indented, not whole offset. --- diff --git a/new/example_client.py b/new/example_client.py index 2a4b80c..88939ba 100755 --- a/new/example_client.py +++ b/new/example_client.py @@ -33,11 +33,11 @@ class ClientMap(Map): cut_end = cut_start + view_width map_lines[:] = [line[cut_start:cut_end] for line in map_lines] - def format_to_view(self, map_cells, center, size, indent_first_line): + def format_to_view(self, map_cells, center, size): def map_cells_to_lines(map_cells): map_view_chars = [] - if indent_first_line: + if self.start_indented: map_view_chars += ['0'] x = 0 y = 0 @@ -51,9 +51,9 @@ class ClientMap(Map): map_view_chars += ['\n'] x = 0 y += 1 - if y % 2 == int(not indent_first_line): + if y % 2 == int(not self.start_indented): map_view_chars += ['0'] - if y % 2 == int(not indent_first_line): + if y % 2 == int(not self.start_indented): map_view_chars = map_view_chars[:-1] map_view_chars = map_view_chars[:-1] return ''.join(map_view_chars).split('\n') @@ -85,9 +85,9 @@ def cmd_TURN(game, n): cmd_TURN.argtypes = 'int:nonneg' -def cmd_VISIBLE_MAP(game, offset, size): - game.new_map(offset, size) -cmd_VISIBLE_MAP.argtypes = 'yx_tuple yx_tuple:pos' +def cmd_VISIBLE_MAP(game, size, indent_first_line): + game.new_map(size, indent_first_line) +cmd_VISIBLE_MAP.argtypes = 'yx_tuple:pos bool' def cmd_VISIBLE_MAP_LINE(game, y, terrain_line): @@ -153,9 +153,8 @@ class Game(GameBase): self.do_quit = False self.tui = None - def new_map(self, offset, size): - self.map_ = ClientMap(size) - self.offset = offset + def new_map(self, size, indent_first_line): + self.map_ = ClientMap(size, start_indented=indent_first_line) @property def player(self): @@ -449,10 +448,8 @@ class MapWidget(Widget): center = self.tui.game.player.position if self.tui.examiner_mode: center = self.tui.examiner_position - indent_first_line = not bool(self.tui.game.offset.y % 2) lines = self.tui.game.map_.\ - format_to_view(annotated_terrain, center, self.size, - indent_first_line) + format_to_view(annotated_terrain, center, self.size) pad_or_cut_x(lines) pad_y(lines) self.safe_write(lines_to_colored_chars(lines)) diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py index 948c97e..13b4002 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -114,8 +114,8 @@ class Game(GameBase): self.io.send('TURN ' + str(self.turn)) visible_map = self.player.get_visible_map() - self.io.send('VISIBLE_MAP %s %s' % (self.player.view_offset, - visible_map.size)) + self.io.send('VISIBLE_MAP %s %s' % (visible_map.size, + visible_map.start_indented)) for y, line in visible_map.lines(): self.io.send('VISIBLE_MAP_LINE %5s %s' % (y, quote(line))) visible_things = self.player.get_visible_things() diff --git a/new/plomrogue/parser.py b/new/plomrogue/parser.py index 13e2c1c..27bd95a 100644 --- a/new/plomrogue/parser.py +++ b/new/plomrogue/parser.py @@ -94,10 +94,12 @@ class Parser: def argsparse(self, signature, args_tokens): """Parse into / return args_tokens as args defined by signature. - Expects signature to be a ' '-delimited sequence of any of the strings - 'int:nonneg', 'yx_tuple', 'yx_tuple:nonneg', 'yx_tuple:pos', 'string', - 'seq:int:nonneg', 'string:' + an option type string accepted by - self.game.get_string_options, defining the respective argument types. + Expects signature to be a ' '-delimited sequence of any of the + strings 'bool', 'int:nonneg', 'yx_tuple', 'yx_tuple:nonneg', + 'yx_tuple:pos', 'string', 'seq:int:nonneg', 'string:' + an + option type string accepted by self.game.get_string_options, + defining the respective argument types. + """ tmpl_tokens = signature.split() if len(tmpl_tokens) != len(args_tokens): @@ -109,7 +111,11 @@ class Parser: for i in range(len(tmpl_tokens)): tmpl = tmpl_tokens[i] arg = args_tokens[i] - if tmpl == 'int:nonneg': + if tmpl == 'bool': + if arg not in {'True', 'False'}: + raise ArgError('Argument must be "True" or "False".') + args += [True if arg == 'True' else False] + elif tmpl == 'int:nonneg': if not arg.isdigit(): raise ArgError('Argument must be non-negative integer.') args += [int(arg)] @@ -147,7 +153,7 @@ class Parser: raise ArgError(msg) args += [arg] else: - raise ArgError('Unknown argument type.') + raise ArgError('Unknown argument type: %s' % tmpl) return args diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index 0e47cc0..1e23809 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -279,7 +279,7 @@ class ThingAnimate(Thing): def get_visible_map(self): stencil = self.get_stencil() - m = Map(self.surroundings.size, ' ') + m = Map(self.surroundings.size, ' ', self.surroundings.start_indented) for pos in m: if stencil[pos] == '.': m[pos] = self.surroundings[pos]