Skip to content

Commit

Permalink
fix: incomplete types for options in ex.FontSource.toFont() (#2973)
Browse files Browse the repository at this point in the history
- Fixed incomplete types for font options in `ex.FontSource().toFont(options)`
  • Loading branch information
mattjennings authored Mar 18, 2024
1 parent c0d04e8 commit 3aeed07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed incomplete types for font options in `ex.FontSource().toFont(options)`
- Fixed issue with `ex.Loader` start button position when using CSS transforms
- Fixed issue where adding scenes with the same name did not work when it was previously removed
- Fixed issue when WebGL context lost occurs where there was no friendly output to the user
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Resources/Font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class FontSource implements Loadable<FontFace> {
* Build a font from this FontSource.
* @param options {FontOptions} Override the font options
*/
toFont(options?: FontOptions): Font {
toFont(options?: FontOptions & GraphicOptions & RasterOptions): Font {
return new Font({ family: this.family, ...this._options, ...options });
}
}
8 changes: 6 additions & 2 deletions src/spec/FontSourceSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ describe('A FontSource', () => {

it('will use options from FontSource', async () => {
const fontSource = new ex.FontSource('src/spec/fonts/Gorgeous Pixel.ttf', 'Gorgeous Pixel', {
size: 50
size: 50,
color: ex.Color.Red
});

await fontSource.load();
const font = fontSource.toFont();

expect(font.size).toBe(50);
expect(font.color.toString()).toBe(ex.Color.Red.toString());
});

it('will override options when converting to a Font', async () => {
Expand All @@ -54,11 +56,13 @@ describe('A FontSource', () => {

await fontSource.load();
const font = fontSource.toFont({
size: 100
size: 100,
color: ex.Color.Red
});

expect(font.size).toBe(100);
expect(font.opacity).toBe(0.5);
expect(font.color.toString()).toBe(ex.Color.Red.toString());
});

it('will resolve the font if already loaded', async () => {
Expand Down

0 comments on commit 3aeed07

Please sign in to comment.