<commit_before>/**
 * Used to display and track inventories.
 */
class InventoryRender {

  /**
   * Used to display and track inventories.
   * @param {object} inventoryData
   * @param {GUI} GUI
   */
  constructor(inventoryData, GUI) {
    this.inventory = inventoryData;
    this.inventory.contents = {};
    this.table = this.renderInventory(inventoryData, GUI);
  }

  /**
   * Tells you about the item in the given slot. First item is at 1, just like in game.
   * @param {number} slotNum 
   * @returns {object}
   */
  getSlot(slotNum) {
    return this.inventory.contents[slotNum - 1];
  }

  /**
   * Change what's in a slot. First item is at 1, just like in game.
   * @param {number} slotNum 
   * @param {object} slotData 
   * @returns {object}
   */
  setSlot(slotNum, slotData) {
    this.inventory.contents[slotNum - 1] = slotData;
    var slotCell = this.table.rows[Math.trunc((slotNum - 1) / 4) + 1].cells[(slotNum - 1) % 4];
    if (slotCell.firstChild) {slotCell.firstChild.remove();}
    if (slotData && slotData.label) {
      slotCell.appendChild(InventoryRender.renderItem(slotData));
    }
    return slotData;
  }

  /**
   * Gets the side this inventory is on. Used to tell if it's internal or external.
   * @returns {number}
   */
  getSide() {
    return this.inventory.side;
  }

  /**
   * Adds the table to an existing element to be displayed.
   * @param {HTMLElement} display 
   */
  addToDisplay(display) {
    display.appendChild(this.table);
  }

  /**
   * Removes the table from its parent display element.
   */
  removeFromDisplay() {
    this.table.remove();
  }

  /**
   * Creates an interactive visual representation of an inventory.
   * @param {object} inventoryData 
   * @returns {HTMLTableElement}
   * @param {GUI} GUI
   */
  renderInventory(inventoryData, GUI) {
    var table = document.createElement('table');
    table.classList.add('mc-table');
    table.setAttribute('data-side', inventoryData.side);
    var numCols = 4;
    var numRows = inventoryData.size / 4;
    for (var i = 0; i < numRows; i++) {
      var row = table.insertRow(-1);
      for (var j = 0; j < numCols; j++) {
        if ((i * 4) + j < inventoryData.size) {
          var cell = row.insertCell(-1);
          cell.classList.add('mc-td');
          if (inventoryData.side == -1) {
            cell.addEventListener('click', this.changeSelectedSlot.bind(GUI));
          }
          
          cell.addEventListener('dragover', this.allowDrop);
          cell.addEventListener('drop', this.itemDrop.bind(GUI));

          var slotNumber = (i * numCols) + j + 1;
          cell.setAttribute('data-slotNumber', slotNumber);
          if (inventoryData.selected == slotNumber) {
            cell.setAttribute('data-selected', true);
          }
        }
      }
    }

    var inventoryLabel = document.createElement('span');
    var inventoryType = inventoryData.side == -1 ? 'Robot' : 'External';
    inventoryLabel.innerText = inventoryType + ' Inventory';

    var header = table.createTHead();
    var headerRow = document.createElement('tr');
    var headerCell = document.createElement('th');
    header.appendChild(headerRow);
    headerRow.appendChild(headerCell);
    headerCell.appendChild(inventoryLabel);

    return table;
  }

  /**
   * Removes inventories from the display.
   * Used when the robot moves or when you select a new robot.
   * @param {boolean} includeInternal
   */
  removeInventories(includeInternal) {
    var inventoryContainer = document.getElementById("inventoryContainer");
    if (includeInternal) {
      for (elem of Array.from(inventoryContainer.childNodes)) {
        elem.remove();
      }
    }
    else {
      var inventories = inventoryContainer.querySelectorAll('[data-side]:not([data-side="-1"])');
      for (var inventory of inventories) {
        inventoryContainer.removeChild(inventory);
      }
    }
  }

  /**
   * Creates a visual representation of an item.
   * @param {object} itemData 
   * @returns {HTMLDivElement}
   */
  static renderItem(itemData) {
    var itemDiv = document.createElement('div');
    itemDiv.setAttribute('title', itemData.label + ', ' + itemData.size);
<commit_msg>this apparently wasn't being used anywhere<commit_after>/**
 * Used to display and track inventories.
 */
class InventoryRender {

  /**
   * Used to display and track inventories.
   * @param {object} inventoryData
   * @param {GUI} GUI
   */
  constructor(inventoryData, GUI) {
    this.inventory = inventoryData;
    this.inventory.contents = {};
    this.table = this.renderInventory(inventoryData, GUI);
  }

  /**
   * Tells you about the item in the given slot. First item is at 1, just like in game.
   * @param {number} slotNum 
   * @returns {object}
   */
  getSlot(slotNum) {
    return this.inventory.contents[slotNum - 1];
  }

  /**
   * Change what's in a slot. First item is at 1, just like in game.
   * @param {number} slotNum 
   * @param {object} slotData 
   * @returns {object}
   */
  setSlot(slotNum, slotData) {
    this.inventory.contents[slotNum - 1] = slotData;
    var slotCell = this.table.rows[Math.trunc((slotNum - 1) / 4) + 1].cells[(slotNum - 1) % 4];
    if (slotCell.firstChild) {slotCell.firstChild.remove();}
    if (slotData && slotData.label) {
      slotCell.appendChild(InventoryRender.renderItem(slotData));
    }
    return slotData;
  }

  /**
   * Gets the side this inventory is on. Used to tell if it's internal or external.
   * @returns {number}
   */
  getSide() {
    return this.inventory.side;
  }

  /**
   * Adds the table to an existing element to be displayed.
   * @param {HTMLElement} display 
   */
  addToDisplay(display) {
    display.appendChild(this.table);
  }

  /**
   * Removes the table from its parent display element.
   */
  removeFromDisplay() {
    this.table.remove();
  }

  /**
   * Creates an interactive visual representation of an inventory.
   * @param {object} inventoryData 
   * @returns {HTMLTableElement}
   * @param {GUI} GUI
   */
  renderInventory(inventoryData, GUI) {
    var table = document.createElement('table');
    table.classList.add('mc-table');
    table.setAttribute('data-side', inventoryData.side);
    var numCols = 4;
    var numRows = inventoryData.size / 4;
    for (var i = 0; i < numRows; i++) {
      var row = table.insertRow(-1);
      for (var j = 0; j < numCols; j++) {
        if ((i * 4) + j < inventoryData.size) {
          var cell = row.insertCell(-1);
          cell.classList.add('mc-td');
          if (inventoryData.side == -1) {
            cell.addEventListener('click', this.changeSelectedSlot.bind(GUI));
          }
          
          cell.addEventListener('dragover', this.allowDrop);
          cell.addEventListener('drop', this.itemDrop.bind(GUI));

          var slotNumber = (i * numCols) + j + 1;
          cell.setAttribute('data-slotNumber', slotNumber);
          if (inventoryData.selected == slotNumber) {
            cell.setAttribute('data-selected', true);
          }
        }
      }
    }

    var inventoryLabel = document.createElement('span');
    var inventoryType = inventoryData.side == -1 ? 'Robot' : 'External';
    inventoryLabel.innerText = inventoryType + ' Inventory';

    var header = table.createTHead();
    var headerRow = document.createElement('tr');
    var headerCell = document.createElement('th');
    header.appendChild(headerRow);
    headerRow.appendChild(headerCell);
    headerCell.appendChild(inventoryLabel);

    return table;
  }

  /**
   * Creates a visual representation of an item.
   * @param {object} itemData 
   * @returns {HTMLDivElement}
   */
  static renderItem(itemData) {
    var itemDiv = document.createElement('div');
    itemDiv.setAttribute('title', itemData.label + ', ' + itemData.size);

{'fraction_non_alphanumeric': 0.13207304526748972, 'fraction_numerical': 0.005015432098765432, 'mean_word_length': 2.7642787996127782, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6701289', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2327, 'n_words': 586}