Source: view/ViewText.js

/**
 * @author    Wolfgang Kowarschick <kowa@hs-augsburg.de>
 * @copyright 2017 - 2018
 * @license   CC-BY-NC-SA-4.0
 */

import {Text} from 'pixi.js';

/**
 * @property {ModelScore} model  - the model to be visualized
 * @property {PIXI.Text}  sprite - a graphic object that visualizes the model
 */
class ViewText
{ /**
   * @param {Object}      p_pixi_app
   * @param {ModelScore}  p_model
   * @param {Object}      p_config
   * @param {Object}      p_config.style
   *         <a href="http://pixijs.download/dev/docs/PIXI.TextStyle.html">see
   *         PIXI.TextStyle</code>
   * @param {{x:number, y:number}} [p_config.anchor = {x: 0, y: 0}]
   *          left: 0, center 0.5, right: 1
   */
  constructor(p_pixi_app, p_model, {style: p_style, anchor: p_anchor={x:0, y:0}})
  { const c_sprite = new Text(p_model.text, p_style);
    c_sprite.anchor = p_anchor;
  
    p_pixi_app.stage.addChild(c_sprite);
  
    this.sprite = c_sprite;
    this.model  = p_model;

    this.render();
  }
  
  /**
   *
   */
  render()
  { this.sprite.text = this.model.text;
    this.sprite.x    = this.model.x;
    this.sprite.y    = this.model.y;
  }
}

export {ViewText};