Tiles can have multiple width according to the used texture pack for a better support of unicode

This commit is contained in:
Yohann D'ANELLO 2020-11-10 22:01:57 +01:00
parent 3f4c809db6
commit d5ef041f48
2 changed files with 14 additions and 9 deletions

View File

@ -12,12 +12,13 @@ class MapDisplay(Display):
def update_map(self, m: Map) -> None:
self.map = m
self.pad = self.newpad(m.height, m.width + 1)
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))
for e in self.map.entities:
self.pad.addstr(e.y, e.x, self.pack[e.name.upper()])
self.pad.addstr(e.y, self.pack.tile_width * e.x,
self.pack[e.name.upper()])
def display(self) -> None:
y, x = self.map.currenty, self.map.currentx
@ -27,10 +28,11 @@ class MapDisplay(Display):
deltay, deltax = self.height - deltay, self.width - deltax
smaxrow = self.map.height - (y + deltay) + self.height - 1
smaxrow = min(smaxrow, self.height - 1)
smaxcol = self.map.width - (x + deltax) + self.width - 1
smaxcol = self.pack.tile_width * self.map.width - \
(x + deltax) + self.width - 1
smaxcol = min(smaxcol, self.width - 1)
pminrow = max(0, min(self.map.height, pminrow))
pmincol = max(0, min(self.map.width, pmincol))
pmincol = max(0, min(self.pack.tile_width * self.map.width, pmincol))
self.pad.clear()
self.update_pad()
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)

View File

@ -2,6 +2,7 @@ class TexturePack:
_packs = dict()
name: str
tile_width: int
EMPTY: str
WALL: str
FLOOR: str
@ -25,6 +26,7 @@ class TexturePack:
TexturePack.ASCII_PACK = TexturePack(
name="ascii",
tile_width=1,
EMPTY=' ',
WALL='#',
FLOOR='.',
@ -34,9 +36,10 @@ TexturePack.ASCII_PACK = TexturePack(
TexturePack.SQUIRREL_PACK = TexturePack(
name="squirrel",
tile_width=2,
EMPTY=' ',
WALL='',
FLOOR='.',
WALL='',
FLOOR='..',
PLAYER='🐿️ ',
HEDGEHOG='🦔 ',
)