home · contact · privacy
Restructure design->design pointers.
authorPlom Heller <plom@plomlompom.com>
Wed, 10 Jun 2026 20:52:56 +0000 (22:52 +0200)
committerPlom Heller <plom@plomlompom.com>
Wed, 10 Jun 2026 20:52:56 +0000 (22:52 +0200)
bricksplom.py

index 914285be7a65ad19e57af145d1bb62f3f17f624d..404ad5a5e28f12d52ab77cb0a732661bf281d8b5 100755 (executable)
@@ -225,6 +225,18 @@ class BrickColor(Textfiled, Lookupable):
                 + self.wavelength)
 
 
+class BrickDesignData:
+    'Whatever be available in BrickDesign.attrs.'
+
+    def __init__(
+            self,
+            n_studs=-1,
+            description=''
+            ) -> None:
+        self.description = description
+        self.n_studs = n_studs
+
+
 class BrickDesign(Textfiled, Lookupable):
     'Shape and texture configurations with descriptions and equalities.'
     _id_indent = 6
@@ -233,29 +245,21 @@ class BrickDesign(Textfiled, Lookupable):
     def __init__(
             self,
             id_: str,
-            n_studs=-1,
-            description='',
+            attrs: Optional[BrickDesignData] = None
             ) -> None:
         self.id_ = id_
-        self._description = description
-        self._n_studs = n_studs
+        self._attrs = attrs
         self.alternate_ids: set[str] = set()
 
     @property
-    def description(
-            self
-            ) -> str:
-        'Description text wherever found between self and .alternate_to.'
-        return (f'={self.alternate_to.id_}: {self.alternate_to.description}'
-                if self.alternate_to else self._description)
-
-    @property
-    def n_studs(
+    def attrs(
             self
-            ) -> int:
-        'Studs count wherever found between self and .alternate_to.'
-        return (self.alternate_to.n_studs
-                if self.alternate_to else self._n_studs)
+            ) -> BrickDesignData:
+        'Collect from either .alternate_to or ._attrs.'
+        if self.alternate_to:
+            return self.alternate_to.attrs
+        assert self._attrs
+        return self._attrs
 
     @property
     def all_ids(
@@ -272,7 +276,7 @@ class BrickDesign(Textfiled, Lookupable):
                 q_body
                 ) -> bool:
             assert q_body.isdigit()
-            return self.n_studs == int(q_body)
+            return self.attrs.n_studs == int(q_body)
         return super().matchers | {CHAR_Q_STUDS: q_studs}
 
     @property
@@ -283,7 +287,7 @@ class BrickDesign(Textfiled, Lookupable):
         return super().sorters | {
             TOK_SORT_BOX: self._by_box_sorter('design'),
             TOK_SORT_STUDS: lambda _, pre_sorted: tuple(
-                sorted(pre_sorted, key=lambda item: item.n_studs))
+                sorted(pre_sorted, key=lambda item: item.attrs.n_studs))
                 }
 
     @classmethod
@@ -312,7 +316,8 @@ class BrickDesign(Textfiled, Lookupable):
                     a_key, a_val_str = attr.split(CHAR_ATTR_EQ, maxsplit=1)
                     assert a_val_str.isdigit()
                     kwargs[a_key] = int(a_val_str)
-                collected[design_id] = cls(design_id, **kwargs)
+                collected[design_id] = cls(design_id,
+                                           BrickDesignData(**kwargs))
         for id_, alternate_ids in alts.items():
             collected[id_].alternate_ids = alternate_ids
             for alt_id in alternate_ids:
@@ -325,9 +330,9 @@ class BrickDesign(Textfiled, Lookupable):
         return (
             f'{self.id_indented()} '
             + (f'{CHAR_DESIGN_ALT}{self.alternate_to.id_}' if self.alternate_to
-               else (('' if self._n_studs < 0
-                      else f'n_studs{CHAR_ATTR_EQ}{self._n_studs}')
-                     + f'{SEP_DESIGN_DESC}{self._description}')))
+               else (('' if self.attrs.n_studs < 0
+                      else f'n_studs{CHAR_ATTR_EQ}{self.attrs.n_studs}')
+                     + f'{SEP_DESIGN_DESC}{self.attrs.description}')))
 
 
 class Brick(Textfiled, WithDb, Lookupable):
@@ -389,7 +394,7 @@ class Brick(Textfiled, WithDb, Lookupable):
         comment = f' # {self.comment}' if self.comment else ''
         return (f'{self.id_indented()} '
                 f'{BrickDesign.indent_id(self.design_id)} '
-                f'{design.description} ({color}){comment}')
+                f'{design.attrs.description} ({color}){comment}')
 
 
 class BrickSet(Textfiled, WithDb, Lookupable):
@@ -539,7 +544,7 @@ class BrickSet(Textfiled, WithDb, Lookupable):
             return (
                 f'{count:>2}× {Brick.indent_id(brick_id)}:'
                 f'{BrickDesign.indent_id(design_id)} {box_listing} {color} '
-                f'{self._db.designs[design_id].description}{tail_comment}')
+                + self._db.designs[design_id].attrs.description + tail_comment)
 
         return f'{self}{CHAR_NEWLINE}{self._format_paginated(format_line)}'
 
@@ -589,7 +594,8 @@ class Box(WithDb, Lookupable):
         lines = []
         for design, listings in self.designs_to_listings:
             lines += [
-                f'=== {" / ".join(design.all_ids)}: {design.description} ===']
+                f'=== {" / ".join(design.all_ids)}: '
+                f'{design.attrs.description} ===']
             for count, brick_id, comment in listings:
                 color = self._db.colors[self._db.bricks[brick_id].color_id]
                 lines += [f'{count:>2}× {Brick.indent_id(brick_id)} / {color} '