Fix some stuff

This commit is contained in:
Minecon724 2024-10-04 20:21:08 +02:00
parent 0452e1f809
commit 903a61e39b
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -51,25 +51,28 @@ public class Renderer {
int textHeight = (int) bounds.getHeight();
y += textHeight;
int textLength = text.length();
String[] lines;
if (textWidth > tileSize) { // TODO ideally this should be splitting by word
int linesAmount = (int) Math.ceil((double) textWidth / tileSize);
if (linesAmount * textHeight > tileSize) {
int removeChars = (int) (text.length() - (text.length() / ((double) textWidth / tileSize)) * (tileSize / textHeight));
System.out.printf("Warning: text can't fit in a tile (%d > %d). Remove %d characters. \"%s\"\n", linesAmount * textHeight, tileSize, removeChars, text);
double tsd = tileSize;
int removeChars = (int) (textLength - (textLength / (textWidth / tsd)) * (tsd / textHeight));
System.out.printf("Warning: text doesn't fit in a tile (%d > %d). Remove %d characters. \"%s\"\n", linesAmount * textHeight, tileSize, removeChars, text);
}
lines = new String[linesAmount];
int partLength = text.length() / linesAmount;
int partLength = textLength / linesAmount;
for (int i=0; i<linesAmount; i++) {
lines[i] = text.substring(partLength * i, partLength * (i + 1));
}
// in case the ending was lost due to imprecise division
if (partLength * linesAmount < text.length()) {
if (partLength * linesAmount < textLength) {
lines[linesAmount - 1] += text.substring(partLength * linesAmount);
}
} else {