Skip to content

Commit

Permalink
fix(fonts): text not entirely visible
Browse files Browse the repository at this point in the history
  • Loading branch information
domi7777 committed Oct 12, 2024
1 parent 51c892c commit 20ff16d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const FontFamily = {
Material: 'Material', // source: https://fonts.google.com/icons
Arial: 'Arial',
Icons: 'Icons', // source: https://fonts.google.com/icons
Text: 'Courier',
}

export const loadFonts = async() => {
const newFontFace = new FontFace(FontFamily.Material, 'url(./fonts/material.woff2)');
const newFontFace = new FontFace(FontFamily.Icons, 'url(./fonts/material.woff2)');
document.fonts.add(newFontFace);
return newFontFace.load().catch(error => console.error(error));
}
3 changes: 1 addition & 2 deletions src/instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export const instrumentToSample: Record<Instrument, () => void> = {
}

export const playInstrument = (instrument: Instrument) => {
console.log(`Playing ${instrument}`);
try {
instrumentToSample[instrument]();
} catch(e){
} catch(e) {
console.error(`Error playing ${instrument}`, e);
resetAudioContext();
instrumentToSample[instrument]();
Expand Down
14 changes: 7 additions & 7 deletions src/scenes/ControlsScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ export class ControlsScene extends Phaser.Scene {
} = this.controls;
// reset fonts to initial icons
[recordText, stopText, playText].forEach(text => text
.setFontFamily(FontFamily.Material)
.setFontFamily(FontFamily.Icons)
.setText(text.getData('initial'))
.setColor(controlColors.idle));
const color = controlColors[this.controls.state];
switch (this.controls.state) {
case 'idle':
break;
case 'readyToRecord':
recordText.setFontFamily(FontFamily.Arial).setText('Hit a pad to start').setColor(color);
recordText.setFontFamily(FontFamily.Text).setText('Hit a pad to start').setColor(color);
break;
case 'recording':
recordText.setFontFamily(FontFamily.Material).setColor(color);
recordText.setFontFamily(FontFamily.Icons).setColor(color);
break;
case 'playing':
playText.setFontFamily(FontFamily.Material).setColor(color);
playText.setFontFamily(FontFamily.Icons).setColor(color);
break;
}
}
Expand All @@ -79,7 +79,7 @@ export class ControlsScene extends Phaser.Scene {

private addControlText(text: string) {
return this.add.text(0, 0, text, {
fontFamily: FontFamily.Material,
fontFamily: FontFamily.Icons,
fontSize: 20,
color: '#FFF',
align: 'center',
Expand Down Expand Up @@ -144,7 +144,7 @@ export class ControlsScene extends Phaser.Scene {
this.controls.state = 'idle';
this.updateControlsText();
console.log('No loop to play');
this.controls.play.text.setFontFamily(FontFamily.Arial).setText('No loop to play, record first');
this.controls.play.text.setFontFamily(FontFamily.Text).setText('Record first!');
this.time.delayedCall(2000, () => {
this.updateControlsText();
});
Expand All @@ -157,7 +157,7 @@ export class ControlsScene extends Phaser.Scene {

[stop, record, play].forEach(({button, text}, index) => {
button.setSize(buttonWidth, buttonHeight).setPosition(buttonWidth * index, -1);
text.setFontSize(buttonHeight / 2)
text.setFontSize(buttonHeight / 3)
.setWordWrapWidth(button.width, true)
.setSize(button.width, button.height)
.setPosition(button.getCenter().x, button.getCenter().y);
Expand Down

0 comments on commit 20ff16d

Please sign in to comment.