2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-06-07 22:49:22 +00:00
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
|
|
|
|
2018-04-19 11:30:38 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} Phaser.GameObjects.BitmapText.ParseRetroFont.RetroFontConfig
|
|
|
|
*
|
|
|
|
* @property {string} image - [description]
|
|
|
|
* @property {number} offset.x - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
|
|
|
|
* @property {number} offset.y - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
|
|
|
|
* @property {number} width - The width of each character in the font set.
|
|
|
|
* @property {number} height - The height of each character in the font set.
|
|
|
|
* @property {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
|
|
|
|
* @property {number} charsPerRow - The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth.
|
|
|
|
* @property {number} spacing.x - If the characters in the font set have horizontal spacing between them set the required amount here.
|
|
|
|
* @property {number} spacing.y - If the characters in the font set have vertical spacing between them set the required amount here.
|
|
|
|
*/
|
2017-06-07 22:49:22 +00:00
|
|
|
|
2018-03-16 17:29:39 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-04-19 11:30:38 +00:00
|
|
|
* @function Phaser.GameObjects.BitmapText.ParseRetroFont
|
2018-03-16 17:29:39 +00:00
|
|
|
* @since 3.0.0
|
2018-04-19 11:30:38 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - A reference to the Phaser Scene.
|
|
|
|
* @param {Phaser.GameObjects.BitmapText.ParseRetroFont.RetroFontConfig} config - The font configuration object.
|
2018-03-16 17:29:39 +00:00
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
var ParseRetroFont = function (scene, config)
|
2017-06-07 22:49:22 +00:00
|
|
|
{
|
|
|
|
var w = config.width;
|
|
|
|
var h = config.height;
|
|
|
|
var cx = Math.floor(w / 2);
|
|
|
|
var cy = Math.floor(h / 2);
|
|
|
|
var letters = config.chars;
|
|
|
|
|
|
|
|
var key = GetValue(config, 'image', '');
|
|
|
|
var offsetX = GetValue(config, 'offset.x', 0);
|
|
|
|
var offsetY = GetValue(config, 'offset.y', 0);
|
|
|
|
var spacingX = GetValue(config, 'spacing.x', 0);
|
|
|
|
var spacingY = GetValue(config, 'spacing.y', 0);
|
|
|
|
|
|
|
|
var charsPerRow = GetValue(config, 'charsPerRow', null);
|
|
|
|
|
|
|
|
if (charsPerRow === null)
|
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
charsPerRow = scene.sys.textures.getFrame(key).width / w;
|
2017-06-28 00:50:34 +00:00
|
|
|
|
|
|
|
if (charsPerRow > letters.length)
|
|
|
|
{
|
|
|
|
charsPerRow = letters.length;
|
|
|
|
}
|
2017-06-07 22:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var x = offsetX;
|
|
|
|
var y = offsetY;
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
retroFont: true,
|
|
|
|
font: key,
|
|
|
|
size: w,
|
|
|
|
lineHeight: h,
|
|
|
|
chars: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var r = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < letters.length; i++)
|
|
|
|
{
|
2017-07-24 13:09:44 +00:00
|
|
|
// var node = letters[i];
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
var charCode = letters.charCodeAt(i);
|
|
|
|
|
|
|
|
data.chars[charCode] =
|
|
|
|
{
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
width: w,
|
|
|
|
height: h,
|
|
|
|
centerX: cx,
|
|
|
|
centerY: cy,
|
|
|
|
xOffset: 0,
|
|
|
|
yOffset: 0,
|
|
|
|
xAdvance: w,
|
2017-06-08 01:24:50 +00:00
|
|
|
data: {},
|
2017-06-07 22:49:22 +00:00
|
|
|
kerning: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
r++;
|
|
|
|
|
|
|
|
if (r === charsPerRow)
|
|
|
|
{
|
|
|
|
r = 0;
|
|
|
|
x = offsetX;
|
|
|
|
y += h + spacingY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x += w + spacingX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 13:09:44 +00:00
|
|
|
var entry = {
|
|
|
|
data: data,
|
|
|
|
frame: null,
|
|
|
|
texture: key
|
|
|
|
};
|
|
|
|
|
|
|
|
return entry;
|
2017-06-07 22:49:22 +00:00
|
|
|
};
|
|
|
|
|
2017-06-28 00:50:34 +00:00
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 1 = !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET1
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET1 = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET2
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET2 = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET3
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET4
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET4 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET5
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET5 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() \'!?-*:0123456789';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET6
|
|
|
|
* @type {string}
|
|
|
|
* /
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET6 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.\' ';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET7
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET7 = 'AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-\'39';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET8
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET8 = '0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET9
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET9 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,\'"?!';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET10
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET10 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-19 11:30:38 +00:00
|
|
|
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.BitmapText.ParseRetroFont.TEXT_SET11
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-02-16 18:17:51 +00:00
|
|
|
ParseRetroFont.TEXT_SET11 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()\':;0123456789';
|
2017-06-07 22:49:22 +00:00
|
|
|
|
|
|
|
module.exports = ParseRetroFont;
|