From b093a6ee763d45a6e4585cdb68864680186acf97 Mon Sep 17 00:00:00 2001 From: TeamSpen210 Date: Mon, 29 Jun 2015 10:46:13 +1000 Subject: [PATCH] Add ability to make unstyled stylevars These will then be applicable for all styles - used for things applying to logic items or similar. --- src/packageLoader.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/packageLoader.py b/src/packageLoader.py index 575b6ca81..43af60fb9 100644 --- a/src/packageLoader.py +++ b/src/packageLoader.py @@ -793,24 +793,41 @@ def __repr__(self): class StyleVar: - def __init__(self, var_id, name, styles, default=False): + def __init__(self, var_id, name, styles, unstyled=False, default=False): self.id = var_id self.name = name - self.styles = styles self.default = default + if unstyled: + self.styles = None + else: + self.styles = styles @classmethod def parse(cls, data): name = data.info['name'] + unstyled = utils.conv_bool(data.info['unstyled', '0']) + default = utils.conv_bool(data.info['enabled', '0']) styles = [ prop.value for prop in data.info.find_all('Style') ] - default = utils.conv_bool(data.info['enabled', '0']) - return cls(data.id, name, styles, default) + return cls( + data.id, + name, + styles, + unstyled=unstyled, + default=default, + ) def add_over(self, override): - self.styles.extend(override.styles) + """Override a stylevar to add more compatible styles.""" + # Setting it to be unstyled overrides any other values! + if self.styles is None: + return + elif override.styles is None: + self.styles = None + else: + self.styles.extend(override.styles) def __repr__(self): return '' @@ -819,6 +836,9 @@ def applies_to_style(self, style): """Check to see if this will apply for the given style. """ + if self.styles is None: + return True # Unstyled stylevar + if style.id in self.styles: return True