habitica/website/common/script/content/gear/index.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

import each from 'lodash/each';
import defaults from 'lodash/defaults';
2015-11-16 23:29:13 +00:00
import {
CLASSES,
GEAR_TYPES,
} from '../constants';
import { ownsItem } from './gear-helper';
import weapon from './weapon';
import armor from './armor';
import head from './head';
import shield from './shield';
import back from './back';
import body from './body';
import headAccessory from './head-accessory';
import eyewear from './eyewear';
2019-10-08 14:57:10 +00:00
const gear = {
2015-11-16 23:29:13 +00:00
weapon,
armor,
head,
shield,
back,
body,
headAccessory,
eyewear,
};
/*
2019-10-09 14:51:17 +00:00
The gear is exported as a tree (defined above), and a flat list
(eg, {weapon_healer_1: .., shield_special_0: ...}) since
2015-11-16 23:29:13 +00:00
they are needed in different forms at different points in the app
*/
2019-10-08 14:57:10 +00:00
const flat = {};
2015-11-16 23:29:13 +00:00
2019-10-08 14:57:10 +00:00
each(GEAR_TYPES, type => {
const allGearTypes = CLASSES.concat(['base', 'special', 'mystery', 'armoire']);
2015-11-16 23:29:13 +00:00
2019-10-08 14:57:10 +00:00
each(allGearTypes, klass => {
2015-11-16 23:29:13 +00:00
each(gear[type][klass], (item, index) => {
2019-10-08 14:57:10 +00:00
const key = `${type}_${klass}_${index}`;
const set = `${klass}-${index}`;
2015-11-16 23:29:13 +00:00
defaults(item, {
type,
key,
set,
2015-11-16 23:29:13 +00:00
klass,
index,
str: 0,
int: 0,
per: 0,
con: 0,
2019-10-08 14:57:10 +00:00
canBuy: () => false,
2015-11-16 23:29:13 +00:00
});
if (item.mystery || key.indexOf('takeThis') !== -1) {
2015-11-16 23:29:13 +00:00
item.canOwn = ownsItem(key);
}
flat[key] = item;
});
});
});
2019-10-01 15:53:48 +00:00
export default {
2015-11-16 23:29:13 +00:00
tree: gear,
flat,
};