Change name of timer condition to loop_timer

This commit is contained in:
Ruben van de Ven 2019-07-10 16:14:46 +02:00
parent 41d0ee8527
commit 95c004eba6
2 changed files with 27 additions and 0 deletions

View File

@ -333,6 +333,8 @@ class Condition(object):
condition.method = condition._hasPlayed
if data['type'] == "variableEquals":
condition.method = condition._variableEquals
if data['type'] == "loop_timer":
condition.method = condition._hasTimerPassed
if data['type'] == "variable_storage":
condition.method = condition._hasVariableStorage
condition.hasRan = False
@ -393,6 +395,27 @@ class Condition(object):
)
return r
def _hasTimerPassed(self, story) -> bool:
if not story.lastMsgFinishTime:
return False
loopTime = story.hugvey.command.timer.getElapsed()
givenTime = int(self.vars['time'])
if 'inverseMatch' in self.vars and self.vars['inverseMatch']:
r = loopTime < givenTime
requiredPos = 'before'
else:
r = loopTime > givenTime
requiredPos = 'beyond'
self.logInfo = "Is {} {} time {}".format(
'' if r else 'not',
requiredPos,
givenTime
)
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

View File

@ -1627,6 +1627,10 @@ class Graph {
'regex': { 'value': '','placeholder': "match any input" },
'instantMatch': { 'value': '', 'title': "When matched, don't wait for reply to finish. Instantly take this direction.", 'type':'checkbox' },
},
'loop_timer': {
'time': {'type':'number', 'value': 0, 'min':0, 'step': 1, 'label': "Time of the loop (seconds)"},
'inverseMatch': { 'title': "Match if before given time (instead of after).", 'type':'checkbox' },
},
'variable': {
'variable': { 'value': '','placeholder': "Variable name (without $)" },
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },