Improve multi-level support and stairs

This commit is contained in:
2026-09-27 07:52:48 -07:00
parent 30c31c185b
commit 917dac9c8e
7 changed files with 276 additions and 46 deletions

View File

@@ -71,6 +71,39 @@ class AvenueStairwayLayoutTest {
assertTrue(flight.roadOpenings().stream().allMatch(step -> step.y() == 76));
}
@Test
void createsOneCenteredStairFlightPerLogicalPlotOnBothAvenueBorders() {
Cuboid twoByTwoPlot = new Cuboid(2, 62, 2, 69, 71, 69);
List<AvenueStairwayLayout.Flight> flights =
AvenueStairwayLayout.forUpperRoadSegments(twoByTwoPlot, 32, 36, 0, 1, 4, 2, 62, 14, 3);
assertEquals(4, flights.size());
assertEquals(
new AvenueStairwayLayout.Step(71, 63, 12), flights.get(0).stairBlocks().getFirst());
assertEquals(
new AvenueStairwayLayout.Step(-1, 63, 12), flights.get(1).stairBlocks().getFirst());
assertEquals(
new AvenueStairwayLayout.Step(71, 63, 48), flights.get(2).stairBlocks().getFirst());
assertEquals(
new AvenueStairwayLayout.Step(-1, 63, 48), flights.get(3).stairBlocks().getFirst());
assertTrue(flights.stream().allMatch(flight -> flight.stairBlocks().getLast().y() == 76));
}
@Test
void appliesStairCadenceToEachLogicalPlotSegment() {
Cuboid twoByTwoPlot = new Cuboid(2, 62, 2, 69, 71, 69);
List<AvenueStairwayLayout.Flight> flights =
AvenueStairwayLayout.forUpperRoadSegments(twoByTwoPlot, 32, 36, 0, 2, 4, 2, 62, 14, 3);
assertEquals(2, flights.size());
assertEquals(
new AvenueStairwayLayout.Step(71, 63, 48), flights.getFirst().stairBlocks().getFirst());
assertEquals(
new AvenueStairwayLayout.Step(-1, 63, 48), flights.getLast().stairBlocks().getFirst());
}
@Test
void rejectsAStairRunThatCannotFitWithinThePlotLength() {
Cuboid plot = new Cuboid(2, 62, 2, 33, 71, 13);

View File

@@ -0,0 +1,55 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Set;
import org.junit.jupiter.api.Test;
class PlotLevelSupportTest {
@Test
void rejectsUpperPlotWhenAnyLogicalCellBelowIsMissing() {
Set<String> generatedCells = Set.of("0:0:0", "0:1:0", "1:0:0");
assertFalse(
PlotLevelSupport.hasCompleteSupport(
0, 0, 2, 1, (row, col, level) -> generatedCells.contains(key(row, col, level))));
}
@Test
void requiresEveryLogicalCellAtEveryLowerLevel() {
Set<String> generatedCells =
Set.of("0:0:0", "0:1:0", "1:0:0", "1:1:0", "0:0:1", "0:1:1", "1:0:1", "1:1:1");
assertTrue(
PlotLevelSupport.hasCompleteSupport(
0, 0, 2, 2, (row, col, level) -> generatedCells.contains(key(row, col, level))));
}
@Test
void baseLevelDoesNotRequireLowerSupport() {
assertTrue(PlotLevelSupport.hasCompleteSupport(3, 4, 2, 0, (row, col, level) -> false));
}
private static String key(int row, int col, int level) {
return row + ":" + col + ":" + level;
}
}