]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
Entry and exit colours in config
authorAxy <gilliardmarthey.axel@gmail.com>
Sun, 29 Mar 2026 22:17:49 +0000 (00:17 +0200)
committerAxy <gilliardmarthey.axel@gmail.com>
Sun, 29 Mar 2026 22:17:49 +0000 (00:17 +0200)
a_maze_ing.py
example.conf
mazegen/config/config_parser.py
mazegen/display/observer.py
mazegen/display/tty.py

index a5ef646ee035cb56d67f853f46a46b3fad261aee..995b89953852283175a9f8336372647566aa063f 100644 (file)
@@ -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
index 3a736baf7e15d1dd2817008ddce2e6f9c46d8b2f..30b2df2d64b612cea908a260e39a849f38d73156 100644 (file)
@@ -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}      "
index ad8c5c64b0c39f5d3bcf57a4af95946565ac4584..5a75f85e72bb5c43605c5efce90132480b6c2e0a 100644 (file)
@@ -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)
                     ),
index d8c0a1d5e40596bdaf1ed6f29f0f6ca61e80e0a4..7ce3d011500f52260fbe1fc38080552132e04438 100644 (file)
@@ -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:
index f956c6b8cb51d8e2e0439e13b758af7c51bc106a..336add762eee22090343b57e50c0467fbf79bdb8 100644 (file)
@@ -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"