Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Debilski committed Mar 12, 2018
1 parent 6dfdd17 commit 75f1438
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pelita/ui/qt/qt_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, address, controller_address=None,
if export:
png_export_path = Path(export)
if not png_export_path.is_dir():
raise RuntimeError(f"Not a directory: {png_export_path}")
raise RuntimeError("Not a directory: {png_export_path}")
self.png_export_path = png_export_path
else:
self.png_export_path = None
Expand All @@ -92,7 +92,7 @@ def __init__(self, address, controller_address=None,
self.exit_socket = self.context.socket(zmq.PAIR)
exit_address = self.exit_socket.bind_to_random_port('tcp://127.0.0.1')

self.zmq_listener = ZMQListener(address, f'tcp://127.0.0.1:{exit_address}')
self.zmq_listener = ZMQListener(address, 'tcp://127.0.0.1:{}'.format(exit_address))
self.zmq_listener.message.connect(self.signal_received)

QtCore.QTimer.singleShot(0, self.zmq_listener.start)
Expand Down Expand Up @@ -167,13 +167,28 @@ def paint(pos):
painter.drawArc(QRectF(pos[0] + 0.2, pos[1] + 0.2, 0.6, 0.6), 0, 5760)

def paint_harvester(pos, color):
painter.save()


direction = self.directions.get(bot.index)
if not direction:
direction = (0, 1)

rotation = math.degrees(cmath.phase(direction[0] - direction[1]*1j))

x, y = pos
painter.translate(x, y)
# painter.scale(0.5, 0.5)
# if bot.index == 0:
# painter.translate(0, 0)
# elif bot.index == 1:
# painter.translate(1, 0)
# elif bot.index == 2:
# painter.translate(0, 1)
# elif bot.index == 3:
# painter.translate(1, 1)

x = y = 0
bounding_rect = QRectF(x, y, 1, 1)
# bot body
path = QtGui.QPainterPath(QPointF(x + 0.5, y + 0.5))
Expand All @@ -194,6 +209,8 @@ def paint_harvester(pos, color):
elif direction == (-1, 0): # left
painter.drawEllipse(QRectF(x + 0.6 - eye_size, y + 0.3 - eye_size, eye_size * 2, eye_size * 2))

painter.restore()

def paint_destroyer(pos, color):
x, y = pos
bounding_rect = QRectF(x, y, 1, 1)
Expand Down Expand Up @@ -281,7 +298,7 @@ def observe(self, observed):
try:
round_index = game_state['round_index']
bot_id = game_state['bot_id']
file_name = f'pelita-{round_index}-{bot_id}.png'
file_name = 'pelita-{}-{}.png'.format(round_index, bot_id)

self.grab().save(str(self.png_export_path / file_name))
except TypeError as e:
Expand Down

0 comments on commit 75f1438

Please sign in to comment.