summaryrefslogtreecommitdiff
path: root/scripts/toy.groovy
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-07-09 16:45:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-07-09 16:45:56 +0100
commitfb288e4259c66de978917e529eac308c1ad68d63 (patch)
tree150251123d54d79b1c0c077a47765715c14a6135 /scripts/toy.groovy
parentDynamic build sessions from activity tags (diff)
downloadtoy-fb288e4259c66de978917e529eac308c1ad68d63.zip
Basic trigger point event system
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r--scripts/toy.groovy19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy
index 3d32f62..1fb02ae 100644
--- a/scripts/toy.groovy
+++ b/scripts/toy.groovy
@@ -274,10 +274,25 @@ return new Object() {
};
};
+ final triggerHandlers = [];
+ final addTriggerHandler = { String triggerName, func, defArg = null ->
+ triggerHandlers << [
+ triggerName: triggerName,
+ func: func,
+ defaultArg: defArg
+ ];
+ };
+ final executeTrigger = { String triggerName, arg = null ->
+ triggerHandlers
+ .findAll { th -> th.triggerName == triggerName }
+ .forEach { th -> th.func(arg ?: th.defaultArg) };
+ };
+
// Session
def sessionSummon = { imageSpec ->
final limit = 5;
final timeMax = 10;
+ executeTrigger("toySummoned");
for (def n = 1; n <= limit; n++) {
switch (n) {
@@ -300,12 +315,14 @@ return new Object() {
}
playBackgroundSound(n == limit ? "shortwhip.wav" : "bell.wav");
if (showButton("Yes, ${dommeTitle()}?", timeMax) < timeMax) {
+ executeTrigger("toySummonSuccess", n);
return true;
};
}
showLounge();
show(null);
adjustPunish(5);
+ executeTrigger("toySummonFail");
return false;
};
def setSessionAbort = { String r = null -> sessionAborted = r };
@@ -412,10 +429,12 @@ return new Object() {
return "toy";
}
addAvail(clickTime);
+ executeTrigger("toyLoungeTime", clickTime);
}
def eStart = getTime();
execEvents(true);
addAvail(getTime() - eStart);
+ executeTrigger("toyEventTime", getTime() - eStart);
}
}
}.main();