diff options
-rw-r--r-- | scripts/toy.groovy | 27 | ||||
-rw-r--r-- | scripts/toy/availability.groovy | 24 |
2 files changed, 29 insertions, 22 deletions
diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 1fb02ae..286ffad 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -94,6 +94,9 @@ return new Object() { int getDay() { return ((int)(getTime() / DAY) * DAY); } + int getDayNum() { + return Math.floorDiv(getTime() - localTimeOffset() - (4 * (int)HOUR), DAY) + } public <T> T getProp(String i, java.util.function.Function<String, T> f, T d = null) { final T v = f.apply("toy.$i".toString()); @@ -358,27 +361,8 @@ return new Object() { OWNER = loadString("toy.owner"); loadDomme(OWNER); def moduleSetup = loadModules(this); - def getDayNum = { Math.floorDiv(getTime() - localTimeOffset() - 14400, 86400) }; - def getAvail = { dayNum -> loadInteger("toy.availability.$dayNum") ?: 0 }; - def addAvail = { amount -> - def dayNum = getDayNum(); - save("toy.availability.$dayNum", (int)(getAvail(dayNum) + amount)); - }; - def tidyAvail = { - def p = load("toy.availability"); - if (!p) return; - def p2 = [:]; - final firstDay = getDayNum() - 20; - p.eachWithIndex{ avail, day -> - if (day >= firstDay && avail > 0) { - p2["$day"] = avail; - } - } - save("toy.availability", p2); - }; setDefault("toy.punishment", 0); execEvents(false); - tidyAvail(); moduleSetup.each { p -> p() }; final cycleTime = 60; @@ -428,12 +412,10 @@ return new Object() { else if (stateIs("DEBUG")) return "toy"; } - addAvail(clickTime); executeTrigger("toyLoungeTime", clickTime); } - def eStart = getTime(); + final eStart = getTime(); execEvents(true); - addAvail(getTime() - eStart); executeTrigger("toyEventTime", getTime() - eStart); } } @@ -443,6 +425,7 @@ return new Object() { /* * Resources * scripts/toy.groovy + * scripts/toy/availability.groovy * scripts/toy/bondage.groovy * scripts/toy/cbt.groovy * scripts/toy/chastity.groovy diff --git a/scripts/toy/availability.groovy b/scripts/toy/availability.groovy new file mode 100644 index 0000000..27b977a --- /dev/null +++ b/scripts/toy/availability.groovy @@ -0,0 +1,24 @@ +{ toy -> + def getAvail = { int dayNum -> toy.loadInteger("toy.availability.$dayNum") ?: 0 }; + def addAvail = { amount -> + if (!amount) return; + def dayNum = toy.getDayNum(); + toy.save("toy.availability.$dayNum", (int)(getAvail(dayNum) + amount)); + }; + + toy.addTriggerHandler("toyLoungeTime", { a -> addAvail(a) }); + toy.addTriggerHandler("toyEventTime", { a -> addAvail(a) }); + + return { + def p = toy.load("toy.availability"); + if (!p) return; + def p2 = [:]; + final firstDay = toy.getDayNum() - 20; + p.eachWithIndex{ avail, day -> + if (day >= firstDay && avail > 0) { + p2["$day"] = avail; + } + } + toy.save("toy.availability", p2); + } +} |