@@ -5,6 +5,9 @@ namespace OpenPolytopia.Common;
55using System . Runtime . CompilerServices ;
66using Godot ;
77
8+ /// <summary>
9+ /// Layer of abstraction to manage all cities in a grid
10+ /// </summary>
811public class CityManager ( Grid grid ) {
912 private readonly List < uint > _cities = [ ] ;
1013
@@ -28,13 +31,25 @@ public CityData this[uint id] {
2831 /// </summary>
2932 /// <param name="id">the id of the city</param>
3033 /// <returns>the id of the tile in the grid</returns>
34+ /// <example>
35+ /// <code>
36+ /// var index = cityManager.GetIndex(cityId);
37+ /// grid[index].Owner = 2;
38+ /// </code>
39+ /// </example>
3140 public uint GetIndex ( uint id ) => _cities [ ( int ) ( id - 1 ) ] ;
3241
3342 /// <summary>
3443 /// Registers a tile as a city
3544 /// </summary>
3645 /// <param name="position">position of the tile in the grid</param>
3746 /// <returns>the id of the city</returns>
47+ /// <example>
48+ /// <code>
49+ /// var position = new Vector2I(0, 5);
50+ /// var cityId = cityManager.RegisterCity(position);
51+ /// </code>
52+ /// </example>
3853 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3954 public uint RegisterCity ( Vector2I position ) => RegisterCity ( grid . GridPositionToIndex ( position ) ) ;
4055
@@ -44,6 +59,13 @@ public CityData this[uint id] {
4459 /// <param name="index">index of the tile in the grid</param>
4560 /// <returns>the id of the city</returns>
4661 /// <exception cref="ArgumentOutOfRangeException">because of internal implementation, there can only be 255 cities</exception>
62+ /// <example>
63+ /// <code>
64+ /// var position = new Vector2I(0, 5);
65+ /// var index = grid.GridPositionToIndex(position);
66+ /// var cityId = cityManager.RegisterCity(index);
67+ /// </code>
68+ /// </example>
4769 public uint RegisterCity ( uint index ) {
4870 if ( _cities . Count == 255 ) {
4971 throw new ArgumentOutOfRangeException ( nameof ( index ) , index , "reached maximum cities possible; max is 255" ) ;
0 commit comments