font-awesome-for-phaser 0.3.7 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/components/icon-text.d.ts +19 -3
- package/dist/components/icon-text.d.ts.map +1 -1
- package/dist/components/icon-text.js +34 -4
- package/dist/components/icon-text.js.map +1 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +1 -1
- package/dist/loader/load-font.d.ts.map +1 -1
- package/dist/loader/load-font.js +11 -2
- package/dist/loader/load-font.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -60,9 +60,16 @@ const iconText = scene.add.text(0, 0, char, {
|
|
|
60
60
|
color: '#ffffff',
|
|
61
61
|
});
|
|
62
62
|
iconText.setOrigin(0.5);
|
|
63
|
+
scene.add.existing(iconText);
|
|
63
64
|
|
|
64
65
|
// Or you can use our component
|
|
65
66
|
import { IconText } from 'font-awesome-for-phaser';
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
// PS: `this` is the scene
|
|
69
|
+
const icon = new IconText(this, 90, 90, 'gamepad', 64, {
|
|
70
|
+
color: '#0066cc',
|
|
71
|
+
});
|
|
72
|
+
this.add.existing(icon); // Don't forget to add in scene
|
|
68
73
|
```
|
|
74
|
+
|
|
75
|
+
<img src="data/image.png" alt="example of button">
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Phaser from 'phaser';
|
|
2
2
|
import { type IconKey } from '../constants/icons';
|
|
3
|
+
export type IconStyle = 'solid' | 'regular' | 'brands';
|
|
4
|
+
export type IconTextParams = {
|
|
5
|
+
scene: Phaser.Scene;
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
icon: IconKey;
|
|
9
|
+
size?: number;
|
|
10
|
+
style?: Phaser.Types.GameObjects.Text.TextStyle;
|
|
11
|
+
iconStyle?: IconStyle;
|
|
12
|
+
};
|
|
3
13
|
/**
|
|
4
14
|
* IconText is a Phaser Text GameObject that displays Font Awesome icons
|
|
5
15
|
* By default, the origin is set to (0.5, 0.5). To change it, use setOrigin() method
|
|
@@ -12,7 +22,13 @@ import { type IconKey } from '../constants/icons';
|
|
|
12
22
|
* @param style - Additional text style configuration options
|
|
13
23
|
*/
|
|
14
24
|
export declare class IconText extends Phaser.GameObjects.Text {
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
private currentIconStyle;
|
|
26
|
+
constructor({ scene, x, y, icon, size, style, iconStyle, }: IconTextParams);
|
|
27
|
+
setIcon(icon: IconKey, opts?: {
|
|
28
|
+
iconStyle?: IconStyle;
|
|
29
|
+
}): void;
|
|
30
|
+
setIconStyle(iconStyle: IconStyle): void;
|
|
31
|
+
getIconStyle(): IconStyle;
|
|
32
|
+
private applyIconStyle;
|
|
17
33
|
}
|
|
18
34
|
//# sourceMappingURL=icon-text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon-text.d.ts","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"icon-text.d.ts","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;IAChD,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,SAAQ,MAAM,CAAC,WAAW,CAAC,IAAI;IACnD,OAAO,CAAC,gBAAgB,CAAsB;gBAElC,EACV,KAAK,EACL,CAAC,EACD,CAAC,EACD,IAAI,EACJ,IAAS,EACT,KAAU,EACV,SAAmB,GACpB,EAAE,cAAc;IAWV,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,IAAI;IAO9D,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIxC,YAAY,IAAI,SAAS;IAIhC,OAAO,CAAC,cAAc;CAevB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Phaser from 'phaser';
|
|
1
2
|
import { getIconChar } from '../utils';
|
|
2
3
|
/**
|
|
3
4
|
* IconText is a Phaser Text GameObject that displays Font Awesome icons
|
|
@@ -11,13 +12,42 @@ import { getIconChar } from '../utils';
|
|
|
11
12
|
* @param style - Additional text style configuration options
|
|
12
13
|
*/
|
|
13
14
|
export class IconText extends Phaser.GameObjects.Text {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
currentIconStyle = 'solid';
|
|
16
|
+
constructor({ scene, x, y, icon, size = 16, style = {}, iconStyle = 'solid', }) {
|
|
17
|
+
super(scene, x, y, getIconChar(icon), {
|
|
18
|
+
fontSize: `${size}px`,
|
|
19
|
+
...style,
|
|
20
|
+
});
|
|
21
|
+
this.currentIconStyle = iconStyle;
|
|
22
|
+
this.applyIconStyle(this.currentIconStyle);
|
|
17
23
|
this.setOrigin(0.5, 0.5);
|
|
18
24
|
}
|
|
19
|
-
setIcon(icon) {
|
|
25
|
+
setIcon(icon, opts) {
|
|
20
26
|
this.setText(getIconChar(icon));
|
|
27
|
+
if (opts?.iconStyle) {
|
|
28
|
+
this.applyIconStyle(opts.iconStyle);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setIconStyle(iconStyle) {
|
|
32
|
+
this.applyIconStyle(iconStyle);
|
|
33
|
+
}
|
|
34
|
+
getIconStyle() {
|
|
35
|
+
return this.currentIconStyle;
|
|
36
|
+
}
|
|
37
|
+
applyIconStyle(iconStyle) {
|
|
38
|
+
// Font Awesome v7:
|
|
39
|
+
// - Free Regular (400) and Free Solid (900) share family "Font Awesome 6 Free"
|
|
40
|
+
// - Brands (400) uses family "Font Awesome 6 Brands"
|
|
41
|
+
if (iconStyle === 'brands') {
|
|
42
|
+
this.setFontFamily("'Font Awesome 7 Brands'");
|
|
43
|
+
this.setFontStyle('normal');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.setFontFamily("'Font Awesome 7 Free'");
|
|
47
|
+
// Use bold for solid, normal for regular. Bold maps to the closest available weight (900 for solid)
|
|
48
|
+
this.setFontStyle(iconStyle === 'solid' ? 'bold' : 'normal');
|
|
49
|
+
}
|
|
50
|
+
this.currentIconStyle = iconStyle;
|
|
21
51
|
}
|
|
22
52
|
}
|
|
23
53
|
//# sourceMappingURL=icon-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon-text.js","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"icon-text.js","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAcvC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,WAAW,CAAC,IAAI;IAC3C,gBAAgB,GAAc,OAAO,CAAC;IAE9C,YAAY,EACV,KAAK,EACL,CAAC,EACD,CAAC,EACD,IAAI,EACJ,IAAI,GAAG,EAAE,EACT,KAAK,GAAG,EAAE,EACV,SA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/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-font.d.ts","sourceRoot":"","sources":["../../src/loader/load-font.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"load-font.d.ts","sourceRoot":"","sources":["../../src/loader/load-font.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,IAAI,CAuBvC,CAAC"}
|
package/dist/loader/load-font.js
CHANGED
|
@@ -3,9 +3,18 @@ export const loadFont = () => {
|
|
|
3
3
|
return new Promise((resolve) => {
|
|
4
4
|
WebFont.load({
|
|
5
5
|
custom: {
|
|
6
|
-
families: [
|
|
6
|
+
families: [
|
|
7
|
+
'Font Awesome 7 Free',
|
|
8
|
+
'Font Awesome 7 Brands',
|
|
9
|
+
'Font Awesome 5 Brands',
|
|
10
|
+
'Font Awesome 5 Free',
|
|
11
|
+
'FontAwesome',
|
|
12
|
+
],
|
|
7
13
|
urls: [
|
|
8
|
-
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/
|
|
14
|
+
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css',
|
|
15
|
+
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/solid.min.css',
|
|
16
|
+
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/regular.min.css',
|
|
17
|
+
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/brands.min.css',
|
|
9
18
|
],
|
|
10
19
|
},
|
|
11
20
|
active: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-font.js","sourceRoot":"","sources":["../../src/loader/load-font.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAkB,EAAE;IAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAQ,EAAE;QACnC,OAAO,CAAC,IAAI,CAAC;YACX,MAAM,EAAE;gBACN,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"load-font.js","sourceRoot":"","sources":["../../src/loader/load-font.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,eAAe,CAAC;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAkB,EAAE;IAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAQ,EAAE;QACnC,OAAO,CAAC,IAAI,CAAC;YACX,MAAM,EAAE;gBACN,QAAQ,EAAE;oBACR,qBAAqB;oBACrB,uBAAuB;oBACvB,uBAAuB;oBACvB,qBAAqB;oBACrB,aAAa;iBACd;gBACD,IAAI,EAAE;oBACJ,2EAA2E;oBAC3E,6EAA6E;oBAC7E,+EAA+E;oBAC/E,8EAA8E;iBAC/E;aACF;YACD,MAAM,EAAE,GAAS,EAAE;gBACjB,OAAO,EAAE,CAAC;YACZ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "font-awesome-for-phaser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Font Awesome icons integration for Phaser games",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"homepage": "https://github.com/renatocassino/phaser-toolkit/tree/main/packages/font-awesome-for-phaser#readme",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint-recommended/eslint-config": "^28.0.0",
|
|
38
|
-
"@types/node": "^24.1
|
|
38
|
+
"@types/node": "^24.2.1",
|
|
39
39
|
"@types/webfontloader": "^1.6.38",
|
|
40
40
|
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
41
41
|
"@typescript-eslint/parser": "^6.15.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vitest": "^3.2.4"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"phaser": "
|
|
55
|
+
"phaser": "*"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"typecheck": "tsc --noEmit",
|
|
70
70
|
"lint": "eslint src --ext .ts,.tsx --max-warnings 0",
|
|
71
71
|
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
72
|
-
"lint:report": "eslint src --ext .ts,.tsx --format html --output-file eslint-report.html"
|
|
72
|
+
"lint:report": "eslint src --ext .ts,.tsx --format html --output-file eslint-report.html",
|
|
73
|
+
"validate": "pnpm run lint && pnpm run typecheck && pnpm run test && lint-staged"
|
|
73
74
|
}
|
|
74
75
|
}
|