<commit_before>import { WebCurses } from './WebCurses';
import { Entity } from './Entity';
import { Map } from './Map';
import { Tile } from './Tile';

export class Game {
  private screen: WebCurses;
  private player: Entity;
  private map: Map;
  public debug: boolean;

  constructor(private canvas: HTMLCanvasElement, public readonly fontSize: number) {
    this.debug = canvas.dataset['debug'] === 'true';
    this.screen = new WebCurses(canvas, fontSize);
    this.player = new Entity({ x: 10, y: 10 }, '@', '#FFFFFF');
    this.map = new Map(this.screen.horizontalTiles, this.screen.verticalTiles);

    window.addEventListener('keydown', (event) => {
      if (this.debug) console.log('keydown : ' + event.key);
      let key = event.key;
      switch (key) {
        case 'ArrowUp':
          event.preventDefault();
          if (this.player.moveUp(this.map))
            this.drawFrame();
          break;
        case 'ArrowDown':
          event.preventDefault();
          if (this.player.moveDown(this.map))
            this.drawFrame();
          break;
        case 'ArrowLeft':
          event.preventDefault();
          if (this.player.moveLeft(this.map))
            this.drawFrame();
          break;
        case 'ArrowRight':
          event.preventDefault();
          if (this.player.moveRight(this.map))
            this.drawFrame();
          break;
      }
    });

    this.drawFrame();
  }

  private drawFrame() {
    this.drawBackground();
    this.drawEntity(this.player);
  }

  private drawBackground() {
    this.screen.clear('#000000');
    this.map.eachTile((x: number, y: number, tile: Tile) => {
      var tileType = tile.type;
      this.screen.putChar(tileType.char, x, y, tileType.color, tileType.bgColor);
    });
  }

  private drawEntity(entity: Entity) {<commit_msg>make it work in Safari<commit_after>import { WebCurses } from './WebCurses';
import { Entity } from './Entity';
import { Map } from './Map';
import { Tile } from './Tile';

export class Game {
  private screen: WebCurses;
  private player: Entity;
  private map: Map;
  public debug: boolean;

  constructor(private canvas: HTMLCanvasElement, public readonly fontSize: number) {
    this.debug = canvas.dataset['debug'] === 'true';
    this.screen = new WebCurses(canvas, fontSize);
    this.player = new Entity({ x: 10, y: 10 }, '@', '#FFFFFF');
    this.map = new Map(this.screen.horizontalTiles, this.screen.verticalTiles);

    window.addEventListener('keydown', (event) => {
      let key = event.charCode || event.which || event.keyCode;
      if (this.debug) console.log('keydown : ' + key);
      switch (key) {
        case 38:
          event.preventDefault();
          if (this.player.moveUp(this.map))
            this.drawFrame();
          break;
        case 40:
          event.preventDefault();
          if (this.player.moveDown(this.map))
            this.drawFrame();
          break;
        case 37:
          event.preventDefault();
          if (this.player.moveLeft(this.map))
            this.drawFrame();
          break;
        case 39:
          event.preventDefault();
          if (this.player.moveRight(this.map))
            this.drawFrame();
          break;
      }
    });

    this.drawFrame();
  }

  private drawFrame() {
    this.drawBackground();
    this.drawEntity(this.player);
  }

  private drawBackground() {
    this.screen.clear('#000000');
    this.map.eachTile((x: number, y: number, tile: Tile) => {
      var tileType = tile.type;
      this.screen.putChar(tileType.char, x, y, tileType.color, tileType.bgColor);
    });
  }

  private drawEntity(entity: Entity) {
{'fraction_non_alphanumeric': 0.14560968896229012, 'fraction_numerical': 0.007707129094412331, 'mean_word_length': 2.4283018867924526, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2673363', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1086, 'n_words': 248}