X-Git-Url: https://plomlompom.com/repos/?p=plomrogue2-experiments;a=blobdiff_plain;f=new%2Fexample_client.py;h=c9fb4b1f638cce13f4b638cf18829ba6b506a66c;hp=44b0993dbff05d4705946518dee944025192b318;hb=6c37a16df7e55754ca89a9de0aaf49c3c778155e;hpb=5ab9dc6129bb816b040a13cfdad833a0526b0f90 diff --git a/new/example_client.py b/new/example_client.py index 44b0993..c9fb4b1 100755 --- a/new/example_client.py +++ b/new/example_client.py @@ -3,7 +3,8 @@ import curses import socket import threading from plomrogue.parser import ArgError, Parser -from plomrogue.commands import cmd_MAP, cmd_THING_POS, cmd_PLAYER_ID +from plomrogue.commands import (cmd_MAP, cmd_THING_POS, cmd_PLAYER_ID, + cmd_THING_HEALTH) from plomrogue.game import Game, WorldBase from plomrogue.mapping import MapHex from plomrogue.io import PlomSocket @@ -90,11 +91,13 @@ def cmd_LAST_PLAYER_TASK_RESULT(game, msg): game.log(msg) cmd_LAST_PLAYER_TASK_RESULT.argtypes = 'string' + def cmd_TURN_FINISHED(game, n): """Do nothing. (This may be extended later.)""" pass cmd_TURN_FINISHED.argtypes = 'int:nonneg' + def cmd_TURN(game, n): """Set game.turn to n, empty game.things.""" game.world.turn = n @@ -102,24 +105,29 @@ def cmd_TURN(game, n): game.world.pickable_items = [] cmd_TURN.argtypes = 'int:nonneg' + def cmd_VISIBLE_MAP_LINE(game, y, terrain_line): game.world.map_.set_line(y, terrain_line) cmd_VISIBLE_MAP_LINE.argtypes = 'int:nonneg string' + def cmd_GAME_STATE_COMPLETE(game): game.tui.to_update['turn'] = True game.tui.to_update['map'] = True game.tui.to_update['inventory'] = True + def cmd_THING_TYPE(game, i, type_): t = game.world.get_thing(i) t.type_ = type_ cmd_THING_TYPE.argtypes = 'int:nonneg string' + def cmd_PLAYER_INVENTORY(game, ids): game.world.player_inventory = ids # TODO: test whether valid IDs cmd_PLAYER_INVENTORY.argtypes = 'seq:int:nonneg' + def cmd_PICKABLE_ITEMS(game, ids): game.world.pickable_items = ids game.tui.to_update['pickable_items'] = True @@ -142,6 +150,7 @@ class Game: 'MAP': cmd_MAP, 'PICKABLE_ITEMS': cmd_PICKABLE_ITEMS, 'THING_TYPE': cmd_THING_TYPE, + 'THING_HEALTH': cmd_THING_HEALTH, 'THING_POS': cmd_THING_POS} self.log_text = '' self.do_quit = False @@ -412,6 +421,8 @@ class MapWidget(Widget): chars_with_attrs += [(c, curses.color_pair(2))] elif c in {'x', 'X', '#'}: chars_with_attrs += [(c, curses.color_pair(3))] + elif c == '?': + chars_with_attrs += [(c, curses.color_pair(5))] else: chars_with_attrs += [c] return chars_with_attrs @@ -439,6 +450,14 @@ class TurnWidget(Widget): self.safe_write((str(self.tui.game.world.turn), curses.color_pair(2))) +class HealthWidget(Widget): + + def draw(self): + if hasattr(self.tui.game.world.player, 'health'): + self.safe_write((str(self.tui.game.world.player.health), + curses.color_pair(2))) + + class TextLineWidget(Widget): def __init__(self, text_line, *args, **kwargs): @@ -508,7 +527,6 @@ class TUI: if new_examine_pos: self.examiner_position = new_examine_pos self.to_update['map'] = True - self.to_update['descriptor'] = True def switch_to_pick_or_drop(target_widget): self.item_pointer = 0 @@ -584,6 +602,7 @@ class TUI: curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE) curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_YELLOW) + curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE) # Basic curses initialization work. setup_screen(stdscr) @@ -596,15 +615,17 @@ class TUI: edit_widget.children += [edit_line_widget] turn_widget = TextLineWidget('TURN:', self, (2, 0), (1, 20)) turn_widget.children += [TurnWidget(self, (2, 6), (1, 14), ['turn'])] - log_widget = LogWidget(self, (4, 0), (None, 20), ['log']) - descriptor_widget = DescriptorWidget(self, (4, 0), (None, 20), - ['descriptor'], False) + health_widget = TextLineWidget('HEALTH:', self, (3, 0), (1, 20)) + health_widget.children += [HealthWidget(self, (3, 8), (1, 12), ['turn'])] + log_widget = LogWidget(self, (5, 0), (None, 20), ['log']) + descriptor_widget = DescriptorWidget(self, (5, 0), (None, 20), + ['map'], False) map_widget = MapWidget(self, (0, 21), (None, None), ['map']) inventory_widget = InventoryWidget(self, (0, 21), (None, None), ['inventory'], False) pickable_items_widget = PickableItemsWidget(self, (0, 21), (None, None), ['pickable_items'], False) - top_widgets = [edit_widget, turn_widget, log_widget, + top_widgets = [edit_widget, turn_widget, health_widget, log_widget, descriptor_widget, map_widget, inventory_widget, pickable_items_widget] popup_widget = PopUpWidget(self, (0, 0), (1, 1), visible=False)