♻️ removed planted state from Fieldstate because it didn't make any sense.
This commit is contained in:
@@ -47,6 +47,8 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
private bool _canWater;
|
private bool _canWater;
|
||||||
private int _currentDay;
|
private int _currentDay;
|
||||||
|
|
||||||
|
public bool IsPlanted;
|
||||||
|
|
||||||
private PlantBehaviour2D? _currentPlant;
|
private PlantBehaviour2D? _currentPlant;
|
||||||
|
|
||||||
private const string DAY_COUNTER_SAVE_ID = "12c6da2e-fc71-4281-a04a-dfd3c7943975";
|
private const string DAY_COUNTER_SAVE_ID = "12c6da2e-fc71-4281-a04a-dfd3c7943975";
|
||||||
@@ -58,7 +60,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
// fieldstate == tilled / watered && samen im Inventar
|
// fieldstate == tilled / watered && samen im Inventar
|
||||||
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
_canPlant = (FieldState == FieldState.Tilled || FieldState == FieldState.Watered) && _seedsActive;
|
||||||
// fieldstate == tilled && watering can ausgewählt
|
// fieldstate == tilled && watering can ausgewählt
|
||||||
_canWater = (FieldState == FieldState.Tilled || FieldState == FieldState.Planted) && _wateringCanActive;
|
_canWater = (FieldState == FieldState.Tilled || IsPlanted) && _wateringCanActive;
|
||||||
|
|
||||||
PlantingInteraction.IsActive = _canPlant || _canWater;
|
PlantingInteraction.IsActive = _canPlant || _canWater;
|
||||||
}
|
}
|
||||||
@@ -103,18 +105,15 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
case FieldState.Tilled:
|
case FieldState.Tilled:
|
||||||
FieldState = FieldState.Tilled;
|
FieldState = FieldState.Tilled;
|
||||||
_fieldSprite.Texture = Tilled;
|
_fieldSprite.Texture = Tilled;
|
||||||
|
if(!IsPlanted)
|
||||||
PlantingInteraction.IsActive = true;
|
PlantingInteraction.IsActive = true;
|
||||||
break;
|
break;
|
||||||
case FieldState.Watered:
|
case FieldState.Watered:
|
||||||
FieldState = FieldState.Watered;
|
FieldState = FieldState.Watered;
|
||||||
_fieldSprite.Texture = Watered;
|
_fieldSprite.Texture = Watered;
|
||||||
|
if(!IsPlanted)
|
||||||
PlantingInteraction.IsActive = true;
|
PlantingInteraction.IsActive = true;
|
||||||
break;
|
break;
|
||||||
case FieldState.Planted:
|
|
||||||
FieldState = FieldState.Planted;
|
|
||||||
_fieldSprite.Texture = Tilled;
|
|
||||||
PlantingInteraction.IsActive = false;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
FieldState = FieldState.NotFound;
|
FieldState = FieldState.NotFound;
|
||||||
break;
|
break;
|
||||||
@@ -124,7 +123,6 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
UpdateSaveData();
|
UpdateSaveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Water()
|
public void Water()
|
||||||
{
|
{
|
||||||
if (WateringCanState.GetFillState() > 0 && FieldState != FieldState.Watered)
|
if (WateringCanState.GetFillState() > 0 && FieldState != FieldState.Watered)
|
||||||
@@ -150,7 +148,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
if (_canPlant && TryPlant())
|
if (_canPlant && TryPlant())
|
||||||
{
|
{
|
||||||
EmitSignal(SignalName.Planted);
|
EmitSignal(SignalName.Planted);
|
||||||
UpdateFieldState(FieldState.Planted);
|
UpdateSaveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_canWater)
|
if (_canWater)
|
||||||
@@ -159,6 +157,17 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangePlantedState()
|
||||||
|
{
|
||||||
|
GD.Print("Adding Plant.");
|
||||||
|
IsPlanted = true;
|
||||||
|
if(FieldState == FieldState.Tilled)
|
||||||
|
_fieldSprite.Texture = Tilled;
|
||||||
|
if(FieldState == FieldState.Watered)
|
||||||
|
_fieldSprite.Texture = Watered;
|
||||||
|
PlantingInteraction.IsActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryPlant()
|
private bool TryPlant()
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
@@ -186,6 +195,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
|
|
||||||
if (_currentPlant != null)
|
if (_currentPlant != null)
|
||||||
{
|
{
|
||||||
|
ChangePlantedState();
|
||||||
_currentPlant.DayPlanted = _currentDay;
|
_currentPlant.DayPlanted = _currentDay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,6 +218,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
{
|
{
|
||||||
_currentPlant = null;
|
_currentPlant = null;
|
||||||
UpdateFieldState(FieldState.Empty, true);
|
UpdateFieldState(FieldState.Empty, true);
|
||||||
|
IsPlanted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region SAVE AND LOAD
|
#region SAVE AND LOAD
|
||||||
@@ -220,11 +231,12 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
var payloadData = new Dictionary<string, Variant>
|
var payloadData = new Dictionary<string, Variant>
|
||||||
{
|
{
|
||||||
{ "field_state", (int)FieldState },
|
{ "field_state", (int)FieldState },
|
||||||
{ "day_count_on_last_exit", _currentDay}
|
{ "day_count_on_last_exit", _currentDay},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_currentPlant != null)
|
if (IsPlanted)
|
||||||
{
|
{
|
||||||
|
GD.Print("Saving plant data.");
|
||||||
payloadData.Add(
|
payloadData.Add(
|
||||||
"plant_data", new Dictionary<string, Variant>()
|
"plant_data", new Dictionary<string, Variant>()
|
||||||
{
|
{
|
||||||
@@ -257,6 +269,7 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
// get plant first because it's also relevant for the field state
|
// get plant first because it's also relevant for the field state
|
||||||
if (save.TryGetValue("plant_data", out Variant plantDataVar))
|
if (save.TryGetValue("plant_data", out Variant plantDataVar))
|
||||||
{
|
{
|
||||||
|
IsPlanted = true;
|
||||||
Dictionary<string, Variant> plantDataDict = plantDataVar.AsGodotDictionary<string, Variant>();
|
Dictionary<string, Variant> plantDataDict = plantDataVar.AsGodotDictionary<string, Variant>();
|
||||||
|
|
||||||
if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar))
|
if (plantDataDict.TryGetValue("prefab_path", out Variant prefabPathVar))
|
||||||
@@ -313,20 +326,13 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
|||||||
// if day is today, then just use the provided field state as is.
|
// if day is today, then just use the provided field state as is.
|
||||||
if (CalendarController.Instance != null && _currentDay != lastDayCount)
|
if (CalendarController.Instance != null && _currentDay != lastDayCount)
|
||||||
{
|
{
|
||||||
// if the field was watered the day before, set it to tilled or planted.
|
// if the field was watered the day before, set it to tilled
|
||||||
if (fieldStateInt == 3)
|
if (fieldStateInt == 3)
|
||||||
{
|
|
||||||
if (_currentPlant != null)
|
|
||||||
{
|
|
||||||
fieldStateInt = 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
fieldStateInt = 1;
|
fieldStateInt = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
FieldState = (FieldState) fieldStateInt;
|
FieldState = (FieldState) fieldStateInt;
|
||||||
UpdateFieldState(FieldState, false);
|
UpdateFieldState(FieldState, false);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ public enum FieldState
|
|||||||
{
|
{
|
||||||
Empty = 0,
|
Empty = 0,
|
||||||
Tilled = 1,
|
Tilled = 1,
|
||||||
Planted = 2,
|
|
||||||
Watered = 3,
|
Watered = 3,
|
||||||
NotFound = 99
|
NotFound = 99
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user