Condition variableEqual: check if 2 variables are the same
This commit is contained in:
parent
eb7449c4e8
commit
417b3d9361
2 changed files with 24 additions and 0 deletions
|
@ -324,6 +324,8 @@ class Condition(object):
|
|||
condition.method = condition._hasVariable
|
||||
if data['type'] == "diversion":
|
||||
condition.method = condition._hasDiverged
|
||||
if data['type'] == "variableEquals":
|
||||
condition.method = condition._variableEquals
|
||||
|
||||
if 'vars' in data:
|
||||
condition.vars = data['vars']
|
||||
|
@ -380,7 +382,24 @@ class Condition(object):
|
|||
self.vars['variable']
|
||||
)
|
||||
return r
|
||||
|
||||
def _variableEquals(self, story) -> bool:
|
||||
v1 = story.variableValues[self.vars['variable1']] if story.hasVariableSet(self.vars['variable1']) else None
|
||||
v2 = story.variableValues[self.vars['variable2']] if story.hasVariableSet(self.vars['variable2']) else None
|
||||
if v1:
|
||||
story.logger.debug(f"Variable {self.vars['variable1']}: {v1}")
|
||||
if v2:
|
||||
story.logger.debug(f"Variable {self.vars['variable2']}: {v2}")
|
||||
|
||||
if 'notEq' in self.vars and self.vars['notEq']:
|
||||
# inverse:
|
||||
r = (v1 != v2)
|
||||
else:
|
||||
r = (v1 == v2)
|
||||
|
||||
story.logger.info("'{}' {} '{}' ({})".format(v1, '==' if v1 == v2 else '!=', v2, r))
|
||||
return r
|
||||
|
||||
def _hasDiverged(self, story) -> bool:
|
||||
if not story.lastMsgFinishTime:
|
||||
return False
|
||||
|
|
|
@ -1355,6 +1355,11 @@ class Graph {
|
|||
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
||||
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },
|
||||
},
|
||||
'variableEquals': {
|
||||
'variable1': { 'value': '','placeholder': "Variable name (without $)" },
|
||||
'variable2': { 'value': '','placeholder': "Variable name (without $)" },
|
||||
'notEq': { "label": "Not equal", 'value': '', 'title': "Match if the variables are _not_ equal.", 'type':'checkbox' },
|
||||
},
|
||||
'diversion': {
|
||||
'diversionId': { 'tag': 'select', 'value': '','placeholder': "Variable name (without $)", 'options': this.diversions.map((d) => d['@id']) },
|
||||
'inverseMatch': { "label": "Match if not done", 'value': '', 'title': "Match if the diversion has _not_ been done.", 'type':'checkbox' },
|
||||
|
|
Loading…
Reference in a new issue