import socket
import threading
from plomrogue.parser import ArgError, Parser
-from plomrogue.commands import (cmd_MAP, cmd_THING_POS, cmd_PLAYER_ID,
- cmd_THING_HEALTH)
+from plomrogue.commands import cmd_PLAYER_ID, cmd_THING_HEALTH
from plomrogue.game import Game, WorldBase
from plomrogue.mapping import MapHex
from plomrogue.io import PlomSocket
return ''.join(map_view_chars).split('\n')
map_lines = map_cells_to_lines(map_cells)
+ if len(map_lines) % 2 == 0:
+ map_lines = map_lines[1:]
+ else:
+ for i in range(len(map_lines)):
+ map_lines[i] = '0' + map_lines[i]
self.y_cut(map_lines, center[0], size[0])
map_width = self.size[1] * 2 + 1
self.x_cut(map_lines, center[1] * 2, size[1], map_width)
"""
super().__init__(*args, **kwargs)
self.map_ = ClientMap()
+ self.offset = (0,0)
self.player_inventory = []
self.player_id = 0
self.pickable_items = []
- def new_map(self, yx):
- self.map_ = ClientMap(yx)
+ def new_map(self, offset, size):
+ self.map_ = ClientMap(size)
+ self.offset = offset
@property
def player(self):
cmd_TURN.argtypes = 'int:nonneg'
+def cmd_VISIBLE_MAP(game, offset, size):
+ game.world.new_map(offset, size)
+cmd_VISIBLE_MAP.argtypes = 'yx_tuple yx_tuple:pos'
+
+
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'
cmd_THING_TYPE.argtypes = 'int:nonneg string'
+def cmd_THING_POS(game, i, yx):
+ t = game.world.get_thing(i)
+ t.position = yx
+cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
+
+
def cmd_PLAYER_INVENTORY(game, ids):
game.world.player_inventory[:] = ids # TODO: test whether valid IDs
game.tui.to_update['inventory'] = True
'PLAYER_ID': cmd_PLAYER_ID,
'PLAYER_INVENTORY': cmd_PLAYER_INVENTORY,
'GAME_STATE_COMPLETE': cmd_GAME_STATE_COMPLETE,
- 'MAP': cmd_MAP,
+ 'VISIBLE_MAP': cmd_VISIBLE_MAP,
'PICKABLE_ITEMS': cmd_PICKABLE_ITEMS,
'THING_TYPE': cmd_THING_TYPE,
'THING_HEALTH': cmd_THING_HEALTH,
def log(self, msg):
"""Prefix msg plus newline to self.log_text."""
self.log_text = msg + '\n' + self.log_text
+ with open('log', 'w') as f:
+ f.write(self.log_text)
self.tui.to_update['log'] = True
def symbol_for_type(self, type_):
def annotated_terrain():
terrain_as_list = list(self.tui.game.world.map_.terrain[:])
for t in self.tui.game.world.things:
- pos_i = self.tui.game.world.map_.get_position_index(t.position)
+ if t.id_ in self.tui.game.world.player_inventory:
+ continue
+ pos_i = self.tui.game.world.map_.\
+ get_position_index(t.position)
symbol = self.tui.game.symbol_for_type(t.type_)
if terrain_as_list[pos_i][0] in {'f', '@', 'm'}:
old_symbol = terrain_as_list[pos_i][0]
center = self.tui.game.world.player.position
if self.tui.examiner_mode:
center = self.tui.examiner_position
- lines = self.tui.game.world.map_.format_to_view(annotated_terrain,
- center, self.size)
+ lines = self.tui.game.world.map_.\
+ format_to_view(annotated_terrain, center, self.size)
pad_or_cut_x(lines)
pad_y(lines)
self.safe_write(lines_to_colored_chars(lines))
self.parser = Parser(self.game)
self.to_update = {}
self.item_pointer = 0
- self.examiner_position = (0, 0)
+ self.examiner_position = ((0,0), (0, 0))
self.examiner_mode = False
self.popup_text = 'Hi bob'
self.to_send = []