From: Christian Heller Date: Mon, 14 Dec 2020 23:15:37 +0000 (+0100) Subject: In pick-up selection, show reachable things' relative direction. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/add_structured?a=commitdiff_plain;h=1c16b715953524a6d9e84993963cf4f7adcc5bbe;p=plomrogue2 In pick-up selection, show reachable things' relative direction. --- diff --git a/rogue_chat.html b/rogue_chat.html index 35dc5d4..c685581 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -861,29 +861,45 @@ let tui = { this.log_msg("Portable things in reach for pick-up:"); const y = game.player.position[0] const x = game.player.position[1] - let select_range = [y.toString() + ':' + x.toString(), - (y + 0).toString() + ':' + (x - 1).toString(), - (y + 0).toString() + ':' + (x + 1).toString(), - (y - 1).toString() + ':' + (x).toString(), - (y + 1).toString() + ':' + (x).toString()]; - if (game.map_geometry == 'Hex') { + let directed_moves = { + 'HERE': [0, 0], 'LEFT': [0, -1], 'RIGHT': [0, 1] + } + if (game.map_geometry == 'Square') { + directed_moves['UP'] = [-1, 0]; + directed_moves['DOWN'] = [1, 0]; + } else if (game.map_geometry == 'Hex') { if (y % 2) { - select_range.push((y - 1).toString() + ':' + (x + 1).toString()); - select_range.push((y + 1).toString() + ':' + (x + 1).toString()); + directed_moves['UPLEFT'] = [-1, 0]; + directed_moves['UPRIGHT'] = [-1, 1]; + directed_moves['DOWNLEFT'] = [1, 0]; + directed_moves['DOWNRIGHT'] = [1, 1]; } else { - select_range.push((y - 1).toString() + ':' + (x - 1).toString()); - select_range.push((y + 1).toString() + ':' + (x - 1).toString()); + directed_moves['UPLEFT'] = [-1, -1]; + directed_moves['UPRIGHT'] = [-1, 0]; + directed_moves['DOWNLEFT'] = [1, -1]; + directed_moves['DOWNRIGHT'] = [1, 0]; } - }; + } + console.log(directed_moves); + let select_range = {}; + for (const direction in directed_moves) { + const move = directed_moves[direction]; + select_range[direction] = [y + move[0], x + move[1]]; + } this.selectables = []; - for (const t_id in game.things) { - const t = game.things[t_id]; - if (select_range.includes(t.position[0].toString() - + ':' + t.position[1].toString()) - && t.portable) { - this.selectables.push(t_id); + let directions = []; + for (const direction in select_range) { + for (const t_id in game.things) { + const t = game.things[t_id]; + const position = select_range[direction]; + if (t.portable + && t.position[0] == position[0] + && t.position[1] == position[1]) { + this.selectables.push(t_id); + directions.push(direction); + } } - }; + } if (this.selectables.length == 0) { this.log_msg('none'); terminal.blink_screen(); @@ -892,7 +908,8 @@ let tui = { } else { for (let [i, t_id] of this.selectables.entries()) { const t = game.things[t_id]; - this.log_msg(i + ': ' + explorer.get_thing_info(t)); + const direction = directions[i]; + this.log_msg(i + ' ' + direction + ': ' + explorer.get_thing_info(t)); } } } else if (this.mode.name == 'drop_thing') { diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index c26c380..65d5385 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -724,26 +724,41 @@ class TUI: self.log_msg('@ enter username') elif self.mode.name == 'take_thing': self.log_msg('Portable things in reach for pick-up:') - select_range = [self.game.player.position, - self.game.player.position + YX(0,-1), - self.game.player.position + YX(0, 1), - self.game.player.position + YX(-1, 0), - self.game.player.position + YX(1, 0)] - if type(self.game.map_geometry) == MapGeometryHex: + directed_moves = { + 'HERE': YX(0, 0), 'LEFT': YX(0, -1), 'RIGHT': YX(0, 1) + } + if type(self.game.map_geometry) == MapGeometrySquare: + directed_moves['UP'] = YX(-1, 0) + directed_moves['DOWN'] = YX(1, 0) + elif type(self.game.map_geometry) == MapGeometryHex: if self.game.player.position.y % 2: - select_range += [self.game.player.position + YX(-1, 1), - self.game.player.position + YX(1, 1)] + directed_moves['UPLEFT'] = YX(-1, 0) + directed_moves['UPRIGHT'] = YX(-1, 1) + directed_moves['DOWNLEFT'] = YX(1, 0) + directed_moves['DOWNRIGHT'] = YX(1, 1) else: - select_range += [self.game.player.position + YX(-1, -1), - self.game.player.position + YX(1, -1)] - self.selectables = [t.id_ for t in self.game.things - if t.portable and t.position in select_range] + directed_moves['UPLEFT'] = YX(-1, -1) + directed_moves['UPRIGHT'] = YX(-1, 0) + directed_moves['DOWNLEFT'] = YX(1, -1) + directed_moves['DOWNRIGHT'] = YX(1, 0) + select_range = {} + for direction in directed_moves: + move = directed_moves[direction] + select_range[direction] = self.game.player.position + move + self.selectables = [] + directions = [] + for direction in select_range: + for t in [t for t in self.game.things + if t.portable and t.position == select_range[direction]]: + self.selectables += [t.id_] + directions += [direction] if len(self.selectables) == 0: return fail('nothing to pick-up') else: for i in range(len(self.selectables)): t = self.game.get_thing(self.selectables[i]) - self.log_msg(str(i) + ': ' + self.get_thing_info(t)) + self.log_msg('%s %s: %s' % (i, directions[i], + self.get_thing_info(t))) elif self.mode.name == 'drop_thing': self.log_msg('Direction to drop thing to:') self.selectables =\