home · contact · privacy
To designs tables add n_studs column, lookup.
authorPlom Heller <plom@plomlompom.com>
Sat, 30 May 2026 03:05:06 +0000 (05:05 +0200)
committerPlom Heller <plom@plomlompom.com>
Sat, 30 May 2026 03:05:06 +0000 (05:05 +0200)
bricksplom.py

index 5daadefb5179ab057ef15e7c87bb72dcdceef2da..d826f776b18df0b9406b827d217c0587bba83253 100755 (executable)
@@ -166,10 +166,12 @@ class Design(Textfiled, Lookupable):
     def __init__(
             self,
             id_: str,
-            description=''
+            n_studs=-1,
+            description='',
             ) -> None:
         self.id_ = id_
         self._description = description
+        self._n_studs = n_studs
         self.alternate_ids: set[str] = set()
 
     @property
@@ -178,8 +180,15 @@ class Design(Textfiled, Lookupable):
             ) -> 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)
+                if self.alternate_to else self._description)
+
+    @property
+    def n_studs(
+            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)
 
     @property
     def all_ids(
@@ -206,8 +215,10 @@ class Design(Textfiled, Lookupable):
                 alts[body] = alts.get(body, set())
                 alts[body].add(design_id)
                 collected[design_id] = cls(design_id)
-            else:  # == CHAR_DESIGN_DESC
-                collected[design_id] = cls(design_id, body)
+            else:
+                n_studs_str, desc = cls.tokify(body, 2)
+                n_studs = int(n_studs_str) if n_studs_str.isdigit() else -1
+                collected[design_id] = cls(design_id, n_studs, desc)
         for id_, alternate_ids in alts.items():
             collected[id_].alternate_ids = alternate_ids
             for alt_id in alternate_ids:
@@ -217,9 +228,11 @@ class Design(Textfiled, Lookupable):
     def raw(
             self
             ) -> str:
-        return f'{self.id_indented()} ' + (f'={self.alternate_to.id_}'
-                                           if self.alternate_to
-                                           else f'_{self._description}')
+        return (f'{self.id_indented()} '
+                + (f'={self.alternate_to.id_}' if self.alternate_to
+                   else ('_'
+                         + ('?' if self._n_studs < 0 else str(self._n_studs))
+                         + f' {self._description}')))
 
 
 class Piece(Textfiled, WithDb, Lookupable):
@@ -561,6 +574,14 @@ class BricksDb:
                      v in sorted(table.values(),
                                  key=lambda v: f'{v.id_indented()}')
                      if inquiry[1:].upper() in str(v.searchable()).upper()])
+        if table_name == 'designs' and inquiry.startswith('s'):
+            n_studs_str = inquiry[1:]
+            assert n_studs_str.isdigit()
+            return CHAR_NEWLINE.join(
+                    [(v.raw() if show_raw else str(v)) for
+                     v in sorted(table.values(),
+                                 key=lambda v: f'{v.id_indented()}')
+                     if v.n_studs == int(n_studs_str)])
         item = table[inquiry]
         return item.raw() if show_raw else item.show()