Skip to content

Commit

Permalink
Fixed issue with region map centralisation not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ben_singer committed Nov 15, 2024
1 parent a4434de commit a7a9f78
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions NetAF/Rendering/FrameBuilders/Console/ConsoleRegionMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ private void DrawLowerLevelRoom(Point2D topLeft)
/// <param name="availableSize">The available size, in the grid.</param>
/// <param name="matrix">The matrix.</param>
/// <param name="roomPosition">The position of the room, in the matrix.</param>
/// <param name="playerPosition">The x position of the player, in the matrix.</param>
/// <param name="focusPosition">The focus position, in the matrix.</param>
/// <param name="gridLeft">The left position to begin rendering the room at, in the grid.</param>
/// <param name="gridTop">The top position to begin rendering the room at, in the grid.</param>
/// <returns>True if the matrix position could be converted to a grid position and fit in the available space.</returns>
private static bool TryConvertMatrixPositionToGridLayoutPosition(Point2D gridStartPosition, Size availableSize, Matrix matrix, Point2D roomPosition, Point2D playerPosition, out int gridLeft, out int gridTop)
private static bool TryConvertMatrixPositionToGridLayoutPosition(Point2D gridStartPosition, Size availableSize, Matrix matrix, Point2D roomPosition, Point2D focusPosition, out int gridLeft, out int gridTop)
{
const int roomWidth = 5;
const int roomHeight = 3;
Expand All @@ -241,9 +241,9 @@ private static bool TryConvertMatrixPositionToGridLayoutPosition(Point2D gridSta
// check if map will fit
if (matrix.Width * roomWidth > availableSize.Width || matrix.Height * roomHeight > availableSize.Height)
{
// centralise on player
gridLeft += availableSize.Width / 2 - playerPosition.X * roomWidth + roomWidth / 2;
gridTop += availableSize.Height / 2 + (playerPosition.Y - matrix.Height) * roomHeight - roomHeight / 2;
// centralise on the focus position
gridLeft += availableSize.Width / 2 - focusPosition.X * roomWidth + roomWidth / 2;
gridTop += availableSize.Height / 2 + (focusPosition.Y - matrix.Height) * roomHeight - roomHeight / 2;
}
else
{
Expand Down Expand Up @@ -316,7 +316,7 @@ public void BuildRegionMap(Region region, Point2D startPosition, Point3D focusPo

foreach (var position in lowerLevelRooms)
{
if (TryConvertMatrixPositionToGridLayoutPosition(new Point2D(x, y), new Size(maxAvailableWidth, maxSize.Height), matrix, new Point2D(position.Position.X, position.Position.Y), new Point2D(playerRoom.Position.X, playerRoom.Position.Y), out var left, out var top))
if (TryConvertMatrixPositionToGridLayoutPosition(new Point2D(x, y), new Size(maxAvailableWidth, maxSize.Height), matrix, new Point2D(position.Position.X, position.Position.Y), new Point2D(focusPosition.X, focusPosition.Y), out var left, out var top))
DrawLowerLevelRoom(new Point2D(left, top));
}
}
Expand All @@ -329,7 +329,7 @@ public void BuildRegionMap(Region region, Point2D startPosition, Point3D focusPo

foreach (var position in focusLevelRooms)
{
if (TryConvertMatrixPositionToGridLayoutPosition(new Point2D(x, y), new Size(maxAvailableWidth, maxSize.Height), matrix, new Point2D(position.Position.X, position.Position.Y), new Point2D(playerRoom.Position.X, playerRoom.Position.Y), out var left, out var top))
if (TryConvertMatrixPositionToGridLayoutPosition(new Point2D(x, y), new Size(maxAvailableWidth, maxSize.Height), matrix, new Point2D(position.Position.X, position.Position.Y), new Point2D(focusPosition.X, focusPosition.Y), out var left, out var top))
DrawCurrentFloorRoom(position.Room, new Point2D(left, top), position.Room == playerRoom.Room, position.Position.Equals(focusPosition));
}
}
Expand Down

0 comments on commit a7a9f78

Please sign in to comment.