summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-06-24 20:31:12 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-06-24 20:31:12 +0100
commit557cef7e041a18a4c16c19d13870ada293c8eeac (patch)
tree6c5d654d85a1288fb5e5841fd20a142f32c13b9b
parentExtract release requests into play module (diff)
downloadtoy-557cef7e041a18a4c16c19d13870ada293c8eeac.zip
Tidy up some misc functions
-rw-r--r--scripts/toy.groovy30
-rw-r--r--scripts/toy/misc.groovy2
2 files changed, 14 insertions, 18 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy
index 93d231b..bfebfc4 100644
--- a/scripts/toy.groovy
+++ b/scripts/toy.groovy
@@ -129,6 +129,14 @@ return new Object() {
void setAway(String a) { save("toy.owner.away", a) }
int randRange(int min, int max) { min + getRandom(1 + max - min) }
int randRange(double min, double max) { randRange((int)min, (int)max) }
+ def setDefault = { prop, val ->
+ if (loadString(prop) == null) {
+ save(prop, val);
+ }
+ };
+ // This exists because calling .wait(t) in a metaClass method
+ // calls it on the metaClass, not on the original object
+ void pause(int t) { wait(t); }
// Events
static class Event {
@@ -290,38 +298,24 @@ return new Object() {
adjustPunish(5);
return false;
};
+
final activityList = [:];
final addActivity = { String name, func ->
activityList[name] = func;
}
- // Setup
- def setDefault = { prop, val ->
- if (loadString(prop) == null) {
- save(prop, val);
- }
- };
- def namedEvents = [
- permit: { name, arg, schedTime, rt -> givePermission(arg) }
- ];
- def showFaq = {
- useUrl("http://toy.randomdan.homeip.net/");
- };
+ final namedEvents = [:];
final addNamedEvent = { String name, func ->
namedEvents[name] = func;
}
- def requestables = [
- faq: [ lbl: "FAQ (webpage)", act: showFaq ],
- ];
+
+ final requestables = [:];
final addRequestable = { String name, String label, func, cond = null ->
requestables[name] = [lbl: label, act: func, cond: cond];
};
final removeRequestable = { String name ->
requestables.remove(name);
};
- // This exists because calling .wait(t) in a metaClass method
- // calls it on the metaClass, not on the original object
- void pause(int t) { wait(t); }
String main()
diff --git a/scripts/toy/misc.groovy b/scripts/toy/misc.groovy
index 92af633..bb88a7f 100644
--- a/scripts/toy/misc.groovy
+++ b/scripts/toy/misc.groovy
@@ -6,5 +6,7 @@
};
};
+ toy.addNamedEvent(toy.PERMIT, { name, arg, schedTime, rt -> toy.givePermission(arg) });
+ toy.addRequestable("faq", "FAQ (webpage)", { useUrl("http://toy.randomdan.homeip.net/"); });
toy.addActivity("playNothing", { toy.playNothing() });
}