From b9aca0c9f521343bcab5f0348f9f69adf369f3a9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 6 Mar 2019 22:00:13 +0000 Subject: Simplify image data 1 --- scripts/toy.groovy | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'scripts/toy.groovy') diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 148d282..1f0547c 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -48,29 +48,30 @@ final IMAGEDATA = { return new File("$DATAFOLDER/images/toy") .listFiles() .findAll { d -> d.isDirectory(); } - .collect { d -> + .collectEntries { d -> [ - domme: d.getName(), - sets: d.listFiles() - .findAll { s -> s.isDirectory(); } - .collect { s -> [ sub: s, f: new File(s.getPath() + "/tags")] } - .findAll { s -> s.f.canRead() } - .collect { s -> - [ - set: s.sub.getName(), - images: s.f - .readLines() - .collect { l -> - def fields = l.split(":"); - return [ - image: fields[0], - tags: fields[1] - .split(",") - .findAll { t -> !t.isEmpty() } - ]; - } - ] - } + d.getName(), [ + sets: d.listFiles() + .findAll { s -> s.isDirectory(); } + .collect { s -> [ sub: s, f: new File(s.getPath() + "/tags")] } + .findAll { s -> s.f.canRead() } + .collect { s -> + [ + set: s.sub.getName(), + images: s.f + .readLines() + .collect { l -> + def fields = l.split(":"); + return [ + image: fields[0], + tags: fields[1] + .split(",") + .findAll { t -> !t.isEmpty() } + ]; + } + ] + } + ] ] }; }(); @@ -80,8 +81,7 @@ def selectImage = { domme, set, spec -> return (s[0] == "!") ? i.tags.indexOf(s.drop(1)) == -1 : i.tags.indexOf(s) != -1; }); }; - def matches = IMAGEDATA - .find({ d -> d.domme == domme }); + def matches = IMAGEDATA[domme]; if (!matches) return null; matches = matches .sets.find({ s -> s.set == set }); @@ -107,8 +107,7 @@ def showLounge = { setImage("toy/$OWNER/lounge.jpg"); }; def selectImageSet = { domme, specs -> - def matches = IMAGEDATA - .find({ d -> d.domme == domme }); + def matches = IMAGEDATA[domme]; if (!matches) return null; matches = matches.sets.findAll({ s -> specs.every({ spec -> selectImage(domme, s.set, spec)})}); return matches[getRandom(matches.size())]; @@ -117,8 +116,7 @@ def dress = { specs -> def outfit = loadString("toy.owner.outfit"); def outfitTime = loadInteger("toy.owner.outfitTime"); if (outfitTime > getTime() - 7200) { // Recent, check - def prev = IMAGEDATA - .find({ d -> d.domme == OWNER }); + def prev = IMAGEDATA[OWNER]; if (prev) { prev = prev.sets.find({ s -> s.set == outfit }); if (prev && specs.every({ spec -> selectImage(OWNER, prev.set, spec)})) { -- cgit v1.2.3