From 0ec30987e5f5310f799ec9f1a82b0473b1a02c6a Mon Sep 17 00:00:00 2001 From: SilasPeters Date: Mon, 22 Apr 2024 11:46:28 +0200 Subject: [PATCH] chore: PR feedback --- aplib.net-demo/Assets/Scripts/Models/Model.cs | 2 +- aplib.net-demo/Assets/Scripts/Tiles/Corner.cs | 2 +- .../Assets/Scripts/Tiles/Crossing.cs | 2 +- .../Assets/Scripts/Tiles/DeadEnd.cs | 2 +- .../Assets/Scripts/Tiles/Direction.cs | 10 ++++++---- aplib.net-demo/Assets/Scripts/Tiles/Empty.cs | 2 +- .../Assets/Scripts/Tiles/Straight.cs | 2 +- .../Assets/Scripts/Tiles/TSection.cs | 4 ++-- aplib.net-demo/Assets/Scripts/WFC/Cell.cs | 2 +- aplib.net-demo/Assets/Scripts/WFC/Grid.cs | 19 ++++++++----------- .../Assets/Scripts/WFC/GridPlacer.cs | 13 +++++++------ .../Assets/Scripts/WFC/RoomObjects.cs | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/aplib.net-demo/Assets/Scripts/Models/Model.cs b/aplib.net-demo/Assets/Scripts/Models/Model.cs index a874f4bc..bd569396 100644 --- a/aplib.net-demo/Assets/Scripts/Models/Model.cs +++ b/aplib.net-demo/Assets/Scripts/Models/Model.cs @@ -1,6 +1,6 @@ using System; using UnityEngine; -using Grid = WFC.Grid; +using Grid = Assets.Scripts.Wfc.Grid; namespace Assets.Scripts.Models { diff --git a/aplib.net-demo/Assets/Scripts/Tiles/Corner.cs b/aplib.net-demo/Assets/Scripts/Tiles/Corner.cs index d0abd843..fc8dbc71 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/Corner.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/Corner.cs @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents a corner tile. - ///

+ /// /// Default orientation (north): /// /// diff --git a/aplib.net-demo/Assets/Scripts/Tiles/Crossing.cs b/aplib.net-demo/Assets/Scripts/Tiles/Crossing.cs index 7cfa2c36..514bc277 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/Crossing.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/Crossing.cs @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents a crossing tile. - ///

+ /// /// Default orientation (north): /// /// diff --git a/aplib.net-demo/Assets/Scripts/Tiles/DeadEnd.cs b/aplib.net-demo/Assets/Scripts/Tiles/DeadEnd.cs index b1455a6c..1af9ab5b 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/DeadEnd.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/DeadEnd.cs @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents a dead end tile. - ///

+ /// /// Default orientation (north): /// /// diff --git a/aplib.net-demo/Assets/Scripts/Tiles/Direction.cs b/aplib.net-demo/Assets/Scripts/Tiles/Direction.cs index 1da61c26..74f78741 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/Direction.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/Direction.cs @@ -17,7 +17,7 @@ public enum Direction public static class DirectionExtensions { /// - /// Rotates the direction X times to the right. + /// Rotates the direction X times clockwise. /// /// The direction to rotate. /// The number of times the direction must be rotated. @@ -26,7 +26,7 @@ public static Direction RotateRight(this Direction direction, int times = 1) => (Direction)(((int)direction + times) % 4); /// - /// Rotates the direction X times to the left. + /// Rotates the direction X times counterclockwise. /// /// The direction to rotate. /// The number of times the direction must be rotated. @@ -38,8 +38,10 @@ public static Direction RotateLeft(this Direction direction, int times = 1) /// Rotates the direction X times to the left or right. ///
/// The direction to rotate. - /// The number of times the direction must be rotated. - /// Negative numbers indicate rotation towards the left. + /// + /// The number of times the direction must be rotated. + /// Negative numbers indicate rotation towards the left. + /// /// The adjusted direction. public static Direction Rotate(this Direction direction, int times) => times >= 0 ? direction.RotateRight(times) : direction.RotateLeft(-times); diff --git a/aplib.net-demo/Assets/Scripts/Tiles/Empty.cs b/aplib.net-demo/Assets/Scripts/Tiles/Empty.cs index 36133198..09d71e32 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/Empty.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/Empty.cs @@ -4,7 +4,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents an empty tile. - ///

+ /// /// Default orientation (north): /// /// diff --git a/aplib.net-demo/Assets/Scripts/Tiles/Straight.cs b/aplib.net-demo/Assets/Scripts/Tiles/Straight.cs index 95072833..286b8a39 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/Straight.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/Straight.cs @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents a straight tile. - ///

+ /// /// Default orientation (north): /// /// diff --git a/aplib.net-demo/Assets/Scripts/Tiles/TSection.cs b/aplib.net-demo/Assets/Scripts/Tiles/TSection.cs index 03a8be1b..1f43e725 100644 --- a/aplib.net-demo/Assets/Scripts/Tiles/TSection.cs +++ b/aplib.net-demo/Assets/Scripts/Tiles/TSection.cs @@ -5,7 +5,7 @@ namespace Assets.Scripts.Tiles { /// /// Represents a T-section tile. - ///

+ /// /// Default orientation (north): /// /// @@ -21,7 +21,7 @@ public class TSection : Tile { /// /// Initializes a new instance of the class. - /// The default is a T-section with the top side opened. + /// The default is a T-section with the bottom side closed. /// /// The direction in which the front of the tile should face. public TSection(Direction facing = North) diff --git a/aplib.net-demo/Assets/Scripts/WFC/Cell.cs b/aplib.net-demo/Assets/Scripts/WFC/Cell.cs index f1df47cf..7f011d22 100644 --- a/aplib.net-demo/Assets/Scripts/WFC/Cell.cs +++ b/aplib.net-demo/Assets/Scripts/WFC/Cell.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using static Assets.Scripts.Tiles.Direction; -namespace WFC +namespace Assets.Scripts.Wfc { /// /// Represents a cell in the grid. diff --git a/aplib.net-demo/Assets/Scripts/WFC/Grid.cs b/aplib.net-demo/Assets/Scripts/WFC/Grid.cs index a88c655a..bf3fb0df 100644 --- a/aplib.net-demo/Assets/Scripts/WFC/Grid.cs +++ b/aplib.net-demo/Assets/Scripts/WFC/Grid.cs @@ -5,7 +5,7 @@ using System.Linq; using static Assets.Scripts.Tiles.Direction; -namespace WFC +namespace Assets.Scripts.Wfc { /// /// Represents a grid. @@ -78,7 +78,7 @@ public void Init() /// Ranging from 0 to infinity, and beyond! But not too far, as you will get an exception. /// The coordinates of the belonging tile. /// - /// When index is larger than times /// . + /// When index is larger than times . /// protected (int x, int y) IndexToCoordinates(int index) { @@ -156,8 +156,8 @@ public ICollection Get8NeighbouringCells(Cell cell) } /// - /// Given a cell, this method determines all directly adjacent neighbours which are connected by their 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 + /// s. These are at most 4, as diagonal tiles cannot be connected. /// /// The cell whose connected tiles are to be determined. /// The cells directly connected through their tiles @@ -168,13 +168,10 @@ public ICollection GetConnectedNeighbours(Cell cell) ICollection 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); } diff --git a/aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs b/aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs index fc823a9c..bfe9e23d 100644 --- a/aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs +++ b/aplib.net-demo/Assets/Scripts/WFC/GridPlacer.cs @@ -3,7 +3,7 @@ using UnityEngine; using static Assets.Scripts.Tiles.Direction; -namespace WFC +namespace Assets.Scripts.Wfc { /// /// Represents the grid placer. @@ -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) @@ -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]; diff --git a/aplib.net-demo/Assets/Scripts/WFC/RoomObjects.cs b/aplib.net-demo/Assets/Scripts/WFC/RoomObjects.cs index 07cf7d7e..aab1a763 100644 --- a/aplib.net-demo/Assets/Scripts/WFC/RoomObjects.cs +++ b/aplib.net-demo/Assets/Scripts/WFC/RoomObjects.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace WFC +namespace Assets.Scripts.Wfc { /// /// Represents the room objects.