From 0ccbd787e48502d9caa990e5683680dda5dbdcaf Mon Sep 17 00:00:00 2001 From: josemgmz Date: Mon, 11 Nov 2024 00:48:24 +0100 Subject: [PATCH] docs: CardGridController.cs documentation --- .../Entities/CardGrid/CardGridController.cs | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Game/Entities/CardGrid/CardGridController.cs b/Assets/Scripts/Game/Entities/CardGrid/CardGridController.cs index c3077b0..ec593ff 100644 --- a/Assets/Scripts/Game/Entities/CardGrid/CardGridController.cs +++ b/Assets/Scripts/Game/Entities/CardGrid/CardGridController.cs @@ -10,22 +10,34 @@ namespace Game.Entities.CardGrid { + /// + /// Controls the card grid, handling the creation and cleanup of the grid. + /// public class CardGridController : GameController { #region Lifecycle + /// + /// Event bus for handling game events. + /// [Inject] private IGameEventBus _eventBus; #endregion - + #region Lifecycle Methods + /// + /// Registers event listeners for setting up and cleaning the grid. + /// private void Awake() { _eventBus.AddListener(CreateGrid); _eventBus.AddListener(CleanGrid); } - + + /// + /// Unregisters event listeners when the controller is destroyed. + /// private void OnDestroy() { _eventBus.RemoveListener(CreateGrid); @@ -36,21 +48,25 @@ private void OnDestroy() #region Methods + /// + /// Creates the card grid based on the provided event data. + /// + /// The event data containing grid setup information. private void CreateGrid(OnCardGridSetupEvent eventData) { - //Get model + // Get model var model = GetModel(); model.ResponsiveGridLayout.SetColumns(eventData.Columns); model.ResponsiveGridLayout.SetSpacing(model.Spacing); - - //Create the grid. + + // Create the grid eventData.Cards.ForEach(it => { CreateCard(model.CardPrefab, it); CreateCard(model.CardPrefab, it); }); - - //Shuffle the cards + + // Shuffle the cards if (!eventData.Shuffle) return; var children = new List(); for (var i = 0; i < transform.childCount; i++) @@ -59,20 +75,29 @@ private void CreateGrid(OnCardGridSetupEvent eventData) children.ForEach(it => it.SetSiblingIndex(0)); } + /// + /// Creates a card in the grid. + /// + /// The card prefab to instantiate. + /// The event data for setting up the card. private void CreateCard(GameObject cardPrefab, OnCardSetupEvent it) { - //Instantiate the card + // Instantiate the card var card = Object.Instantiate(cardPrefab, transform); card.name = $"Card {it.CardShape.GetString()} {it.CardType.GetString()}"; - - //Get the view and initialize it + + // Get the view and initialize it var cardView = card.GetComponent(); cardView.Initialize(it.CardShape, it.CardType, true); } - + + /// + /// Cleans up the card grid by destroying all child objects. + /// + /// The event data for ending the round. private void CleanGrid(OnRoundEndEvent eventData) { - //Destroy + // Destroy for (var i = 0; i < transform.childCount; i++) Object.Destroy(transform.GetChild(i).gameObject); }