2017-04-25 17:07:15 +00:00
|
|
|
var Text = require('./Text');
|
|
|
|
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
|
|
|
|
var BuildGameObject = require('../../BuildGameObject');
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
var TextCreator = function (scene, config)
|
2017-04-25 17:07:15 +00:00
|
|
|
{
|
|
|
|
// style Object = {
|
|
|
|
// font: [ 'font', '16px Courier' ],
|
|
|
|
// backgroundColor: [ 'backgroundColor', null ],
|
|
|
|
// fill: [ 'fill', '#fff' ],
|
|
|
|
// stroke: [ 'stroke', '#fff' ],
|
|
|
|
// strokeThickness: [ 'strokeThickness', 0 ],
|
|
|
|
// shadowOffsetX: [ 'shadow.offsetX', 0 ],
|
|
|
|
// shadowOffsetY: [ 'shadow.offsetY', 0 ],
|
|
|
|
// shadowColor: [ 'shadow.color', '#000' ],
|
|
|
|
// shadowBlur: [ 'shadow.blur', 0 ],
|
|
|
|
// shadowStroke: [ 'shadow.stroke', false ],
|
|
|
|
// shadowFill: [ 'shadow.fill', false ],
|
|
|
|
// align: [ 'align', 'left' ],
|
|
|
|
// maxLines: [ 'maxLines', 0 ],
|
|
|
|
// fixedWidth: [ 'fixedWidth', false ],
|
|
|
|
// fixedHeight: [ 'fixedHeight', false ],
|
|
|
|
// rtl: [ 'rtl', false ]
|
|
|
|
// }
|
|
|
|
|
|
|
|
var content = GetAdvancedValue(config, 'text', '');
|
|
|
|
var style = GetAdvancedValue(config, 'style', null);
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
var text = new Text(scene, 0, 0, content, style);
|
2017-04-25 17:07:15 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
BuildGameObject(scene, text, config);
|
2017-04-25 17:07:15 +00:00
|
|
|
|
|
|
|
// Text specific config options:
|
|
|
|
|
|
|
|
text.autoRound = GetAdvancedValue(config, 'autoRound', true);
|
|
|
|
text.resolution = GetAdvancedValue(config, 'resolution', 1);
|
|
|
|
|
2017-04-25 18:46:13 +00:00
|
|
|
// Padding
|
|
|
|
// Either: { padding: 2 } or { padding: { x: 2, y: 2 }}
|
|
|
|
|
|
|
|
var padding = GetAdvancedValue(config, 'padding', null);
|
|
|
|
|
|
|
|
if (typeof padding === 'number')
|
|
|
|
{
|
|
|
|
text.padding.x = padding;
|
|
|
|
text.padding.y = padding;
|
|
|
|
}
|
|
|
|
else if (padding !== null)
|
|
|
|
{
|
|
|
|
text.padding.x = GetAdvancedValue(padding, 'x', 1);
|
|
|
|
text.padding.y = GetAdvancedValue(padding, 'y', 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
text.updateText();
|
|
|
|
|
2017-04-25 17:07:15 +00:00
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
module.exports = TextCreator;
|