Merge remote-tracking branch 'origin/develop' into quest_system
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
[Export] private Area2D _area;
|
||||
[Export] private Label _label;
|
||||
[Export] private SpriteSwitcher2D _sprites;
|
||||
[Export] private bool _showLabel = true;
|
||||
[Export] private int _id;
|
||||
|
||||
[Signal] public delegate void InteractedToolEventHandler(int id);
|
||||
[Signal] public delegate void InteractedEventHandler();
|
||||
|
||||
public void OnPlayerEntered(Node2D player)
|
||||
{
|
||||
if(_showLabel)
|
||||
_label.Show();
|
||||
}
|
||||
|
||||
public void OnPlayerExited(Node2D player)
|
||||
{
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
||||
{
|
||||
_label.Hide();
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSpriteActiveState(bool success, int id)
|
||||
{
|
||||
if (_id == id)
|
||||
{
|
||||
_sprites.SwitchState(!success);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ckp413wrub5fm
|
||||
@@ -2,19 +2,59 @@ using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player2D : Node2D
|
||||
public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
|
||||
private bool anyActionPressed;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
Position = new Vector2(Position.X + (_speed * (float)delta), Position.Y);
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
Position = new Vector2(Position.X - (_speed * (float)delta), Position.Y);
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
Position = new Vector2(Position.X, Position.Y - (_speed * (float)delta));
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
Position = new Vector2(Position.X, Position.Y + (_speed * (float)delta));
|
||||
anyActionPressed = false;
|
||||
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
{
|
||||
Velocity = new Vector2(_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = false;
|
||||
_sprite.Animation = "side_walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
{
|
||||
Velocity = new Vector2(-_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = true;
|
||||
_sprite.Animation = "side_walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
{
|
||||
Velocity = new Vector2(0, -_speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "back walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
{
|
||||
Velocity = new Vector2(0, _speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "front walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (anyActionPressed)
|
||||
{
|
||||
_sprite.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
_sprite.Animation = "front idle";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using Babushka.scripts.CSharp.Common.Farming;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class VesnaBehaviour : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService _fieldParent;
|
||||
[Export] private FarmingControls _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldParent = _fieldParent;
|
||||
}
|
||||
|
||||
#region Farming
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 0);
|
||||
}
|
||||
|
||||
public void ActivateWateringCan(bool activate)
|
||||
{
|
||||
ActivateTool(activate, 1);
|
||||
}
|
||||
|
||||
private void ActivateTool(bool activate , int toolId)
|
||||
{
|
||||
bool success = false;
|
||||
if (toolId == 0)
|
||||
{
|
||||
success = _farmingControls.ActivateHoe(activate);
|
||||
}
|
||||
else if (toolId == 1)
|
||||
{
|
||||
success = _farmingControls.ActivateWateringCan(activate);
|
||||
}
|
||||
EmitSignal(SignalName.ToolPickup, success);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://xm0um640aes7
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
@@ -10,6 +13,7 @@ public partial class FarmingControls : Node3D
|
||||
[Export] private Sprite3D _wateringCanSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node3D _movingPlayer;
|
||||
[Export] private Camera3D _camera;
|
||||
|
||||
public FieldService FieldParent;
|
||||
|
||||
@@ -42,45 +46,62 @@ public partial class FarmingControls : Node3D
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
{
|
||||
MakeField();
|
||||
}
|
||||
Vector2 mousePosition = GetViewport().GetMousePosition();
|
||||
var dropPlane = new Plane(new Vector3(0, 0, 10), 10);
|
||||
Vector3? position3D = dropPlane.IntersectsRay(_camera.ProjectRayOrigin(mousePosition),
|
||||
_camera.ProjectRayNormal(mousePosition));
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
if (position3D.HasValue)
|
||||
{
|
||||
WaterTheField();
|
||||
Vector2I adjustedPosition = new Vector2I(AdjustValue(position3D.Value.X), AdjustValue(position3D.Value.Y));
|
||||
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
{
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
{
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WaterTheField()
|
||||
private void WaterTheField(Vector2I fieldPosition)
|
||||
{
|
||||
FieldBehaviour field = FieldParent.Get(fieldPosition);
|
||||
if (field == null)
|
||||
return;
|
||||
|
||||
field.Water();
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
private void MakeField(Vector2I fieldPosition)
|
||||
{
|
||||
if(FieldParent == null || _fieldPrefab == null)
|
||||
return;
|
||||
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
|
||||
if (fieldInstance is Node3D field3d)
|
||||
// only instantiate a field if there isn't one already.
|
||||
if(FieldParent.Get(fieldPosition) == null)
|
||||
{
|
||||
Vector3 playerPos = _movingPlayer.GlobalPosition;
|
||||
playerPos = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
field3d.Position = playerPos;
|
||||
Vector2I intPosition = new Vector2I((int) playerPos.X, (int) playerPos.Z);
|
||||
FieldParent.AddEntry(intPosition, FieldState.Tilled);
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
Array<Node> fields = field3d.FindChildren("*", nameof(FieldBehaviour));
|
||||
if (fields.Count > 0)
|
||||
FieldParent.TryAddEntry(fieldPosition, fields[0] as FieldBehaviour);
|
||||
|
||||
// reposition and reparent the instance
|
||||
field3d.Position = new Vector3(fieldPosition.X, 0.1f, fieldPosition.Y * -1);;
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
|
||||
private float AdjustValue(float value)
|
||||
private int AdjustValue(float value)
|
||||
{
|
||||
return Mathf.Floor(value);
|
||||
return (int) Mathf.Floor(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FarmingControls2D : Node2D
|
||||
{
|
||||
[Export] private Sprite2D _hoeSprite;
|
||||
[Export] private Sprite2D _wateringCanEmptySprite;
|
||||
[Export] private Sprite2D _wateringCanFilledSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node2D _movingPlayer;
|
||||
[Export] private Camera2D _camera;
|
||||
|
||||
public FieldService2D FieldService;
|
||||
|
||||
private int _toolId = -1;
|
||||
private bool _wateringCanFilled = false;
|
||||
private int _currentWateringCanStep = 0;
|
||||
private int _wateringCanCapacity = 3;
|
||||
|
||||
#region Tools
|
||||
|
||||
/// <summary>
|
||||
/// If no tool has been set, then set the current tool to the incoming tool id.
|
||||
/// </summary>
|
||||
/// <param name="toolId">The id of the tool to activate if possible</param>
|
||||
/// <returns>If the tool in question was activated.</returns>
|
||||
public bool TryActivateTool(int toolId)
|
||||
{
|
||||
bool activate;
|
||||
|
||||
//if our hands are empty, activate
|
||||
if (_toolId == -1)
|
||||
{
|
||||
activate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we're already carrying a tool, deactivate or fail return
|
||||
if (_toolId == toolId)
|
||||
{
|
||||
activate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (toolId)
|
||||
{
|
||||
case 0:
|
||||
_hoeSprite.Visible = activate;
|
||||
break;
|
||||
case 1:
|
||||
if (activate)
|
||||
{
|
||||
_wateringCanEmptySprite.Visible = true;
|
||||
GD.Print("Activating empty Watering can sprite.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_wateringCanEmptySprite.Visible = false;
|
||||
_wateringCanFilledSprite.Visible = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_toolId = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
_toolId = activate ? toolId : -1;
|
||||
return activate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
||||
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
||||
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
||||
|
||||
if (@event.IsActionPressed("click") && _toolId == 0)
|
||||
{
|
||||
MakeField(adjustedPosition);
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _toolId == 1 && _wateringCanFilled)
|
||||
{
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void FillWateringCan(bool fillUp)
|
||||
{
|
||||
if (_toolId == 1 )
|
||||
{
|
||||
GD.Print("Watering can in hand, filling.");
|
||||
_wateringCanEmptySprite.Visible = !fillUp;
|
||||
_wateringCanFilledSprite.Visible = fillUp;
|
||||
_wateringCanFilled = fillUp;
|
||||
}
|
||||
}
|
||||
|
||||
private void WaterTheField(Vector2I fieldPosition)
|
||||
{
|
||||
FieldBehaviour2D field = FieldService.Get(fieldPosition);
|
||||
if (field == null || field.FieldState == FieldState.Watered)
|
||||
return;
|
||||
|
||||
field.Water();
|
||||
|
||||
if (_currentWateringCanStep < _wateringCanCapacity)
|
||||
{
|
||||
_currentWateringCanStep++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentWateringCanStep = 0;
|
||||
FillWateringCan(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void MakeField(Vector2I fieldPosition)
|
||||
{
|
||||
if(FieldService == null || _fieldPrefab == null)
|
||||
return;
|
||||
|
||||
// only try to instantiate a field if you're in the allowed area
|
||||
if (!FieldService.FieldAllowed())
|
||||
return;
|
||||
|
||||
// only instantiate a field if there isn't one already.
|
||||
if(FieldService.Get(fieldPosition) == null)
|
||||
{
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
if (fieldInstance is Node2D field2d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
||||
if (fields.Count > 0)
|
||||
FieldService.TryAddEntry(fieldPosition, fields[0] as FieldBehaviour2D);
|
||||
|
||||
// reposition and reparent the instance
|
||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
||||
FieldService.AddChild(fieldInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int AdjustValue(float value)
|
||||
{
|
||||
float adjustedValue = value / 500;
|
||||
adjustedValue = Mathf.RoundToInt(adjustedValue);
|
||||
adjustedValue *= 500;
|
||||
return (int)adjustedValue;
|
||||
}
|
||||
|
||||
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
||||
{
|
||||
return input.Snapped(step);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcskt5ckh3rqa
|
||||
@@ -1,54 +1,59 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public enum FieldState
|
||||
namespace Babushka.scripts.CSharp.Common.Farming
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3
|
||||
public enum FieldState
|
||||
{
|
||||
Empty = 0,
|
||||
Tilled = 1,
|
||||
Planted = 2,
|
||||
Watered = 3,
|
||||
NotFound = 99
|
||||
}
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Empty;
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture = Tilled;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void Water()
|
||||
{
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] private FieldState FieldState = FieldState.Empty;
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture = Tilled;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void Water()
|
||||
{
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field'S interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldBehaviour2D : Sprite2D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Tilled;
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
UpdateFieldState(FieldState);
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void UpdateFieldState(FieldState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
FieldState = FieldState.Empty;
|
||||
break;
|
||||
case FieldState.Tilled:
|
||||
FieldState = FieldState.Tilled;
|
||||
Texture = Tilled;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
default:
|
||||
FieldState = FieldState.NotFound;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Water()
|
||||
{
|
||||
FieldState = FieldState.Watered;
|
||||
Texture = Watered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player enters the field's interaction area and presses <E>.
|
||||
/// </summary>
|
||||
public void Farm()
|
||||
{
|
||||
switch (FieldState)
|
||||
{
|
||||
case FieldState.Empty:
|
||||
Texture = Tilled;
|
||||
FieldState = FieldState.Tilled;
|
||||
break;
|
||||
case FieldState.Watered:
|
||||
FieldState = FieldState.Planted;
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bdffon388rkty
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
@@ -6,32 +7,40 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
[GlobalClass]
|
||||
public partial class FieldService : Node3D
|
||||
{
|
||||
[Export] private Dictionary<Vector2I, FieldState> fields = new Dictionary<Vector2I, FieldState>();
|
||||
[Export] private Dictionary<Vector2I, FieldBehaviour> fields = new Dictionary<Vector2I, FieldBehaviour>();
|
||||
|
||||
//Create
|
||||
|
||||
public void AddEntry(Vector2I key, FieldState state)
|
||||
public bool TryAddEntry(Vector2I key, FieldBehaviour field)
|
||||
{
|
||||
fields.Add(key, state);
|
||||
if (!fields.ContainsKey(key))
|
||||
{
|
||||
fields.Add(key, field);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
public FieldState Get(Vector2I key)
|
||||
public FieldBehaviour Get(Vector2I key)
|
||||
{
|
||||
return fields[key];
|
||||
if (fields.TryGetValue(key, out FieldBehaviour field))
|
||||
return field;
|
||||
return field;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Update
|
||||
public void UpdateEntry(Vector2I fieldPosition, FieldState state)
|
||||
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour state)
|
||||
{
|
||||
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields[fieldPosition] = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntry(fieldPosition, state);
|
||||
TryAddEntry(fieldPosition, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
uid://12hleqx8amr8
|
||||
uid://c6hh7m8wikv04
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldService2D : Node2D
|
||||
{
|
||||
[Export] private Dictionary<Vector2I, FieldBehaviour2D> fields = new Dictionary<Vector2I, FieldBehaviour2D>();
|
||||
|
||||
private bool _fieldAllowed = false;
|
||||
|
||||
//Validate
|
||||
|
||||
public void MouseEnteredAllowedArea()
|
||||
{
|
||||
_fieldAllowed = true;
|
||||
}
|
||||
|
||||
public void MouseExitedAllowedArea()
|
||||
{
|
||||
_fieldAllowed = false;
|
||||
}
|
||||
|
||||
public bool FieldAllowed()
|
||||
{
|
||||
return _fieldAllowed;
|
||||
}
|
||||
|
||||
//Create
|
||||
public bool TryAddEntry(Vector2I key, FieldBehaviour2D field)
|
||||
{
|
||||
if (!fields.ContainsKey(key))
|
||||
{
|
||||
fields.Add(key, field);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read
|
||||
public FieldBehaviour2D Get(Vector2I key)
|
||||
{
|
||||
if (fields.TryGetValue(key, out FieldBehaviour2D field))
|
||||
return field;
|
||||
return field;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Update
|
||||
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour2D state)
|
||||
{
|
||||
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields[fieldPosition] = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
TryAddEntry(fieldPosition, state);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete
|
||||
|
||||
public void RemoveEntry(Vector2I fieldPosition)
|
||||
{
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields.Remove(fieldPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dhxtdhfqx3bte
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
/// <summary>
|
||||
/// Determines the behaviour of a plant in Babushka.
|
||||
/// </summary>
|
||||
public partial class PlantBehaviour2D : Node2D
|
||||
{
|
||||
[Export] private Sprite2D[] _seeds;
|
||||
[Export] private Sprite2D[] _smallPlants;
|
||||
[Export] private Sprite2D[] _bigPlants;
|
||||
[Export] private Sprite2D[] _readyPlants;
|
||||
[Export] private PlantState _state = PlantState.None;
|
||||
[Export] private FieldBehaviour2D _field;
|
||||
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
|
||||
/// <summary>
|
||||
/// Transitions the plant to its next growth stage.
|
||||
/// </summary>
|
||||
public void Grow()
|
||||
{
|
||||
if (_field.FieldState != FieldState.Watered)
|
||||
return;
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case PlantState.None:
|
||||
_state = PlantState.Planted;
|
||||
_currentPlantSprite = GetRandomSprite(_seeds);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.Planted:
|
||||
_state = PlantState.SmallPlant;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_smallPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.SmallPlant:
|
||||
_state = PlantState.BigPlant;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_bigPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.BigPlant:
|
||||
_state = PlantState.Ready;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = GetRandomSprite(_readyPlants);
|
||||
_currentPlantSprite.Visible = true;
|
||||
break;
|
||||
case PlantState.Ready:
|
||||
_state = PlantState.None;
|
||||
_currentPlantSprite.Visible = false;
|
||||
_currentPlantSprite = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_field.UpdateFieldState(FieldState.Tilled);
|
||||
}
|
||||
|
||||
private Sprite2D GetRandomSprite(Sprite2D[] sprites)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return sprites[rand.Next(sprites.Length)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cms357f23fmfy
|
||||
@@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class VesnaBehaviour2D : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
|
||||
[Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldService = _fieldParent;
|
||||
}
|
||||
|
||||
#region Farming
|
||||
|
||||
public void ActivateTool(int toolId)
|
||||
{
|
||||
bool activated = _farmingControls.TryActivateTool(toolId);
|
||||
EmitSignal(SignalName.PickedUpTool, activated, toolId);
|
||||
}
|
||||
|
||||
public void TryFillWateringCan(int toolId)
|
||||
{
|
||||
if (toolId == 1)
|
||||
{
|
||||
_farmingControls.FillWateringCan(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b05uyj001ehwi
|
||||
@@ -1 +0,0 @@
|
||||
uid://b7vlkecrn0t5c
|
||||
@@ -0,0 +1 @@
|
||||
uid://hg7jay2kt441
|
||||
@@ -0,0 +1,36 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Switches between two available Sprite Options.
|
||||
/// </summary>
|
||||
public partial class SpriteSwitcher2D : Node2D
|
||||
{
|
||||
[Export] private Sprite2D _activeSprite;
|
||||
[Export] private Sprite2D _inactiveSprite;
|
||||
[Export] private bool _active = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetSprites();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches the State of the Sprites to the opposite.
|
||||
/// Emits Switch Signal.
|
||||
/// </summary>
|
||||
public void SwitchState(bool state)
|
||||
{
|
||||
_active = state;
|
||||
SetSprites();
|
||||
}
|
||||
|
||||
private void SetSprites()
|
||||
{
|
||||
if(_activeSprite != null)
|
||||
_activeSprite.Visible = _active;
|
||||
if(_inactiveSprite != null)
|
||||
_inactiveSprite.Visible = !_active;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://pemu31f6fe4l
|
||||
Reference in New Issue
Block a user