Skip to content

Commit

Permalink
🛠️ Fix #231
Browse files Browse the repository at this point in the history
The code was checking for an array with length > 1 instead of > 0. Oops!
  • Loading branch information
SnaveSutit committed Jul 20, 2024
1 parent 6782deb commit c70e4a8
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions src/systems/minecraft/fontManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,41 +376,41 @@ export class MinecraftFont {
const { lines, backgroundWidth } = await computeTextWrapping(words, maxLineWidth)
const width = backgroundWidth + 1
const height = lines.length * 10 + 1
// // Debug output
// const wordWidths = words.map(word => this.getWordWidth(word))
// for (const word of words) {
// console.log(
// `${words.indexOf(word)} '${word.text.toString()}' width: ${
// wordWidths[words.indexOf(word)]
// }`
// )
// for (const span of word.styles) {
// console.log(
// `'${word.text.slice(span.start, span.end).toString()}' ${span.start}-${
// span.end
// } = `,
// span.style
// )
// }
// }
// console.log('Lines:', lines, 'CanvasWidth:', canvasWidth)
// for (const line of lines) {
// console.log('Line', lines.indexOf(line), line.width)
// for (const word of line.words) {
// console.log(
// 'Word',
// line.words.indexOf(word),
// `'${word.text.toString()}'`,
// word.styles.map(span => span.style),
// word.styles.map(
// span =>
// `${span.start}-${span.end} '${word.text
// .slice(span.start, span.end)
// .toString()}'`
// )
// )
// }
// }
// Debug output
const wordWidths = words.map(word => this.getWordWidth(word))
for (const word of words) {
console.log(
`${words.indexOf(word)} '${word.text.toString()}' width: ${
wordWidths[words.indexOf(word)]
}`
)
for (const span of word.styles) {
console.log(
`'${word.text.slice(span.start, span.end).toString()}' ${span.start}-${
span.end
} = `,
span.style
)
}
}
console.log('Lines:', lines, 'CanvasWidth:', maxLineWidth)
for (const line of lines) {
console.log('Line', lines.indexOf(line), line.width)
for (const word of line.words) {
console.log(
'Word',
line.words.indexOf(word),
`'${word.text.toString()}'`,
word.styles.map(span => span.style),
word.styles.map(
span =>
`${span.start}-${span.end} '${word.text
.slice(span.start, span.end)
.toString()}'`
)
)
}
}

const backgroundGeo = new THREE.PlaneBufferGeometry(width, height)
const backgroundMesh = new THREE.Mesh(
Expand Down Expand Up @@ -438,7 +438,6 @@ export class MinecraftFont {
default:
cursor.x = -width / 2 + 1
}
// center the line
for (const word of line.words) {
for (const span of word.styles) {
const text = word.text.slice(span.start, span.end)
Expand All @@ -458,7 +457,7 @@ export class MinecraftFont {
}

let charGeo: THREE.BufferGeometry | undefined
if (geos.length > 1) {
if (geos.length > 0) {
charGeo = mergeGeometries(geos)!
const charMesh = new THREE.Mesh(
charGeo,
Expand Down

0 comments on commit c70e4a8

Please sign in to comment.