2020-11-06 14:34:24 +00:00
|
|
|
#!/usr/bin/env python
|
2020-11-08 22:03:59 +00:00
|
|
|
from dungeonbattle.entities.player import Player
|
2020-11-06 14:34:24 +00:00
|
|
|
from dungeonbattle.interfaces import Map
|
2020-11-10 17:08:06 +00:00
|
|
|
from .display import Display
|
2020-11-06 16:43:30 +00:00
|
|
|
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
class MapDisplay(Display):
|
2020-11-10 09:49:11 +00:00
|
|
|
player: Player
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args)
|
|
|
|
|
2020-11-10 19:34:22 +00:00
|
|
|
def update_map(self, m: Map) -> None:
|
2020-11-10 09:49:11 +00:00
|
|
|
self.map = m
|
2020-11-10 21:01:57 +00:00
|
|
|
self.pad = self.newpad(m.height, self.pack.tile_width * m.width + 1)
|
2020-11-06 14:34:24 +00:00
|
|
|
|
2020-11-06 20:15:09 +00:00
|
|
|
def update_pad(self) -> None:
|
2020-11-10 21:30:55 +00:00
|
|
|
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))
|
2020-11-06 14:34:24 +00:00
|
|
|
for e in self.map.entities:
|
2020-11-10 21:01:57 +00:00
|
|
|
self.pad.addstr(e.y, self.pack.tile_width * e.x,
|
2020-11-10 21:30:55 +00:00
|
|
|
self.pack[e.name.upper()], self.color_pair(2))
|
2020-11-06 14:34:24 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
def display(self) -> None:
|
2020-11-11 14:10:46 +00:00
|
|
|
y, x = self.map.currenty, self.pack.tile_width * self.map.currentx
|
2020-11-06 20:15:09 +00:00
|
|
|
deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1
|
|
|
|
pminrow, pmincol = y - deltay, x - deltax
|
2020-11-06 14:34:24 +00:00
|
|
|
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
|
|
|
|
deltay, deltax = self.height - deltay, self.width - deltax
|
2020-11-06 20:15:09 +00:00
|
|
|
smaxrow = self.map.height - (y + deltay) + self.height - 1
|
|
|
|
smaxrow = min(smaxrow, self.height - 1)
|
2020-11-10 21:01:57 +00:00
|
|
|
smaxcol = self.pack.tile_width * self.map.width - \
|
|
|
|
(x + deltax) + self.width - 1
|
2020-11-06 20:15:09 +00:00
|
|
|
smaxcol = min(smaxcol, self.width - 1)
|
|
|
|
pminrow = max(0, min(self.map.height, pminrow))
|
2020-11-10 21:01:57 +00:00
|
|
|
pmincol = max(0, min(self.pack.tile_width * self.map.width, pmincol))
|
2020-11-06 14:34:24 +00:00
|
|
|
self.pad.clear()
|
|
|
|
self.update_pad()
|
2020-11-10 19:34:22 +00:00
|
|
|
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|