Tiles can have multiple width according to the used texture pack for a better support of unicode
This commit is contained in:
parent
3f4c809db6
commit
d5ef041f48
|
@ -12,12 +12,13 @@ class MapDisplay(Display):
|
||||||
|
|
||||||
def update_map(self, m: Map) -> None:
|
def update_map(self, m: Map) -> None:
|
||||||
self.map = m
|
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:
|
def update_pad(self) -> None:
|
||||||
self.pad.addstr(0, 0, self.map.draw_string(self.pack))
|
self.pad.addstr(0, 0, self.map.draw_string(self.pack))
|
||||||
for e in self.map.entities:
|
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:
|
def display(self) -> None:
|
||||||
y, x = self.map.currenty, self.map.currentx
|
y, x = self.map.currenty, self.map.currentx
|
||||||
|
@ -27,10 +28,11 @@ class MapDisplay(Display):
|
||||||
deltay, deltax = self.height - deltay, self.width - deltax
|
deltay, deltax = self.height - deltay, self.width - deltax
|
||||||
smaxrow = self.map.height - (y + deltay) + self.height - 1
|
smaxrow = self.map.height - (y + deltay) + self.height - 1
|
||||||
smaxrow = min(smaxrow, 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)
|
smaxcol = min(smaxcol, self.width - 1)
|
||||||
pminrow = max(0, min(self.map.height, pminrow))
|
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.pad.clear()
|
||||||
self.update_pad()
|
self.update_pad()
|
||||||
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|
||||||
|
|
|
@ -2,6 +2,7 @@ class TexturePack:
|
||||||
_packs = dict()
|
_packs = dict()
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
tile_width: int
|
||||||
EMPTY: str
|
EMPTY: str
|
||||||
WALL: str
|
WALL: str
|
||||||
FLOOR: str
|
FLOOR: str
|
||||||
|
@ -25,6 +26,7 @@ class TexturePack:
|
||||||
|
|
||||||
TexturePack.ASCII_PACK = TexturePack(
|
TexturePack.ASCII_PACK = TexturePack(
|
||||||
name="ascii",
|
name="ascii",
|
||||||
|
tile_width=1,
|
||||||
EMPTY=' ',
|
EMPTY=' ',
|
||||||
WALL='#',
|
WALL='#',
|
||||||
FLOOR='.',
|
FLOOR='.',
|
||||||
|
@ -34,9 +36,10 @@ TexturePack.ASCII_PACK = TexturePack(
|
||||||
|
|
||||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||||
name="squirrel",
|
name="squirrel",
|
||||||
|
tile_width=2,
|
||||||
EMPTY=' ',
|
EMPTY=' ',
|
||||||
WALL='█',
|
WALL='██',
|
||||||
FLOOR='.',
|
FLOOR='..',
|
||||||
PLAYER='🐿️',
|
PLAYER='🐿️ ',
|
||||||
HEDGEHOG='🦔',
|
HEDGEHOG='🦔 ',
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue