<commit_before>'use strict';

var _ = require('lodash');
var allUpgrades = require('../upgrades').all;
var keyedUpgrades = require('../upgrades').keyed;
// var pilots = require('../pilots').allRebels;
var events = require('../../controllers/events');
var arrayUtils = require('../../utils/array-utils');

var upgradesModel = function (build, upgradeIdList, equippedIdList) {
    this.build = build;
    // Upgrades in order of purchase
    this.purchased = this.upgradesFromIds(upgradeIdList);
    this.all = this.purchased.concat(this.build.currentShip.startingUpgrades);
    this.equipped = this.upgradesFromIds(equippedIdList);
    this.validateEquipped();
};

upgradesModel.prototype.upgradesFromIds = function (upgradeIdList) {
    return _.map(upgradeIdList, this.getUpgradeById);
};

upgradesModel.prototype.validateEquipped = function () {
    // Make sure equipped list only contains upgrades we have purchased or started with
    this.equipped = arrayUtils.intersectionSingle(this.equipped, this.all);

    // TODO: Make sure equipped list only contains upgrade types allowed on ship
};

upgradesModel.prototype.allForType = function (slotType) {
    return _.filter(this.purchased, function (upgrade) {
        return upgrade.slot === slotType;
    });
};

upgradesModel.prototype.refreshUpgradesState = function () {
    // Upgrades sorted alphabetically by slot type and then name
    this.sorted = this.getSorted();
    // upgrades object keyed by slot type with values being array or upgrades for that slot
    this.allbyType = this.getPurchasedByType();
    // Can only call refreshDisabled() once equipped is set
    this.disabled = this.getDisabled();
    this.unequipped = this.getUnequipped();
};

upgradesModel.prototype.getUnequipped = function () {
    // Remove *All* copies of any upgrades which should be disabled
    var notDisabled = _.difference(this.purchased, this.disabled);
    // Remove one copy of each item which is equipped<commit_msg>make sure all upgrades updated after purchase<commit_after>'use strict';

var _ = require('lodash');
var allUpgrades = require('../upgrades').all;
var keyedUpgrades = require('../upgrades').keyed;
// var pilots = require('../pilots').allRebels;
var events = require('../../controllers/events');
var arrayUtils = require('../../utils/array-utils');

var upgradesModel = function (build, upgradeIdList, equippedIdList) {
    this.build = build;
    // Upgrades in order of purchase
    this.purchased = this.upgradesFromIds(upgradeIdList);
    this.equipped = this.upgradesFromIds(equippedIdList);
    this.validateEquipped();
};

upgradesModel.prototype.upgradesFromIds = function (upgradeIdList) {
    return _.map(upgradeIdList, this.getUpgradeById);
};

upgradesModel.prototype.validateEquipped = function () {
    // Make sure equipped list only contains upgrades we have purchased or started with
    this.equipped = arrayUtils.intersectionSingle(this.equipped, this.all);

    // TODO: Make sure equipped list only contains upgrade types allowed on ship
};

upgradesModel.prototype.allForType = function (slotType) {
    return _.filter(this.purchased, function (upgrade) {
        return upgrade.slot === slotType;
    });
};

upgradesModel.prototype.refreshUpgradesState = function () {
    this.all = this.purchased.concat(this.build.currentShip.startingUpgrades);
    // Upgrades sorted alphabetically by slot type and then name
    this.sorted = this.getSorted();
    // upgrades object keyed by slot type with values being array or upgrades for that slot
    this.allbyType = this.getPurchasedByType();
    // Can only call refreshDisabled() once equipped is set
    this.disabled = this.getDisabled();
    this.unequipped = this.getUnequipped();
};

upgradesModel.prototype.getUnequipped = function () {
    // Remove *All* copies of any upgrades which should be disabled
    var notDisabled = _.difference(this.purchased, this.disabled);
    // Remove one copy of each item which is equipped
{'fraction_non_alphanumeric': 0.11519114688128773, 'fraction_numerical': 0.0, 'mean_word_length': 4.0405576679340935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2760086', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1104, 'n_words': 309}