Skip to content

Commit

Permalink
test(SettlementEntityManager): make some methods available to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keturn committed Sep 27, 2021
1 parent 86ecc9c commit 69b1234
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public boolean checkOutsideAllSettlements(Vector2ic pos) {
return true;
}

private EntityRef createSettlement(EntityRef siteRegion) {
EntityRef createSettlement(EntityRef siteRegion) {
EntityRef settlementEntity = entityManager.create();

SiteComponent siteComponent = siteRegion.getComponent(SiteComponent.class);
Expand Down Expand Up @@ -352,7 +352,7 @@ private void getSurroundingRegions(EntityRef settlement) {
float radius = parcelList.cityRadius;
int size = Math.max(Math.round(radius / 32), 1);
BlockArea settlementRectArea = new BlockArea(-size, -size, size, size);
Circlef settlementCircle = new Circlef(pos.x,pos.y, radius);
Circlef settlementCircle = new Circlef(pos.x, pos.y, radius);
Vector2i regionWorldPos = new Vector2i();

for (Vector2ic regionPos : settlementRectArea) {
Expand Down Expand Up @@ -628,8 +628,8 @@ public void buildRoads(EntityRef sourceSettlement) {
sourceSettlement.saveComponent(parcelList);
}

private Optional<DynParcel> placeParcel(Vector3ic center, String zone, ParcelList parcels,
BuildingQueue buildingQueue, DistrictFacetComponent districtFacetComponent, int maxIterations) {
Optional<DynParcel> placeParcel(Vector3ic center, String zone, ParcelList parcels,
BuildingQueue buildingQueue, DistrictFacetComponent districtFacetComponent, int maxIterations) {
int iter = 0;
Map<String, List<Vector2i>> minMaxSizes = buildingManager.getMinMaxSizePerZone();
int minSize = (minMaxSizes.get(zone).get(0).x() < minMaxSizes.get(zone).get(0).y())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

package org.terasology.dynamicCities.settlements;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.joml.RoundingMode;
import org.joml.Vector2i;
import org.joml.Vector2ic;
import org.joml.Vector3fc;
import org.joml.Vector3i;
import org.joml.Vector3ic;
Expand Down Expand Up @@ -34,8 +35,6 @@
import org.terasology.moduletestingenvironment.extension.Dependencies;
import org.terasology.namegenerator.town.TownAssetTheme;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -50,7 +49,7 @@ class SettlementEntityManagerTest {

static final int MAX_PLACEMENT_ATTEMPTS = 20;
static final String zone = "TestZone";
static final Vector2ic buildingSize = new Vector2i(9, 9);
static final Vector2i buildingSize = new Vector2i(9, 9);
static final Vector3ic siteLocation = new Vector3i(1234, 0, -5678);
static final int population = 3;

Expand All @@ -63,7 +62,7 @@ void initialiseZones() {
// Should have a way for this test to add a building prefab,
// or a way to add to BuildingManager without prefabs.
BuildingManager buildingManager = spy(context.get(BuildingManager.class));
when(buildingManager.getMinMaxSizePerZone()).thenReturn(Map.of(zone, List.of(buildingSize, buildingSize)));
when(buildingManager.getMinMaxSizePerZone()).thenReturn(ImmutableMap.of(zone, ImmutableList.of(buildingSize, buildingSize)));
context.put(BuildingManager.class, buildingManager);

// re-inject this so it has the mock version.
Expand Down Expand Up @@ -97,15 +96,15 @@ EntityRef newSite() {
}

@Test
void placeParcel(SettlementEntityManager manager) {
void placeParcel(SettlementEntityManager settlements) {
ParcelList parcels = new ParcelList();
BuildingQueue buildingQueue = new BuildingQueue();

EntityRef site = newSite();
EntityRef settlement = manager.createSettlement(site);
EntityRef settlement = settlements.createSettlement(site);
Vector3fc center = settlement.getComponent(LocationComponent.class).getLocalPosition();

Optional<DynParcel> parcel = manager.placeParcel(
Optional<DynParcel> parcel = settlements.placeParcel(
new Vector3i(center, RoundingMode.FLOOR), zone, parcels, buildingQueue,
settlement.getComponent(DistrictFacetComponent.class), MAX_PLACEMENT_ATTEMPTS
);
Expand Down

0 comments on commit 69b1234

Please sign in to comment.