From 3f6aeac609f6337713f6cca17e4f54960ecf4d7f Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 4 Nov 2020 06:02:25 +0100
Subject: [PATCH] Fix screen jumping around.

---
 new2/plomrogue/game.py    |  1 -
 new2/rogue_chat_curses.py | 12 +++++-------
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py
index 5e33bc4..1cb6e22 100755
--- a/new2/plomrogue/game.py
+++ b/new2/plomrogue/game.py
@@ -88,7 +88,6 @@ class Game(GameBase):
             if hasattr(thing, 'nickname'):
                 self.io.send('THING_NAME %s %s' % (thing.id_, quote(t.nickname)))
 
-
         self.io.send('TURN ' + str(self.turn))
         for t in self.things:
             send_thing(t)
diff --git a/new2/rogue_chat_curses.py b/new2/rogue_chat_curses.py
index e272fb2..ad6f4f9 100755
--- a/new2/rogue_chat_curses.py
+++ b/new2/rogue_chat_curses.py
@@ -10,8 +10,6 @@ from plomrogue.mapping import YX
 from plomrogue.things import ThingBase
 from plomrogue.misc import quote
 
-# TODO: fix screen refreshes on intermediary map results
-
 def cmd_TURN(game, n):
     game.turn = n
     game.things = []
@@ -240,6 +238,10 @@ class TUI:
             stdscr.addstr(1, self.window_width, 'MODE: ' + self.mode.name)
 
         def draw_map():
+            player = self.game.get_thing(self.game.player_id, False)
+            if not player:
+                # catches race conditions where game.things still empty
+                return
             map_lines_split = []
             for y in range(self.game.map_size.y):
                 start = self.game.map_size.x * y
@@ -256,13 +258,9 @@ class TUI:
                             int(self.game.map_size.x / 2))
             window_center = YX(int(self.size.y / 2),
                                int(self.window_width / 2))
-            center = map_center
+            center = player
             if self.mode.shows_info:
                 center = self.explorer
-            else:
-                player = self.game.get_thing(self.game.player_id, False)
-                if player:
-                    center = player.position
             offset = center - window_center
             term_y = max(0, -offset.y)
             term_x = max(0, -offset.x)
-- 
2.30.2