Added logs to the layout, clear logs on new game (tests still aren't fixed)

This commit is contained in:
Nicolas Margulies 2020-11-19 12:55:06 +01:00
parent 6e71146aa2
commit 589f825765
4 changed files with 13 additions and 5 deletions

View File

@ -33,7 +33,7 @@ class Display:
self.width = width
self.height = height
if hasattr(self, "pad") and resize_pad:
self.pad.resize(self.height - 1, self.width - 1)
self.pad.resize(self.height, self.width)
def refresh(self, *args, resize_pad: bool = True) -> None:
if len(args) == 4:

View File

@ -47,7 +47,9 @@ class DisplayManager:
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, self.cols,
resize_pad=False)
self.statsdisplay.refresh(self.rows * 4 // 5, 0,
self.rows // 5, self.cols)
self.rows // 10, self.cols)
self.logsdisplay.refresh(self.rows * 9 // 10, 0,
self.rows // 10, self.cols)
if self.game.state == GameMode.MAINMENU:
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
if self.game.state == GameMode.SETTINGS:

View File

@ -12,6 +12,11 @@ class LogsDisplay(Display):
self.logs = logs
def display(self) -> None:
messages = self.logs.messages[-self.height:].reverse()
for i, y in enumerate(range(self.y + self.height - 1, self.y - 1, - 1)):
self.pad.addstr(y, self.x, messages[i][:self.width])
print(type(self.logs.messages), flush=True)
messages = self.logs.messages[-self.height:]
messages = messages[::-1]
self.pad.clear()
for i in range(min(self.height, len(messages))):
self.pad.addstr(self.height - i - 1, self.x, messages[i][:self.width])
self.pad.refresh(0, 0, self.y, self.x, self.y + self.height,
self.x + self.width)

View File

@ -42,6 +42,7 @@ class Game:
# TODO generate a new map procedurally
self.map = Map.load(ResourceManager.get_asset_path("example_map_2.txt"))
self.map.logs = self.logs
self.logs.clear()
self.player = Player()
self.map.add_entity(self.player)
self.player.move(self.map.start_y, self.map.start_x)