Skip to content

Commit

Permalink
Untested fnt format preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
hubol committed Jan 15, 2024
1 parent 5c4428a commit e882587
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib/pixi/create-bitmap-font-factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { BitmapFont, Texture } from "pixi.js";

export async function createBitmapFontFactory(fntUrl: string) {
const fntData = await fetch(fntUrl).then(x => x.text());
const fntData = await fetch(fntUrl).then(x => x.text()).then(preprocessFntText);

return (texture: Texture) => BitmapFont.install(fntData, texture);
}
}

const atSignRegex = /(?:@(.))/gm;
const atSignSubstitution = (_: string, y: string) => String(y.charCodeAt(0));

// Allows writing e.g. @a and replacing with 97
function preprocessFntText(fntText: string) {
if (!fntText.includes("info NeedsPreprocessing"))
return fntText;
return fntText.replace(atSignRegex, atSignSubstitution)
}

0 comments on commit e882587

Please sign in to comment.