Skip to content

Commit acae215

Browse files
committed
♻️ Update fontManager.ts to handle new node configs
1 parent 55a41e6 commit acae215

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/systems/minecraft-temp/fontManager.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import MissingCharacter from '@assets/missing_character.png'
22
import EVENTS from '@events'
33
import { createHash } from 'crypto'
4-
import { type Alignment } from '../../blockbench-additions/outliner-elements/textDisplay'
54
import { mergeGeometries } from '../../util/bufferGeometryUtils'
65
import { getPathFromResourceLocation } from '../../util/minecraftUtil'
76
import { UnicodeString } from '../../util/unicodeString'
7+
import type { TextDisplayConfig } from '../node-configs'
88
import * as assets from './assetManager'
99
import { COLOR_MAP, JsonText } from './jsonText'
1010
import {
@@ -354,27 +354,21 @@ export class MinecraftFont {
354354
}
355355

356356
async generateTextMesh({
357-
jsonText,
358-
maxLineWidth,
357+
textComponent,
358+
lineWidth,
359359
backgroundColor,
360-
backgroundAlpha,
361360
shadow,
362361
alignment,
363-
}: {
364-
jsonText: JsonText
365-
maxLineWidth: number
366-
backgroundColor: string
367-
backgroundAlpha: number
368-
shadow?: boolean
369-
alignment?: Alignment
370-
}): Promise<{ mesh: THREE.Mesh; outline: THREE.LineSegments }> {
362+
}: Required<TextDisplayConfig>): Promise<{ mesh: THREE.Mesh; outline: THREE.LineSegments }> {
371363
console.time('drawTextToMesh')
372364
const mesh = new THREE.Mesh()
373365

366+
const jsonText = new JsonText(textComponent)
374367
const words = getComponentWords(jsonText)
375-
const { lines, backgroundWidth } = await computeTextWrapping(words, maxLineWidth)
368+
const { lines, backgroundWidth } = await computeTextWrapping(words, lineWidth)
376369
const width = backgroundWidth + 1
377370
const height = lines.length * 10 + 1
371+
378372
// // Debug output
379373
// const wordWidths = words.map(word => this.getWordWidth(word))
380374
// for (const word of words) {
@@ -392,7 +386,7 @@ export class MinecraftFont {
392386
// )
393387
// }
394388
// }
395-
// console.log('Lines:', lines, 'CanvasWidth:', maxLineWidth)
389+
// console.log('Lines:', lines, 'CanvasWidth:', lineWidth)
396390
// for (const line of lines) {
397391
// console.log('Line', lines.indexOf(line), line.width)
398392
// for (const word of line.words) {
@@ -411,11 +405,15 @@ export class MinecraftFont {
411405
// }
412406
// }
413407

408+
const color = tinycolor(backgroundColor)
409+
const backgroundHex = color.toHexString()
410+
const backgroundAlpha = color.getAlpha()
411+
414412
const backgroundGeo = new THREE.PlaneBufferGeometry(width, height)
415413
const backgroundMesh = new THREE.Mesh(
416414
backgroundGeo,
417415
new THREE.MeshBasicMaterial({
418-
color: backgroundColor,
416+
color: backgroundHex,
419417
transparent: true,
420418
opacity: backgroundAlpha,
421419
})
@@ -535,6 +533,7 @@ export class MinecraftFont {
535533
if (style.underlined) hash.update('underlined')
536534
if (style.strikethrough) hash.update('strikethrough')
537535
if (style.font) hash.update(';' + font.id)
536+
// I'm not rendering this...
538537
// if (style.obfuscated) hash.update('obfuscated')
539538
const digest = hash.digest('hex')
540539

0 commit comments

Comments
 (0)