<commit_before>
const RG = require('../rg');

const System = {};
System.Base = require('./system.base');

/* Processes entities with communication component.*/
System.Communication = function(compTypes) {
    System.Base.call(this, RG.SYS.COMMUNICATION, compTypes);

    // Each entity here has received communication and must capture its
    // information contents
    this.updateEntity = function(ent) {
        const comComp = ent.get('Communication');
        const messages = comComp.getMsg();
        for (let i = 0; i < messages.length; i++) {
            this.processMessage(ent, messages[i]);
        }
        ent.remove('Communication');
    };

    this.processMessage = (ent, msg) => {
        if (_msgFunc.hasOwnProperty(msg.type)) {
            _msgFunc[msg.type](ent, msg);
        }
        else {
            RG.err('CommunicationSystem', 'processMessage',
                'No function for msg type |' + msg.type + '| in dtable.');
        }
    };

    this.processEnemies = (ent, msg) => {
        const enemies = msg.enemies;
        const srcName = msg.src.getName();
        for (let i = 0; i < enemies.length; i++) {
            ent.addEnemy(enemies[i]);
        }
        const msgObj = {cell: ent.getCell(),
            msg: `${srcName} seems to communicate with ${ent.getName()}`
        };
        RG.gameInfo(msgObj);
    };

    this.processShout = (ent, msg) => {
        const shoutMsg = msg.shout;
        const srcName = msg.src.getName();
        const msgObj = {cell: msg.src.getCell(),
            msg: `${srcName} shouts ${shoutMsg}`};
        RG.gameInfo(msgObj);
    };

    // Dispatch table for different messages
    const _msgFunc = {
        Enemies: this.processEnemies,
        Shout: this.processShout
    };

};
RG.extend2(System.Communication, System.Base);

module.exports = System.Communication;<commit_msg>Changed into class format.<commit_after>
import RG from '../rg';
import {Entity} from  '../entity';
import {SystemBase} from './system.base';
import {Communication} from '../component';
import {EventPool} from '../eventpool';

/* Processes entities with communication component.*/
export class SystemCommunication extends SystemBase { 

    private _msgFunc: {[key: string]: (ent, msg) => void};

    constructor(compTypes, pool?: EventPool) {
        super('Communication', compTypes, pool);

        // Dispatch table for different messages
        this._msgFunc = {
            Enemies: this.processEnemies.bind(this),
            Shout: this.processShout.bind(this)
        }

    }

    // Each entity here has received communication and must capture its
    // information contents
    updateEntity(ent: Entity): void {
        const comComp = ent.get('Communication');
        const messages = comComp.getMsg();
        for (let i = 0; i < messages.length; i++) {
            this.processMessage(ent, messages[i]);
        }
        ent.remove('Communication');
    };

    processMessage(ent, msg) {
        if (this._msgFunc.hasOwnProperty(msg.type)) {
            this._msgFunc[msg.type](ent, msg);
        }
        else {
            RG.err('CommunicationSystem', 'processMessage',
                'No function for msg type |' + msg.type + '| in dtable.');
        }
    }

    processEnemies(ent, msg) {
        const enemies = msg.enemies;
        const srcName = msg.src.getName();
        for (let i = 0; i < enemies.length; i++) {
            ent.addEnemy(enemies[i]);
        }
        const msgObj = {cell: ent.getCell(),
            msg: `${srcName} seems to communicate with ${ent.getName()}`
        };
        RG.gameInfo(msgObj);
    }

    processShout(ent, msg) {
        const shoutMsg = msg.shout;
        const srcName = msg.src.getName();
        const msgObj = {cell: msg.src.getCell(),
            msg: `${srcName} shouts ${shoutMsg}`};
        RG.gameInfo(msgObj);
    }

}

{'fraction_non_alphanumeric': 0.1404189294026377, 'fraction_numerical': 0.0012929919834497026, 'mean_word_length': 2.2531539108494534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3420825', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1125, 'n_words': 277}