+ 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
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(
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
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
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:
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):
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):
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)}'
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} '