From 557cef7e041a18a4c16c19d13870ada293c8eeac Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 24 Jun 2019 20:31:12 +0100 Subject: Tidy up some misc functions --- scripts/toy.groovy | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'scripts/toy.groovy') 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() -- cgit v1.2.3