diff options
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r-- | scripts/toy.groovy | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 246dd63..3bef835 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -152,59 +152,70 @@ return new Object() { save("toy.owner.outfitTime", getTime()); DOMME = loadDomme(OWNER, outfit.set); }; + // Utils - def localTimeOffset = { + int localTimeOffset() { return java.time.ZoneId.systemDefault() .getRules() .getOffset(java.time.Instant.now()) .getTotalSeconds(); - }; - def localTimeOf = { s -> - java.time.LocalDateTime.ofInstant( - java.time.Instant.ofEpochSecond(s), java.time.ZoneId.systemDefault()) } - def localTime = { + + java.time.LocalDateTime localTimeOf(int s) { + return java.time.LocalDateTime.ofInstant( + java.time.Instant.ofEpochSecond(s), java.time.ZoneId.systemDefault()); + } + + float localTime() { // A float between 4.0 (4am) and 28.0 (4am) def wallclock = ((getTime() + localTimeOffset()) % DAY) / HOUR; if (wallclock < 4) { wallclock += 24; } return wallclock; - }; - def getDay = { (int)(getTime() / DAY) * DAY }; - def getProp = {i, f, d = null -> - final v = f("toy.$i".toString()); + } + + int getDay() { + return (getTime() / DAY) * DAY; + } + + public <T> T getProp(String i, java.util.function.Function<String, T> f, T d = null) { + final T v = f("toy.$i".toString()); if (v == null) return d; return v; - }; - def getDommeProp = { i, d = null -> + } + + Object getDommeProp = { String i, Object d = null -> if (DOMME == null) return d; final v = DOMME[i]; if (v == null) return d; return v; - }; - def dommeTitle = { getDommeProp("title", "Mistress") }; - def dommeName = { getDommeProp("name", "") }; - 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 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 }; - def getPunish = { loadInteger("toy.punishment") ?: 0; }; - def adjustPunish = { p -> save("toy.punishment", Math.max(getPunish() + (int)p, 0)); }; - def getAway = { loadString("toy.owner.away") }; - def setAway = { a -> save("toy.owner.away", a) }; - def randRange = { min, max -> (int)min + getRandom((int)(1 + max - min)) } + } + + String dommeTitle() { getDommeProp("title", "Mistress") } + String dommeName() { getDommeProp("name", "") } + boolean loadB(String p) { loadBoolean(p) } + int loadI(String p) { loadInteger(p) } + String loadS(String p ) { loadString(p) } + void setProp(String i, Object v) { save("toy.$i".toString(), v) } + boolean has(String i) { loadBoolean("toys.$i") == true } + boolean likes(String i) { loadBoolean("fetish.$i") == true } + boolean can(String i) { loadBoolean("toy.permission.$i") == true } + boolean perm(String i) { can(it) } + boolean getPermission(String i) { getProp("permission.$i", loadB) } + void setPermission(String i, boolean v) { setProp("permission.$i", v) } + void givePermission(String i) { setPermission(i, true) } + void revokePermission(String i) { setPermission(i, false) } + boolean is(String i) { loadBoolean("toy.state.$i") == true } + void set(String i, boolean s) { save("toy.state.$i", s) } + boolean positioned(String i) { ("toy.position") == i } + int getPunish() { loadInteger("toy.punishment") ?: 0 } + void adjustPunish(int p) { save("toy.punishment", Math.max(getPunish() + p, 0)) } + void adjustPunish(double p) { adjustPunish((int)p) } + String getAway() { loadString("toy.owner.away") } + 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 loadEvents = { return (loadMap("toy.events") ?: [:]); } @@ -1292,13 +1303,13 @@ return new Object() { def sessionPlay = { if (is(CHASTE)) sessionToys[CHASTITY] = getTime(); def playScope = [ - 'randRange': randRange, - 'currentPunishment': getPunish, + 'randRange': { min, max -> randRange(min, max) }, + 'currentPunishment': { getPunish() }, 'sessionAborted': { return sessionAborted }, - 'can': can, - 'has': has, - 'is': is, - 'likes': likes, + 'can': { return can(it) }, + 'has': { return has(it) }, + 'is': { return is(it) }, + 'likes': { return likes(it) }, 'punishMultiple': (float)1.0, 'prop': load('toy') ?: [:] ]; |