You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Farming/WateringCanState.cs

99 lines
2.6 KiB

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