mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Move flattening function to gear module
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {translator as t} from '../helpers';
|
||||
import events from '../events';
|
||||
import {each, defaults} from 'lodash';
|
||||
import classes from '../classes';
|
||||
|
||||
import weapon from './weapon';
|
||||
import armor from './armor';
|
||||
@@ -10,6 +11,8 @@ import body from './body';
|
||||
import headAccessory from './head-accessory';
|
||||
import eyewear from './eyewear';
|
||||
|
||||
const GEAR_TYPES = [ 'weapon', 'armor', 'head', 'shield', 'body', 'back', 'headAccessory', 'eyewear']
|
||||
|
||||
let gear = {
|
||||
weapon: weapon,
|
||||
armor: armor,
|
||||
@@ -21,4 +24,48 @@ let gear = {
|
||||
eyewear: eyewear,
|
||||
};
|
||||
|
||||
export default gear;
|
||||
let flat = {};
|
||||
|
||||
|
||||
// The gear is exported as a tree (defined above), and a flat list (eg, {weapon_healer_1: .., shield_special_0: ...}) since
|
||||
// they are needed in different forms at different points in the app
|
||||
|
||||
each(GEAR_TYPES, function(type) {
|
||||
let classTypes = classes.concat(['base', 'special', 'mystery', 'armoire']);
|
||||
|
||||
each(classTypes, function(klass) {
|
||||
each(gear[type][klass], function(item, i) {
|
||||
let key = type + "_" + klass + "_" + i;
|
||||
defaults(item, {
|
||||
type: type,
|
||||
key: key,
|
||||
klass: klass,
|
||||
index: i,
|
||||
str: 0,
|
||||
int: 0,
|
||||
per: 0,
|
||||
con: 0
|
||||
});
|
||||
if (item.event) {
|
||||
let _canOwn = item.canOwn || (function() {
|
||||
return true;
|
||||
});
|
||||
item.canOwn = function(u) {
|
||||
return _canOwn(u) && ((u.items.gear.owned[key] != null) || (moment().isAfter(item.event.start) && moment().isBefore(item.event.end))) && (item.specialClass ? u.stats["class"] === item.specialClass : true);
|
||||
};
|
||||
}
|
||||
if (item.mystery) {
|
||||
item.canOwn = function(u) {
|
||||
return u.items.gear.owned[key] != null;
|
||||
};
|
||||
}
|
||||
flat[key] = item;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export default {
|
||||
tree: gear,
|
||||
flat: flat,
|
||||
gearTypes: GEAR_TYPES
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user