From d98120edc82fd90d1d47706e44a6ad0e4dc3c10d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Dec 2018 18:13:12 +0000 Subject: Add some checks to ensure the check passes --- scripts/toy.groovy | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 509fb74..05c817e 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -70,16 +70,27 @@ def selectImage = { domme, set, spec -> }); }; def matches = IMAGEDATA - .find({ d -> d.domme == domme }) - .sets.find({ s -> s.set == set }) + .find({ d -> d.domme == domme }); + if (!matches) return null; + matches = matches + .sets.find({ s -> s.set == set }); + if (!matches) return null; + matches = matches .images.findAll({ i -> meets(i) }); + if (matches.isEmpty()) return null; return matches[getRandom(matches.size())]; }; def showImage = { spec -> def outfit = loadString("toy.owner.outfit"); def image = selectImage(OWNER, outfit, spec); - setImage("toy/$OWNER/$outfit/${image.image}.jpg"); - return image.tags; + if (image) { + setImage("toy/$OWNER/$outfit/${image.image}.jpg"); + return image.tags; + } + else { + setImage(null); + return null; + } }; def selectImageSet = { domme, specs -> def matches = IMAGEDATA @@ -94,7 +105,7 @@ def dress = { specs -> def prev = IMAGEDATA .find({ d -> d.domme == OWNER }) .sets.find({ s -> s.set == outfit }); - if (specs.every({ spec -> selectImage(OWNER, prev.set, spec)})) { + if (prev && specs.every({ spec -> selectImage(OWNER, prev.set, spec)})) { return outfit; } } @@ -131,7 +142,7 @@ def can = {i -> loadBoolean("toy.permission.$i") == true}; 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"); }; +def getPunish = { loadInteger("toy.punishment") ?: 0; }; def adjustPunish = { p -> save("toy.punishment", Math.max(getPunish() + (int)p, 0)); }; def sessionAborted = null; def gagText = { t, p -> @@ -401,7 +412,7 @@ def strokes = { amount, imageSpec -> save("toy.strokeTeaseOffset", sto); } def clampPulls = { amount -> - getRandom(amount).times { + getRandom(1 + amount).times { present([DRESSED], [ ["Pull them tight.", "Pull them!"]]); wait(getRandom(10) + 5); -- cgit v1.2.3