feat(io): welcome banner for game start
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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());
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user