feat(ui): Font

This commit is contained in:
Jakub Žitník 2025-03-31 10:23:20 +02:00
parent 72e4594165
commit 6ece6d3096
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
5 changed files with 53 additions and 31 deletions

View File

@ -6,19 +6,10 @@ public class Font {
private final String[] lines = ResourceLoader.loadResource("ui/font.ans").split("\n");
private final int HEIGHT = 7;
public String getChar(char character, String color) {
if (character == ' ') {
return ("\033[49m ".repeat(12) + "\n").repeat(HEIGHT);
}
boolean upper = Character.isUpperCase(character);
int width = upper ? 14 : 12;
int startY = (upper ? 0 : 1) * HEIGHT;
int startX = (upper ? character - 'A' : character - 'a') * width;
private String get(int startY, int startX, int height, int width, String color) {
StringBuilder stringBuilder = new StringBuilder();
for (int y = startY; y < startY + HEIGHT; y++) {
for (int y = startY; y < startY + height; y++) {
String[] line = lines[y].split("\033");
for (int x = startX; x < startX + width - 1; x++) {
@ -31,6 +22,37 @@ public class Font {
return stringBuilder.toString();
}
private String getDigit(char digit, String color) {
int num = Integer.valueOf(digit);
int width = 12;
int startY = HEIGHT;
int left = 26 * width;
int startX = left + (num - '1') * width;
if (num == '0') {
startX = (26 + 9) * width;
}
return get(startY, startX, HEIGHT, width, color);
}
public String getChar(char character, String color) {
if (character == ' ') {
return ("\033[49m ".repeat(12) + "\n").repeat(HEIGHT);
}
if (Character.isDigit(character)) {
return getDigit(character, color);
}
boolean upper = Character.isUpperCase(character);
int width = upper ? 14 : 12;
int startY = (upper ? 0 : 1) * HEIGHT;
int startX = (upper ? character - 'A' : character - 'a') * width;
return get(startY, startX, HEIGHT, width, color);
}
public String getLine(String text) {
char[] chars = text.toCharArray();

View File

@ -91,10 +91,10 @@ public class InputHandlerThread extends Thread {
game.setWindow(Window.ESC);
}
screenRenderer.render(game);
System.out.println("Exiting game...");
isRunning[0] = false;
game.getGameStates().dependencies.gameSaver.save(game);
System.exit(0);
// System.out.println("Exiting game...");
// isRunning[0] = false;
// game.getGameStates().dependencies.gameSaver.save(game);
// System.exit(0);
}
default -> {
}

View File

@ -7,7 +7,7 @@ import cz.jzitnik.game.sprites.ui.Font;
public class Escape {
public static void render(StringBuilder buffer, Terminal terminal) {
Font font = new Font();
String character = font.getLine("Hello world");
String character = font.getLine("Never gonna give you up never gonna let you down");
buffer.append(character);
}

View File

@ -10,7 +10,7 @@
<!-- Max history (how many days to keep) -->
<maxHistory>30</maxHistory>
<!-- Total size cap -->
<totalSizeCap>500MB</totalSizeCap>
<totalSizeCap>100MB</totalSizeCap>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">

View File

@ -1,14 +1,14 @@