<commit_before>const blessed = require('blessed');

const SculptureStore = require('@anyware/game-logic/lib/sculpture-store');
const DisksActionCreator = require('@anyware/game-logic/lib/actions/disks-action-creator');
const Disk = require('@anyware/game-logic/lib/utils/disk');

const VIEW_TITLE = "{center}{bold}Disks{/bold}{/center}";
const CELL_WIDTH = 3;

export default class DiskView extends blessed.Box {
  constructor(store, config, dispatcher, windowOptions) {
    super(Object.assign({
      tags: true,
      border: {
        type: 'line'
      },
      style: {
        fg: 'white',
        bg: 'gray'
      }
    }, windowOptions));

    this.store = store;
    this.config = config;
    this.viewConfig = this.config.DISK_VIEW;

    this._disksActionCreator = new DisksActionCreator(dispatcher);

    this.renderDisks();
    this.store.on(SculptureStore.EVENT_CHANGE, this._handleChanges.bind(this));

    setInterval(this._updateDiskPositions.bind(this), this.viewConfig.TURN_UPDATE_INTERVAL);
  }

  renderDisks() {
    const disks = this.store.data.get('disks');
    
    const content = Array.from(this.formatDisks(disks)).join('\n');

    this.setBodyContent(content);
  }

  resetDisks() {
    // emulate the sculpture by doing this after a small interval
    setTimeout(() => {
      const disks = this.store.data.get('disks');

      for (let diskId of disks) {
        this._disksActionCreator.sendDiskUpdate(diskId, {
          position: 0
        });
      }
    }, 1000);
  }

  _handleChanges(changes) {
    if (changes.hasOwnProperty('disk') && changes.disk.hasOwnProperty('level')) {
      this.resetDisks();
    }

    this.renderDisks();
  }

  /**
   * Sets the view's body content to the given content leaving the title
   * and any other pertinent details in tact
   */
  setBodyContent(bodyContent) {
    let content = VIEW_TITLE + '\n';
    content += bodyContent;
    this.setContent(content);
  }

  *formatDisks(disks) {
    for (let diskId of disks) {
      const disk = disks.get(diskId);
      
      yield this.formatDisk(diskId, disk);
    }
  }

  formatDisk(diskId, disk) {
    let formattedDisk =`{yellow-fg}${diskId}:{/yellow-fg}  `;

    const formattedPos = (" " + disk.getPosition()).slice(-2);
    formattedDisk += `{yellow-fg}POS:{/yellow-fg} ${formattedPos} `;

    let formattedDir = this._lpad({
      [Disk.CLOCKWISE]: "+1",
      [Disk.COUNTERCLOCKWISE]: "-1",
      [Disk.STOPPED]: "0",
      [Disk.CONFLICT]: "x"
    }[disk.getDirection()], 2);

    formattedDisk += `{yellow-fg}CW:{/yellow-fg} ${this._lpad(disk.clockwisePull, 2)} `;
    formattedDisk += `{yellow-fg}CCW:{/yellow-fg} ${this._lpad(disk.counterclockwisePull, 2)} `;
    formattedDisk += `{yellow-fg}DIR:{/yellow-fg} ${formattedDir} `;

    formattedDisk += `{yellow-fg}STATE:{/yellow-fg} ${disk.getState()} `;
    formattedDisk += `{yellow-fg}USER:{/yellow-fg} '${disk.getUser()}'`;
    return formattedDisk;
  }
<commit_msg>Removed pulls as they are no longer used<commit_after>const blessed = require('blessed');

const SculptureStore = require('@anyware/game-logic/lib/sculpture-store');
const DisksActionCreator = require('@anyware/game-logic/lib/actions/disks-action-creator');
const Disk = require('@anyware/game-logic/lib/utils/disk');

const VIEW_TITLE = "{center}{bold}Disks{/bold}{/center}";
const CELL_WIDTH = 3;

export default class DiskView extends blessed.Box {
  constructor(store, config, dispatcher, windowOptions) {
    super(Object.assign({
      tags: true,
      border: {
        type: 'line'
      },
      style: {
        fg: 'white',
        bg: 'gray'
      }
    }, windowOptions));

    this.store = store;
    this.config = config;
    this.viewConfig = this.config.DISK_VIEW;

    this._disksActionCreator = new DisksActionCreator(dispatcher);

    this.renderDisks();
    this.store.on(SculptureStore.EVENT_CHANGE, this._handleChanges.bind(this));

    setInterval(this._updateDiskPositions.bind(this), this.viewConfig.TURN_UPDATE_INTERVAL);
  }

  renderDisks() {
    const disks = this.store.data.get('disks');
    
    const content = Array.from(this.formatDisks(disks)).join('\n');

    this.setBodyContent(content);
  }

  resetDisks() {
    // emulate the sculpture by doing this after a small interval
    setTimeout(() => {
      const disks = this.store.data.get('disks');

      for (let diskId of disks) {
        this._disksActionCreator.sendDiskUpdate(diskId, {
          position: 0
        });
      }
    }, 1000);
  }

  _handleChanges(changes) {
    if (changes.hasOwnProperty('disk') && changes.disk.hasOwnProperty('level')) {
      this.resetDisks();
    }

    this.renderDisks();
  }

  /**
   * Sets the view's body content to the given content leaving the title
   * and any other pertinent details in tact
   */
  setBodyContent(bodyContent) {
    let content = VIEW_TITLE + '\n';
    content += bodyContent;
    this.setContent(content);
  }

  *formatDisks(disks) {
    for (let diskId of disks) {
      const disk = disks.get(diskId);
      
      yield this.formatDisk(diskId, disk);
    }
  }

  formatDisk(diskId, disk) {
    let formattedDisk =`{yellow-fg}${diskId}:{/yellow-fg}  `;

    const formattedPos = (" " + disk.getPosition()).slice(-2);
    formattedDisk += `{yellow-fg}POS:{/yellow-fg} ${formattedPos} `;

    let formattedDir = this._lpad({
      [Disk.CLOCKWISE]: "+1",
      [Disk.COUNTERCLOCKWISE]: "-1",
      [Disk.STOPPED]: "0",
      [Disk.CONFLICT]: "x"
    }[disk.getDirection()], 2);

    formattedDisk += `{yellow-fg}DIR:{/yellow-fg} ${formattedDir} `;

    formattedDisk += `{yellow-fg}STATE:{/yellow-fg} ${disk.getState()} `;
    formattedDisk += `{yellow-fg}USER:{/yellow-fg} '${disk.getUser()}'`;
    return formattedDisk;
  }

{'fraction_non_alphanumeric': 0.15764746824430137, 'fraction_numerical': 0.0041760918740212285, 'mean_word_length': 3.2140762463343107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7205079', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1902, 'n_words': 347}