feat(io): travelStep hook for animated auto-walk (console no-op, Swing override)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 20:04:17 +02:00
parent 86e138223a
commit 62b7663e34
3 changed files with 43 additions and 0 deletions

View File

@@ -44,6 +44,17 @@ public interface GameIO {
// no-op
}
/**
* One frame of an auto-walk (the {@code go to} command), as the player moves
* through a room en route. Default is a no-op: text mode travels silently.
* The GUI overrides this to repaint the map and pace the animation.
*
* @param view the map snapshot at this step
*/
default void travelStep(MapView view) {
// no animation in text mode
}
/** On-demand map (the 'map' command). Default renders ASCII (Unicode frames). */
default void showMap(MapView view) {
print(AsciiMap.render(view, true));

View File

@@ -66,6 +66,9 @@ public class SwingIO implements GameIO {
/** Unscaled size for the HUD and side-panel font, in points. */
private static final float SMALL_SIZE = 12.5f;
/** Delay between rooms while animating a go-to auto-walk, in milliseconds. */
private static final long TRAVEL_STEP_MS = 300L;
/** Side-panel width as a fraction of the window width, clamped by the bounds below. */
private static final double SIDE_RATIO = 0.28;
private static final int SIDE_MIN = 180;
@@ -335,6 +338,16 @@ public class SwingIO implements GameIO {
map.show(view);
}
@Override
public void travelStep(MapView view) {
setMap(view);
try {
Thread.sleep(TRAVEL_STEP_MS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
@Override
public void setQuests(QuestView view) {
quests.show(view);

View File

@@ -0,0 +1,19 @@
package thb.jeanluc.adventure.io;
import org.junit.jupiter.api.Test;
import thb.jeanluc.adventure.io.text.MapView;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class TravelStepDefaultTest {
@Test
void defaultTravelStepIsSilentNoOp() {
TestIO io = new TestIO();
// An empty map view is fine; the default must not print or throw.
io.travelStep(new MapView(List.of(), List.of()));
assertThat(io.outputs()).isEmpty();
}
}