<commit_before>/// <reference path="../../../../type-declarations/index.d.ts" />
import * as Phaser from 'phaser';

import { setResponsiveWidth, polarity } from '../utils';
import { getGameState } from '../../store';

const enum TILE {
  WIDTH = 16,
  HEIGHT = 16
};

interface Location {
  x: number; 
  y: number;
};

class Link extends Phaser.Sprite {
  gridPosition: Phaser.Point;

  constructor(game: Phaser.Game, {x, y}: Location) {
    super(game, x * TILE.WIDTH, y * TILE.HEIGHT, 'link', 0);
    this.gridPosition = new Phaser.Point(x, y);
  }

  preload() {

  }

  init() {
    
  }

  create() {
    this.animations.add('down',  [0, 4], 10, true);
    this.animations.add('left',  [1, 5], 10, true);
    this.animations.add('up',    [2, 6], 10, true);
    this.animations.add('right', [3, 7], 10, true);
    this.animations.add('none',  [0],    10, false);
    
  }

  move(loc: Location) {
    const dir = this.determineDirection(loc);

    if (dir) { 
      this.animations.play(dir); 
    } else {
      this.animations.stop();
    }
    this.travelTo(loc);
  }

  determineDirection({x, y}: Location): string {
    const [xPolarity, yPolarity] = [
      polarity(x - this.gridPosition.x),
      polarity(y - this.gridPosition.y),
    ];

    console.log(xPolarity, yPolarity);

    if (xPolarity ===  1) { return 'right'; } 
    if (xPolarity === -1) { return  'left'; } 
    if (yPolarity ===  1) { return  'down'; } 
    if (yPolarity === -1) { return    'up'; }
    return null;
  }

  travelTo({x, y}: Location) {
    this.gridPosition.x = x * TILE.WIDTH;
    this.gridPosition.y = y * TILE.HEIGHT;
    this.game.add.tween(this).to({
        x: this.gridPosition.x, 
        y: this.gridPosition.y
      }, 
      250, Phaser.Easing.Quadratic.Out, true
    );
  }

  update() {
    this.animations.play('up');
    console.log(this);
  }

  getLocation(): Location {
    return {
      x: this.gridPosition.x,
      y: this.gridPosition.y,
    };
  }

  atLocation({x, y}: Location) {
    return x === this.gridPosition.x && 
           y === this.gridPosition.y;
  }
}

class Enemy extends Phaser.Sprite {
  constructor(
    game: Phaser.Game, 
    {x, y}: Location, 
    sprite: string = 'octorock'
  ) {
    super(game, x, y, sprite);
  }
}


export class GameState extends Phaser.State {
  link: Link;

  tilemap: Phaser.Tilemap;
  layer: Phaser.TilemapLayer;

  camera: Phaser.Camera;
  dragPoint: Phaser.Point;

  create () {
    const {charState} = getGameState();
<commit_msg>style (client): delete extra lines<commit_after>/// <reference path="../../../../type-declarations/index.d.ts" />
import * as Phaser from 'phaser';

import { setResponsiveWidth, polarity } from '../utils';
import { getGameState } from '../../store';

const enum TILE {
  WIDTH = 16,
  HEIGHT = 16
};

interface Location {
  x: number; 
  y: number;
};

class Link extends Phaser.Sprite {
  gridPosition: Phaser.Point;

  constructor(game: Phaser.Game, {x, y}: Location) {
    super(game, x * TILE.WIDTH, y * TILE.HEIGHT, 'link', 0);
    this.gridPosition = new Phaser.Point(x, y);
  }

  preload() {

  }

  init() {
    
  }

  create() {
    this.animations.add('down',  [0, 4], 10, true);
    this.animations.add('left',  [1, 5], 10, true);
    this.animations.add('up',    [2, 6], 10, true);
    this.animations.add('right', [3, 7], 10, true);
    this.animations.add('none',  [0],    10, false);
    
  }

  move(loc: Location) {
    const dir = this.determineDirection(loc);

    if (dir) { 
      this.animations.play(dir); 
    } else {
      this.animations.stop();
    }
    this.travelTo(loc);
  }

  determineDirection({x, y}: Location): string {
    const [xPolarity, yPolarity] = [
      polarity(x - this.gridPosition.x),
      polarity(y - this.gridPosition.y),
    ];

    console.log(xPolarity, yPolarity);

    if (xPolarity ===  1) { return 'right'; } 
    if (xPolarity === -1) { return  'left'; } 
    if (yPolarity ===  1) { return  'down'; } 
    if (yPolarity === -1) { return    'up'; }
    return null;
  }

  travelTo({x, y}: Location) {
    this.gridPosition.x = x * TILE.WIDTH;
    this.gridPosition.y = y * TILE.HEIGHT;
    this.game.add.tween(this).to({
        x: this.gridPosition.x, 
        y: this.gridPosition.y
      }, 
      250, Phaser.Easing.Quadratic.Out, true
    );
  }

  update() {
    this.animations.play('up');
    console.log(this);
  }

  getLocation(): Location {
    return {
      x: this.gridPosition.x,
      y: this.gridPosition.y,
    };
  }

  atLocation({x, y}: Location) {
    return x === this.gridPosition.x && 
           y === this.gridPosition.y;
  }
}

class Enemy extends Phaser.Sprite {
  constructor(
    game: Phaser.Game, 
    {x, y}: Location, 
    sprite: string = 'octorock'
  ) {
    super(game, x, y, sprite);
  }
}

export class GameState extends Phaser.State {
  link: Link;
  tilemap: Phaser.Tilemap;
  layer: Phaser.TilemapLayer;
  camera: Phaser.Camera;
  dragPoint: Phaser.Point;

  create () {
    const {charState} = getGameState();

{'fraction_non_alphanumeric': 0.17184388689765034, 'fraction_numerical': 0.012345679012345678, 'mean_word_length': 2.5224403927068724, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7635158', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1824, 'n_words': 396}