<commit_before>import { Point } from './Point'
import { Map } from './Map'
import * as ActorClass from './ActorClass'


export class Actor {
  constructor(
    public readonly actorClass: ActorClass.ActorClass,
    public pos: Point,
    public hp: number
  ) {}

  public setPos(pos: Point) {
    this.pos = pos;
  }

  public attack(other: Actor) {
    console.log('Attacking!');
  }

  public toString() {
    return 'Actor(char=' + this.actorClass.char + ', pos={x:' + this.pos.x + ', y:' + this.pos.y + '}, color=' + this.actorClass.color + ')';
  }

  public static serialize(actor: Actor) {
    return {
      className: actor.actorClass.className,
      pos: actor.pos,
      hp: actor.hp
    };
  }

  public static deserialize(data: any) {
    if (!data.pos || typeof data.className !== 'string' || typeof data.hp !== 'number') {
      console.log('bad actor data: ' + data);
      return null;
    }

    // re-establish reference to ActorClass
    let className = <string>data.className;
    let pos = <Point>data.pos;
    let actorClass = ActorClass.getClassByName(className);
    if (!actorClass) {
      console.log('Unknown actor class: ' + className);
      return null;
    }
    return new Actor(actorClass, pos, data.hp);
  }
}<commit_msg>serialize actor properties dynamically<commit_after>import { Point } from './Point'
import { Map } from './Map'
import * as ActorClass from './ActorClass'


export class Actor {
  constructor(
    public readonly actorClass: ActorClass.ActorClass,
    public pos: Point,
    public hp: number
  ) {}

  public setPos(pos: Point) {
    this.pos = pos;
  }

  public attack(other: Actor) {
    console.log('Attacking!');
  }

  public toString() {
    return 'Actor(char=' + this.actorClass.char + ', pos={x:' + this.pos.x + ', y:' + this.pos.y + '}, color=' + this.actorClass.color + ')';
  }

  public static serialize(actor: Actor) {
    let clone = <any>{};
    for (let key in actor) {
      if (!actor.hasOwnProperty(key)) continue;
      if (key === 'actorClass') {
        clone.className = actor.actorClass.className;
      } else {
        clone[key] = (<any>actor)[key];
      }
    }
    return clone;
  }

  public static deserialize(data: any) {
    if (!data.pos || typeof data.className !== 'string' || typeof data.hp !== 'number') {
      console.log('bad actor data: ' + data);
      return null;
    }

    // re-establish reference to ActorClass
    let className = <string>data.className;
    let pos = <Point>data.pos;
    let actorClass = ActorClass.getClassByName(className);
    if (!actorClass) {
      console.log('Unknown actor class: ' + className);
      return null;
    }
    return new Actor(actorClass, pos, data.hp);
  }
}
{'fraction_non_alphanumeric': 0.14885777450257923, 'fraction_numerical': 0.0, 'mean_word_length': 2.8347457627118646, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5951822', 'n_tokens_mistral': 870, 'n_tokens_neox': 840, 'n_words': 221}