Skip to content

Commit e5f5b55

Browse files
committed
Added Retro Font to BitmapText convertor
1 parent 9244b27 commit e5f5b55

5 files changed

Lines changed: 184 additions & 12 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '43bc4e80-47b0-11e7-88ab-6b6b368a5071'
2+
build: '6119e880-4bd3-11e7-aa12-bf3ba1adff6e'
33
};
44
module.exports = CHECKSUM;
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
var GetValue = require('../../utils/object/GetValue');
2+
3+
// * @param {number} characterWidth - The width of each character in the font set.
4+
// * @param {number} characterHeight - The height of each character in the font set.
5+
// * @param {string} chars - The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
6+
// * @param {number} [charsPerRow] - The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth.
7+
// * @param {number} [xSpacing=0] - If the characters in the font set have horizontal spacing between them set the required amount here.
8+
// * @param {number} [ySpacing=0] - If the characters in the font set have vertical spacing between them set the required amount here.
9+
// * @param {number} [xOffset=0] - If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
10+
// * @param {number} [yOffset=0] - If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
11+
// Phaser.GameObject.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset)
12+
13+
// {
14+
// image: key,
15+
// width: 32,
16+
// height: 32,
17+
// chars: 'string',
18+
// charsPerRow: null,
19+
// spacing: { x: 0, y: 0 },
20+
// offset: { x: 0, y: 0 }
21+
// }
22+
23+
var ParseRetroFont = function (state, config)
24+
{
25+
var w = config.width;
26+
var h = config.height;
27+
var cx = Math.floor(w / 2);
28+
var cy = Math.floor(h / 2);
29+
var letters = config.chars;
30+
31+
var key = GetValue(config, 'image', '');
32+
var offsetX = GetValue(config, 'offset.x', 0);
33+
var offsetY = GetValue(config, 'offset.y', 0);
34+
var spacingX = GetValue(config, 'spacing.x', 0);
35+
var spacingY = GetValue(config, 'spacing.y', 0);
36+
37+
var charsPerRow = GetValue(config, 'charsPerRow', null);
38+
39+
if (charsPerRow === null)
40+
{
41+
charsPerRow = state.sys.textures.getFrame(key).width / w;
42+
}
43+
44+
var x = offsetX;
45+
var y = offsetY;
46+
47+
var data = {
48+
retroFont: true,
49+
font: key,
50+
size: w,
51+
lineHeight: h,
52+
chars: {}
53+
};
54+
55+
var r = 0;
56+
57+
for (var i = 0; i < letters.length; i++)
58+
{
59+
var node = letters[i];
60+
61+
var charCode = letters.charCodeAt(i);
62+
63+
data.chars[charCode] =
64+
{
65+
x: x,
66+
y: y,
67+
width: w,
68+
height: h,
69+
centerX: cx,
70+
centerY: cy,
71+
xOffset: 0,
72+
yOffset: 0,
73+
xAdvance: w,
74+
kerning: {}
75+
};
76+
77+
r++;
78+
79+
if (r === charsPerRow)
80+
{
81+
r = 0;
82+
x = offsetX;
83+
y += h + spacingY;
84+
}
85+
else
86+
{
87+
x += w + spacingX;
88+
}
89+
}
90+
91+
return data;
92+
};
93+
94+
ParseRetroFont.TEXT_SET1 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
95+
96+
/**
97+
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
98+
* @constant
99+
* @type {string}
100+
*/
101+
ParseRetroFont.TEXT_SET2 = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ";
102+
103+
/**
104+
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
105+
* @constant
106+
* @type {string}
107+
*/
108+
ParseRetroFont.TEXT_SET3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
109+
110+
/**
111+
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
112+
* @constant
113+
* @type {string}
114+
*/
115+
ParseRetroFont.TEXT_SET4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
116+
117+
/**
118+
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
119+
* @constant
120+
* @type {string}
121+
*/
122+
ParseRetroFont.TEXT_SET5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789";
123+
124+
/**
125+
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
126+
* @constant
127+
* @type {string}
128+
*/
129+
ParseRetroFont.TEXT_SET6 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789\"(),-.' ";
130+
131+
/**
132+
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
133+
* @constant
134+
* @type {string}
135+
*/
136+
ParseRetroFont.TEXT_SET7 = "AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW\")28FLRX-'39";
137+
138+
/**
139+
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
140+
* @constant
141+
* @type {string}
142+
*/
143+
ParseRetroFont.TEXT_SET8 = "0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ";
144+
145+
/**
146+
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
147+
* @constant
148+
* @type {string}
149+
*/
150+
ParseRetroFont.TEXT_SET9 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'\"?!";
151+
152+
/**
153+
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
154+
* @constant
155+
* @type {string}
156+
*/
157+
ParseRetroFont.TEXT_SET10 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
158+
159+
/**
160+
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
161+
* @constant
162+
* @type {string}
163+
*/
164+
ParseRetroFont.TEXT_SET11 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\"-+!?()':;0123456789";
165+
166+
module.exports = ParseRetroFont;

v3/src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var GameObject = require('../../GameObject');
33
var Components = require('../../../components');
44
var Render = require('./BitmapTextRender');
55
var GetBitmapTextSize = require('../GetBitmapTextSize');
6+
var ParseRetroFont = require('../ParseRetroFont');
67

78
var BitmapText = new Class({
89

@@ -13,6 +14,7 @@ var BitmapText = new Class({
1314
Components.BlendMode,
1415
Components.Origin,
1516
Components.RenderTarget,
17+
Components.ScaleMode,
1618
Components.Size,
1719
Components.Texture,
1820
Components.Transform,
@@ -25,7 +27,6 @@ var BitmapText = new Class({
2527
function BitmapText (state, x, y, font, text, size, align)
2628
{
2729
if (text === undefined) { text = ''; }
28-
if (size === undefined) { size = 32; }
2930
if (align === undefined) { align = 'left'; }
3031

3132
GameObject.call(this, state, 'BitmapText');
@@ -35,7 +36,7 @@ var BitmapText = new Class({
3536

3637
this.text = text;
3738

38-
this.fontSize = size;
39+
this.fontSize = size || this.fontData.size;
3940

4041
this.setTexture(font);
4142
this.setPosition(x, y);
@@ -98,4 +99,6 @@ var BitmapText = new Class({
9899

99100
});
100101

102+
BitmapText.ParseRetroFont = ParseRetroFont;
103+
101104
module.exports = BitmapText;

v3/src/phaser.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@ var Phaser = {
4242

4343
Class: require('./utils/Class'),
4444

45-
Utils: {
46-
47-
Align: require('./utils/align/'),
48-
Array: require('./utils/array/'),
49-
Bounds: require('./utils/bounds/'),
50-
Objects: require('./utils/object/'),
51-
String: require('./utils/string/')
52-
53-
}
45+
Utils: require('./utils')
5446

5547
};
5648

v3/src/utils/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Phaser.Utils
2+
3+
module.exports = {
4+
5+
Align: require('./align/'),
6+
Array: require('./array/'),
7+
Bounds: require('./bounds/'),
8+
Objects: require('./object/'),
9+
String: require('./string/')
10+
11+
};

0 commit comments

Comments
 (0)