squirrel-battle/dungeonbattle/display/display.py

45 lines
1.1 KiB
Python

import curses
from typing import Any, Optional, Union
from dungeonbattle.display.texturepack import TexturePack
from dungeonbattle.tests.screen import FakePad
class Display:
x: int
y: int
width: int
height: int
pad: Any
def __init__(self, screen: Any, pack: Optional[TexturePack] = None):
self.screen = screen
self.pack = pack or TexturePack.get_pack("ascii")
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
return curses.newpad(height, width) if self.screen else FakePad()
def resize(self, y: int, x: int, height: int, width: int) -> None:
self.x = x
self.y = y
self.width = width
self.height = height
if self.pad:
self.pad.resize(height - 1, width - 1)
def refresh(self, *args) -> None:
if len(args) == 4:
self.resize(*args)
self.display()
def display(self) -> None:
raise NotImplementedError
@property
def rows(self) -> int:
return curses.LINES if self.screen else 42
@property
def cols(self) -> int:
return curses.COLS if self.screen else 42