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
) -> 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(
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:
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):
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()