Skip to content

Commit

Permalink
chore: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Apr 22, 2024
1 parent ebbb7b8 commit 0ec3098
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Models/Model.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using UnityEngine;
using Grid = WFC.Grid;
using Grid = Assets.Scripts.Wfc.Grid;

namespace Assets.Scripts.Models
{
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Tiles/Corner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents a corner tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Tiles/Crossing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents a crossing tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Tiles/DeadEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents a dead end tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand Down
10 changes: 6 additions & 4 deletions aplib.net-demo/Assets/Scripts/Tiles/Direction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum Direction
public static class DirectionExtensions
{
/// <summary>
/// Rotates the direction X times to the right.
/// Rotates the direction X times clockwise.
/// </summary>
/// <param name="direction">The direction to rotate.</param>
/// <param name="times">The number of times the direction must be rotated.</param>
Expand All @@ -26,7 +26,7 @@ public static Direction RotateRight(this Direction direction, int times = 1)
=> (Direction)(((int)direction + times) % 4);

/// <summary>
/// Rotates the direction X times to the left.
/// Rotates the direction X times counterclockwise.
/// </summary>
/// <param name="direction">The direction to rotate.</param>
/// <param name="times">The number of times the direction must be rotated.</param>
Expand All @@ -38,8 +38,10 @@ public static Direction RotateLeft(this Direction direction, int times = 1)
/// Rotates the direction X times to the left or right.
/// </summary>
/// <param name="direction">The direction to rotate.</param>
/// <param name="times">The number of times the direction must be rotated.
/// Negative numbers indicate rotation towards the left.</param>
/// <param name="times">
/// The number of times the direction must be rotated.
/// Negative numbers indicate rotation towards the left.
/// </param>
/// <returns>The adjusted direction.</returns>
public static Direction Rotate(this Direction direction, int times)
=> times >= 0 ? direction.RotateRight(times) : direction.RotateLeft(-times);
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Tiles/Empty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents an empty tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/Tiles/Straight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents a straight tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand Down
4 changes: 2 additions & 2 deletions aplib.net-demo/Assets/Scripts/Tiles/TSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles
{
/// <summary>
/// Represents a T-section tile.
/// <br/><br/>
/// <para/>
/// Default orientation (north):
/// <code>
///
Expand All @@ -21,7 +21,7 @@ public class TSection : Tile
{
/// <summary>
/// Initializes a new instance of the <see cref="TSection"/> class.
/// The default is a T-section with the top side opened.
/// The default is a T-section with the bottom side closed.
/// </summary>
/// <param name="facing">The direction in which the front of the tile should face.</param>
public TSection(Direction facing = North)
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/WFC/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using static Assets.Scripts.Tiles.Direction;

namespace WFC
namespace Assets.Scripts.Wfc
{
/// <summary>
/// Represents a cell in the grid.
Expand Down
19 changes: 8 additions & 11 deletions aplib.net-demo/Assets/Scripts/WFC/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using static Assets.Scripts.Tiles.Direction;

namespace WFC
namespace Assets.Scripts.Wfc
{
/// <summary>
/// Represents a grid.
Expand Down Expand Up @@ -78,7 +78,7 @@ public void Init()
/// <param name="index">Ranging from 0 to infinity, and beyond! But not too far, as you will get an exception.</param>
/// <returns>The coordinates of the belonging tile.</returns>
/// <exception cref="IndexOutOfRangeException">
/// When index is larger than <see cref="Width"/> times /// <see cref="Height"/>.
/// When index is larger than <see cref="Width"/> times <see cref="Height"/>.
/// </exception>
protected (int x, int y) IndexToCoordinates(int index)
{
Expand Down Expand Up @@ -156,8 +156,8 @@ public ICollection<Cell> Get8NeighbouringCells(Cell cell)
}

/// <summary>
/// Given a cell, this method determines all directly adjacent neighbours which are connected by their <see cref="Tile"/>s.
/// These are at most 4, as diagonal tiles cannot be connected.
/// Given a cell, this method determines all directly adjacent neighbours which are connected by their
/// <see cref="Tile"/>s. These are at most 4, as diagonal tiles cannot be connected.
/// </summary>
/// <param name="cell">The cell whose connected tiles are to be determined.</param>
/// <returns>The cells directly connected through their tiles</returns>
Expand All @@ -168,13 +168,10 @@ public ICollection<Cell> GetConnectedNeighbours(Cell cell)
ICollection<Cell> neighbours = Get4NeighbouringCells(cell); // Note: no diagonal neighbours
foreach (Cell neighbour in neighbours)
{
if (cell.Tile.CanConnectInDirection(East) && neighbour.X > cell.X && neighbour.Tile.CanConnectInDirection(West))
connectedNeighbours.Add(neighbour);
else if (cell.Tile.CanConnectInDirection(West) && neighbour.X < cell.X && neighbour.Tile.CanConnectInDirection(East))
connectedNeighbours.Add(neighbour);
else if (cell.Tile.CanConnectInDirection(North) && neighbour.Y > cell.Y && neighbour.Tile.CanConnectInDirection(South))
connectedNeighbours.Add(neighbour);
else if (cell.Tile.CanConnectInDirection(South) && neighbour.Y < cell.Y && neighbour.Tile.CanConnectInDirection(North))
if (cell.Tile.CanConnectInDirection(East) && neighbour.X > cell.X && neighbour.Tile.CanConnectInDirection(West)
|| cell.Tile.CanConnectInDirection(West) && neighbour.X < cell.X && neighbour.Tile.CanConnectInDirection(East)
|| cell.Tile.CanConnectInDirection(North) && neighbour.Y > cell.Y && neighbour.Tile.CanConnectInDirection(South)
|| cell.Tile.CanConnectInDirection(South) && neighbour.Y < cell.Y && neighbour.Tile.CanConnectInDirection(North))
connectedNeighbours.Add(neighbour);
}

Expand Down
13 changes: 7 additions & 6 deletions aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;
using static Assets.Scripts.Tiles.Direction;

namespace WFC
namespace Assets.Scripts.Wfc
{
/// <summary>
/// Represents the grid placer.
Expand Down Expand Up @@ -85,14 +85,14 @@ public void PlaceTile(int x, int y, Tile tile)
{
GameObject prefab = tile switch
{
Corner => RoomObjects.Corner,
Corner => RoomObjects.Corner,
Crossing => RoomObjects.Crossing,
DeadEnd => RoomObjects.DeadEnd,
Empty => RoomObjects.Empty,
Room => RoomObjects.Room,
DeadEnd => RoomObjects.DeadEnd,
Empty => RoomObjects.Empty,
Room => RoomObjects.Room,
Straight => RoomObjects.Straight,
TSection => RoomObjects.TSection,
_ => null
_ => null
};

if (prefab != null)
Expand Down Expand Up @@ -122,6 +122,7 @@ private void JoinConnectedComponentsWithTeleporters()
// TODO the joining of the connected components with teleporters will be done in another PR.
}

// Here are temporary helper methods used to display the connected components in different colors.
private static Color[] _colors = { Color.red, Color.blue, Color.green, Color.yellow, Color.magenta, Color.cyan };
private static int _colorIndex = -1;
private static Color GetUnusedColor() => _colors[_colorIndex = (_colorIndex + 1) % _colors.Length];
Expand Down
2 changes: 1 addition & 1 deletion aplib.net-demo/Assets/Scripts/WFC/RoomObjects.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;

namespace WFC
namespace Assets.Scripts.Wfc
{
/// <summary>
/// Represents the room objects.
Expand Down

0 comments on commit 0ec3098

Please sign in to comment.