Skip to content

Commit 2e79b8a

Browse files
committed
Code Clean up
1 parent 0707fa2 commit 2e79b8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+453
-237
lines changed

Assets/Scripts/BoardSystem/Board/Board.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ public Board(BoardController controller, BoardDataShape dataShape, Orientation o
1616
GeneratePositions();
1717
}
1818

19-
BoardController Controller { get; }
19+
private BoardController Controller { get; }
2020
public BoardDataShape DataShape { get; }
2121
public Orientation Orientation { get; }
2222
public Position[] Positions { get; private set; }
2323

24-
public bool HasPosition(Hex point) => GetPosition(point) != null;
24+
public bool HasPosition(Hex point)
25+
{
26+
return GetPosition(point) != null;
27+
}
2528

2629
public Position GetPosition(Hex point)
2730
{
@@ -32,7 +35,7 @@ public Position GetPosition(Hex point)
3235
return null;
3336
}
3437

35-
void GeneratePositions()
38+
private void GeneratePositions()
3639
{
3740
var points = DataShape.GetHexPoints();
3841
Positions = new Position[points.Length];
@@ -45,6 +48,9 @@ void GeneratePositions()
4548
OnCreateBoard();
4649
}
4750

48-
void OnCreateBoard() => Controller.DispatchCreateBoard(this);
51+
private void OnCreateBoard()
52+
{
53+
Controller.DispatchCreateBoard(this);
54+
}
4955
}
5056
}

Assets/Scripts/BoardSystem/Board/BoardManipulationOddR.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ namespace HexBoardGame.Runtime
99
/// </summary>
1010
public class BoardManipulationOddR : IBoardManipulation
1111
{
12-
static readonly Hex[] NeighboursDirections =
12+
private static readonly Hex[] NeighboursDirections =
1313
{
1414
new Hex(1, 0), new Hex(1, -1), new Hex(0, -1),
1515
new Hex(-1, 0), new Hex(-1, 1), new Hex(0, 1)
1616
};
1717

18-
readonly Hex[] _hexPoints;
18+
private readonly Hex[] _hexPoints;
1919

20-
public BoardManipulationOddR(BoardDataShape dataShape) => _hexPoints = dataShape.GetHexPoints();
20+
public BoardManipulationOddR(BoardDataShape dataShape)
21+
{
22+
_hexPoints = dataShape.GetHexPoints();
23+
}
2124

2225
public Hex[] GetNeighbours(Vector3Int cell)
2326
{
@@ -37,7 +40,7 @@ public Hex[] GetNeighbours(Vector3Int cell)
3740
/// <summary>
3841
/// If the point is present among the starting configuration returns it. Otherwise returns a empty array.
3942
/// </summary>
40-
Hex[] GetIfExistsOrEmpty(Hex hex)
43+
private Hex[] GetIfExistsOrEmpty(Hex hex)
4144
{
4245
foreach (var i in _hexPoints)
4346
if (i == hex)
@@ -54,7 +57,10 @@ public bool Contains(Vector3Int cell)
5457
return GetIfExistsOrEmpty(center).Length > 0;
5558
}
5659

57-
public Hex[] GetVertical(Vector3Int cell, int length) => new Hex[] { };
60+
public Hex[] GetVertical(Vector3Int cell, int length)
61+
{
62+
return new Hex[] { };
63+
}
5864

5965
public Hex[] GetHorizontal(Vector3Int cell, int length)
6066
{
@@ -111,15 +117,19 @@ public Hex[] GetDiagonalDescendant(Vector3Int cell, int length)
111117
/// Unity by default makes use the R-Offset Odd to reference tiles inside a TileMap with a vector3Int cell.
112118
/// The internal board manipulation works with HexCoordinates, this method converts vector3int cell to hex.
113119
/// </summary>
114-
public static Hex GetHexCoordinate(Vector3Int cell) =>
115-
OffsetCoordHelper.RoffsetToCube(OffsetCoord.Parity.Odd, new OffsetCoord(cell.x, cell.y));
120+
public static Hex GetHexCoordinate(Vector3Int cell)
121+
{
122+
return OffsetCoordHelper.RoffsetToCube(OffsetCoord.Parity.Odd, new OffsetCoord(cell.x, cell.y));
123+
}
116124

117125
/// <summary>
118126
/// Unity by default makes use the R-Offset Odd to reference tiles inside a TileMap with a vector3Int cell.
119127
/// The internal board manipulation works with HexCoordinates, this method converts hex to unity vector3int cell.
120128
/// </summary>
121-
public static Vector3Int GetCellCoordinate(Hex hex) =>
122-
OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, hex).ToVector3Int();
129+
public static Vector3Int GetCellCoordinate(Hex hex)
130+
{
131+
return OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, hex).ToVector3Int();
132+
}
123133

124134
#endregion
125135
}

Assets/Scripts/BoardSystem/BoardController.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ namespace HexBoardGame.Runtime.GameBoard
88
public class BoardController : MonoBehaviour
99
{
1010
public BoardDataShape boardShape;
11-
[SerializeField] Tilemap tileMap;
11+
[SerializeField] private Tilemap tileMap;
1212
public IBoard Board { get; private set; }
1313
public IBoardManipulation BoardManipulation { get; private set; }
1414
public event Action<IBoard> OnCreateBoard = board => { };
1515

16-
void Start() => CreateBoard();
16+
private void Start()
17+
{
18+
CreateBoard();
19+
}
1720

18-
void CreateBoard()
21+
private void CreateBoard()
1922
{
2023
//using the tile map orientation to pick the default value
2124
if (tileMap.orientation == Tilemap.Orientation.XY)
@@ -45,6 +48,9 @@ public void CreateBoardPointy()
4548
Board = new Board(this, boardShape, Orientation.PointyTop);
4649
}
4750

48-
public void DispatchCreateBoard(IBoard board) => OnCreateBoard(board);
51+
public void DispatchCreateBoard(IBoard board)
52+
{
53+
OnCreateBoard(board);
54+
}
4955
}
5056
}

Assets/Scripts/BoardSystem/BoardElementsController.cs

+25-14
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ namespace HexBoardGame.Runtime.GameBoard
66
{
77
public class BoardElementsController : MonoBehaviour
88
{
9-
[SerializeField] BoardController boardController;
10-
[SerializeField] UiTileMapInputHandler uiTileMapInputHandler;
11-
IBoard CurrentBoard { get; set; }
12-
IDataProvider ElementProvider { get; set; }
9+
[SerializeField] private BoardController boardController;
10+
[SerializeField] private UiTileMapInputHandler uiTileMapInputHandler;
11+
private IBoard CurrentBoard { get; set; }
12+
private IDataProvider ElementProvider { get; set; }
1313
public event Action<BoardElement, Vector3Int> OnAddElement = (element, cell) => { };
1414
public event Action<BoardElement, Vector3Int> OnRemoveElement = (element, cell) => { };
15-
public void SetElementProvider(IDataProvider provider) => ElementProvider = provider;
1615

17-
void Awake()
16+
public void SetElementProvider(IDataProvider provider)
17+
{
18+
ElementProvider = provider;
19+
}
20+
21+
private void Awake()
1822
{
1923
boardController.OnCreateBoard += OnCreateBoard;
2024
uiTileMapInputHandler.OnClickTile += OnClickTile;
2125
}
2226

23-
void OnClickTile(Vector3Int cell)
27+
private void OnClickTile(Vector3Int cell)
2428
{
2529
var hex = GetHexCoordinate(cell);
2630
if (ElementProvider == null)
@@ -34,9 +38,12 @@ void OnClickTile(Vector3Int cell)
3438
}
3539
}
3640

37-
void OnCreateBoard(IBoard board) => CurrentBoard = board;
41+
private void OnCreateBoard(IBoard board)
42+
{
43+
CurrentBoard = board;
44+
}
3845

39-
void AddElement(BoardElement element, Hex hex)
46+
private void AddElement(BoardElement element, Hex hex)
4047
{
4148
var position = CurrentBoard.GetPosition(hex);
4249
if (position == null)
@@ -49,7 +56,7 @@ void AddElement(BoardElement element, Hex hex)
4956
OnAddElement(element, cell);
5057
}
5158

52-
void RemoveElement(Hex hex)
59+
private void RemoveElement(Hex hex)
5360
{
5461
var position = CurrentBoard?.GetPosition(hex);
5562
if (position == null)
@@ -61,10 +68,14 @@ void RemoveElement(Hex hex)
6168
OnRemoveElement(data, GetCellCoordinate(hex));
6269
}
6370

64-
static Hex GetHexCoordinate(Vector3Int cell) =>
65-
OffsetCoordHelper.RoffsetToCube(OffsetCoord.Parity.Odd, new OffsetCoord(cell.x, cell.y));
71+
private static Hex GetHexCoordinate(Vector3Int cell)
72+
{
73+
return OffsetCoordHelper.RoffsetToCube(OffsetCoord.Parity.Odd, new OffsetCoord(cell.x, cell.y));
74+
}
6675

67-
static Vector3Int GetCellCoordinate(Hex hex) =>
68-
OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, hex).ToVector3Int();
76+
private static Vector3Int GetCellCoordinate(Hex hex)
77+
{
78+
return OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, hex).ToVector3Int();
79+
}
6980
}
7081
}

Assets/Scripts/BoardSystem/BoardShape/HexagonalBoardDataShape.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HexBoardGame.SharedData
77
[CreateAssetMenu(menuName = "BoardShape/BoardData", fileName = "HexagonalBoardData")]
88
public class HexagonalBoardDataShape : BoardDataShape
99
{
10-
readonly List<Hex> _points = new List<Hex>();
10+
private readonly List<Hex> _points = new List<Hex>();
1111
[Range(0, 10)] public int radius;
1212

1313
public override Hex[] GetHexPoints()

Assets/Scripts/BoardSystem/BoardShape/ParallelogramBoardDataShape.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HexBoardGame.SharedData
77
[CreateAssetMenu(menuName = "BoardShape/ParallelogramData", fileName = "ParallelogramData")]
88
public class ParallelogramBoardDataShape : BoardDataShape
99
{
10-
readonly List<Hex> _points = new List<Hex>();
10+
private readonly List<Hex> _points = new List<Hex>();
1111
[Range(2, 10)] public int height;
1212
[Range(2, 10)] public int width;
1313

Assets/Scripts/BoardSystem/BoardShape/RectBoardDataShape.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HexBoardGame.SharedData
77
[CreateAssetMenu(menuName = "BoardShape/RectBoardData", fileName = "RectBoardData")]
88
public class RectBoardDataShape : BoardDataShape
99
{
10-
readonly List<Hex> _points = new List<Hex>();
10+
private readonly List<Hex> _points = new List<Hex>();
1111
[Range(1, 10)] public int height;
1212
[Range(1, 10)] public int width;
1313

Assets/Scripts/BoardSystem/BoardShape/TriangleBoardDataShape.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HexBoardGame.SharedData
77
[CreateAssetMenu(menuName = "BoardShape/TriangleBoardData", fileName = "TriangleBoardData")]
88
public class TriangleBoardDataShape : BoardDataShape
99
{
10-
readonly List<Hex> _points = new List<Hex>();
10+
private readonly List<Hex> _points = new List<Hex>();
1111
[Range(1, 10)] public int size;
1212

1313
public override Hex[] GetHexPoints()

Assets/Scripts/BoardSystem/Coordinates/AxialCoord.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public override bool Equals(object obj)
4444
return q == other.q && r == other.r;
4545
}
4646

47-
public Vector3Int ToVector3Int() => new Vector3Int(q, r, 0);
47+
public Vector3Int ToVector3Int()
48+
{
49+
return new Vector3Int(q, r, 0);
50+
}
4851
}
4952
}

Assets/Scripts/BoardSystem/Coordinates/Hex.cs

+56-12
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,40 @@ public Hex(int q, int r, int s)
3030

3131
#region Operators
3232

33-
public override string ToString() => $"Hex: ({q}, {r}, {s})";
33+
public override string ToString()
34+
{
35+
return $"Hex: ({q}, {r}, {s})";
36+
}
37+
38+
public static Hex Add(Hex a, Hex b)
39+
{
40+
return new Hex(a.q + b.q, a.r + b.r);
41+
}
42+
43+
public static Hex Subtract(Hex a, Hex b)
44+
{
45+
return new Hex(a.q - b.q, a.r - b.r);
46+
}
3447

35-
public static Hex Add(Hex a, Hex b) => new Hex(a.q + b.q, a.r + b.r);
36-
public static Hex Subtract(Hex a, Hex b) => new Hex(a.q - b.q, a.r - b.r);
37-
public static Hex Multiply(Hex a, int k) => new Hex(a.q * k, a.r * k);
38-
public static int Distance(Hex a, Hex b) => Subtract(a, b).Length;
48+
public static Hex Multiply(Hex a, int k)
49+
{
50+
return new Hex(a.q * k, a.r * k);
51+
}
52+
53+
public static int Distance(Hex a, Hex b)
54+
{
55+
return Subtract(a, b).Length;
56+
}
57+
58+
public static bool operator ==(Hex a, Hex b)
59+
{
60+
return a.q == b.q && a.r == b.r && a.s == b.s;
61+
}
3962

40-
public static bool operator ==(Hex a, Hex b) => a.q == b.q && a.r == b.r && a.s == b.s;
41-
public static bool operator !=(Hex a, Hex b) => !(a == b);
63+
public static bool operator !=(Hex a, Hex b)
64+
{
65+
return !(a == b);
66+
}
4267

4368
public override bool Equals(object obj)
4469
{
@@ -84,11 +109,30 @@ public int CompareTo(object obj)
84109

85110
#region Conversion to other Coordinate Systems
86111

87-
public AxialCoord ToAxialCoord() => new AxialCoord(q, r);
88-
public OffsetCoord ToQoffsetEven() => OffsetCoordHelper.QoffsetFromCube(OffsetCoord.Parity.Even, this);
89-
public OffsetCoord ToQoffsetOdd() => OffsetCoordHelper.QoffsetFromCube(OffsetCoord.Parity.Odd, this);
90-
public OffsetCoord ToRoffsetEven() => OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Even, this);
91-
public OffsetCoord ToRoffsetOdd() => OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, this);
112+
public AxialCoord ToAxialCoord()
113+
{
114+
return new AxialCoord(q, r);
115+
}
116+
117+
public OffsetCoord ToQoffsetEven()
118+
{
119+
return OffsetCoordHelper.QoffsetFromCube(OffsetCoord.Parity.Even, this);
120+
}
121+
122+
public OffsetCoord ToQoffsetOdd()
123+
{
124+
return OffsetCoordHelper.QoffsetFromCube(OffsetCoord.Parity.Odd, this);
125+
}
126+
127+
public OffsetCoord ToRoffsetEven()
128+
{
129+
return OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Even, this);
130+
}
131+
132+
public OffsetCoord ToRoffsetOdd()
133+
{
134+
return OffsetCoordHelper.RoffsetFromCube(OffsetCoord.Parity.Odd, this);
135+
}
92136

93137
#endregion
94138
}

Assets/Scripts/BoardSystem/Coordinates/OffsetCoord.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ public OffsetCoord(int col, int row)
1919
this.row = row;
2020
}
2121

22-
public Vector3Int ToVector3Int() => new Vector3Int(col, row, 0);
22+
public Vector3Int ToVector3Int()
23+
{
24+
return new Vector3Int(col, row, 0);
25+
}
2326

24-
public override string ToString() => $"Offset: (x: {col}, y: {row})";
27+
public override string ToString()
28+
{
29+
return $"Offset: (x: {col}, y: {row})";
30+
}
2531
}

Assets/Scripts/BoardSystem/Creature/CreatureData.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ namespace HexBoardGame.Runtime.GameBoard
55
[CreateAssetMenu]
66
public class CreatureData : ScriptableObject, IDataProvider
77
{
8-
[SerializeField] Sprite artwork;
9-
[SerializeField] GameObject model;
8+
[SerializeField] private Sprite artwork;
9+
[SerializeField] private GameObject model;
1010

11-
public BoardElement GetElement() => new BoardCreature(this);
12-
public Sprite GetArtwork() => artwork;
13-
public GameObject GetModel() => model;
11+
public BoardElement GetElement()
12+
{
13+
return new BoardCreature(this);
14+
}
15+
16+
public Sprite GetArtwork()
17+
{
18+
return artwork;
19+
}
20+
21+
public GameObject GetModel()
22+
{
23+
return model;
24+
}
1425
}
1526
}

0 commit comments

Comments
 (0)