✨ watering can fillstate is saving and loading
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class WateringCanSaveHelper : Node
|
||||
{
|
||||
[Export] private SaveableVariableNode _wateringCanFillStateNode;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
WateringCanState.OnFill += SetFillState;
|
||||
WateringCanState.OnWater += SetFillState;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
WateringCanState.OnFill -= SetFillState;
|
||||
WateringCanState.OnWater -= SetFillState;
|
||||
}
|
||||
|
||||
|
||||
public void SetFillState()
|
||||
{
|
||||
_wateringCanFillStateNode.Payload = WateringCanState.GetFillState();
|
||||
}
|
||||
|
||||
private void OnLoad()
|
||||
{
|
||||
WateringCanState.SetFillState(_wateringCanFillStateNode.Payload.AsInt32());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dj1qjambsa4pg
|
||||
@@ -29,6 +29,7 @@ public static class WateringCanState
|
||||
public delegate void WateringCanDelegate(bool state);
|
||||
public static event WateringCanDelegate WateringCanActiveStateChanged;
|
||||
public static event Action? OnWater;
|
||||
public static event Action? OnFill;
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +39,7 @@ public static class WateringCanState
|
||||
public static void Fill()
|
||||
{
|
||||
_fillstate = MAX_FILLSTATE;
|
||||
OnFill?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,6 +71,15 @@ public static class WateringCanState
|
||||
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>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
@@ -9,6 +8,9 @@ public partial class SaveableVariableNode : VariableNode, ISaveable
|
||||
{
|
||||
[Export] private bool _debug;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnLoadingCompleteEventHandler();
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
LoadFromSaveData();
|
||||
@@ -60,5 +62,7 @@ public partial class SaveableVariableNode : VariableNode, ISaveable
|
||||
GD.Print($"SaveableVariable {Name} loaded payload: {Payload}.");
|
||||
}
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.OnLoadingComplete);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user