feat(io): welcome banner for game start

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 20:22:59 +02:00
parent 963ddfb89e
commit 650bbbe58c
3 changed files with 35 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import thb.jeanluc.adventure.game.Game;
import thb.jeanluc.adventure.game.GameContext; import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.io.ConsoleIO; import thb.jeanluc.adventure.io.ConsoleIO;
import thb.jeanluc.adventure.io.GameIO; import thb.jeanluc.adventure.io.GameIO;
import thb.jeanluc.adventure.io.text.Banner;
import thb.jeanluc.adventure.loader.WorldLoader; import thb.jeanluc.adventure.loader.WorldLoader;
/** /**
@@ -77,7 +78,7 @@ public final class App {
Game game = new Game(ctx, registry, new CommandParser()); Game game = new Game(ctx, registry, new CommandParser());
quit.bind(game); quit.bind(game);
io.write(loaded.world().getTitle()); io.print(Banner.welcome(loaded.world().getTitle()));
io.write(loaded.world().getWelcomeMessage()); io.write(loaded.world().getWelcomeMessage());
new LookCommand().execute(ctx, java.util.List.of()); new LookCommand().execute(ctx, java.util.List.of());

View File

@@ -0,0 +1,18 @@
package thb.jeanluc.adventure.io.text;
/** Builds styled banners for big moments (game start, finale). */
public final class Banner {
private Banner() {
}
/** A framed, heading-styled welcome banner for the given title. */
public static StyledText welcome(String title) {
String bar = "=".repeat(Math.max(8, title.length() + 8));
return StyledText.builder()
.heading(bar + "\n")
.heading(" " + title + "\n")
.heading(bar)
.build();
}
}

View File

@@ -0,0 +1,15 @@
package thb.jeanluc.adventure.io.text;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class BannerTest {
@Test
void welcome_containsTitleAsHeading() {
StyledText b = Banner.welcome("Haunted Manor");
assertThat(b.plainText()).contains("Haunted Manor");
boolean hasHeading = b.spans().stream().anyMatch(s -> s.style() == Style.HEADING);
assertThat(hasHeading).isTrue();
}
}