From 995b005ba5fa1713d82d87cc11f212cac25eb59d Mon Sep 17 00:00:00 2001 From: Harry Morgan Date: Thu, 23 May 2019 13:21:40 +0100 Subject: [PATCH] removed whitespace --- noobhack/game/events.py | 2 +- noobhack/game/graphics.py | 4 +-- noobhack/game/intrinsics.py | 4 +-- noobhack/game/mapping.py | 36 ++++++++++++------------- noobhack/game/save.py | 4 +-- noobhack/game/shops.py | 12 ++++----- noobhack/game/sounds.py | 12 ++++----- noobhack/game/status.py | 6 ++--- noobhack/process.py | 12 ++++----- noobhack/proxy.py | 10 +++---- noobhack/telnet.py | 8 +++--- noobhack/ui/common.py | 4 +-- noobhack/ui/game.py | 2 +- noobhack/ui/helper.py | 38 +++++++++++++------------- noobhack/ui/minimap.py | 54 ++++++++++++++++++------------------- 15 files changed, 104 insertions(+), 104 deletions(-) diff --git a/noobhack/game/events.py b/noobhack/game/events.py index e6254dd..23c51fa 100644 --- a/noobhack/game/events.py +++ b/noobhack/game/events.py @@ -4,7 +4,7 @@ def __init__(self): def listen(self, event, function): if not self.listeners.has_key(event): - self.listeners[event] = set() + self.listeners[event] = set() self.listeners[event].add(function) diff --git a/noobhack/game/graphics.py b/noobhack/game/graphics.py index 162de93..d2c30c4 100644 --- a/noobhack/game/graphics.py +++ b/noobhack/game/graphics.py @@ -1,4 +1,4 @@ -ibm = dict( +ibm = dict( zip( (ord(code_point) for code_point in # Normal IBMgraphics... @@ -7,7 +7,7 @@ # Rogue level IBMgraphics... u'\u2551\u2550\u2554\u2557\u255a\u255d\u256c\u2569\u2566\u2563\u2560' + - u'\u263a\u2666\u2663\u2640\u266b\u263c\u2191[\xa1\u2592\u2593\u03c4' + + u'\u263a\u2666\u2663\u2640\u266b\u263c\u2191[\xa1\u2592\u2593\u03c4' + u'\u2261\xb7' ), # And... the normal way we expect them... diff --git a/noobhack/game/intrinsics.py b/noobhack/game/intrinsics.py index b5894e2..eab9995 100644 --- a/noobhack/game/intrinsics.py +++ b/noobhack/game/intrinsics.py @@ -26,7 +26,7 @@ "Disintegration resist.": { "You are disintegration-resistant":True, "You feel very firm.":True, - "You feel totally together, man.":True + "You feel totally together, man.":True }, "Poison resistance": { "You are poison resistant":True, @@ -51,7 +51,7 @@ "See invisible": { "You see an image of someone stalking you.":True, "You feel transparent":True, - "You feel very self-conscious":True, + "You feel very self-conscious":True, "Your vision becomes clear":True }, "Searching": { diff --git a/noobhack/game/mapping.py b/noobhack/game/mapping.py index c435755..4a5c131 100644 --- a/noobhack/game/mapping.py +++ b/noobhack/game/mapping.py @@ -1,5 +1,5 @@ class Branch: - """ + """ Given a level, provide some methods to treat that level's dungeon branch as a distinct entity. Probably most importantly, Branch's are iters that iterate from the top (lowest dlvl) to the bottom (highest dlvl). @@ -21,7 +21,7 @@ def find_top(self, level): branch """ - ups = [l for l + ups = [l for l in level.stairs.values() if l.dlvl < level.dlvl and l.branch == level.branch] @@ -36,7 +36,7 @@ def name(self): def sub_branches(self): """ - Return all branches that are connected to this one (whether they're + Return all branches that are connected to this one (whether they're parents or children) """ @@ -54,8 +54,8 @@ def next(self): raise StopIteration else: current = self.current - potential_nexts = [l for l - in current.stairs.values() + potential_nexts = [l for l + in current.stairs.values() if l.branch == current.branch and l.dlvl > current.dlvl] if len(potential_nexts) > 0: @@ -67,7 +67,7 @@ def next(self): class Level(object): """ - A single dungeon level. This can be thought of as "mines, level 3", or + A single dungeon level. This can be thought of as "mines, level 3", or "main, level 5". There can be multiple levels of the same dlvl, but they should generally be in different branches. Dungeons have stairs to other levels. @@ -79,7 +79,7 @@ class Level(object): def __init__(self, dlvl, branch="main"): self.dlvl = dlvl - self.branch = branch + self.branch = branch self.stairs = {} # Level features @@ -116,28 +116,28 @@ def is_a_junction(self): class Map: def __init__(self, level, x, y): - self.current = level + self.current = level self.levels = set([self.current]) - self.location = (x, y) + self.location = (x, y) def move(self, x, y): self.location = (x, y) self.current.breadcrumbs.add((x, y)) def level_at(self, branch, dlvl): - maybe_level = [l for l - in self.levels - if l.dlvl == dlvl + maybe_level = [l for l + in self.levels + if l.dlvl == dlvl and l.branch == branch] if len(maybe_level) == 1: return maybe_level[0] - else: + else: return None def change_branch_to(self, branch): - peers = [l for l - in self.levels - if l.dlvl == self.current.dlvl + peers = [l for l + in self.levels + if l.dlvl == self.current.dlvl and l != self.current and l.branch == "not sure"] @@ -158,8 +158,8 @@ def _add(self, new_level, pos): self._link(new_level, pos) def _handle_existing_level(self, to_dlvl, to_pos): - has_stairs_to_other_lower = [l for l - in self.current.stairs.values() + has_stairs_to_other_lower = [l for l + in self.current.stairs.values() if l.dlvl == to_dlvl] if len(has_stairs_to_other_lower) > 0: diff --git a/noobhack/game/save.py b/noobhack/game/save.py index 0723662..a60522e 100644 --- a/noobhack/game/save.py +++ b/noobhack/game/save.py @@ -11,11 +11,11 @@ def load(save_file): save.close() else: raise RuntimeError( - "NetHack is trying to restore a game file, but noobhack " + + "NetHack is trying to restore a game file, but noobhack " + "doesn't have any memory of this game. While noobhack will " + "still work on a game it doesn't know anything about, there " + "will probably be errors. If you'd like to use noobhack, " + - "run nethack and quit your current game, then restart " + + "run nethack and quit your current game, then restart " + "noobhack." ) diff --git a/noobhack/game/shops.py b/noobhack/game/shops.py index 60dde96..e009173 100644 --- a/noobhack/game/shops.py +++ b/noobhack/game/shops.py @@ -13,7 +13,7 @@ "quality apparel and accessories": "90/10 wand/misc", "hardware store": "tools", "rare books": "90/10 books/scrolls", - "lighting store": "97/3 light/m.lamp" + "lighting store": "97/3 light/m.lamp" } amulets = set([ @@ -30,7 +30,7 @@ ("Yendor", 30000, 0, None), ]) -weapons = { +weapons = { "dagger": set([ ("orcish dagger", 4, 12, "crude dagger"), ("dagger", 4, 30, None), @@ -215,7 +215,7 @@ ]) rings = set([ - ("meat ring", 5, 0, None), + ("meat ring", 5, 0, None), ("adornment",100, 1, None), ("hunger",100, 1, None), ("protection",100, 1, None), @@ -436,7 +436,7 @@ def get_item_set(name): def buy_identify(charisma, item, cost, sucker=False): possibles = get_item_set(item) if possibles is None: - return set() + return set() markup = buy_price_markup(charisma) price_adjusted = [(p[0], p[1] + round(p[1] * markup)) + p[2:] for p in possibles] @@ -445,10 +445,10 @@ def buy_identify(charisma, item, cost, sucker=False): if sucker: real_possibles = [(p[0], p[1] + round(p[1] * 0.333)) + p[2:] for p in real_possibles] - + appearance_ids = set([p for p in real_possibles if p[3] == item and abs(p[1] - cost) <= 1]) if len(appearance_ids) > 0: - return appearance_ids + return appearance_ids price_ids = set([p for p in real_possibles if abs(p[1] - cost) <= 1]) diff --git a/noobhack/game/sounds.py b/noobhack/game/sounds.py index 52ec1f9..8b139cb 100644 --- a/noobhack/game/sounds.py +++ b/noobhack/game/sounds.py @@ -1,5 +1,5 @@ messages = { - "oracle": set(( + "oracle": set(( "You hear a strange wind.", "You hear convulsive ravings.", "You hear snoring snakes.", @@ -10,19 +10,19 @@ "rogue": set(("You enter what seems to be an older, more primitive world.",)), "angry watch": set(("You hear the shrill sound of a guard's whistle.",)), "zoo": set(( - "You hear a sound reminiscent of an elephant stepping on a peanut.", - "You hear a sound reminiscent of a seal barking.", + "You hear a sound reminiscent of an elephant stepping on a peanut.", + "You hear a sound reminiscent of a seal barking.", "You hear Doctor Doolittle!" )), "beehive": set(( "You hear a low buzzing.", - "You hear an angry drone.", + "You hear an angry drone.", "You hear bees in your.*bonnet!" )), "barracks": set(( "You hear blades being honed.", - "You hear loud snoring.", - "You hear dice being thrown.", + "You hear loud snoring.", + "You hear dice being thrown.", "You hear General MacArthur!" )), "shop": set(( diff --git a/noobhack/game/status.py b/noobhack/game/status.py index eed12eb..863e7e7 100644 --- a/noobhack/game/status.py +++ b/noobhack/game/status.py @@ -3,7 +3,7 @@ def type_of(status): """ - Return the type of a particular status; either `"good"`, `"bad"` or + Return the type of a particular status; either `"good"`, `"bad"` or `"neutral"` """ if status in bads: @@ -26,7 +26,7 @@ def type_of(status): "You feel quick!": True, "You seem faster.": True, "You speed up.": True, - "Your quickness feels more natural.": True, + "Your quickness feels more natural.": True, "\"and thus I grant thee the gift of Speed!\"": True, "You are slowing down.": False, "You feel slow!": False, @@ -57,7 +57,7 @@ def type_of(status): "You feel less jumpy.": False }, "stoning": { - "You are slowing down.": True, + "You are slowing down.": True, "Your limbs are stiffening.": True, "You feel limber!": False, "You feel more limber.": False, diff --git a/noobhack/process.py b/noobhack/process.py index 626cde9..d35ec31 100644 --- a/noobhack/process.py +++ b/noobhack/process.py @@ -59,7 +59,7 @@ def open(self): def _close(self, *_): """ Raise an exception signaling that the child process has finished. - Whoever catches the exception is responsible for flushing the child's + Whoever catches the exception is responsible for flushing the child's stdout. """ @@ -91,16 +91,16 @@ def write(self, buf): self.stdin.write(buf) def read(self): - """ - Proxy output from the nethack process' stdout. This shouldn't block + """ + Proxy output from the nethack process' stdout. This shouldn't block """ buf = "" - while self.data_is_available(): + while self.data_is_available(): buf += self.stdout.read(1) return buf def data_is_available(self): - """ - Return a non-empty list when the nethack process has data to read + """ + Return a non-empty list when the nethack process has data to read """ return select.select([self.stdout], [], [], 0) == ([self.stdout], [], []) diff --git a/noobhack/proxy.py b/noobhack/proxy.py index 17c534d..a9a63f1 100644 --- a/noobhack/proxy.py +++ b/noobhack/proxy.py @@ -14,12 +14,12 @@ class Input: def __init__(self, game): self.game = game - self.callbacks = [] + self.callbacks = [] def register(self, callback): """ Register a function that will be called *before* any input read off of - stdin is forwarded to the game. The callback should return `False` if + stdin is forwarded to the game. The callback should return `False` if it's not to forward the input to the game. """ if callback not in self.callbacks: @@ -52,19 +52,19 @@ def proxy(self): class Output: """ - Proxies raw output from the game and calls a set of callbacks each time + Proxies raw output from the game and calls a set of callbacks each time with the stream that was output. Typically you'd want to attach a terminal emulator, or something that can parse the output as meaningful to this. """ def __init__(self, game): self.game = game - self.callbacks = [] + self.callbacks = [] def register(self, callback): """ Register a function that will be called whenever any input is read. The - function should accept one argument, which will be the data read from + function should accept one argument, which will be the data read from the game. """ if callback not in self.callbacks: diff --git a/noobhack/telnet.py b/noobhack/telnet.py index f13cca4..317d85f 100644 --- a/noobhack/telnet.py +++ b/noobhack/telnet.py @@ -4,7 +4,7 @@ class Telnet: """ - Runs and manages the input/output of a remote nethack game. The class + Runs and manages the input/output of a remote nethack game. The class implements a telnet client in as much as the python telnetlib makes that possible (grumble, grumble, grumble). """ @@ -20,8 +20,8 @@ def write(self, buf): self.conn.get_socket().send(buf) def read(self): - """ - Proxy output from the telnet process' stdout. This shouldn't block + """ + Proxy output from the telnet process' stdout. This shouldn't block """ try: return self.conn.read_very_eager() @@ -77,7 +77,7 @@ def set_option(self, socket, command, option): telnetlib.IAC, telnetlib.SE)) # We're being asked for the terminal type that we promised earlier - socket.send("%s%s\x18\x00%s%s%s" % + socket.send("%s%s\x18\x00%s%s%s" % (telnetlib.IAC, telnetlib.SB, "xterm-color", diff --git a/noobhack/ui/common.py b/noobhack/ui/common.py index d10586e..fa470a9 100644 --- a/noobhack/ui/common.py +++ b/noobhack/ui/common.py @@ -1,6 +1,6 @@ import sys import fcntl -import curses +import curses import struct import termios @@ -52,4 +52,4 @@ def size(): """ raw = fcntl.ioctl(sys.stdin, termios.TIOCGWINSZ, 'SSSS') - return struct.unpack('hh', raw) + return struct.unpack('hh', raw) diff --git a/noobhack/ui/game.py b/noobhack/ui/game.py index 65d1b24..32216ae 100644 --- a/noobhack/ui/game.py +++ b/noobhack/ui/game.py @@ -30,7 +30,7 @@ def _write_attrs(self, window, row): background = colors.get(background, -1) char_style = [styles.get(s, curses.A_NORMAL) for s in char_style] attrs = char_style + [get_color(foreground, background)] - window.chgat(row, col, 1, reduce(lambda a, b: a | b, attrs)) + window.chgat(row, col, 1, reduce(lambda a, b: a | b, attrs)) def _redraw_row(self, window, row): """ diff --git a/noobhack/ui/helper.py b/noobhack/ui/helper.py index ad5c037..bd6f706 100644 --- a/noobhack/ui/helper.py +++ b/noobhack/ui/helper.py @@ -1,5 +1,5 @@ import re -import curses +import curses from noobhack.game import shops, status from noobhack.ui.common import get_color @@ -12,7 +12,7 @@ class Helper: intrinsic_width = 25 status_width = 12 - level_width = 25 + level_width = 25 def __init__(self, manager): self.manager = manager @@ -38,7 +38,7 @@ def sort_statuses(left, right): def _height(self): """ Return the height of the helper ui. This means finding the max number - of lines that is to be displayed in all of the boxes. + of lines that is to be displayed in all of the boxes. """ level = self.dungeon.current_level() @@ -70,9 +70,9 @@ def _level_box(self): default = "(none)" dungeon_frame = curses.newwin( - self._height(), - self.level_width, - self._top(), + self._height(), + self.level_width, + self._top(), 0 ) @@ -110,21 +110,21 @@ def _intrinsic_box(self): def res_color(res): """Return the color of a intrinsic.""" - if res == "fire": + if res == "fire": return curses.COLOR_RED - elif res == "cold": - return curses.COLOR_BLUE - elif res == "poison": + elif res == "cold": + return curses.COLOR_BLUE + elif res == "poison": return curses.COLOR_GREEN - elif res == "disintegration": + elif res == "disintegration": return curses.COLOR_YELLOW - else: + else: return -1 res_frame = curses.newwin( - self._height(), - self.intrinsic_width, - self._top(), + self._height(), + self.intrinsic_width, + self._top(), self.level_width + self.status_width - 2 ) @@ -209,9 +209,9 @@ def _status_box(self): default = "(none)" status_frame = curses.newwin( - self._height(), - self.status_width, - self._top(), + self._height(), + self.status_width, + self._top(), self.level_width - 1 ) @@ -239,7 +239,7 @@ def _breadcrumbs(self, window): for crumb in breadcrumbs: x, y = crumb - if self.manager.char_at(x, y) not in [".", "#", " "]: + if self.manager.char_at(x, y) not in [".", "#", " "]: # Ignore anything that's not something we can step on. continue diff --git a/noobhack/ui/minimap.py b/noobhack/ui/minimap.py index d7e4dd0..559d3e4 100644 --- a/noobhack/ui/minimap.py +++ b/noobhack/ui/minimap.py @@ -1,5 +1,5 @@ import sys -import curses +import curses from noobhack.ui.common import get_color, size @@ -18,8 +18,8 @@ def shop_text_as_buffer(self, shops): return [] def feature_text_as_buffer(self, features): - return [" * %s" % f.capitalize() - for f in sorted(features) + return [" * %s" % f.capitalize() + for f in sorted(features) if f != "shop"] def level_text_as_buffer(self, level): @@ -32,8 +32,8 @@ def line_to_display(self, text, width, border="|", padding=" "): # If the text is too long to fit in the width, then trim it. text = text[:(width + len(border) * 2 + 2)] return "%s%s%s%s%s" % ( - border, padding, - text + padding * (width - len(text) - len(border) * 2 - len(padding) * 2), + border, padding, + text + padding * (width - len(text) - len(border) * 2 - len(padding) * 2), padding, border ) @@ -55,7 +55,7 @@ def layout_level_text_buffers(self, levels): last_level = level - return indices, result + return indices, result def header_as_buffer(self, text, width): return [ @@ -85,11 +85,11 @@ def unconnected_branch_as_buffer_with_indices(self, display_name, branch, end=Fa footer = self.end_as_buffer(width) # Adjust the indices to account for the header - indices = dict([(dlvl, index + len(header)) - for dlvl, index + indices = dict([(dlvl, index + len(header)) + for dlvl, index in indices.iteritems()]) - return (indices, header + body + footer) + return (indices, header + body + footer) def get_plane_for_map(self, levels): # Hopefully 10 lines per dungeon level on average is large enough... @@ -135,10 +135,10 @@ def loop_and_listen_for_scroll_events(self, window, plane, bounds, close): if move_y > 0: scroll_y = min(scroll_y + move_y, bottom - 5) else: - scroll_y = max(scroll_y + move_y, top - size()[0] + 5) + scroll_y = max(scroll_y + move_y, top - size()[0] + 5) if move_x > 0: - scroll_x = min(scroll_x + move_x, right - 20) + scroll_x = min(scroll_x + move_x, right - 20) else: scroll_x = max(scroll_x + move_x, left - size()[1] + 20) @@ -160,12 +160,12 @@ def _draw_up_connecter(self, plane, x_offset, y_offset, left=False): for i, sym in enumerate(syms): if left: real_y_offset = y_offset + i - len(syms) - else: + else: real_y_offset = y_offset - i plane.addstr(real_y_offset, x_offset + i, sym) - def _draw_sub_branches(self, parent, current, plane, - indices, left_x_offset, right_x_offset, y_offset, + def _draw_sub_branches(self, parent, current, plane, + indices, left_x_offset, right_x_offset, y_offset, color, drawn, left=False, alternate=True): left_x, right_x, top_y, bottom_y = plane.getmaxyx()[1], 0, plane.getmaxyx()[0], 0 bounds = (left_x, right_x, top_y, bottom_y, 0, 0) @@ -195,8 +195,8 @@ def _draw_sub_branches(self, parent, current, plane, connect_offset = right_x_offset connect_at = y_offset + indices[branch_junction.dlvl] - 1 - sub_bounds = draw(sub_branch, current, plane, - x_offset, connect_at, color, + sub_bounds = draw(sub_branch, current, plane, + x_offset, connect_at, color, drawn, left, False) bounds = ( @@ -212,20 +212,20 @@ def _draw_sub_branches(self, parent, current, plane, return bounds def _draw_branch_to(self, branch, current, plane, - x_offset, y_offset, color, drawn, + x_offset, y_offset, color, drawn, left=False, alternate=True): return self._draw_branch(branch, current, plane, x_offset, y_offset, color, drawn, True, left, alternate) - def _draw_branch_at(self, branch, current, plane, - x_offset, y_offset, color, drawn, + def _draw_branch_at(self, branch, current, plane, + x_offset, y_offset, color, drawn, left=False, alternate=True): return self._draw_branch(branch, current, plane, x_offset, y_offset, color, drawn, False, left, alternate) - def _draw_branch(self, branch, current, plane, + def _draw_branch(self, branch, current, plane, x_offset, y_offset, color, drawn, to=False, left=False, alternate=True): drawn.update({branch.name(): True}) @@ -253,9 +253,9 @@ def _draw_branch(self, branch, current, plane, index >= indices[current.dlvl] and \ index < indices.get(current.dlvl + 1, len(buf) - 1): plane.chgat( - real_y_offset + index, - real_x_offset + 1, - len(line) - 2, + real_y_offset + index, + real_x_offset + 1, + len(line) - 2, curses.A_BOLD | color(curses.COLOR_GREEN) ) @@ -269,13 +269,13 @@ def _draw_branch(self, branch, current, plane, current_lvl_x = real_x_offset current_lvl_y = real_y_offset + indices[current.dlvl] else: - current_lvl_x = left_x - current_lvl_y = top_y + current_lvl_x = left_x + current_lvl_y = top_y bounds = (left_x, right_x, top_y, bottom_y, current_lvl_x, current_lvl_y) sub_bounds = self._draw_sub_branches( - branch, current, plane, indices, + branch, current, plane, indices, real_x_offset, real_x_offset + len(buf[0]), real_y_offset, color, drawn, left, alternate ) @@ -291,7 +291,7 @@ def _draw_branch(self, branch, current, plane, def draw_dungeon(self, dungeon, plane, x_offset, y_offset, color=get_color): return self._draw_branch_at( - dungeon.main(), dungeon.current, plane, + dungeon.main(), dungeon.current, plane, x_offset, y_offset, color, {} )