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
|
condition.method = condition._hasVariable
|
||||||
if data['type'] == "diversion":
|
if data['type'] == "diversion":
|
||||||
condition.method = condition._hasDiverged
|
condition.method = condition._hasDiverged
|
||||||
|
if data['type'] == "variableEquals":
|
||||||
|
condition.method = condition._variableEquals
|
||||||
|
|
||||||
if 'vars' in data:
|
if 'vars' in data:
|
||||||
condition.vars = data['vars']
|
condition.vars = data['vars']
|
||||||
|
@ -381,6 +383,23 @@ class Condition(object):
|
||||||
)
|
)
|
||||||
return r
|
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:
|
def _hasDiverged(self, story) -> bool:
|
||||||
if not story.lastMsgFinishTime:
|
if not story.lastMsgFinishTime:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1355,6 +1355,11 @@ class Graph {
|
||||||
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
||||||
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },
|
'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': {
|
'diversion': {
|
||||||
'diversionId': { 'tag': 'select', 'value': '','placeholder': "Variable name (without $)", 'options': this.diversions.map((d) => d['@id']) },
|
'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' },
|
'inverseMatch': { "label": "Match if not done", 'value': '', 'title': "Match if the diversion has _not_ been done.", 'type':'checkbox' },
|
||||||
|
|
Loading…
Reference in a new issue