fix(board): make readable signs glow
This commit is contained in:
@@ -89,6 +89,34 @@ final class BukkitPhysicalBoardWorldTest {
|
||||
assertFalse(adapter.matches(placement, BoardFacing.SOUTH));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readableSignsGlowWhileDecorativeSignsDoNot() {
|
||||
UUID worldId = UUID.randomUUID();
|
||||
BoardId location = new BoardId(worldId, 1, 65, 2);
|
||||
World world = mock(World.class);
|
||||
Block block = mock(Block.class);
|
||||
WallSign wallSign = mock(WallSign.class);
|
||||
Sign sign = mock(Sign.class);
|
||||
SignSide signSide = mock(SignSide.class);
|
||||
when(world.getUID()).thenReturn(worldId);
|
||||
when(world.getBlockAt(1, 65, 2)).thenReturn(block);
|
||||
when(block.getBlockData()).thenReturn(wallSign);
|
||||
when(block.getState()).thenReturn(sign);
|
||||
when(sign.getSide(Side.FRONT)).thenReturn(signSide);
|
||||
when(sign.update(true, false)).thenReturn(true);
|
||||
BukkitPhysicalBoardWorld adapter = new BukkitPhysicalBoardWorld(world);
|
||||
|
||||
adapter.place(new PhysicalBoardPlan.Placement(
|
||||
location, "OAK_WALL_SIGN", PhysicalBoardSignKind.TITLE
|
||||
), BoardFacing.NORTH);
|
||||
verify(signSide).setGlowingText(true);
|
||||
|
||||
adapter.place(new PhysicalBoardPlan.Placement(
|
||||
location, "OAK_WALL_SIGN", PhysicalBoardSignKind.DECORATIVE
|
||||
), BoardFacing.NORTH);
|
||||
verify(signSide).setGlowingText(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rendersReadableTitleAndInstructionText() {
|
||||
assertEquals(
|
||||
|
||||
@@ -35,6 +35,33 @@ final class PhysicalBoardUpgraderTest {
|
||||
assertEquals(2, world.placed.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void refreshesBothReadableSignsOnAnExactRegisteredFullBoard() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(fullRegistrations(), false);
|
||||
BoardRegistry registry = new BoardRegistry(repository);
|
||||
FakeWorld world = fullWorld(false);
|
||||
|
||||
assertEquals(1, upgrader(registry, world).upgrade());
|
||||
|
||||
assertEquals(17, registry.size());
|
||||
assertEquals(0, repository.saves);
|
||||
assertEquals(Set.of(PhysicalBoardSignKind.TITLE, PhysicalBoardSignKind.INSTRUCTION),
|
||||
world.placed.values().stream().map(PhysicalBoardPlan.Placement::signKind)
|
||||
.collect(Collectors.toSet()));
|
||||
assertTrue(newSigns().stream().allMatch(sign -> world.glowing.get(sign.location())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotReportOrRefreshAnAlreadyGlowingFullBoard() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(fullRegistrations(), false);
|
||||
FakeWorld world = fullWorld(true);
|
||||
|
||||
assertEquals(0, upgrader(new BoardRegistry(repository), world).upgrade());
|
||||
|
||||
assertTrue(world.placed.isEmpty());
|
||||
assertEquals(0, repository.saves);
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotAlterCustomBoardsOrStructuresThatDoNotExactlyMatch() throws Exception {
|
||||
RegisteredBoard custom = new RegisteredBoard(
|
||||
@@ -58,6 +85,23 @@ final class PhysicalBoardUpgraderTest {
|
||||
assertTrue(changedWorld.placed.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotRefreshAFullBoardWithCustomSignText() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(fullRegistrations(), false);
|
||||
FakeWorld world = fullWorld(false);
|
||||
PhysicalBoardPlan.Placement title = newSigns().stream()
|
||||
.filter(sign -> sign.signKind() == PhysicalBoardSignKind.TITLE)
|
||||
.findFirst().orElseThrow();
|
||||
world.existing.put(title.location(), new PhysicalBoardPlan.Placement(
|
||||
title.location(), title.material(), PhysicalBoardSignKind.INSTRUCTION
|
||||
));
|
||||
|
||||
assertEquals(0, upgrader(new BoardRegistry(repository), world).upgrade());
|
||||
|
||||
assertTrue(world.placed.isEmpty());
|
||||
assertTrue(newSigns().stream().noneMatch(sign -> world.glowing.get(sign.location())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotOverwriteAnOccupiedNewSignCell() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(legacyRegistrations(), false);
|
||||
@@ -89,6 +133,19 @@ final class PhysicalBoardUpgraderTest {
|
||||
assertEquals(0, repository.saves);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollsBackBothReadableSignsWhenFullBoardRefreshFails() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(fullRegistrations(), false);
|
||||
FakeWorld world = fullWorld(false);
|
||||
world.failPlacement = 1;
|
||||
|
||||
assertThrows(IOException.class,
|
||||
() -> upgrader(new BoardRegistry(repository), world).upgrade());
|
||||
|
||||
assertTrue(newSigns().stream().noneMatch(sign -> world.glowing.get(sign.location())));
|
||||
assertEquals(0, repository.saves);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollsBackBothCellsWhenAtomicPersistenceFails() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(legacyRegistrations(), true);
|
||||
@@ -120,6 +177,12 @@ final class PhysicalBoardUpgraderTest {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static Set<RegisteredBoard> fullRegistrations() {
|
||||
return plan().interactionLocations().stream()
|
||||
.map(location -> new RegisteredBoard(location, "survival"))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static FakeWorld legacyWorld() {
|
||||
FakeWorld world = new FakeWorld();
|
||||
plan().placements().stream().filter(placement ->
|
||||
@@ -132,6 +195,19 @@ final class PhysicalBoardUpgraderTest {
|
||||
return world;
|
||||
}
|
||||
|
||||
private static FakeWorld fullWorld(boolean readableGlowing) {
|
||||
FakeWorld world = new FakeWorld();
|
||||
plan().placements().forEach(placement -> {
|
||||
world.existing.put(placement.location(), placement);
|
||||
if (placement.sign()) {
|
||||
world.facings.put(placement.location(), FACING);
|
||||
world.glowing.put(placement.location(),
|
||||
placement.signKind() != PhysicalBoardSignKind.DECORATIVE && readableGlowing);
|
||||
}
|
||||
});
|
||||
return world;
|
||||
}
|
||||
|
||||
private static java.util.List<PhysicalBoardPlan.Placement> newSigns() {
|
||||
return plan().placements().stream().filter(placement ->
|
||||
placement.signKind() == PhysicalBoardSignKind.TITLE
|
||||
@@ -140,8 +216,13 @@ final class PhysicalBoardUpgraderTest {
|
||||
}
|
||||
|
||||
private static final class FakeWorld implements PhysicalBoardWorld {
|
||||
private record Snapshot(
|
||||
PhysicalBoardPlan.Placement placement, BoardFacing facing, Boolean glowing
|
||||
) { }
|
||||
|
||||
private final Map<BoardId, PhysicalBoardPlan.Placement> existing = new HashMap<>();
|
||||
private final Map<BoardId, BoardFacing> facings = new HashMap<>();
|
||||
private final Map<BoardId, Boolean> glowing = new HashMap<>();
|
||||
private final Map<BoardId, PhysicalBoardPlan.Placement> placed = new HashMap<>();
|
||||
private int placements;
|
||||
private int failPlacement = -1;
|
||||
@@ -151,7 +232,9 @@ final class PhysicalBoardUpgraderTest {
|
||||
}
|
||||
|
||||
@Override public Object snapshot(BoardId location) {
|
||||
return existing.get(location);
|
||||
return new Snapshot(
|
||||
existing.get(location), facings.get(location), glowing.get(location)
|
||||
);
|
||||
}
|
||||
|
||||
@Override public void place(PhysicalBoardPlan.Placement placement, BoardFacing facing) {
|
||||
@@ -160,6 +243,8 @@ final class PhysicalBoardUpgraderTest {
|
||||
}
|
||||
existing.put(placement.location(), placement);
|
||||
facings.put(placement.location(), facing);
|
||||
glowing.put(placement.location(),
|
||||
placement.signKind() != PhysicalBoardSignKind.DECORATIVE);
|
||||
placed.put(placement.location(), placement);
|
||||
}
|
||||
|
||||
@@ -170,13 +255,25 @@ final class PhysicalBoardUpgraderTest {
|
||||
&& (!placement.sign() || facing == facings.get(placement.location()));
|
||||
}
|
||||
|
||||
@Override public boolean matches(
|
||||
PhysicalBoardPlan.Placement placement, BoardFacing facing, boolean glowingText
|
||||
) {
|
||||
return matches(placement, facing)
|
||||
&& glowingText == glowing.getOrDefault(placement.location(), false);
|
||||
}
|
||||
|
||||
@Override public void restore(BoardId location, Object snapshot) {
|
||||
if (snapshot == null) {
|
||||
existing.remove(location);
|
||||
facings.remove(location);
|
||||
Snapshot captured = (Snapshot) snapshot;
|
||||
restore(existing, location, captured.placement());
|
||||
restore(facings, location, captured.facing());
|
||||
restore(glowing, location, captured.glowing());
|
||||
}
|
||||
|
||||
private static <T> void restore(Map<BoardId, T> values, BoardId location, T value) {
|
||||
if (value == null) {
|
||||
values.remove(location);
|
||||
} else {
|
||||
PhysicalBoardPlan.Placement placement = (PhysicalBoardPlan.Placement) snapshot;
|
||||
existing.put(location, placement);
|
||||
values.put(location, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user