Added Comments

This commit is contained in:
j-weissen 2022-06-24 08:05:57 +02:00
parent 9151d987a7
commit 5f1a5e5abc
10 changed files with 67 additions and 2 deletions

View file

@ -3,6 +3,10 @@ using Assets.Scripts.Actions;
using UnityEngine;
namespace Actions {
/// <summary>
/// AcrionManagaer managing Actions.
/// ActionHandler implement either NextDayActionHandler or ClickActionHandler and have to be added to the matching list in the instatiationmethod
/// </summary>
public class ActionManager {
#region Singleton
private static ActionManager _instance;
@ -27,10 +31,17 @@ namespace Actions {
instantiateNextDayActionHandlers();
}
/// <summary>
/// NextDayActionHandlers to be instatiated and added to the corresponding List
/// </summary>
private void instantiateNextDayActionHandlers() {
_nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler());
}
/// <summary>
/// ClickActionHandlers to be instatiated and added to the corresponding List
/// </summary>
private void instantiateClickActionHandlers() {
_clickActionHandlers.Add(new GrassTileClickHoeActionHandler());
_clickActionHandlers.Add(new GrassTileClickShovelActionHandler());
@ -45,6 +56,12 @@ namespace Actions {
_clickActionHandlers.Add(new WaterTileClickFishingRodActionHandler());
}
/// <summary>
/// Used to Invoke ClickActions, all ClickActionHandlers in ClickActionHandlers list are iterated through,
/// only one will be invoked per method call
/// </summary>
/// <param name="gameObject">The affected gameObject</param>
/// <param name="usableItem">the current tool</param>
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
foreach (ClickActionHandler actionHandler in _clickActionHandlers) {
if(actionHandler.Matches(gameObject, usableItem)) {
@ -54,6 +71,12 @@ namespace Actions {
}
}
/// <summary>
/// Used to Invoke ClickActions, all ClickActionHandlers in ClickActionHandlers list are iterated through,
/// only one will be invoked per method call
/// </summary>
/// <param name="gameObject">The affected gameObject</param>
/// <param name="usableItem">the current tool</param>
public void NextDayAction(GameObject gameObject) {
Debug.Log("nextday action");
foreach (NextDayActionHandler actionHandler in _nextDayActionHandlers) {

View file

@ -3,6 +3,9 @@ using System.Transactions;
using UnityEngine;
namespace Actions {
/// <summary>
/// Implementing classes handle ClickActions
/// </summary>
public interface ClickActionHandler {
public void InvokeAction(GameObject gameObject);
public bool Matches(GameObject gameObject, UsableItem usableItem);

View file

@ -2,6 +2,7 @@
using Tiles;
using UnityEngine;
/// Definitions of ClickActionHandlers here
namespace Assets.Scripts.Actions {
public abstract class AbstractTileClickActionHandler : ClickActionHandler {
protected BaseTile _tile;
@ -183,7 +184,7 @@ namespace Assets.Scripts.Actions {
public override void InvokeAction(GameObject gameObject) {
if(crop.FullyGrown) {
Inventory.instance.AddElement(ItemContainer.Instance.GetItemByName("Wheat Seeds"),
(int)(Random.Range(1, 300)));
(int)(Random.Range(1, 3)));
Inventory.instance.AddElement(ItemContainer.Instance.GetItemByName("Wheat"), 1);
crop.ResetPlant();
updateFarmlandSprites(gameObject);

View file

@ -1,6 +1,9 @@
using UnityEngine;
namespace Actions {
/// <summary>
/// Implementing classes handle nextDayAction
/// </summary>
public interface NextDayActionHandler {
public void InvokeAction(GameObject gameObject);
public bool Matches(GameObject gameObject);

View file

@ -2,6 +2,7 @@
using Tiles;
using UnityEngine;
/// Definitions of NextDayActionHandlers here
namespace Actions {
public abstract class AbstractTileNextDayActionHandler : NextDayActionHandler {
protected BaseTile _tile;