Added spot merge, fixed horizontal border bug
This commit is contained in:
parent
729a7107eb
commit
4a36800cde
@ -338,7 +338,8 @@ namespace Parking
|
||||
private bool TryReconfigureSpotForSize(Size newSize)
|
||||
{
|
||||
foreach (List<Spot> currentLaneSpots in _spotMap)
|
||||
foreach (Spot spot in currentLaneSpots) {
|
||||
for (int i = 0; i < currentLaneSpots.Count; i++) {
|
||||
Spot spot = currentLaneSpots[i];
|
||||
if (!(spot.Free && spot.Size != Size.D)) // && !spot.Reserved))
|
||||
continue;
|
||||
if (GetSpotCountOfSize(Size.A) <= 2 && spot.Size == Size.A)
|
||||
@ -401,33 +402,62 @@ namespace Parking
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
float nextBorderLeft = GetNextBorderHorizontal(newPosition, spot.Lane, spot.Perpendicular, newSize,
|
||||
!spot.AlignToTop);
|
||||
float nextBorderRight = GetNextBorderHorizontal(newPosition, spot.Lane, spot.Perpendicular,
|
||||
newSize,
|
||||
!spot.AlignToTop);
|
||||
if (nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize]) {
|
||||
float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular,
|
||||
spot.Size,
|
||||
false);
|
||||
float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular,
|
||||
spot.Size,
|
||||
true);
|
||||
if (nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize] + 1f) {
|
||||
// Try perpendicular
|
||||
float bottomBorder = newPosition.y - 2.25f / 2.0f;
|
||||
float topBorder = newPosition.y + 2.25f / 2.0f;
|
||||
bool foundByRemoval = false;
|
||||
if (spot.AlignToTop) {
|
||||
float newBottomBorder = topBorder - _spotHeights[size];
|
||||
float newTopBorder = topBorder;
|
||||
float nextBorder = GetNextBorderVectical(newPosition, spot.Lane, spot.Perpendicular,
|
||||
newSize,
|
||||
!spot.AlignToTop);
|
||||
if (Math.Abs(nextBorder - newBottomBorder) < 5.5f)
|
||||
if (Math.Abs(nextBorder - newBottomBorder) < 5.5f) {
|
||||
if (i < currentLaneSpots.Count - 1) {
|
||||
Spot nextSpot = currentLaneSpots[i + 1];
|
||||
if (nextSpot.Free && !nextSpot.Reserved) {
|
||||
Destroy(nextSpot.GameObject);
|
||||
currentLaneSpots.RemoveAt(i + 1);
|
||||
i--;
|
||||
newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f;
|
||||
newPosition.y = position.y;
|
||||
foundByRemoval = true;
|
||||
}else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
float newBottomBorder = bottomBorder;
|
||||
float newTopBorder = bottomBorder + _spotHeights[size];
|
||||
float nextBorder = GetNextBorderVectical(newPosition, spot.Lane, spot.Perpendicular,
|
||||
newSize,
|
||||
!spot.AlignToTop);
|
||||
if (Math.Abs(newTopBorder - nextBorder) < 5.5f)
|
||||
if (Math.Abs(newTopBorder - nextBorder) < 5.5f) {
|
||||
if (i < currentLaneSpots.Count - 1) {
|
||||
Spot nextSpot = currentLaneSpots[i + 1];
|
||||
if (nextSpot.Free && !nextSpot.Reserved) {
|
||||
Destroy(nextSpot.GameObject);
|
||||
currentLaneSpots.RemoveAt(i + 1);
|
||||
i--;
|
||||
newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f;
|
||||
newPosition.y = position.y;
|
||||
foundByRemoval = true;
|
||||
}else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!foundByRemoval) {
|
||||
|
||||
newPosition.y = bottomBorder + _spotHeights[(int) newSize] / 2.0f;
|
||||
float newX = nextBorderRight;
|
||||
@ -445,17 +475,40 @@ namespace Parking
|
||||
}
|
||||
|
||||
|
||||
if (spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f)
|
||||
if (spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f) {
|
||||
// Try to remove one spot next
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
newPosition.x = newX;
|
||||
spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) % 2 == 0;
|
||||
spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) %
|
||||
2 == 0;
|
||||
rotation *= Quaternion.Euler(0, 0, spot.Flipped ? 90 : -90);
|
||||
spot.Perpendicular = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
newPosition.x = nextBorderRight - _spotHeights[(int) newSize] / 2.0f - 0.5f;
|
||||
if (i == 0)
|
||||
newPosition.x += 0.5f;
|
||||
newPosition.y = position.y;
|
||||
|
||||
// if (i < currentLaneSpots.Count - 1) {
|
||||
// Spot nextSpot = currentLaneSpots[i + 1];
|
||||
// if (nextSpot.Free && !nextSpot.Reserved) {
|
||||
// Destroy(nextSpot.GameObject);
|
||||
// currentLaneSpots.RemoveAt(i + 1);
|
||||
// i--;
|
||||
// newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f;
|
||||
// newPosition.y = position.y;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Destroy(spot.GameObject);
|
||||
spot.Size = (Size) size;
|
||||
@ -519,13 +572,24 @@ namespace Parking
|
||||
}
|
||||
|
||||
allBorders.Sort();
|
||||
if (right) {
|
||||
foreach (float adjacentBorder in allBorders)
|
||||
if (adjacentBorder > position.x)
|
||||
return adjacentBorder;
|
||||
}
|
||||
else {
|
||||
allBorders.Reverse();
|
||||
foreach (float adjacentBorder in allBorders)
|
||||
if (adjacentBorder < position.x)
|
||||
return adjacentBorder;
|
||||
}
|
||||
|
||||
if (perpendicular)
|
||||
return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f;
|
||||
return (right ? 1 : -1) * Width / 2.0f;
|
||||
if (right)
|
||||
return Width / 2.0f;
|
||||
else
|
||||
return -Width / 2.0f + 5.5f;
|
||||
}
|
||||
|
||||
|
||||
@ -662,12 +726,12 @@ namespace Parking
|
||||
currentX += (i != 0 ? 1 : -1) *
|
||||
(spotMap[i][j].Perpendicular
|
||||
? 2.25f / 2.0f
|
||||
: spotSizes[(int) spotMap[i][j].Size] / 2.0f + (j != 0 ? 0.25f : 0));
|
||||
: spotSizes[(int) spotMap[i][j].Size] / 2.0f + 0.25f);
|
||||
else
|
||||
currentX += (i != 0 ? 1 : -1) *
|
||||
(spotMap[i][j].Perpendicular
|
||||
? 2.5f / 2.0f
|
||||
: spotSizes[(int) spotMap[i][j].Size] / 2.0f + (j != 0 ? 0.25f : 0));
|
||||
: spotSizes[(int) spotMap[i][j].Size] / 2.0f + 0.25f);
|
||||
|
||||
flipped = !flipped;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user