split remaining utilities from shared

This commit is contained in:
Matteo Pagliazzi
2016-03-08 19:35:02 +01:00
parent bb6f0f4252
commit 986bfd8035
14 changed files with 266 additions and 246 deletions

View File

@@ -0,0 +1,36 @@
import _ from 'lodash';
import content from '../content/index';
/*
Update the in-browser store with new gear. FIXME this was in user.fns, but it was causing strange issues there
*/
var sortOrder = _.reduce(content.gearTypes, (function(m, v, k) {
m[v] = k;
return m;
}), {});
module.exports = function(user) {
var changes;
if (!user) {
return;
}
changes = [];
_.each(content.gearTypes, function(type) {
var found;
found = _.find(content.gear.tree[type][user.stats["class"]], function(item) {
return !user.items.gear.owned[item.key];
});
if (found) {
changes.push(found);
}
return true;
});
changes = changes.concat(_.filter(content.gear.flat, function(v) {
var ref;
return ((ref = v.klass) === 'special' || ref === 'mystery' || ref === 'armoire') && !user.items.gear.owned[v.key] && (typeof v.canOwn === "function" ? v.canOwn(user) : void 0);
}));
return _.sortBy(changes, function(c) {
return sortOrder[c.type];
});
};