Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Dec 28, 2024
1 parent f80aab7 commit e9c1609
Showing 1 changed file with 60 additions and 44 deletions.
104 changes: 60 additions & 44 deletions src/toniarts/openkeeper/view/map/MapViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,17 @@ private Spatial getWallSpatial(IMapTileInformation tile, WallDirection direction
String modelName = artResource.getName();
Point p = tile.getLocation();
IMapTileInformation neigbourTile;
switch (direction) {
case NORTH:
neigbourTile = getMapData().getTile(p.x, p.y - 1);
break;
case SOUTH:
neigbourTile = getMapData().getTile(p.x, p.y + 1);
break;
case EAST:
neigbourTile = getMapData().getTile(p.x + 1, p.y);
break;
default: // WEST
neigbourTile = getMapData().getTile(p.x - 1, p.y);
break;
}
neigbourTile = switch (direction) {
case NORTH ->
getMapData().getTile(p.x, p.y - 1);
case SOUTH ->
getMapData().getTile(p.x, p.y + 1);
case EAST ->
getMapData().getTile(p.x + 1, p.y);
default ->
getMapData().getTile(p.x - 1, p.y); // WEST
};

// Check for out of bounds
if (neigbourTile == null) {
return loadModel(modelName, artResource);
Expand Down Expand Up @@ -643,7 +640,7 @@ public void flashTile(boolean enabled, List<Point> points) {
flashedTiles.removeAll(points);
}

updateTiles(points.toArray(new Point[0]));
updateTiles(points.toArray(Point[]::new));
}

/**
Expand Down Expand Up @@ -933,15 +930,20 @@ private List<Point> getRoomWalls(Point p, RoomInstance roomInstance, WallDirecti

// See if the starting point has a wall to the given direction
IMapTileInformation tile;
if (wallDirection == WallDirection.NORTH) {
tile = getMapData().getTile(p.x, p.y + 1);
} else if (wallDirection == WallDirection.EAST) {
tile = getMapData().getTile(p.x - 1, p.y);
} else if (wallDirection == WallDirection.SOUTH) {
tile = getMapData().getTile(p.x, p.y - 1);
} else {
if (null == wallDirection) {
tile = getMapData().getTile(p.x + 1, p.y); // West
}
} else
tile = switch (wallDirection) {
case NORTH ->
getMapData().getTile(p.x, p.y + 1);
case EAST ->
getMapData().getTile(p.x - 1, p.y);
case SOUTH ->
getMapData().getTile(p.x, p.y - 1);
default ->
getMapData().getTile(p.x + 1, p.y); // West
};

Terrain terrain = kwdFile.getTerrain(tile.getTerrainId());
if (terrain.getFlags().contains(Terrain.TerrainFlag.SOLID)
&& terrain.getFlags().contains(Terrain.TerrainFlag.ALLOW_ROOM_WALLS)) {
Expand All @@ -952,38 +954,52 @@ private List<Point> getRoomWalls(Point p, RoomInstance roomInstance, WallDirecti

// Traverse possible directions, well one direction, "to the right"
List<Point> adjacentWallPoints = null;
if (wallDirection == WallDirection.NORTH) {
Point nextPoint = new Point(p.x + 1, p.y); // East
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
} else if (wallDirection == WallDirection.EAST) {
Point nextPoint = new Point(p.x, p.y + 1); // South
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
} else if (wallDirection == WallDirection.SOUTH) {
Point nextPoint = new Point(p.x + 1, p.y); // East, sorting, so right is left now
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
} else {
if (null == wallDirection) {
Point nextPoint = new Point(p.x, p.y + 1); // South, sorting, so right is left now
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
}
} else
switch (wallDirection) {
case NORTH -> {
Point nextPoint = new Point(p.x + 1, p.y); // East
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
}
case EAST -> {
Point nextPoint = new Point(p.x, p.y + 1); // South
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
}
case SOUTH -> {
Point nextPoint = new Point(p.x + 1, p.y); // East, sorting, so right is left now
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
}
default -> {
Point nextPoint = new Point(p.x, p.y + 1); // South, sorting, so right is left now
RoomInstance instance = roomCoordinates.get(nextPoint);
if (instance != null && instance.equals(roomInstance)) {
adjacentWallPoints = getRoomWalls(nextPoint, roomInstance, wallDirection);
}
}
}

// Add the point(s)
if (adjacentWallPoints != null) {
wallPoints.addAll(adjacentWallPoints);
}

return wallPoints;
}

return null;
}

Expand All @@ -999,7 +1015,7 @@ protected void updateRoomWalls(RoomInstance... rooms) {
}

protected void updateRoomWalls(List<RoomInstance> rooms) {
updateRoomWalls(rooms.toArray(new RoomInstance[0]));
updateRoomWalls(rooms.toArray(RoomInstance[]::new));
}

/**
Expand Down

0 comments on commit e9c1609

Please sign in to comment.