mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
split remaining utilities from shared
This commit is contained in:
36
common/script/libs/updateStore.js
Normal file
36
common/script/libs/updateStore.js
Normal 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];
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user