using System;
namespace Babushka.scripts.CSharp.Common.Farming;
///
/// Holds Information about the current state of the watering can.
/// Since there is only one watering can, we can track this in one central static class.
///
public static class WateringCanState
{
private static int _fillstate = 0;
///
/// How many fields can be watered with one filling of the watering can.
///
public const int MAX_FILLSTATE = 6;
///
/// The Tool ID of the watering can. Used to identify it amongst other pickup items (and things that can be held by Vesna).
///
public const int WATERING_CAN_ID = 1;
///
/// Whether or not the watering can is currently active, i.e. held in hand by Vesna.
/// Triggers animations and ui.
///
public static bool Active = false;
public delegate void WateringCanDelegate(bool state);
public static event WateringCanDelegate WateringCanActiveStateChanged;
public static event Action? OnWater;
///
/// Resets the fillstate to the max amount.
///
public static void Fill()
{
_fillstate = MAX_FILLSTATE;
}
///
/// Called when watering a field. Reduces the current fillstate.
///
public static void Water()
{
if(_fillstate > 0)
{
_fillstate--;
OnWater?.Invoke();
}
}
///
/// Resets the watering can. Equivalent to "Empty" state.
///
public static void Reset()
{
_fillstate = 0;
}
///
/// Returns the current fill state of the watering can.
///
///
public static int GetFillState()
{
return _fillstate;
}
///
/// Sets the Active state of the watering can, i.e. if it is currently in hand and if the ui should be active.
///
///
public static void SetActive(bool active)
{
if(active != Active)
WateringCanActiveStateChanged?.Invoke(active);
Active = active;
}
}