from sys import stderr
-import time
from typing import Never
from mazegen.config.parser_combinator import ParseError
from mazegen.display.observer import MazeRegenerate, TTYTracker
#TILEMAP_PATH="{100,100,1000:100,100,1000} "
#TILEMAP_PATH="{100,100,1000:100,100,1000} "
#
+#TILEMAP_ENTRY="{100,100,1000:1000,1000,1000}######"
+#TILEMAP_ENTRY="{100,100,1000:1000,1000,1000}######"
+#TILEMAP_ENTRY="{100,100,1000:1000,1000,1000}######"
+#
+#TILEMAP_EXIT="{100,100,1000:0,0,0}######"
+#TILEMAP_EXIT="{100,100,1000:0,0,0}######"
+#TILEMAP_EXIT="{100,100,1000:0,0,0}######"
+#
#TILEMAP_EMPTY="{0,0,0:0,0,0} "
#TILEMAP_EMPTY="{0,0,0:0,0,0} "
#TILEMAP_EMPTY="{0,0,0:0,0,0} "
tilemap_full: list[list[ColoredLine]]
tilemap_empty: list[list[ColoredLine]]
tilemap_path: list[list[ColoredLine]]
+ tilemap_entry: list[list[ColoredLine]]
+ tilemap_exit: list[list[ColoredLine]]
tilemap_background_size: IVec2
tilemap_background: list[list[ColoredLine]]
tilemap_box_size: IVec2
'2"{RED:RED} "',
],
),
+ "TILEMAP_ENTRY": DefaultedStrField(
+ ColoredLineField,
+ [
+ '1"{WHITE:BLUE}####"',
+ '1"{WHITE:BLUE}####"',
+ '2"{WHITE:RED}####"',
+ '2"{WHITE:RED}####"',
+ ],
+ ),
+ "TILEMAP_EXIT": DefaultedStrField(
+ ColoredLineField,
+ [
+ '1"{BLACK:BLUE}####"',
+ '1"{BLACK:BLUE}####"',
+ '2"{BLACK:RED}####"',
+ '2"{BLACK:RED}####"',
+ ],
+ ),
"TILEMAP_BACKGROUND_SIZE": DefaultedField(
CoordField, IVec2(4, 2)
),
self.__path_style = TileCycle(
tilemaps.path, self.__backend.map_style_cb()
)
+ self.__entry_style = TileCycle(
+ tilemaps.entry, self.__backend.map_style_cb()
+ )
+ self.__exit_style = TileCycle(
+ tilemaps.exit, self.__backend.map_style_cb()
+ )
self.__backend.set_bg_init(lambda _: self.__empty_style.curr_style())
src = src.get_neighbour(card)
return False
- def redraw_path(self, style: int) -> None:
+ def redraw_path(self, entry: int, path: int, exit: int) -> None:
"""
Draws the current path with the given style
"""
if self.__path is not None:
- self.__backend.set_style(style)
+ self.__backend.set_style(path)
for tile in Cardinal.path_to_tiles(self.__path, self.__maze.entry):
self.__backend.draw_tile(tile)
+ self.__backend.set_style(entry)
+ self.__backend.draw_tile(self.__maze.entry.tile_coords())
+ self.__backend.set_style(exit)
+ self.__backend.draw_tile(self.__maze.exit.tile_coords())
def display_path(self) -> None:
"""
):
return None
path = pathfind_astar(self.__maze) if self.__draw_path else None
- self.redraw_path(self.__empty_style.curr_style())
+ empty = self.__empty_style.curr_style()
+ self.redraw_path(empty, empty, empty)
self.__path = path
- self.redraw_path(self.__path_style.curr_style())
+ self.redraw_path(
+ self.__entry_style.curr_style(),
+ self.__path_style.curr_style(),
+ self.__exit_style.curr_style(),
+ )
def poll_events(self) -> None:
"""
self.__filler_style.cycle()
self.__full_style.cycle()
self.__path_style.cycle()
+ self.__entry_style.cycle()
+ self.__exit_style.cycle()
self.__empty_style.cycle()
if event.sym == "v":
self.__filler_style.cycle(-1)
self.__full_style.cycle(-1)
self.__path_style.cycle(-1)
+ self.__entry_style.cycle(-1)
+ self.__exit_style.cycle(-1)
self.__empty_style.cycle(-1)
if event.sym == "p":
self.__draw_path = not self.__draw_path
finally:
self.__paused = False
if event.sym == "r":
- self.redraw_path(self.__empty_style.curr_style())
+ empty = self.__empty_style.curr_style()
+ self.redraw_path(empty, empty, empty)
self.__path = None
raise MazeRegenerate
else:
config.tilemap_empty,
config.tilemap_full,
config.tilemap_path,
+ config.tilemap_entry,
+ config.tilemap_exit,
config.tilemap_background,
)
for e in tilemaps
self.empty: list[int] = list(map(add_style, config.tilemap_empty))
self.full: list[int] = list(map(add_style, config.tilemap_full))
self.path: list[int] = list(map(add_style, config.tilemap_path))
+ self.entry: list[int] = list(map(add_style, config.tilemap_entry))
+ self.exit: list[int] = list(map(add_style, config.tilemap_exit))
self.filler: list[int] = list(
map(
lambda e: add_style(e, config.tilemap_background_size),
self.__uninit: bool = True
try:
self.__screen: curses.window = curses.initscr()
- except curses.error as e:
+ except curses.error:
raise BackendException(
"Failed to initiate screen, "
+ "check that your terminal is setup correctly"