X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=client-curses.py;h=a8add972df17428ae24e9ae87be7699353c6cc13;hb=52463b31fbb7f121a52f72e863a779560a6de531;hp=28d912d00b0c6fe9f183835cf3daf22af186507e;hpb=8c9d8857d363d9e3faf11eac9df2f96abab359aa;p=plomrogue2-experiments diff --git a/client-curses.py b/client-curses.py index 28d912d..a8add97 100755 --- a/client-curses.py +++ b/client-curses.py @@ -15,11 +15,10 @@ class Map(game_common.Map): if center_y > map_height - view_height / 2: map_lines[:] = map_lines[map_height - view_height:] else: - start = center_y - int(view_height / 2) + start = center_y - int(view_height / 2) - 1 map_lines[:] = map_lines[start:start + view_height] - def x_cut(self, map_lines, center_x, view_width): - map_width = len(map_lines[0]) + def x_cut(self, map_lines, center_x, view_width, map_width): if map_width > view_width and center_x > view_width / 2: if center_x > map_width - view_width / 2: cut_start = map_width - view_width @@ -45,7 +44,7 @@ class MapSquare(Map): map_lines = map_string_to_lines(map_string) self.y_cut(map_lines, center[0], size[0]) - self.x_cut(map_lines, center[1], size[1]) + self.x_cut(map_lines, center[1], size[1], self.size[1]) return map_lines @@ -54,7 +53,7 @@ class MapHex(Map): def format_to_view(self, map_string, center, size): def map_string_to_lines(map_string): - map_view_chars = [' '] + map_view_chars = ['0'] x = 0 y = 0 for c in map_string: @@ -65,16 +64,20 @@ class MapHex(Map): x = 0 y += 1 if y % 2 == 0: - map_view_chars += [' '] + map_view_chars += ['0'] + if y % 2 == 0: + map_view_chars = map_view_chars[:-1] + map_view_chars = map_view_chars[:-1] return ''.join(map_view_chars).split('\n') map_lines = map_string_to_lines(map_string) self.y_cut(map_lines, center[0], size[0]) - self.x_cut(map_lines, center[1] * 2, size[1]) + map_width = self.size[1] * 2 + 1 + self.x_cut(map_lines, center[1] * 2, size[1], map_width) return map_lines -map_manager = game_common.MapManager(globals()) +map_manager = game_common.MapManager((MapHex, MapSquare)) class World(game_common.World): @@ -105,20 +108,35 @@ class Game(game_common.CommonCommandsMixin): } self.do_quit = False + def get_command_signature(self, command_name): + method_candidate = 'cmd_' + command_name + method = None + argtypes = '' + if hasattr(self, method_candidate): + method = getattr(self, method_candidate) + if hasattr(method, 'argtypes'): + argtypes = method.argtypes + return method, argtypes + + def get_string_options(self, string_option_type): + if string_option_type == 'geometry': + return self.map_manager.get_map_geometries() + return None + def handle_input(self, msg): if msg == 'BYE': self.do_quit = True return try: - command = self.parser.parse(msg) + command, args = self.parser.parse(msg) if command is None: self.log('UNHANDLED INPUT: ' + msg) self.to_update['log'] = True else: - command() + command(*args) except ArgError as e: - self.log('ARGUMENT ERROR: ' + msg + '\n' + str(e)) - self.to_update['log'] = True + self.log('ARGUMENT ERROR: ' + msg + '\n' + str(e)) + self.to_update['log'] = True def log(self, msg): """Prefix msg plus newline to self.log_text.""" @@ -143,11 +161,13 @@ class Game(game_common.CommonCommandsMixin): pass cmd_TURN_FINISHED.argtypes = 'int:nonneg' - def cmd_NEW_TURN(self, n): + def cmd_TURN(self, n): """Set self.turn to n, empty self.things.""" self.world.turn = n self.world.things = [] - cmd_NEW_TURN.argtypes = 'int:nonneg' + self.to_update['turn'] = False + self.to_update['map'] = False + cmd_TURN.argtypes = 'int:nonneg' def cmd_VISIBLE_MAP_LINE(self, y, terrain_line): self.world.map_.set_line(y, terrain_line) @@ -380,26 +400,26 @@ class TUI: elif map_mode: if type(self.game.world.map_) == MapSquare: if key == 'a': - plom_socket_io.send(self.socket, 'MOVE LEFT') + plom_socket_io.send(self.socket, 'TASK:MOVE LEFT') elif key == 'd': - plom_socket_io.send(self.socket, 'MOVE RIGHT') + plom_socket_io.send(self.socket, 'TASK:MOVE RIGHT') elif key == 'w': - plom_socket_io.send(self.socket, 'MOVE UP') + plom_socket_io.send(self.socket, 'TASK:MOVE UP') elif key == 's': - plom_socket_io.send(self.socket, 'MOVE DOWN') + plom_socket_io.send(self.socket, 'TASK:MOVE DOWN') elif type(self.game.world.map_) == MapHex: if key == 'w': - plom_socket_io.send(self.socket, 'MOVE UPLEFT') + plom_socket_io.send(self.socket, 'TASK:MOVE UPLEFT') elif key == 'e': - plom_socket_io.send(self.socket, 'MOVE UPRIGHT') + plom_socket_io.send(self.socket, 'TASK:MOVE UPRIGHT') if key == 's': - plom_socket_io.send(self.socket, 'MOVE LEFT') + plom_socket_io.send(self.socket, 'TASK:MOVE LEFT') elif key == 'd': - plom_socket_io.send(self.socket, 'MOVE RIGHT') + plom_socket_io.send(self.socket, 'TASK:MOVE RIGHT') if key == 'x': - plom_socket_io.send(self.socket, 'MOVE DOWNLEFT') + plom_socket_io.send(self.socket, 'TASK:MOVE DOWNLEFT') elif key == 'c': - plom_socket_io.send(self.socket, 'MOVE DOWNRIGHT') + plom_socket_io.send(self.socket, 'TASK:MOVE DOWNRIGHT') else: if len(key) == 1 and key in ASCII_printable and \ len(self.to_send) < len(self.edit):