font-awesome-for-phaser 0.3.4
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 +68 -0
- package/dist/components/icon-text.d.ts +18 -0
- package/dist/components/icon-text.d.ts.map +1 -0
- package/dist/components/icon-text.js +23 -0
- package/dist/components/icon-text.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -0
- package/dist/constants/icons.d.ts +5197 -0
- package/dist/constants/icons.d.ts.map +1 -0
- package/dist/constants/icons.js +1736 -0
- package/dist/constants/icons.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/index.d.ts +2 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/index.js +2 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/load-font.d.ts +2 -0
- package/dist/loader/load-font.d.ts.map +1 -0
- package/dist/loader/load-font.js +17 -0
- package/dist/loader/load-font.js.map +1 -0
- package/dist/utils/__tests__/get-icon-char.test.d.ts +2 -0
- package/dist/utils/__tests__/get-icon-char.test.d.ts.map +1 -0
- package/dist/utils/__tests__/get-icon-char.test.js +25 -0
- package/dist/utils/__tests__/get-icon-char.test.js.map +1 -0
- package/dist/utils/__tests__/get-icon-hex.test.d.ts +2 -0
- package/dist/utils/__tests__/get-icon-hex.test.d.ts.map +1 -0
- package/dist/utils/__tests__/get-icon-hex.test.js +33 -0
- package/dist/utils/__tests__/get-icon-hex.test.js.map +1 -0
- package/dist/utils/convert-to-font-awesome.d.ts +9 -0
- package/dist/utils/convert-to-font-awesome.d.ts.map +1 -0
- package/dist/utils/convert-to-font-awesome.js +14 -0
- package/dist/utils/convert-to-font-awesome.js.map +1 -0
- package/dist/utils/get-icon-char.d.ts +3 -0
- package/dist/utils/get-icon-char.d.ts.map +1 -0
- package/dist/utils/get-icon-char.js +9 -0
- package/dist/utils/get-icon-char.js.map +1 -0
- package/dist/utils/get-icon-hex.d.ts +3 -0
- package/dist/utils/get-icon-hex.d.ts.map +1 -0
- package/dist/utils/get-icon-hex.js +8 -0
- package/dist/utils/get-icon-hex.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Font Awesome for Phaser
|
2
|
+
|
3
|
+
Utilitários e tipos principais para desenvolvimento de jogos com Phaser.
|
4
|
+
|
5
|
+
## 📦 Instalação
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install font-awesome-for-phaser
|
9
|
+
# or
|
10
|
+
pnpm add font-awesome-for-phaser
|
11
|
+
# or
|
12
|
+
yarn add font-awesome-for-phaser
|
13
|
+
```
|
14
|
+
|
15
|
+
## 🚀 Add to your project
|
16
|
+
|
17
|
+
First, you must have the free font awesome imported in your page.
|
18
|
+
|
19
|
+
```html
|
20
|
+
<style>
|
21
|
+
@import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css';
|
22
|
+
</style>
|
23
|
+
```
|
24
|
+
|
25
|
+
Or, you can use our auto import
|
26
|
+
|
27
|
+
```typescript
|
28
|
+
import { loadFont } from 'font-awesome-for-phaser';
|
29
|
+
|
30
|
+
loadFont().then(() => {
|
31
|
+
const config: Phaser.Types.Core.GameConfig = {
|
32
|
+
// .....
|
33
|
+
};
|
34
|
+
new Game(config);
|
35
|
+
});
|
36
|
+
|
37
|
+
// or
|
38
|
+
async function startGame() {
|
39
|
+
await loadFont();
|
40
|
+
|
41
|
+
const config: Phaser.Types.Core.GameConfig = {
|
42
|
+
// .....
|
43
|
+
};
|
44
|
+
new Game(config);
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
You can use Font Awesome icons in your Phaser game in two ways:
|
51
|
+
|
52
|
+
### Using icon as text
|
53
|
+
|
54
|
+
```typescript
|
55
|
+
import { getIconChar } from 'font-awesome-for-phaser';
|
56
|
+
|
57
|
+
// .....
|
58
|
+
const iconText = scene.add.text(0, 0, char, {
|
59
|
+
font: `36px 'FontAwesome'`, // IMPORTANT! The name of the font MUST BE between char ('), if you use `font: '36px FontAwesome', won't work
|
60
|
+
color: '#ffffff',
|
61
|
+
});
|
62
|
+
iconText.setOrigin(0.5);
|
63
|
+
|
64
|
+
// Or you can use our component
|
65
|
+
import { IconText } from 'font-awesome-for-phaser';
|
66
|
+
|
67
|
+
const iconText = new IconText(this, 10, 10, 'facebook', { fontSize: 42 });
|
68
|
+
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Scene } from 'phaser';
|
2
|
+
import { type IconKey } from '../constants/icons';
|
3
|
+
/**
|
4
|
+
* IconText is a Phaser Text GameObject that displays Font Awesome icons
|
5
|
+
* By default, the origin is set to (0.5, 0.5). To change it, use setOrigin() method
|
6
|
+
*
|
7
|
+
* @param scene - The Scene to which this IconText belongs
|
8
|
+
* @param x - The horizontal position of this IconText in the world
|
9
|
+
* @param y - The vertical position of this IconText in the world
|
10
|
+
* @param icon - The Font Awesome icon key to display
|
11
|
+
* @param size - The font size in pixels (default: 16)
|
12
|
+
* @param style - Additional text style configuration options
|
13
|
+
*/
|
14
|
+
export declare class IconText extends Phaser.GameObjects.Text {
|
15
|
+
constructor(scene: Scene, x: number, y: number, icon: IconKey, size?: number, style?: Phaser.Types.GameObjects.Text.TextStyle);
|
16
|
+
setIcon(icon: IconKey): void;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=icon-text.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"icon-text.d.ts","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,SAAQ,MAAM,CAAC,WAAW,CAAC,IAAI;gBAEjD,KAAK,EAAE,KAAK,EACZ,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,OAAO,EACb,IAAI,GAAE,MAAW,EACjB,KAAK,GAAE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,SAAc;IAO9C,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;CAGpC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { getIconChar } from '../utils';
|
2
|
+
/**
|
3
|
+
* IconText is a Phaser Text GameObject that displays Font Awesome icons
|
4
|
+
* By default, the origin is set to (0.5, 0.5). To change it, use setOrigin() method
|
5
|
+
*
|
6
|
+
* @param scene - The Scene to which this IconText belongs
|
7
|
+
* @param x - The horizontal position of this IconText in the world
|
8
|
+
* @param y - The vertical position of this IconText in the world
|
9
|
+
* @param icon - The Font Awesome icon key to display
|
10
|
+
* @param size - The font size in pixels (default: 16)
|
11
|
+
* @param style - Additional text style configuration options
|
12
|
+
*/
|
13
|
+
export class IconText extends Phaser.GameObjects.Text {
|
14
|
+
constructor(scene, x, y, icon, size = 16, style = {}) {
|
15
|
+
super(scene, x, y, getIconChar(icon), { fontSize: `${size}px`, ...style });
|
16
|
+
this.setFontFamily("'FontAwesome'");
|
17
|
+
this.setOrigin(0.5, 0.5);
|
18
|
+
}
|
19
|
+
setIcon(icon) {
|
20
|
+
this.setText(getIconChar(icon));
|
21
|
+
}
|
22
|
+
}
|
23
|
+
//# sourceMappingURL=icon-text.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"icon-text.js","sourceRoot":"","sources":["../../src/components/icon-text.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,WAAW,CAAC,IAAI;IACnD,YACE,KAAY,EACZ,CAAS,EACT,CAAS,EACT,IAAa,EACb,OAAe,EAAE,EACjB,QAAiD,EAAE;QAEnD,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,IAAI,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,CAAC,IAAa;QAC1B,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAClC,CAAC;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|