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