def get_description(global_last, glob_desc, style_desc): """Join together the general and style description for an item.""" if glob_desc and style_desc: if global_last: return tkMarkdown.join(style_desc, glob_desc) else: return tkMarkdown.join(glob_desc, style_desc) elif glob_desc: return glob_desc elif style_desc: return style_desc else: return tkMarkdown.MarkdownData() # No description
def override_from_folder(self, other: ItemVariant) -> None: """Perform the override from another item folder.""" self.authors.extend(other.authors) self.tags.extend(self.tags) self.vbsp_config = lazy_conf.concat(self.vbsp_config, other.vbsp_config) self.desc = tkMarkdown.join(self.desc, other.desc)
def add_over(self, override: 'ConfigGroup'): """Override a ConfigGroup to add additional widgets.""" # Make sure they don't double-up. conficts = self.widget_ids() & override.widget_ids() if conficts: raise ValueError('Duplicate IDs in "{}" override - {}', self.id, conficts) self.widgets.extend(override.widgets) self.multi_widgets.extend(override.multi_widgets) self.desc = tkMarkdown.join(self.desc, override.desc) # Don't display that as well. CONFIG_ORDER.remove(override)
def __add__(self, other: 'SelitemData') -> 'SelitemData': """Join together two sets of selitem data. This uses the over_data values if defined, using our_data if not. Authors and descriptions will be joined to each other. """ if not isinstance(other, SelitemData): return NotImplemented return SelitemData( self.name, self.short_name, self.auth + other.auth, other.icon or self.icon, other.large_icon or self.large_icon, tkMarkdown.join(self.desc, other.desc), other.group or self.group, other.sort_key or self.sort_key, )
async def modify(self, pak_id: str, props: Property, source: str) -> ItemVariant: """Apply a config to this item variant. This produces a copy with various modifications - switching out palette or instance values, changing the config, etc. """ vbsp_config: lazy_conf.LazyConf if 'config' in props: # Item.parse() has resolved this to the actual config. vbsp_config = get_config( props, 'items', pak_id, ) else: vbsp_config = self.vbsp_config if 'replace' in props: # Replace property values in the config via regex. vbsp_config = lazy_conf.replace( vbsp_config, [(re.compile(prop.real_name, re.IGNORECASE), prop.value) for prop in props.find_children('Replace')]) vbsp_config = lazy_conf.concat( vbsp_config, get_config( props, 'items', pak_id, prop_name='append', )) if 'description' in props: desc = desc_parse(props, source, pak_id) else: desc = self.desc.copy() if 'appenddesc' in props: desc = tkMarkdown.join( desc, desc_parse(props, source, pak_id, prop_name='appenddesc'), ) if 'authors' in props: authors = sep_values(props['authors', '']) else: authors = self.authors if 'tags' in props: tags = sep_values(props['tags', '']) else: tags = self.tags.copy() variant = ItemVariant( pak_id, self.editor, vbsp_config, self.editor_extra.copy(), authors=authors, tags=tags, desc=desc, icons=self.icons.copy(), ent_count=props['ent_count', self.ent_count], url=props['url', self.url], all_name=self.all_name, all_icon=self.all_icon, source=f'{source} from {self.source}', ) [variant.editor] = variant._modify_editoritems( props, [variant.editor], pak_id, source, is_extra=False, ) if 'extra' in props: variant.editor_extra = variant._modify_editoritems( props.find_key('extra'), variant.editor_extra, pak_id, source, is_extra=True) return variant
def modify(self, fsys: FileSystem, props: Property, source: str) -> 'ItemVariant': """Apply a config to this item variant. This produces a copy with various modifications - switching out palette or instance values, changing the config, etc. """ if 'config' in props: # Item.parse() has resolved this to the actual config. vbsp_config = get_config( props, fsys, 'items', pak_id=fsys.path, ) else: vbsp_config = self.vbsp_config.copy() if 'replace' in props: # Replace property values in the config via regex. replace_vals = [(re.compile(prop.real_name, re.IGNORECASE), prop.value) for prop in props.find_children('Replace')] for prop in vbsp_config.iter_tree(): for regex, sub in replace_vals: prop.name = regex.sub(sub, prop.real_name) prop.value = regex.sub(sub, prop.value) vbsp_config += list( get_config( props, fsys, 'items', prop_name='append', pak_id=fsys.path, )) if 'description' in props: desc = desc_parse(props, source) else: desc = self.desc.copy() if 'appenddesc' in props: desc = tkMarkdown.join( desc, desc_parse(props, source, prop_name='appenddesc'), ) if 'authors' in props: authors = sep_values(props['authors', '']) else: authors = self.authors if 'tags' in props: tags = sep_values(props['tags', '']) else: tags = self.tags.copy() variant = ItemVariant( self.editor, vbsp_config, self.editor_extra.copy(), authors=authors, tags=tags, desc=desc, icons=self.icons.copy(), ent_count=props['ent_count', self.ent_count], url=props['url', self.url], all_name=self.all_name, all_icon=self.all_icon, source='{} from {}'.format(source, self.source), ) [variant.editor] = variant._modify_editoritems( props, [variant.editor], source, is_extra=False, ) if 'extra' in props: variant.editor_extra = variant._modify_editoritems( props.find_key('extra'), variant.editor_extra, source, is_extra=True) return variant