diff --git a/hugvey/story.py b/hugvey/story.py index 0078ee9..711affb 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -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 diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index a8743b3..96deb8e 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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' },