WIP moving seed to plant matching into separate system, making fields independent of specific plants.
This commit is contained in:
@@ -165,4 +165,5 @@ public partial class FarmingControls2D : Node2D
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -13,7 +14,9 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Tilled;
|
||||
[Export] private InteractionArea2D _growingCollider;
|
||||
[Export] public InteractionArea2D PlantingInteraction;
|
||||
[Export] public Node PlantingPlaceholder;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
@@ -31,19 +34,21 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
{
|
||||
case FieldState.Empty:
|
||||
FieldState = FieldState.Empty;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Tilled;
|
||||
_fieldSprite.Texture = Tilled;
|
||||
_growingCollider.Visible = false;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Watered;
|
||||
_fieldSprite.Texture = Watered;
|
||||
_growingCollider.Visible = true;
|
||||
PlantingInteraction.IsActive = true;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
FieldState = FieldState.Planted;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
default:
|
||||
FieldState = FieldState.NotFound;
|
||||
@@ -62,19 +67,37 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
if (FieldState == FieldState.Watered)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
_fieldSprite.Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (TryPlant())
|
||||
{
|
||||
UpdateFieldState(FieldState.Planted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryPlant()
|
||||
{
|
||||
bool success = false;
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null)
|
||||
return success;
|
||||
|
||||
PackedScene? plantPrefab = SeedRepository.Instance.GetPlant(item.blueprint);
|
||||
|
||||
if (plantPrefab != null)
|
||||
{
|
||||
Node plantInstance = plantPrefab.Instantiate();
|
||||
if (plantInstance is Node2D plant2d)
|
||||
{
|
||||
PlantingPlaceholder.AddChild(plant2d);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,20 +12,6 @@ public partial class FieldService2D : Node2D
|
||||
|
||||
[Signal] public delegate void FieldCreatedEventHandler();
|
||||
|
||||
/*
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var spaceState = GetWorld2D().DirectSpaceState;
|
||||
// use global coordinates, not local to node
|
||||
var query = PhysicsRayQueryParameters2D.Create(GetGlobalMousePosition(), new Vector3(0,0,-1),
|
||||
CollisionMask, [GetRid()]);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
GD.Print("Hit at point: ", result["position"]);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//Create
|
||||
public bool TryAddEntry(Vector2I key, FieldBehaviour2D field)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class SeedRepository : Node
|
||||
{
|
||||
public static SeedRepository Instance { get; private set; } = null!;
|
||||
|
||||
// todo: Find out how to not use PackedScene here because it does not inherit from Node
|
||||
[Export] private Dictionary<ItemResource, PackedScene> seedToPlantRepository;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public PackedScene? GetPlant(ItemResource resource)
|
||||
{
|
||||
if (seedToPlantRepository.ContainsKey(resource))
|
||||
{
|
||||
return seedToPlantRepository[resource];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://coqch6yjvjuc0
|
||||
Reference in New Issue
Block a user