From: Plom Heller Date: Wed, 10 Jun 2026 20:52:56 +0000 (+0200) Subject: Restructure design->design pointers. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/%7B%7Bprefix%7D%7D?a=commitdiff_plain;h=90d370e85a1bc82f4da72e28fb5ed21b9d13e9bf;p=bricksplom Restructure design->design pointers. --- diff --git a/bricksplom.py b/bricksplom.py index 914285b..404ad5a 100755 --- a/bricksplom.py +++ b/bricksplom.py @@ -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} '