From b0fffeb66df179c95a5ba0f7cb42fe4303ea2dcf Mon Sep 17 00:00:00 2001 From: Axy Date: Mon, 30 Mar 2026 00:17:49 +0200 Subject: [PATCH] Entry and exit colours in config --- a_maze_ing.py | 1 - example.conf | 8 ++++++++ mazegen/config/config_parser.py | 20 ++++++++++++++++++++ mazegen/display/observer.py | 30 +++++++++++++++++++++++++----- mazegen/display/tty.py | 6 +++++- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/a_maze_ing.py b/a_maze_ing.py index a5ef646..995b899 100644 --- a/a_maze_ing.py +++ b/a_maze_ing.py @@ -1,5 +1,4 @@ from sys import stderr -import time from typing import Never from mazegen.config.parser_combinator import ParseError from mazegen.display.observer import MazeRegenerate, TTYTracker diff --git a/example.conf b/example.conf index 3a736ba..30b2df2 100644 --- a/example.conf +++ b/example.conf @@ -23,6 +23,14 @@ SEED=111 #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} " diff --git a/mazegen/config/config_parser.py b/mazegen/config/config_parser.py index ad8c5c6..5a75f85 100644 --- a/mazegen/config/config_parser.py +++ b/mazegen/config/config_parser.py @@ -554,6 +554,8 @@ class Config: 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 @@ -611,6 +613,24 @@ class Config: '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) ), diff --git a/mazegen/display/observer.py b/mazegen/display/observer.py index d8c0a1d..7ce3d01 100644 --- a/mazegen/display/observer.py +++ b/mazegen/display/observer.py @@ -43,6 +43,12 @@ class TTYTracker: 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()) @@ -79,14 +85,18 @@ class TTYTracker: 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: """ @@ -99,9 +109,14 @@ class TTYTracker: ): 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: """ @@ -120,11 +135,15 @@ class TTYTracker: 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 @@ -136,7 +155,8 @@ class TTYTracker: 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: diff --git a/mazegen/display/tty.py b/mazegen/display/tty.py index f956c6b..336add7 100644 --- a/mazegen/display/tty.py +++ b/mazegen/display/tty.py @@ -368,6 +368,8 @@ def extract_pairs( config.tilemap_empty, config.tilemap_full, config.tilemap_path, + config.tilemap_entry, + config.tilemap_exit, config.tilemap_background, ) for e in tilemaps @@ -461,6 +463,8 @@ class 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), @@ -549,7 +553,7 @@ class TTYBackend: 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" -- 2.53.0