TextStyle.setStyle & TextStyle.setFont now set fontSize, fontStyle & fontFamily when font is a string

TextStyle.setFont now sets fontFamily, fontSize, and fontStyle when "font" is a string. 
TextStyle.setStyle calls TextStyle.setFont when "font" is overridden.
This fixes an issue where TextStyle.update(true) overrides TextStyle._font
This commit is contained in:
Taran van Groenigen 2018-10-09 11:13:23 +02:00 committed by GitHub
parent 1025362781
commit 9a2a0ad45f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -399,6 +399,8 @@ var TextStyle = new Class({
else
{
this._font = font;
this.setFont(font, false);
}
// Allow for 'fill' to be used in place of 'color'
@ -515,11 +517,14 @@ var TextStyle = new Class({
* @since 3.0.0
*
* @param {(string|object)} font - The font family or font settings to set.
* @param {boolean} [updateText=true] - Whether to update the text immediately.
*
* @return {Phaser.GameObjects.Text} The parent Text object.
*/
setFont: function (font)
setFont: function (font, updateText)
{
if (updateText === undefined) { updateText = true; }
var fontFamily = font;
var fontSize = '';
var fontStyle = '';
@ -530,14 +535,28 @@ var TextStyle = new Class({
fontSize = GetValue(font, 'fontSize', '16px');
fontStyle = GetValue(font, 'fontStyle', '');
}
else
{
var fontSplit = font.split(' ');
var i = 0;
if (fontSplit.length > 2)
{
this.fontStyle = fontSplit[i++];
}
this.fontSize = fontSplit[i++] || this.fontSize;
this.fontFamily = fontSplit[i++] || this.fontFamily;
}
if (fontFamily !== this.fontFamily || fontSize !== this.fontSize || fontStyle !== this.fontStyle)
{
this.fontFamily = fontFamily;
this.fontSize = fontSize;
this.fontStyle = fontStyle;
this.update(true);
if (updateText)
{
this.update(true);
}
}
return this.parent;