58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import curses
|
|
from typing import Any, Union
|
|
|
|
from dungeonbattle.tests.screen import FakePad
|
|
from dungeonbattle.display.mapdisplay import MapDisplay
|
|
from dungeonbattle.display.statsdisplay import StatsDisplay
|
|
from dungeonbattle.display.menudisplay import MenuDisplay
|
|
from dungeonbattle.interfaces import Map
|
|
from .entities.player import Player
|
|
|
|
class Display:
|
|
map: Map
|
|
player: Player
|
|
|
|
def __init__(self, screen: Any, texture: Any):
|
|
self.screen = screen
|
|
self.texture = texture
|
|
self.mapdisplay = MapDisplay(self.texture, curses.LINES * 4//5, curses.COLS)
|
|
self.statsdisplay = StatsDisplay(curses.LINES//5, curses.COLS, curses.LINES * 4//5, 0)
|
|
|
|
def refresh(self, m : Map, p : Player) -> None:
|
|
self.map = m
|
|
self.player = p
|
|
self.mapdisplay.refresh(self.map, self.player)
|
|
self.statsdisplay.refresh(self.player)
|
|
# self.menudisplay.refresh(self.position)
|
|
|
|
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
|
return curses.newpad(height, width) if self.screen else FakePad()
|
|
|
|
def ensure_resized(self, *pads) -> bool:
|
|
"""
|
|
If the window got resized, ensure that the pads are also resized.
|
|
"""
|
|
y, x = self.screen.getmaxyx() if self.screen else (0, 0)
|
|
for pad in pads:
|
|
pad.resize(y, x)
|
|
if self.screen and curses.is_term_resized(self.rows, self.cols):
|
|
curses.resizeterm(y, x)
|
|
return True
|
|
return False
|
|
|
|
@property
|
|
def rows(self) -> int:
|
|
return curses.LINES if self.screen else 42
|
|
|
|
@property
|
|
def height(self) -> int:
|
|
return self.rows
|
|
|
|
@property
|
|
def cols(self) -> int:
|
|
return curses.COLS if self.screen else 42
|
|
|
|
@property
|
|
def width(self) -> int:
|
|
return self.cols
|