summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-03-24 14:48:11 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2019-03-24 14:48:11 +0000
commit30d294d9f305b16423da990c2686901a7f83d085 (patch)
tree48fb884ccac26f7af7f23da74967bfbaef3bb69d /scripts
parentAdd periodic reminder who's boss (diff)
downloadtoy-30d294d9f305b16423da990c2686901a7f83d085.zip
Better property helpers
Diffstat (limited to 'scripts')
-rw-r--r--scripts/toy.groovy15
1 files changed, 13 insertions, 2 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy
index 5828903..68d7114 100644
--- a/scripts/toy.groovy
+++ b/scripts/toy.groovy
@@ -153,12 +153,23 @@ def localTime = {
return wallclock;
};
def getDay = { (int)(getTime() / DAY) * DAY };
+def getProp = {i, f, d = null ->
+ final v = f("toy.$i".toString());
+ if (v == null) return d;
+ return v;
+};
+def loadB = { p -> loadBoolean(p)};
+def loadI = { p -> loadInteger(p)};
+def loadS = { p -> loadString(p)};
+def setProp = {i, v -> save("toy.$i".toString(), v)};
def has = {i -> loadBoolean("toys.$i") == true};
def likes = {i -> loadBoolean("fetish.$i") == true};
def can = {i -> loadBoolean("toy.permission.$i") == true};
def perm = can;
-def givePermission = {i -> save("toy.permission.$i", true)};
-def revokePermission = {i -> save("toy.permission.$i", false)};
+def getPermission = {i -> getProp("permission.$i", loadB)};
+def setPermission = {i, v -> setProp("permission.$i", v)};
+def givePermission = {i -> setPermission(i, true)};
+def revokePermission = {i -> setPermission(i, false)};
def is = {i -> loadBoolean("toy.state.$i") == true};
def set = {i, s -> save("toy.state.$i", s)};
def positioned = { i -> loadString("toy.position") == i };