diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index 64314e9..1a2e0ca 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -19,6 +19,13 @@ class Display: def newpad(self, height: int, width: int) -> Union[FakePad, Any]: return curses.newpad(height, width) if self.screen else FakePad() + def init_pair(self, number: int, foreground: int, background: int) -> None: + return curses.init_pair(number, foreground, background) \ + if self.screen else None + + def color_pair(self, number: int) -> int: + return curses.color_pair(number) if self.screen else 0 + def resize(self, y: int, x: int, height: int, width: int) -> None: self.x = x self.y = y diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index 85e8c37..8ab7be7 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -15,10 +15,13 @@ class MapDisplay(Display): self.pad = self.newpad(m.height, self.pack.tile_width * m.width + 1) def update_pad(self) -> None: - self.pad.addstr(0, 0, self.map.draw_string(self.pack)) + self.init_pair(1, self.pack.tile_fg_color, self.pack.tile_bg_color) + self.init_pair(2, self.pack.entity_fg_color, self.pack.entity_bg_color) + self.pad.addstr(0, 0, self.map.draw_string(self.pack), + self.color_pair(1)) for e in self.map.entities: self.pad.addstr(e.y, self.pack.tile_width * e.x, - self.pack[e.name.upper()]) + self.pack[e.name.upper()], self.color_pair(2)) def display(self) -> None: y, x = self.map.currenty, self.map.currentx diff --git a/dungeonbattle/display/texturepack.py b/dungeonbattle/display/texturepack.py index adb1d49..7d9113f 100644 --- a/dungeonbattle/display/texturepack.py +++ b/dungeonbattle/display/texturepack.py @@ -1,3 +1,4 @@ +import curses from typing import Any @@ -6,6 +7,10 @@ class TexturePack: name: str tile_width: int + tile_fg_color: int + tile_bg_color: int + entity_fg_color: int + entity_bg_color: int EMPTY: str WALL: str FLOOR: str @@ -19,7 +24,7 @@ class TexturePack: self.__dict__.update(**kwargs) TexturePack._packs[name] = self - def __getitem__(self, item) -> Any: + def __getitem__(self, item: str) -> Any: return self.__dict__[item] @classmethod @@ -30,6 +35,10 @@ class TexturePack: TexturePack.ASCII_PACK = TexturePack( name="ascii", tile_width=1, + tile_fg_color=curses.COLOR_WHITE, + tile_bg_color=curses.COLOR_BLACK, + entity_fg_color=curses.COLOR_WHITE, + entity_bg_color=curses.COLOR_BLACK, EMPTY=' ', WALL='#', FLOOR='.', @@ -40,9 +49,13 @@ TexturePack.ASCII_PACK = TexturePack( TexturePack.SQUIRREL_PACK = TexturePack( name="squirrel", tile_width=2, + tile_fg_color=curses.COLOR_WHITE, + tile_bg_color=curses.COLOR_BLACK, + entity_fg_color=curses.COLOR_WHITE, + entity_bg_color=curses.COLOR_WHITE, EMPTY=' ', - WALL='██', - FLOOR='..', - PLAYER='🐿️', + WALL='🟫', + FLOOR='██', + PLAYER='🐿 ️', HEDGEHOG='🦔', ) diff --git a/dungeonbattle/term_manager.py b/dungeonbattle/term_manager.py index ab7f4dd..a425272 100644 --- a/dungeonbattle/term_manager.py +++ b/dungeonbattle/term_manager.py @@ -13,6 +13,8 @@ class TermManager: # pragma: no cover curses.cbreak() # make cursor invisible curses.curs_set(False) + # Enable colors + curses.start_color() def __enter__(self): return self diff --git a/dungeonbattle/tests/screen.py b/dungeonbattle/tests/screen.py index b9ec851..6eb2cd0 100644 --- a/dungeonbattle/tests/screen.py +++ b/dungeonbattle/tests/screen.py @@ -3,7 +3,7 @@ class FakePad: In order to run tests, we simulate a fake curses pad that accepts functions but does nothing with them. """ - def addstr(self, y: int, x: int, message: str) -> None: + def addstr(self, y: int, x: int, message: str, color: int = 0) -> None: pass def refresh(self, pminrow: int, pmincol: int, sminrow: int,