Implement locale font loading

Revert multiple font usage from style fe7fe845
Dynamic font loading on language changed
pull/737/head
Mr.WaterT 2024-05-15 12:35:28 +09:00
parent 0591da443a
commit bc7c6b763d
6 changed files with 29 additions and 9 deletions

View File

@ -19,10 +19,6 @@
font-family: 'emerald'; font-family: 'emerald';
src: url('./fonts/pokemon-emerald-pro.ttf') format('truetype'); src: url('./fonts/pokemon-emerald-pro.ttf') format('truetype');
} }
@font-face {
font-family: 'dppt';
src: url('./fonts/pokemon-dppt.ttf') format('truetype');
}
@font-face { @font-face {
font-family: 'pkmnems'; font-family: 'pkmnems';

View File

@ -307,7 +307,7 @@ export class LoadingScene extends SceneBase {
y: height / 2 - 24, y: height / 2 - 24,
text: '0%', text: '0%',
style: { style: {
font: "72px emerald, dppt", font: "72px emerald",
color: "#ffffff", color: "#ffffff",
}, },
}); });
@ -318,7 +318,7 @@ export class LoadingScene extends SceneBase {
y: height / 2 + 48, y: height / 2 + 48,
text: "", text: "",
style: { style: {
font: "48px emerald, dppt", font: "48px emerald",
color: "#ffffff", color: "#ffffff",
}, },
}); });

View File

@ -91,7 +91,7 @@ Phaser.GameObjects.Text.prototype.setPositionRelative = setPositionRelative;
BBCodeText.prototype.setPositionRelative = setPositionRelative; BBCodeText.prototype.setPositionRelative = setPositionRelative;
Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative; Phaser.GameObjects.Rectangle.prototype.setPositionRelative = setPositionRelative;
document.fonts.load('16px emerald, dppt').then(() => document.fonts.load('10px pkmnems')); document.fonts.load('16px emerald').then(() => document.fonts.load('10px pkmnems'));
let game; let game;

View File

@ -36,12 +36,36 @@ export interface Localizable {
localize(): void; localize(): void;
} }
const alternativeFonts = {
'ko': [
new FontFace("emerald", "url(./fonts/pokemon-dppt.ttf)")
],
}
function loadFont(language: string) {
Object.keys(alternativeFonts).forEach(l => {
if (language == l) {
alternativeFonts[l].forEach(f=> { document.fonts.add(f); });
}
else {
alternativeFonts[l].forEach(f=> {
if (f && f.status == "loaded") { document.fonts.delete(f); }
});
}
});
}
export function initI18n(): void { export function initI18n(): void {
let lang = ''; let lang = '';
if (localStorage.getItem('prLang')) if (localStorage.getItem('prLang'))
lang = localStorage.getItem('prLang'); lang = localStorage.getItem('prLang');
loadFont(lang);
i18next.on("languageChanged", lng=> {
loadFont(lng);
});
/** /**
* i18next is a localization library for maintaining and using translation resources. * i18next is a localization library for maintaining and using translation resources.
* *

View File

@ -144,7 +144,7 @@ export default abstract class MessageUiHandler extends AwaitableUiHandler {
const wrappedTextLines = this.message.runWordWrap(this.message.text).split(/\n/g); const wrappedTextLines = this.message.runWordWrap(this.message.text).split(/\n/g);
const textLinesCount = wrappedTextLines.length; const textLinesCount = wrappedTextLines.length;
const lastTextLine = wrappedTextLines[wrappedTextLines.length - 1]; const lastTextLine = wrappedTextLines[wrappedTextLines.length - 1];
const lastLineTest = this.scene.add.text(0, 0, lastTextLine, { font: '96px emerald, dppt' }); const lastLineTest = this.scene.add.text(0, 0, lastTextLine, { font: '96px emerald' });
lastLineTest.setScale(this.message.scale); lastLineTest.setScale(this.message.scale);
const lastLineWidth = lastLineTest.displayWidth; const lastLineWidth = lastLineTest.displayWidth;
lastLineTest.destroy(); lastLineTest.destroy();

View File

@ -68,7 +68,7 @@ function getTextStyleOptions(style: TextStyle, uiTheme: UiTheme, extraStyleOptio
let shadowSize = 6; let shadowSize = 6;
let styleOptions: Phaser.Types.GameObjects.Text.TextStyle = { let styleOptions: Phaser.Types.GameObjects.Text.TextStyle = {
fontFamily: 'emerald, dppt', fontFamily: 'emerald',
fontSize: '96px', fontSize: '96px',
color: getTextColor(style, false, uiTheme), color: getTextColor(style, false, uiTheme),
padding: { padding: {