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
|
||||
if data['type'] == "variableEquals":
|
||||
condition.method = condition._variableEquals
|
||||
if data['type'] == "loop_is_beyond_time":
|
||||
condition.method = condition._hasTimerPassed
|
||||
if data['type'] == "loop_time":
|
||||
condition.method = condition._hasTimer
|
||||
if data['type'] == "variable_storage":
|
||||
condition.method = condition._hasVariableStorage
|
||||
condition.hasRan = False
|
||||
|
@ -409,25 +409,38 @@ class Condition(object):
|
|||
)
|
||||
return r
|
||||
|
||||
def _hasTimerPassed(self, story) -> bool:
|
||||
def _hasTimer(self, story) -> bool:
|
||||
if not story.lastMsgFinishTime:
|
||||
return False
|
||||
|
||||
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']:
|
||||
r = loopTime < givenTime
|
||||
requiredPos = 'before'
|
||||
else:
|
||||
r = loopTime > givenTime
|
||||
requiredPos = 'beyond'
|
||||
r = not r
|
||||
|
||||
self.logInfo = "Is {} {} time {}".format(
|
||||
|
||||
|
||||
self.logInfo = "Looptime is {} {} < {} < {}".format(
|
||||
'' if r else 'not',
|
||||
requiredPos,
|
||||
givenTime
|
||||
f'{gtTime}' if gtTime else '-',
|
||||
loopTime,
|
||||
f'{ltTime}' if ltTime else '-',
|
||||
)
|
||||
|
||||
return r
|
||||
|
||||
def _variableEquals(self, story) -> bool:
|
||||
|
|
|
@ -1677,9 +1677,11 @@ 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_is_beyond_time': {
|
||||
'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' },
|
||||
'loop_time': {
|
||||
// can be used in two ways
|
||||
'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': { 'value': '','placeholder': "Variable name (without $)" },
|
||||
|
|
Loading…
Reference in a new issue