From b3d789e3e79ac68f8c70b21fe84cc8f36c10cc83 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 6 Nov 2020 20:18:27 +0100 Subject: [PATCH] Fix texture packs --- dungeonbattle/display/texturepack.py | 3 +++ dungeonbattle/interfaces.py | 9 +++++++- example_map.txt | 34 ++++++++++++++-------------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/dungeonbattle/display/texturepack.py b/dungeonbattle/display/texturepack.py index 0ed6323..fa8cd2d 100644 --- a/dungeonbattle/display/texturepack.py +++ b/dungeonbattle/display/texturepack.py @@ -7,6 +7,9 @@ class TexturePack: FLOOR: str PLAYER: str + ASCII_PACK: "TexturePack" + SQUIRREL_PACK: "TexturePack" + def __init__(self, name: str, **kwargs): self.name = name self.__dict__.update(**kwargs) diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 90b7e9c..2459149 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -46,7 +46,7 @@ class Map: lines = [line for line in lines if line] height = len(lines) width = len(lines[0]) - tiles = [[Tile(c) + tiles = [[Tile.from_ascii_char(c) for x, c in enumerate(line)] for y, line in enumerate(lines)] return Map(width, height, tiles) @@ -65,6 +65,13 @@ class Tile(Enum): WALL = auto() FLOOR = auto() + @classmethod + def from_ascii_char(cls, ch: str) -> "Tile": + for tile in Tile: + if tile.char(TexturePack.ASCII_PACK) == ch: + return tile + raise ValueError(ch) + def char(self, pack: TexturePack) -> str: return getattr(pack, self.name) diff --git a/example_map.txt b/example_map.txt index bc0c464..4111fae 100644 --- a/example_map.txt +++ b/example_map.txt @@ -1,17 +1,17 @@ - ███████ █████████████ - █.....█ █...........█ - █.....█ █████...........█ - █.....█ █...............█ - █.█████ █.███...........█ - █.█ █.█ █...........█ - █.█ █.█ █████████████ - █.█ █.█ - █.████ █.█ - █....█ █.█ - ████.███████████████████.█ - █.....................█ █████████████████ - █.....................█ █...............█ - █.....................███████...............█ - █...........................................█ - █.....................███████...............█ - ███████████████████████ █████████████████ + ####### ############# + #.....# #...........# + #.....# #####...........# + #.....# #...............# + #.##### #.###...........# + #.# #.# #...........# + #.# #.# ############# + #.# #.# + #.#### #.# + #....# #.# + ####.###################.# + #.....................# ################# + #.....................# #...............# + #.....................#######...............# + #...........................................# + #.....................#######...............# + ####################### #################