Project cleanup: Removed 3D scripts and scenes from project. Also renamed and moved some minor stuff.

This commit is contained in:
2025-05-28 16:02:51 +02:00
committed by cblech
parent 1f17cca62d
commit c6ec99e87a
76 changed files with 35 additions and 5744 deletions
@@ -1,107 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.Farming;
[GlobalClass]
public partial class FarmingControls : Node3D
{
[Export] private Sprite3D _hoeSprite;
[Export] private Sprite3D _wateringCanSprite;
[Export] private PackedScene _fieldPrefab;
[Export] private Node3D _movingPlayer;
[Export] private Camera3D _camera;
public FieldService FieldParent;
private bool _hoeInHand = false;
private bool _waterCanInHand = false;
#region Tools
public bool ActivateHoe(bool activate)
{
bool success = ActivateTool(activate, _hoeSprite);
_hoeInHand = success;
return success;
}
public bool ActivateWateringCan(bool activate)
{
bool success = ActivateTool(activate, _wateringCanSprite);
_waterCanInHand = success;
return success;
}
private bool ActivateTool(bool activate, Sprite3D tool)
{
tool.Visible = !activate;
return !activate;
}
#endregion
public override void _Input(InputEvent @event)
{
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 (position3D.HasValue)
{
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(Vector2I fieldPosition)
{
FieldBehaviour field = FieldParent.Get(fieldPosition);
if (field == null)
return;
field.Water();
}
private void MakeField(Vector2I fieldPosition)
{
if(FieldParent == null || _fieldPrefab == null)
return;
// only instantiate a field if there isn't one already.
if(FieldParent.Get(fieldPosition) == null)
{
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);
}
}
}
private int AdjustValue(float value)
{
return (int) Mathf.Floor(value);
}
}
@@ -1 +0,0 @@
uid://b1sscdr4ptec8
@@ -1,59 +0,0 @@
using System.Diagnostics;
using Godot;
namespace Babushka.scripts.CSharp.Common.Farming
{
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;
}
}
}
}
@@ -1 +0,0 @@
uid://histmmyi1wr
@@ -2,6 +2,15 @@ using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
public enum FieldState
{
Empty = 0,
Tilled = 1,
Planted = 2,
Watered = 3,
NotFound = 99
}
[GlobalClass]
public partial class FieldBehaviour2D : Sprite2D
{
@@ -1,56 +0,0 @@
using System.Diagnostics;
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.Farming;
[GlobalClass]
public partial class FieldService : Node3D
{
[Export] private Dictionary<Vector2I, FieldBehaviour> fields = new Dictionary<Vector2I, FieldBehaviour>();
//Create
public bool TryAddEntry(Vector2I key, FieldBehaviour field)
{
if (!fields.ContainsKey(key))
{
fields.Add(key, field);
return true;
}
return false;
}
// Read
public FieldBehaviour Get(Vector2I key)
{
if (fields.TryGetValue(key, out FieldBehaviour field))
return field;
return field;
return null;
}
//Update
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour 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);
}
}
}
@@ -1 +0,0 @@
uid://c6hh7m8wikv04
@@ -1,68 +0,0 @@
using System;
using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
public enum PlantState
{
None = 0,
Planted = 1,
SmallPlant = 2,
BigPlant = 3,
Ready = 4
}
public partial class PlantBehaviour : Node3D
{
[Export] private Sprite3D[] _seeds;
[Export] private Sprite3D[] _smallPlants;
[Export] private Sprite3D[] _bigPlants;
[Export] private Sprite3D[] _readyPlants;
[Export] private PlantState _state = PlantState.None;
private Sprite3D _currentPlantSprite = null;
public void Grow()
{
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;
}
}
private Sprite3D GetRandomSprite(Sprite3D[] sprites)
{
Random rand = new Random();
return sprites[rand.Next(sprites.Length)];
}
}
@@ -1 +0,0 @@
uid://yfnjmuuxs3oq
@@ -5,6 +5,15 @@ using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
public enum PlantState
{
None = 0,
Planted = 1,
SmallPlant = 2,
BigPlant = 3,
Ready = 4
}
/// <summary>
/// Determines the behaviour of a plant in Babushka.
/// </summary>