🐛 fixed dayplanted confusion on plants
This commit is contained in:
@@ -19,7 +19,7 @@ public partial class VesnaAnimations : Node
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Signal] public delegate void LookDirectionEventHandler(Vector2 direction);
|
[Signal] public delegate void LookDirectionEventHandler(Vector2 direction);
|
||||||
|
|
||||||
public override void _EnterTree()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
InventoryManager.Instance.playerInventory.InventoryContentsChanged += HandleNewItemInInventory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,9 +74,13 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
UpdateInteractionArea();
|
UpdateInteractionArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _EnterTree()
|
||||||
{
|
{
|
||||||
LoadFromSaveData();
|
LoadFromSaveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
if(PlantingPlaceholder.GetChildCount() > 0)
|
if(PlantingPlaceholder.GetChildCount() > 0)
|
||||||
_currentPlant = PlantingPlaceholder.GetChild<PlantBehaviour2D>(0);
|
_currentPlant = PlantingPlaceholder.GetChild<PlantBehaviour2D>(0);
|
||||||
UpdateFieldState(FieldState);
|
UpdateFieldState(FieldState);
|
||||||
@@ -169,6 +173,16 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void PlantPrefab(string prefabPath)
|
private void PlantPrefab(string prefabPath)
|
||||||
|
{
|
||||||
|
InstantiatePlant(prefabPath);
|
||||||
|
|
||||||
|
if (_currentPlant != null)
|
||||||
|
{
|
||||||
|
_currentPlant.DayPlanted = _currentDay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstantiatePlant(string prefabPath)
|
||||||
{
|
{
|
||||||
PackedScene prefab = ResourceLoader.Load<PackedScene>(prefabPath, nameof(PackedScene));
|
PackedScene prefab = ResourceLoader.Load<PackedScene>(prefabPath, nameof(PackedScene));
|
||||||
Node2D plant2d = prefab.Instantiate<Node2D>();
|
Node2D plant2d = prefab.Instantiate<Node2D>();
|
||||||
@@ -179,7 +193,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
if (_currentPlant != null)
|
if (_currentPlant != null)
|
||||||
{
|
{
|
||||||
_currentPlant.Field = this;
|
_currentPlant.Field = this;
|
||||||
_currentPlant.DayPlanted = _currentDay;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,15 +247,16 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
|
|
||||||
if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar))
|
if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar))
|
||||||
{
|
{
|
||||||
PlantPrefab(prefabPathVar.AsString());
|
InstantiatePlant(prefabPathVar.AsString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantDaysGrowingVar) && _currentPlant != null)
|
if (plantDataDict.TryGetValue("plant_start_day", out Variant plantStartDay) && _currentPlant != null)
|
||||||
{
|
{
|
||||||
_currentPlant.DayPlanted = plantDaysGrowingVar.AsInt32();
|
_currentPlant.DayPlanted = plantStartDay.AsInt32();
|
||||||
|
GD.Print($"Current plant {_currentPlant.Name} was planted on day: {_currentPlant.DayPlanted}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,8 +268,10 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
if (dayCountSave.TryGetValue("payload", out Variant dayCountVar))
|
if (dayCountSave.TryGetValue("payload", out Variant dayCountVar))
|
||||||
{
|
{
|
||||||
_currentDay = dayCountVar.AsInt32();
|
_currentDay = dayCountVar.AsInt32();
|
||||||
if(_currentPlant != null)
|
if (_currentPlant != null)
|
||||||
_currentPlant.CurrentDayInCalendar = dayCountVar.AsInt32();
|
{
|
||||||
|
_currentPlant.CurrentDayInCalendar = _currentDay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ public partial class PlantBehaviour2D : Node2D
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The day count at the day this plant was planted.
|
/// The day count at the day this plant was planted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int DayPlanted { get; set; }
|
public int DayPlanted
|
||||||
|
{
|
||||||
|
get => _dayPlanted;
|
||||||
|
set => _dayPlanted = value;
|
||||||
|
}
|
||||||
|
|
||||||
public int CurrentDayInCalendar
|
public int CurrentDayInCalendar
|
||||||
{
|
{
|
||||||
@@ -65,6 +69,7 @@ public partial class PlantBehaviour2D : Node2D
|
|||||||
private void DaysGrowingChanged()
|
private void DaysGrowingChanged()
|
||||||
{
|
{
|
||||||
int _daysGrowing = _currentDay - _dayPlanted;
|
int _daysGrowing = _currentDay - _dayPlanted;
|
||||||
|
GD.Print($"Plant {Name} is growing for {_daysGrowing}. Day Planted was {_dayPlanted} and the current day is {_currentDay}.");
|
||||||
int lifecycle = _lifecycle.Payload.AsInt32();
|
int lifecycle = _lifecycle.Payload.AsInt32();
|
||||||
Debug.Assert(lifecycle > 0);
|
Debug.Assert(lifecycle > 0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Babushka.scripts.CSharp.Common.Inventory;
|
||||||
using Babushka.scripts.CSharp.Common.Savegame;
|
using Babushka.scripts.CSharp.Common.Savegame;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
@@ -6,15 +7,25 @@ namespace Babushka.scripts.CSharp.Low_Code.Variables;
|
|||||||
|
|
||||||
public partial class SaveableVariableNode : VariableNode, ISaveable
|
public partial class SaveableVariableNode : VariableNode, ISaveable
|
||||||
{
|
{
|
||||||
public override void _Ready()
|
[Export] private bool _debug;
|
||||||
|
|
||||||
|
public override void _EnterTree()
|
||||||
{
|
{
|
||||||
LoadFromSaveData();
|
LoadFromSaveData();
|
||||||
ValueChanged += UpdateSaveData;
|
ValueChanged += UpdateSaveData;
|
||||||
|
SavegameService.OnSaveGameReset += SaveGameReset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveGameReset()
|
||||||
|
{
|
||||||
|
Payload = default;
|
||||||
|
GD.Print($"Saveable Variable reset to {Payload}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
{
|
{
|
||||||
ValueChanged -= UpdateSaveData;
|
ValueChanged -= UpdateSaveData;
|
||||||
|
SavegameService.OnSaveGameReset -= SaveGameReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSaveData()
|
public void UpdateSaveData()
|
||||||
@@ -43,6 +54,11 @@ public partial class SaveableVariableNode : VariableNode, ISaveable
|
|||||||
{
|
{
|
||||||
Payload = save["payload"];
|
Payload = save["payload"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
GD.Print($"SaveableVariable {Name} loaded payload: {Payload}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user