<commit_before>"use strict";

const Symbols = require("dc-constants").Symbols;

function PresetHelper(preset, gameData, choiceProvider) {
    function createStateFromPreset() {
        return new preset.state.class(...evaluateStateArgs());
    }
    this.createStateFromPreset = createStateFromPreset;

    function evaluateStateArgs() {
        let args = [ gameData, choiceProvider ];
        preset.state.args.forEach(function(arg) {
            switch(arg) {
                case Symbols.player1:
                    args.push(gameData.players[0]);
                    break;
                case Symbols.player2:
                    args.push(gameData.players[1]);
                    break;
                case Symbols.player3:
                    args.push(gameData.players[2]);
                    break;
                case Symbols.player4:
                    args.push(gameData.players[3]);
                    break;
                default:
                    args.push(arg);
                    break;
            }
        });

        return args;
    }

    function adjustPlayer(player, playerPreset, gameData) {
        player.money = playerPreset.money;

        playerPreset.dcCards.forEach(
            adjustCards.bind(null, player.gainDcCard, gameData.dcDeck)
        );

        playerPreset.cars.forEach(
            adjustCards.bind(null, player.gainCar, gameData.carDeck)
        );

        playerPreset.insurances.forEach(
            adjustCards.bind(null, player.gainInsurance, gameData.insuranceDeck)
        );
    }
    this.adjustPlayer = adjustPlayer;

    function adjustCards(gainCard, cards, cardPreset) {
        let card;
        if(cardPreset === Symbols.random)
            card = cards.pop();
        else
            card = cards.pickCard(cardPreset);

        gainCard(card);
    }
}

module.exports = PresetHelper;<commit_msg>Presets in database<commit_after>"use strict";

const Symbols = require("dc-constants").Symbols;

function PresetHelper(preset, gameData, choiceProvider) {
    function createStateFromPreset() {
        return new preset.state.stateClass(...evaluateStateArgs());
    }
    this.createStateFromPreset = createStateFromPreset;

    function evaluateStateArgs() {
        let args = [ gameData, choiceProvider ];
        preset.state.args.forEach(function(arg) {
            switch(arg) {
                case Symbols.player1:
                    args.push(gameData.players[0]);
                    break;
                case Symbols.player2:
                    args.push(gameData.players[1]);
                    break;
                case Symbols.player3:
                    args.push(gameData.players[2]);
                    break;
                case Symbols.player4:
                    args.push(gameData.players[3]);
                    break;
                default:
                    args.push(arg);
                    break;
            }
        });

        return args;
    }

    function adjustPlayer(player, playerPreset, gameData) {
        player.money = playerPreset.money;

        playerPreset.dcCards.forEach(
            adjustCards.bind(null, player.gainDcCard, gameData.dcDeck)
        );

        playerPreset.cars.forEach(
            adjustCards.bind(null, player.gainCar, gameData.carDeck)
        );

        playerPreset.insurances.forEach(
            adjustCards.bind(null, player.gainInsurance, gameData.insuranceDeck)
        );
    }
    this.adjustPlayer = adjustPlayer;

    function adjustCards(gainCard, cards, cardPreset) {
        let card;
        if(cardPreset === Symbols.random)
            card = cards.pop();
        else
            card = cards.pickCard(cardPreset);

        gainCard(card);
    }
}

module.exports = PresetHelper;
{'fraction_non_alphanumeric': 0.09827357237715803, 'fraction_numerical': 0.004249667994687915, 'mean_word_length': 1.6957766642806014, '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': '1875476', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1011, 'n_words': 163}