"use strict";
-Array.prototype.firstWhere = function (callback, thisArg) {
- for (var i = 0; i < this.length; ++i)
- if (callback.call(thisArg, this[i]))
- return this[i];
-};
-
Array.prototype.contains = function (o) {
return this.indexOf(o) >= 0;
};
return os[Math.floor(os.length * Math.random())];
}
-function category (item) {
- return Object.keys(ACNL_WEARABLES).firstWhere(function (type) {
- return ACNL_WEARABLES[type].contains(item);
- });
-}
+var flatten1 = Array.prototype.concat.apply.bind(Array.prototype.concat, []);
-function notLewd (outfit) {
- var categories = outfit.map(category);
- return (categories.contains("wetsuits")
- || categories.contains("dresses")
- || categories.containsSubset(["tops", "bottoms"]));
+function get (attr) {
+ return this[attr];
}
-function buildArray (a, l) {
- return (a || []).concat(l);
+var category = get.bind(ACNL_WEARABLES_CATEGORY);
+var wearables = get.bind(ACNL_WEARABLES);
+
+function isLewd (outfit) {
+ return ![["wetsuits"], ["dresses"], ["tops", "bottoms"]].some(
+ Array.prototype.containsSubset, outfit.map(category));
}
-function impossibilities (categories) {
- return categories.map(function (c) { return BLOCKS[c]; }
- ).reduce(buildArray, []);
+function impossibilities (outfit) {
+ return flatten1(outfit.map(category).map(get, BLOCKS));
}
function possibilities (outfit) {
- return Object.keys(ACNL_WEARABLES
- ).filter(Array.prototype.lacks, impossibilities(outfit.map(category))
- ).map(function (k) { return ACNL_WEARABLES[k] }
- ).reduce(buildArray, []);
+ return Object.keys(ACNL_WEARABLES).filter(
+ Array.prototype.lacks, impossibilities(outfit));
}
-function isFinished(outfit) {
- return notLewd(outfit) && Math.random() > 0.5;
+function outfit () {
+ var ps = [];
+ while (isLewd(ps))
+ ps.push(choice(flatten1(possibilities(ps).map(wearables))));
+ return ps;
}
-function nextItem (outfit) {
- return !isFinished(outfit) && choice(possibilities(outfit));
+function isPosessive (item) {
+ return item[0].toUpperCase() === item[0] && item.indexOf("'s") >= 0;
}
-function outfit () {
- var ps = [];
- var next;
- while (next = nextItem(ps))
- ps.push(next);
- return ps;
+function isPlural (item) {
+ return (item.substr(-1) === "s"
+ && item.substr(-2) !== "ss"
+ && item.substr(-6) !== "cosmos"); // :(
}
function article (item) {
if (item[0].toUpperCase() === item[0] && item.indexOf("'s") >= 0)
return "";
- else if (item.substr(-1) === "s" && item.substr(-2) !== "ss"
- && item.substr(-6) !== "cosmos") // :(
+ else if (isPlural(item))
return "";
else if ("aeiouAEIO".indexOf(item[0]) >= 0
|| ("FHLMNRSX".indexOf(item[0]) >= 0