From d87aa9c1b183b8de7f0f20e762a2ba7720f6fd11 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 16 Mar 2019 12:04:02 +0000 Subject: Simplify image data 2 --- scripts/toy.groovy | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'scripts') diff --git a/scripts/toy.groovy b/scripts/toy.groovy index 1f0547c..fdcc10f 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -48,30 +48,30 @@ final IMAGEDATA = { return new File("$DATAFOLDER/images/toy") .listFiles() .findAll { d -> d.isDirectory(); } - .collectEntries { d -> - [ - 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() } - ]; - } - ] - } - ] + .collectEntries { d -> [ + d.getName(), [ + 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() } + .collectEntries { s -> [ + s.sub.getName(), [ + 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() } + ]; + } + ] + ]} + ] ] }; }(); @@ -83,8 +83,7 @@ def selectImage = { domme, set, spec -> }; def matches = IMAGEDATA[domme]; if (!matches) return null; - matches = matches - .sets.find({ s -> s.set == set }); + matches = matches.sets[set]; if (!matches) return null; matches = matches .images.findAll({ i -> meets(i) }); @@ -109,7 +108,7 @@ def showLounge = { def selectImageSet = { domme, specs -> def matches = IMAGEDATA[domme]; if (!matches) return null; - matches = matches.sets.findAll({ s -> specs.every({ spec -> selectImage(domme, s.set, spec)})}); + matches = matches.sets.values().findAll({ s -> specs.every({ spec -> selectImage(domme, s.set, spec)})}); return matches[getRandom(matches.size())]; }; def dress = { specs -> @@ -118,7 +117,7 @@ def dress = { specs -> if (outfitTime > getTime() - 7200) { // Recent, check def prev = IMAGEDATA[OWNER]; if (prev) { - prev = prev.sets.find({ s -> s.set == outfit }); + prev = prev.sets[outfit]; if (prev && specs.every({ spec -> selectImage(OWNER, prev.set, spec)})) { return outfit; } -- cgit v1.2.3