diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/ConsoleIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/ConsoleIO.java index bce6c4d..dcd7a5a 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/ConsoleIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/ConsoleIO.java @@ -6,6 +6,8 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import thb.jeanluc.adventure.io.text.StyledText; + /** * {@link GameIO} backed by {@code System.in} and {@code System.out}. * Each {@code write} appends a newline so output blocks are visually @@ -51,7 +53,7 @@ public class ConsoleIO implements GameIO { } @Override - public void write(String s) { - out.println(s); + public void print(StyledText text) { + out.println(text.plainText()); } } diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java index b4b2ea2..3af5b09 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/GameIO.java @@ -1,24 +1,35 @@ package thb.jeanluc.adventure.io; +import thb.jeanluc.adventure.io.text.Hud; +import thb.jeanluc.adventure.io.text.Renderings; +import thb.jeanluc.adventure.io.text.RoomView; +import thb.jeanluc.adventure.io.text.StyledText; + /** - * Bidirectional text channel between the engine and the player. Implemented - * by both {@code ConsoleIO} and {@code SwingIO} so the game loop is agnostic - * to the actual interface. + * Bidirectional channel between the engine and the player. Commands emit + * semantic, role-styled output via {@link #print(StyledText)} (the primitive) + * and the {@link #showRoom}/{@link #setHud} views; each frontend renders them. */ public interface GameIO { - /** - * Blocks until a line of input is available. - * - * @return the next user input line, or an empty string at end of input - */ + /** Blocks until a line of input is available; empty string at end of input. */ String readLine(); - /** - * Writes a message to the player. Each call corresponds to one logical - * output block; the implementation handles line breaks at the boundary. - * - * @param s message text; must not be null - */ - void write(String s); + /** Renders one styled output block. The only method implementors must provide. */ + void print(StyledText text); + + /** Convenience: a plain, unstyled line. */ + default void write(String s) { + print(StyledText.of(s)); + } + + /** Renders a room. Default flattens via {@link Renderings}; renderers may override. */ + default void showRoom(RoomView room) { + print(Renderings.roomToStyledText(room)); + } + + /** Updates the status/HUD region. No-op by default; renderers may override. */ + default void setHud(Hud hud) { + // no-op + } } diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java index 70ec556..791e257 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java @@ -11,6 +11,8 @@ import java.awt.Color; import java.awt.Font; import java.util.concurrent.LinkedBlockingQueue; +import thb.jeanluc.adventure.io.text.StyledText; + /** * {@link GameIO} backed by a Swing window. A read-only output area shows * game text; a bottom text field collects player input. The input from @@ -79,7 +81,7 @@ public class SwingIO implements GameIO { } @Override - public void write(String s) { - SwingUtilities.invokeLater(() -> output.append(s + "\n")); + public void print(StyledText text) { + SwingUtilities.invokeLater(() -> output.append(text.plainText() + "\n")); } } diff --git a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TestIO.java b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TestIO.java index 7a8bacd..872c5b2 100644 --- a/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TestIO.java +++ b/Semesterprojekt/src/test/java/thb/jeanluc/adventure/io/TestIO.java @@ -36,7 +36,7 @@ public class TestIO implements GameIO { } @Override - public void write(String s) { - outputs.add(s); + public void print(thb.jeanluc.adventure.io.text.StyledText text) { + outputs.add(text.plainText()); } }