WIP reworking the field behaviour to implement watering. Broken state.
This commit is contained in:
+15
-2
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=302 format=3 uid="uid://dbd1niu3tp8y5"]
|
||||
[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"]
|
||||
[ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"]
|
||||
@@ -6,6 +6,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"]
|
||||
[ext_resource type="Texture2D" uid="uid://c4ggew55w0icj" path="res://art/farm/farming/farmobjekte/harke.png" id="4_kngqo"]
|
||||
[ext_resource type="Script" uid="uid://b1sscdr4ptec8" path="res://scripts/CSharp/Common/Farming/FarmingControls.cs" id="4_q5t2e"]
|
||||
[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="5_pkl5l"]
|
||||
[ext_resource type="Texture2D" uid="uid://dygkh117flcou" path="res://art/animation/vesna/Front/F01-Idle/0001.png" id="7_okmao"]
|
||||
[ext_resource type="Texture2D" uid="uid://rwqptk0hk53" path="res://art/animation/vesna/Front/F01-Idle/0002.png" id="8_ctpgn"]
|
||||
[ext_resource type="Texture2D" uid="uid://c5om11bu7mtvh" path="res://art/animation/vesna/Front/F01-Idle/0003.png" id="9_8n7il"]
|
||||
@@ -1257,6 +1258,15 @@ billboard = 1
|
||||
render_priority = 51
|
||||
texture = ExtResource("4_kngqo")
|
||||
|
||||
[node name="Watering can" type="Sprite3D" parent="CharacterBody3D/Farming"]
|
||||
visible = false
|
||||
pixel_size = 0.002
|
||||
billboard = 1
|
||||
render_priority = 51
|
||||
texture = ExtResource("5_pkl5l")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(-2, 1135, 425, 291)
|
||||
|
||||
[node name="Front" type="Node3D" parent="CharacterBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.001, 0.1, 0.003)
|
||||
|
||||
@@ -1327,9 +1337,12 @@ sprite_frames = SubResource("SpriteFrames_4q8ml")
|
||||
autoplay = "default"
|
||||
frame_progress = 0.481133
|
||||
|
||||
[node name="FarmingControls" type="Node3D" parent="." node_paths=PackedStringArray("_hoeSprite", "_movingPlayer")]
|
||||
[node name="FarmingControls" type="Node3D" parent="." node_paths=PackedStringArray("_hoeSprite", "_wateringCanSprite", "_movingPlayer")]
|
||||
script = ExtResource("4_q5t2e")
|
||||
_hoeSprite = NodePath("../CharacterBody3D/Farming/Hoe")
|
||||
_wateringCanSprite = NodePath("../CharacterBody3D/Farming/Watering can")
|
||||
_fieldPrefab = ExtResource("2_oq5hi")
|
||||
_movingPlayer = NodePath("../CharacterBody3D")
|
||||
metadata/_custom_type_script = "uid://b1sscdr4ptec8"
|
||||
|
||||
[connection signal="WaterField" from="FarmingControls" to="." method="UseWateringCan"]
|
||||
|
||||
@@ -13,17 +13,17 @@ emission = Color(1, 1, 1, 1)
|
||||
|
||||
[node name="SpriteSwitcher" type="Node3D" node_paths=PackedStringArray("_trueSprite", "_falseSprite")]
|
||||
script = ExtResource("1_scmhv")
|
||||
_trueSprite = NodePath("Hoe on")
|
||||
_falseSprite = NodePath("Hoe off")
|
||||
_trueSprite = NodePath("On Sprite")
|
||||
_falseSprite = NodePath("Off Sprite")
|
||||
|
||||
[node name="Hoe on" type="Sprite3D" parent="."]
|
||||
[node name="On Sprite" type="Sprite3D" parent="."]
|
||||
modulate = Color(0, 0.996078, 0, 1)
|
||||
pixel_size = 0.001
|
||||
billboard = 1
|
||||
texture = ExtResource("2_jv400")
|
||||
region_rect = Rect2(484, 143, 365, 1317)
|
||||
|
||||
[node name="Hoe off" type="Sprite3D" parent="."]
|
||||
[node name="Off Sprite" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, -8.47033e-22, 0, 8.47033e-22, 1, 0.106585, 0, 0.0173626)
|
||||
visible = false
|
||||
modulate = Color(1, 0, 0, 1)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://br7yq757cawts"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://br7yq757cawts"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="1_b1ibi"]
|
||||
[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_72r8y"]
|
||||
[ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="4_r4sre"]
|
||||
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="5_obfp0"]
|
||||
[ext_resource type="Texture2D" uid="uid://x8hr8287ff2n" path="res://art/farm/farming/farmobjekte/tools atlas.png" id="5_r4sre"]
|
||||
[ext_resource type="PackedScene" uid="uid://cf0jpuio8tgim" path="res://prefabs/interactions/sprite_switcher.tscn" id="6_r4sre"]
|
||||
[ext_resource type="Script" uid="uid://c6hh7m8wikv04" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_0ptl4"]
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
|
||||
|
||||
@@ -34,13 +36,14 @@ shape = SubResource("BoxShape3D_t58di")
|
||||
|
||||
[node name="Player3d" parent="." node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_b1ibi")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249)
|
||||
_fieldParent = NodePath("../FieldParent")
|
||||
_fieldParent = NodePath("../FieldService")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262)
|
||||
|
||||
[node name="BaseField" parent="." instance=ExtResource("2_72r8y")]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0)
|
||||
visible = false
|
||||
|
||||
[node name="HoePickup" parent="." instance=ExtResource("4_r4sre")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -4.327, 1.5, -3.447)
|
||||
@@ -50,12 +53,36 @@ shape = SubResource("SphereShape3D_0ptl4")
|
||||
|
||||
[node name="SpriteSwitcher Hoe" parent="HoePickup" instance=ExtResource("6_r4sre")]
|
||||
|
||||
[node name="FieldParent" type="Node3D" parent="."]
|
||||
[node name="Watering Can Pickup" parent="." instance=ExtResource("4_r4sre")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -2.3908, 1.5, -3.447)
|
||||
|
||||
[node name="CollisionShape3D" parent="Watering Can Pickup/Area3D" index="0"]
|
||||
shape = SubResource("SphereShape3D_0ptl4")
|
||||
|
||||
[node name="SpriteSwitcher Hoe" parent="Watering Can Pickup" instance=ExtResource("6_r4sre")]
|
||||
|
||||
[node name="On Sprite" parent="Watering Can Pickup/SpriteSwitcher Hoe" index="0"]
|
||||
texture = ExtResource("5_r4sre")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(-3, 1141, 423, 280)
|
||||
|
||||
[node name="Off Sprite" parent="Watering Can Pickup/SpriteSwitcher Hoe" index="1"]
|
||||
texture = ExtResource("5_r4sre")
|
||||
region_enabled = true
|
||||
region_rect = Rect2(-3, 1137, 424, 285)
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource("5_obfp0")]
|
||||
visible = false
|
||||
|
||||
[node name="FieldService" type="Node3D" parent="."]
|
||||
script = ExtResource("7_0ptl4")
|
||||
metadata/_custom_type_script = "uid://c6hh7m8wikv04"
|
||||
|
||||
[connection signal="Interacted" from="HoePickup" to="HoePickup/SpriteSwitcher Hoe" method="SwitchState"]
|
||||
[connection signal="Switch" from="HoePickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateHoe"]
|
||||
[connection signal="Interacted" from="Watering Can Pickup" to="Watering Can Pickup/SpriteSwitcher Hoe" method="SwitchState"]
|
||||
[connection signal="Switch" from="Watering Can Pickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateWateringCan"]
|
||||
|
||||
[editable path="HoePickup"]
|
||||
[editable path="Watering Can Pickup"]
|
||||
[editable path="Watering Can Pickup/SpriteSwitcher Hoe"]
|
||||
|
||||
@@ -6,9 +6,11 @@ namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
public partial class VesnaBehaviour : Node
|
||||
{
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private Node _fieldParent;
|
||||
[Export] private FieldService _fieldParent;
|
||||
[Export] private FarmingControls _farmingControls;
|
||||
|
||||
[Signal] public delegate void ToolPickupEventHandler(bool success);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_farmingControls.FieldParent = _fieldParent;
|
||||
@@ -18,7 +20,26 @@ public partial class VesnaBehaviour : Node
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
_farmingControls.ActivateHoe(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
|
||||
|
||||
@@ -7,25 +7,55 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class FarmingControls : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _hoeSprite;
|
||||
[Export] private Sprite3D _wateringCanSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node3D _movingPlayer;
|
||||
|
||||
public Node FieldParent;
|
||||
public FieldService FieldParent;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
private Dictionary<KeyValuePair<int, int>, bool> _spawnedFields = new Dictionary<KeyValuePair<int, int>, bool>();
|
||||
public void ActivateHoe(bool activate)
|
||||
private bool _waterCanInHand = false;
|
||||
|
||||
#region Tools
|
||||
|
||||
public bool ActivateHoe(bool activate)
|
||||
{
|
||||
_hoeSprite.Visible = !activate;
|
||||
_hoeInHand = !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)
|
||||
{
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
{
|
||||
MakeField();
|
||||
}
|
||||
|
||||
if (@event.IsActionPressed("click") && _waterCanInHand)
|
||||
{
|
||||
WaterTheField();
|
||||
}
|
||||
}
|
||||
|
||||
private void WaterTheField()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
@@ -38,9 +68,13 @@ public partial class FarmingControls : Node3D
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
Vector3 playerPos = _movingPlayer.GlobalPosition;
|
||||
field3d.Position = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,23 @@ public enum FieldState
|
||||
public partial class FieldBehaviour : Sprite3D
|
||||
{
|
||||
[Export] private Texture2D Tilled;
|
||||
[Export] private Texture3D Watered;
|
||||
[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>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FieldService : Node3D
|
||||
{
|
||||
[Export] private Dictionary<Vector2I, FieldState> fields = new Dictionary<Vector2I, FieldState>();
|
||||
|
||||
//Create
|
||||
|
||||
public void AddEntry(Vector2I key, FieldState state)
|
||||
{
|
||||
fields.Add(key, state);
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
public FieldState Get(Vector2I key)
|
||||
{
|
||||
return fields[key];
|
||||
}
|
||||
|
||||
//Update
|
||||
public void UpdateEntry(Vector2I fieldPosition, FieldState state)
|
||||
{
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields[fieldPosition] = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntry(fieldPosition, state);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete
|
||||
|
||||
public void RemoveEntry(Vector2I fieldPosition)
|
||||
{
|
||||
if (fields.ContainsKey(fieldPosition))
|
||||
{
|
||||
fields.Remove(fieldPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user