loop time beyond to a general loop time before/after condition
This commit is contained in:
parent
a4858b4b8c
commit
76ad34be99
2 changed files with 30 additions and 15 deletions
|
@ -344,8 +344,8 @@ class Condition(object):
|
||||||
condition.method = condition._hasPlayed
|
condition.method = condition._hasPlayed
|
||||||
if data['type'] == "variableEquals":
|
if data['type'] == "variableEquals":
|
||||||
condition.method = condition._variableEquals
|
condition.method = condition._variableEquals
|
||||||
if data['type'] == "loop_is_beyond_time":
|
if data['type'] == "loop_time":
|
||||||
condition.method = condition._hasTimerPassed
|
condition.method = condition._hasTimer
|
||||||
if data['type'] == "variable_storage":
|
if data['type'] == "variable_storage":
|
||||||
condition.method = condition._hasVariableStorage
|
condition.method = condition._hasVariableStorage
|
||||||
condition.hasRan = False
|
condition.hasRan = False
|
||||||
|
@ -409,25 +409,38 @@ class Condition(object):
|
||||||
)
|
)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def _hasTimerPassed(self, story) -> bool:
|
def _hasTimer(self, story) -> bool:
|
||||||
if not story.lastMsgFinishTime:
|
if not story.lastMsgFinishTime:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
loopTime = story.hugvey.command.timer.getElapsed() % 3600
|
loopTime = story.hugvey.command.timer.getElapsed() % 3600
|
||||||
givenTime = int(self.vars['time'])
|
ltTime = int(self.vars['less_than'])
|
||||||
|
gtTime = int(self.vars['more_than'])
|
||||||
|
|
||||||
|
if not ltTime and not gtTime:
|
||||||
|
# ignore invalid times
|
||||||
|
return
|
||||||
|
elif not gtTime and loopTime < ltTime:
|
||||||
|
r = True
|
||||||
|
elif not ltTime and loopTime > gtTime:
|
||||||
|
r = True
|
||||||
|
elif loopTime < ltTime and loopTime > gtTime:
|
||||||
|
r = True
|
||||||
|
else:
|
||||||
|
r = False
|
||||||
|
|
||||||
if 'inverseMatch' in self.vars and self.vars['inverseMatch']:
|
if 'inverseMatch' in self.vars and self.vars['inverseMatch']:
|
||||||
r = loopTime < givenTime
|
r = not r
|
||||||
requiredPos = 'before'
|
|
||||||
else:
|
|
||||||
r = loopTime > givenTime
|
|
||||||
requiredPos = 'beyond'
|
|
||||||
|
|
||||||
self.logInfo = "Is {} {} time {}".format(
|
|
||||||
|
|
||||||
|
self.logInfo = "Looptime is {} {} < {} < {}".format(
|
||||||
'' if r else 'not',
|
'' if r else 'not',
|
||||||
requiredPos,
|
f'{gtTime}' if gtTime else '-',
|
||||||
givenTime
|
loopTime,
|
||||||
|
f'{ltTime}' if ltTime else '-',
|
||||||
)
|
)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def _variableEquals(self, story) -> bool:
|
def _variableEquals(self, story) -> bool:
|
||||||
|
|
|
@ -1677,9 +1677,11 @@ class Graph {
|
||||||
'regex': { 'value': '','placeholder': "match any input" },
|
'regex': { 'value': '','placeholder': "match any input" },
|
||||||
'instantMatch': { 'value': '', 'title': "When matched, don't wait for reply to finish. Instantly take this direction.", 'type':'checkbox' },
|
'instantMatch': { 'value': '', 'title': "When matched, don't wait for reply to finish. Instantly take this direction.", 'type':'checkbox' },
|
||||||
},
|
},
|
||||||
'loop_is_beyond_time': {
|
'loop_time': {
|
||||||
'time': {'type':'number', 'value': 0, 'min':0, 'step': 1, 'label': "Time of the loop (seconds)"},
|
// can be used in two ways
|
||||||
'inverseMatch': { 'title': "Match if before given time (instead of after).", 'type':'checkbox' },
|
'less_than': {'type':'number', 'value': 0, 'min':0, 'step': 1, 'label': "Time in seconds, the loop should be before, 0 is ignored"},
|
||||||
|
'more_than': {'type':'number', 'value': 0, 'min':0, 'step': 1, 'label': "Time the loop should be after, 0 is ignored"},
|
||||||
|
'inverseMatch': { 'title': "Inverse the matching.", 'type':'checkbox' },
|
||||||
},
|
},
|
||||||
'variable': {
|
'variable': {
|
||||||
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
||||||
|
|
Loading…
Reference in a new issue