/**
* @author Wolfgang Kowarschick <kowa@hs-augsburg.de>
* @copyright 2017-2018
* @license CC-BY-NC-SA-4.0
*/
import {ViewRectangleSprite} from './ViewRectangleSprite';
/**
* @class
* @extends ViewRectangleSprite
*/
class ViewToken extends ViewRectangleSprite
{ /**
* @param {Object} p_pixi_app
* @param {ModelToken} p_model
* @param {Object} p_config
* @param {Object} p_config.images
* @param {Object} p_config.border = {left: 0, top: 0}]
* @param {number} [p_config.gap = 0]
* @param {Object} p_resources
* @ignore
*/
constructor(p_pixi_app,
p_model,
{ images: p_images,
border: p_border = {left: 0, top: 0},
gap: p_gap = 0
},
p_resources
)
{ super(p_pixi_app, p_model, {}, p_resources);
/**
* The name of the image to be used for visualization.
* @member {Object} ViewRectangleSprite#image
*/
this.images = p_images;
/**
* The border width and height of the board view.
* @member {{left: number, top: number}} ViewRectangleSprite#border
*/
this.border = p_border;
/**
* The vertical and horizontal gap between two tokens.
* @member {number} ViewRectangleSprite#gap
*/
this.gap = p_gap;
this.sprite.x = this.border.left + p_model.i*(this.gap + p_model.width);
this.sprite.y = this.border.top + p_model.j*(this.gap + p_model.height);
this.v_type = null;
this.render();
}
/**
* Renders the token.
*/
render()
{ const
c_model = this.model,
c_type_model = c_model.type;
if (this.v_type !== c_type_model) // the type has changed, so change the image
{ this.image = this.images[c_type_model];
this.v_type = c_type_model;
}
}
}
export {ViewToken};