Project cleanup: Removed 3D scripts and scenes from project. Also renamed and moved some minor stuff.
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Camera;
|
||||
|
||||
public partial class CameraPivot : Node3D
|
||||
{
|
||||
[Export] private bool _canPitch;
|
||||
[Export] private bool _canYaw;
|
||||
[Export] private float _rotateSpeed = 0.003f;
|
||||
[Export] private Node3D _subPivot;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if(@event.IsActionPressed("click"))
|
||||
{
|
||||
if (Input.MouseMode == Input.MouseModeEnum.Visible)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("ui_cancel"))
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
}
|
||||
|
||||
if (@event is InputEventMouseMotion test)
|
||||
{
|
||||
if (Input.MouseMode != Input.MouseModeEnum.Captured)
|
||||
return;
|
||||
|
||||
if (_canYaw)
|
||||
_subPivot.RotateX(test.Relative.Y * -_rotateSpeed);
|
||||
if(_canPitch)
|
||||
this.RotateY(test.Relative.X * -_rotateSpeed);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://r5tahuqvbucy
|
||||
@@ -1 +1 @@
|
||||
uid://dumwt7lledufm
|
||||
uid://5fwv33fkvy5
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player3D : CharacterBody3D
|
||||
{
|
||||
[Export] private float _speed = 1.0f;
|
||||
[Export] private Camera3D _camera;
|
||||
|
||||
/// <summary>
|
||||
/// The sprite arrays are all setup like this:
|
||||
/// 0 - idle
|
||||
/// 1 - walking
|
||||
/// </summary>
|
||||
[Export] private AnimatedSprite3D[] _frontSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _sideSpritesAnimated;
|
||||
[Export] private AnimatedSprite3D[] _backSpritesAnimated;
|
||||
|
||||
private bool _sideFlipped;
|
||||
private Vector2 _lastDirection;
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var inputDir = Input.GetVector("move_left", "move_right", "move_down", "move_up");
|
||||
if (inputDir == Vector2.Zero)
|
||||
{
|
||||
if(_lastDirection != Vector2.Zero)
|
||||
SwitchIdleSprites();
|
||||
return;
|
||||
}
|
||||
|
||||
MoveOnInput(inputDir, delta);
|
||||
SwitchMovementSprites(inputDir);
|
||||
}
|
||||
|
||||
private void MoveOnInput(Vector2 inputDir, double delta)
|
||||
{
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y * (-1))).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
Velocity = new Vector3(direction.X * _speed * (float) delta * Scale.X, Velocity.Y, direction.Z * _speed * (float) delta * Scale.Z);
|
||||
else
|
||||
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private void SwitchIdleSprites()
|
||||
{
|
||||
if (_lastDirection.X != 0)
|
||||
{
|
||||
ActivateSprite(0, false, true, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if(_lastDirection.Y <= 0.0f)
|
||||
ActivateSprite(0, true, false, false);
|
||||
|
||||
if(_lastDirection.Y > 0.0f)
|
||||
ActivateSprite(0, false, false, true);
|
||||
|
||||
_lastDirection = Vector2.Zero;
|
||||
}
|
||||
|
||||
private void SwitchMovementSprites(Vector2 inputDir)
|
||||
{
|
||||
float X = inputDir.X;
|
||||
float Y = inputDir.Y;
|
||||
|
||||
_lastDirection = new Vector2(X, Y);
|
||||
|
||||
if (X != 0)
|
||||
{
|
||||
ActivateSprite(1, false, true, false);
|
||||
|
||||
if (X > 0.0f)
|
||||
{
|
||||
_sideFlipped = false;
|
||||
}
|
||||
|
||||
if (X < 0.0f)
|
||||
{
|
||||
_sideFlipped = true;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.FlipH = _sideFlipped;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Y != 0)
|
||||
{
|
||||
if (Y > 0.0f)
|
||||
{
|
||||
ActivateSprite(1, false, false, true);
|
||||
}
|
||||
|
||||
if (Y < 0.0f)
|
||||
{
|
||||
ActivateSprite(1, true, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateSprite(int index, bool frontActive, bool sideActive, bool backActive)
|
||||
{
|
||||
DeactivateAll();
|
||||
_frontSpritesAnimated[index].Visible = frontActive;
|
||||
_sideSpritesAnimated[index].Visible = sideActive;
|
||||
_backSpritesAnimated[index].Visible = backActive;
|
||||
}
|
||||
|
||||
private void DeactivateAll()
|
||||
{
|
||||
foreach (var animatedSprite in _frontSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _sideSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
|
||||
foreach (var animatedSprite in _backSpritesAnimated)
|
||||
{
|
||||
animatedSprite.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://b4ugrget2x6lb
|
||||
@@ -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>
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGround : Node3D
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
[Export]
|
||||
private bool _infiniteSupply = false;
|
||||
|
||||
private Label3D _itemLabel => GetNode<Label3D>("ItemLabel");
|
||||
private Label3D _pickupErrorLabel => GetNode<Label3D>("PickupErrorLabel");
|
||||
|
||||
public ItemInstance itemInstance
|
||||
{
|
||||
get => _itemInstance;
|
||||
set
|
||||
{
|
||||
_itemInstance = value;
|
||||
UpdateVisuals();
|
||||
}
|
||||
}
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
|
||||
if (result == InventoryActionResult.Success)
|
||||
{
|
||||
if (!_infiniteSupply)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_pickupErrorLabel.Text = "Inventory Full";
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenInterval(2);
|
||||
tween.TweenCallback(Callable.From(() => _pickupErrorLabel.Text = ""));
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVisuals()
|
||||
{
|
||||
_itemLabel.Text = itemInstance.blueprint?.name ?? "Error Item";
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://udhigottc8rg
|
||||
@@ -1,36 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Switches between two Sprite Options.
|
||||
/// </summary>
|
||||
public partial class SpriteSwitcher : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _trueSprite;
|
||||
[Export] private Sprite3D _falseSprite;
|
||||
[Export] private bool _state = true;
|
||||
|
||||
[Signal]
|
||||
public delegate void SwitchEventHandler(bool state);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetState();
|
||||
}
|
||||
|
||||
public void SwitchState()
|
||||
{
|
||||
_state = !_state;
|
||||
EmitSignal(SignalName.Switch, _state);
|
||||
SetState();
|
||||
}
|
||||
|
||||
private void SetState()
|
||||
{
|
||||
if(_trueSprite != null)
|
||||
_trueSprite.Visible = _state;
|
||||
if(_falseSprite != null)
|
||||
_falseSprite.Visible = !_state;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://v34pl0nlp4x
|
||||
Reference in New Issue
Block a user