From 45a58f701bdb23e0a47eb20b74dc77d3bc9869f7 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sun, 6 Apr 2025 23:13:25 +0200 Subject: [PATCH] Spawning fields works --- prefabs/Player3D.tscn | 7 ++-- prefabs/farming/base_field.tscn | 25 +++++++------- scenes/Babushka_scene_farm_vesna.tscn | 15 +++++---- .../CSharp/Common/Farming/FarmingControls.cs | 33 ++++++++++++++++++- .../CSharp/Common/Farming/FieldBehaviour.cs | 7 +++- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 2427536..c3b11f3 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://dbd1niu3tp8y5"] +[gd_scene load_steps=8 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="Texture2D" uid="uid://duaideiajsu8r" path="res://art/Characters/Vesna/babushka concept art vesna.png" id="2_3trg2"] +[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"] [ext_resource type="Script" uid="uid://r5tahuqvbucy" path="res://scripts/CSharp/Common/Camera/CameraPivot.cs" id="3_3trg2"] [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"] @@ -9,9 +10,11 @@ [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1vdrh"] height = 1.5 -[node name="Player3d" type="Node3D" node_paths=PackedStringArray("_hoeSprite")] +[node name="Player3d" type="Node3D" node_paths=PackedStringArray("_hoeSprite", "_movingPlayer")] script = ExtResource("4_q5t2e") _hoeSprite = NodePath("CharacterBody3D/Farming/Hoe") +_fieldPrefab = ExtResource("2_oq5hi") +_movingPlayer = NodePath("CharacterBody3D") [node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera", "_frontSprite", "_sideSprite")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0) diff --git a/prefabs/farming/base_field.tscn b/prefabs/farming/base_field.tscn index 49115ce..bbb6788 100644 --- a/prefabs/farming/base_field.tscn +++ b/prefabs/farming/base_field.tscn @@ -1,33 +1,30 @@ -[gd_scene load_steps=6 format=3 uid="uid://biwd3jj65qrlh"] +[gd_scene load_steps=5 format=3 uid="uid://biwd3jj65qrlh"] [ext_resource type="Texture2D" uid="uid://c2pirgay3jfnn" path="res://art/farm/tilable grounds/böden/trockene farming erde.png" id="1_2cisk"] [ext_resource type="Script" uid="uid://histmmyi1wr" path="res://scripts/CSharp/Common/Farming/FieldBehaviour.cs" id="2_u7egi"] -[ext_resource type="Texture2D" uid="uid://lvhbicmwqab5" path="res://art/farm/tilable grounds/böden/fruchtbarer wilder trockender boden.png" id="3_0rx5h"] [ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="4_xc4m0"] [sub_resource type="SphereShape3D" id="SphereShape3D_u7egi"] resource_local_to_scene = true radius = 2.0 -[node name="BaseField" type="Sprite3D"] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) -modulate = Color(0.690196, 0.690196, 0.690196, 1) -pixel_size = 0.004 -texture = ExtResource("1_2cisk") -script = ExtResource("2_u7egi") -Untilled = ExtResource("3_0rx5h") -Tilled = ExtResource("1_2cisk") +[node name="BaseField" type="Node3D"] [node name="InteractionArea" parent="." instance=ExtResource("4_xc4m0")] -transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0.00334358, -0.3811, -0.120426) +transform = Transform3D(0.939693, -0.34202, 0, 0.34202, 0.939693, 0, 0, 0, 1, 0.00334358, -0.3811, -0.120426) _showLabel = false -[node name="Area3D" parent="InteractionArea" index="0"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.381738) - [node name="CollisionShape3D" parent="InteractionArea/Area3D" index="0"] shape = SubResource("SphereShape3D_u7egi") +[node name="Sprite3D" type="Sprite3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +pixel_size = 0.004 +texture = ExtResource("1_2cisk") +script = ExtResource("2_u7egi") +Tilled = ExtResource("1_2cisk") +FieldState = 1 + [connection signal="Interacted" from="InteractionArea" to="." method="Farm"] [editable path="InteractionArea"] diff --git a/scenes/Babushka_scene_farm_vesna.tscn b/scenes/Babushka_scene_farm_vesna.tscn index 6010b2f..f260e19 100644 --- a/scenes/Babushka_scene_farm_vesna.tscn +++ b/scenes/Babushka_scene_farm_vesna.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=11 format=3 uid="uid://br7yq757cawts"] +[gd_scene load_steps=10 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="Texture2D" uid="uid://lvhbicmwqab5" path="res://art/farm/tilable grounds/böden/fruchtbarer wilder trockender boden.png" id="3_0ptl4"] [ext_resource type="PackedScene" uid="uid://bjhj1wa5olwcu" path="res://prefabs/farming/base_plant.tscn" id="3_oyw0x"] [ext_resource type="PackedScene" uid="uid://ob04y3syvo0e" path="res://prefabs/interaction_area.tscn" id="4_r4sre"] [ext_resource type="PackedScene" uid="uid://cf0jpuio8tgim" path="res://prefabs/interactions/sprite_switcher.tscn" id="6_r4sre"] @@ -33,28 +32,30 @@ surface_material_override/0 = SubResource("StandardMaterial3D_8tgff") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915) shape = SubResource("BoxShape3D_t58di") -[node name="Player3d" parent="." instance=ExtResource("1_b1ibi")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.80632, 0.725631, 3.57249) +[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") [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, -2.18557e-08, -0.5, 0, 0.5, -2.18557e-08, 0, 0.001, 0) -texture = ExtResource("3_0ptl4") +transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.001, 0) [node name="BasePlant" parent="BaseField" instance=ExtResource("3_oyw0x")] transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0) top_level = true [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, -3.447) +transform = Transform3D(1, 0, 0, 0, 1, -1.06581e-14, 0, 1.06581e-14, 1, -4.327, 1.5, -3.447) [node name="CollisionShape3D" parent="HoePickup/Area3D" index="0"] shape = SubResource("SphereShape3D_0ptl4") [node name="SpriteSwitcher Hoe" parent="HoePickup" instance=ExtResource("6_r4sre")] +[node name="FieldParent" type="Node3D" parent="."] + [connection signal="Interacted" from="HoePickup" to="HoePickup/SpriteSwitcher Hoe" method="SwitchState"] [connection signal="Switch" from="HoePickup/SpriteSwitcher Hoe" to="Player3d" method="ActivateHoe"] diff --git a/scripts/CSharp/Common/Farming/FarmingControls.cs b/scripts/CSharp/Common/Farming/FarmingControls.cs index fd42111..b2a31f7 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls.cs @@ -5,13 +5,44 @@ namespace Babushka.scripts.CSharp.Common.Farming; public partial class FarmingControls : Node3D { [Export] private Sprite3D _hoeSprite; + [Export] private PackedScene _fieldPrefab; + [Export] private Node _fieldParent; + [Export] private Node3D _movingPlayer; private bool _hoeInHand = false; - public void ActivateHoe(bool activate) { _hoeSprite.Visible = !activate; _hoeInHand = !activate; } + + public override void _Input(InputEvent @event) + { + if (@event.IsActionPressed("click") && _hoeInHand) + { + MakeField(); + } + } + + public override void _Notification(int notification) + { + GD.Print("Player global position: " + _movingPlayer.GlobalPosition); + } + + private void MakeField() + { + if(_fieldParent == null || _fieldPrefab == null) + return; + Node fieldInstance = _fieldPrefab.Instantiate(); + + if (fieldInstance is Node3D field3d) + { + field3d.Position = _movingPlayer.GlobalPosition; + } + + _fieldParent.AddChild(fieldInstance); + + + } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FieldBehaviour.cs b/scripts/CSharp/Common/Farming/FieldBehaviour.cs index 2ac2024..dd7ba4d 100644 --- a/scripts/CSharp/Common/Farming/FieldBehaviour.cs +++ b/scripts/CSharp/Common/Farming/FieldBehaviour.cs @@ -12,10 +12,15 @@ public enum FieldState public partial class FieldBehaviour : Sprite3D { - [Export] private Texture2D Untilled; [Export] private Texture2D Tilled; [Export] private Texture3D Watered; [Export] private FieldState FieldState = FieldState.Empty; + + public override void _Ready() + { + Texture = Tilled; + base._Ready(); + } /// /// Called when the player enters the field'S interaction area and presses .