| | 1 | | using System; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// This interface is responsible to handle the lands of builder in world panel. |
| | 5 | | /// It will handle the listeners that will add/remove projects to the list |
| | 6 | | /// </summary> |
| | 7 | | internal interface ILandsController |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// This action will be called each time that we changes the land list |
| | 11 | | /// </summary> |
| | 12 | | event Action<LandWithAccess[]> OnLandsSet; |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// This will set the land list |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="lands"></param> |
| | 18 | | void SetLands(LandWithAccess[] lands); |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// This will add a listener that will be responsible to add/remove lands |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="listener"></param> |
| | 24 | | void AddListener(ILandsListener listener); |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// This will remove a listener that will be responsible to add/remove lands |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="listener"></param> |
| | 30 | | void RemoveListener(ILandsListener listener); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// This will return all the lands that we have access |
| | 34 | | /// </summary> |
| | 35 | | /// <returns>An array with the lands that we have access</returns> |
| | 36 | | LandWithAccess[] GetLands(); |
| | 37 | | } |
| | 38 | |
|
| | 39 | | internal class LandsController : ILandsController |
| | 40 | | { |
| | 41 | | public event Action<LandWithAccess[]> OnLandsSet; |
| | 42 | |
|
| | 43 | | private LandWithAccess[] userLands = null; |
| | 44 | |
|
| | 45 | | void ILandsController.SetLands(LandWithAccess[] lands) |
| | 46 | | { |
| 0 | 47 | | userLands = lands; |
| 0 | 48 | | OnLandsSet?.Invoke(lands); |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | void ILandsController.AddListener(ILandsListener listener) |
| | 52 | | { |
| 0 | 53 | | OnLandsSet += listener.OnSetLands; |
| 0 | 54 | | listener.OnSetLands(userLands); |
| 0 | 55 | | } |
| | 56 | |
|
| 0 | 57 | | void ILandsController.RemoveListener(ILandsListener listener) { OnLandsSet -= listener.OnSetLands; } |
| 0 | 58 | | public LandWithAccess[] GetLands() { return userLands; } |
| | 59 | | } |