Compare commits

..

4 Commits

Author SHA1 Message Date
cblech 71ca6c3305 World transision WIP 2025-04-21 15:32:13 +02:00
cblech 1782ff91b4 Scene Restructuring 2025-04-17 17:47:20 +02:00
cblech 54b07cccad added autogenerated items 2025-04-17 16:10:31 +02:00
cblech fb0c14c3f1 Added item stacking 2025-04-17 16:10:12 +02:00
32 changed files with 395 additions and 53 deletions
@@ -4,11 +4,12 @@ importer="scene"
importer_version=1 importer_version=1
type="PackedScene" type="PackedScene"
uid="uid://b3kyrsoobmkhp" uid="uid://b3kyrsoobmkhp"
valid=false path="res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"
[deps] [deps]
source_file="res://art/mockups/3d/best_house_blender.blend" source_file="res://art/mockups/3d/best_house_blender.blend"
dest_files=["res://.godot/imported/best_house_blender.blend-ac89c74aef2f275bdf4b4baadee17c0c.scn"]
[params] [params]
+1 -3
View File
@@ -1,7 +1,7 @@
[gd_scene load_steps=303 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://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"] [ext_resource type="Script" uid="uid://xm0um640aes7" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"]
[ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_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="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="Texture2D" uid="uid://c4ggew55w0icj" path="res://art/farm/farming/farmobjekte/harke.png" id="4_kngqo"]
@@ -1344,5 +1344,3 @@ _wateringCanSprite = NodePath("../CharacterBody3D/Farming/Watering can")
_fieldPrefab = ExtResource("2_oq5hi") _fieldPrefab = ExtResource("2_oq5hi")
_movingPlayer = NodePath("../CharacterBody3D") _movingPlayer = NodePath("../CharacterBody3D")
metadata/_custom_type_script = "uid://b1sscdr4ptec8" metadata/_custom_type_script = "uid://b1sscdr4ptec8"
[connection signal="WaterField" from="FarmingControls" to="." method="UseWateringCan"]
+18
View File
@@ -41,4 +41,22 @@ label_settings = SubResource("LabelSettings_7emux")
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1
[node name="AmountLabel" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -409.0
offset_top = -329.0
offset_right = -10.0
offset_bottom = -10.0
grow_horizontal = 0
grow_vertical = 0
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "999"
horizontal_alignment = 2
vertical_alignment = 2
[connection signal="gui_input" from="." to="." method="_on_gui_input"] [connection signal="gui_input" from="." to="." method="_on_gui_input"]
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bs3vs05wp5a20"]
[ext_resource type="Script" uid="uid://cpbv0b3ahorep" path="res://scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs" id="1_wqqyh"]
[node name="WorldChangeTrigger" type="Area3D"]
script = ExtResource("1_wqqyh")
+1 -5
View File
@@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="Babushka" config/name="Babushka"
run/main_scene="uid://dbxy2y85r1d8x" run/main_scene="uid://dbgkbil1ultks"
config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/features=PackedStringArray("4.4", "C#", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
@@ -66,10 +66,6 @@ translation/id_counter=22
translation/locales=["de", "en"] translation/locales=["de", "en"]
text/autopauses={} text/autopauses={}
[display]
window/size/always_on_top=true
[dotnet] [dotnet]
project/assembly_name="Babushka" project/assembly_name="Babushka"
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://cipetn2hmnew4"]
[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_ymkjy"]
[resource]
script = ExtResource("1_ymkjy")
name = ""
metadata/_custom_type_script = "uid://cjr2efpm660kr"
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://daow8nx85vuc8"]
[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_kdbco"]
[resource]
script = ExtResource("1_kdbco")
name = "GameStart"
metadata/_custom_type_script = "uid://cjr2efpm660kr"
+8
View File
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://dissbtj4nflu5"]
[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_vyl4c"]
[resource]
script = ExtResource("1_vyl4c")
name = "tmp1"
metadata/_custom_type_script = "uid://cjr2efpm660kr"
+21
View File
@@ -0,0 +1,21 @@
[gd_scene load_steps=6 format=3 uid="uid://dbgkbil1ultks"]
[ext_resource type="Script" uid="uid://g338f4yomfo3" path="res://scripts/CSharp/Common/WorldManagement/WorldContainer.cs" id="1_l112d"]
[ext_resource type="PackedScene" uid="uid://dbxy2y85r1d8x" path="res://scenes/worlds/Babushka_world_item_pickup_testing.tscn" id="2_akoq3"]
[ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="2_l45op"]
[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="3_4ix36"]
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="3_akoq3"]
[node name="BabushkaSceneMain" type="Node"]
[node name="WorldContainer" type="Node" parent="."]
script = ExtResource("1_l112d")
startingWorld = ExtResource("2_akoq3")
startingSpawnPoint = ExtResource("3_4ix36")
[node name="Player3d" parent="." instance=ExtResource("2_l45op")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249)
[node name="Inventory" parent="." instance=ExtResource("3_akoq3")]
[connection signal="WorldChanged" from="WorldContainer" to="Player3d" method="TeleportTo"]
@@ -1,13 +1,17 @@
[gd_scene load_steps=12 format=3 uid="uid://dbxy2y85r1d8x"] [gd_scene load_steps=17 format=3 uid="uid://dbxy2y85r1d8x"]
[ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="1_pdc5e"] [ext_resource type="Script" uid="uid://6aq8mr0sofrs" path="res://scripts/CSharp/Common/WorldManagement/World.cs" id="1_jnel3"]
[ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_741gk"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_741gk"]
[ext_resource type="PackedScene" uid="uid://5hltxpdxmqcq" path="res://prefabs/interactions/generic_item_on_ground.tscn" id="5_sjt6k"] [ext_resource type="PackedScene" uid="uid://5hltxpdxmqcq" path="res://prefabs/interactions/generic_item_on_ground.tscn" id="5_sjt6k"]
[ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="6_876p1"]
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"]
[ext_resource type="Script" uid="uid://dbkkeo3gw2xgy" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"] [ext_resource type="Script" uid="uid://12hleqx8amr8" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"]
[ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"] [ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"]
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_hv2km"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_hv2km"]
[ext_resource type="Script" uid="uid://c7eaa0neniiss" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs" id="8_w0pbi"]
[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="9_sal3e"]
[ext_resource type="Resource" uid="uid://cipetn2hmnew4" path="res://resources/spawnpoints/from_test_scene.tres" id="10_sal3e"]
[ext_resource type="PackedScene" uid="uid://bs3vs05wp5a20" path="res://prefabs/world_elements/world_change_trigger.tscn" id="11_43jow"]
[ext_resource type="PackedScene" uid="uid://cidjhvp38n4b4" path="res://scenes/worlds/babushka_world_level_change_test.tscn" id="12_oux87"]
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"] [sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
@@ -17,7 +21,11 @@ albedo_color = Color(0.505882, 0.588235, 0.494118, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_t58di"] [sub_resource type="BoxShape3D" id="BoxShape3D_t58di"]
size = Vector3(2.01563, 0.160522, 2.00824) size = Vector3(2.01563, 0.160522, 2.00824)
[node name="SceneFarmVesna" type="Node3D"] [sub_resource type="BoxShape3D" id="BoxShape3D_oux87"]
size = Vector3(1, 1, 2.94604)
[node name="WorldItemPickupTest" type="Node3D"]
script = ExtResource("1_jnel3")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0) transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
@@ -31,10 +39,6 @@ surface_material_override/0 = SubResource("StandardMaterial3D_8tgff")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915)
shape = SubResource("BoxShape3D_t58di") shape = SubResource("BoxShape3D_t58di")
[node name="Player3d" parent="." node_paths=PackedStringArray("_fieldParent") instance=ExtResource("1_pdc5e")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249)
_fieldParent = NodePath("../FieldService")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [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) transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262)
@@ -42,8 +46,6 @@ transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408,
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0) transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.0574723, 0)
visible = false visible = false
[node name="Inventory" parent="." instance=ExtResource("6_876p1")]
[node name="FieldService" type="Node3D" parent="."] [node name="FieldService" type="Node3D" parent="."]
script = ExtResource("7_3rkjv") script = ExtResource("7_3rkjv")
@@ -69,6 +71,28 @@ _infiniteSupply = true
[node name="SpawnWithItem" parent="GenericItemOnGround4" index="1"] [node name="SpawnWithItem" parent="GenericItemOnGround4" index="1"]
_blueprint = ExtResource("8_hv2km") _blueprint = ExtResource("8_hv2km")
[node name="Spawnpoint" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.87715, 0, 1.54015)
script = ExtResource("8_w0pbi")
spawnPointResource = ExtResource("9_sal3e")
[node name="Spawnpoint tmp" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.3672, 0, 0.113484)
script = ExtResource("8_w0pbi")
spawnPointResource = ExtResource("10_sal3e")
[node name="WorldChangeTrigger" parent="." instance=ExtResource("11_43jow")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.78829, 0.546566, -0.241783)
collision_mask = 17
switchToWorld = ExtResource("12_oux87")
switchToSpawnPoint = ExtResource("10_sal3e")
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldChangeTrigger"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.193655, 0, 0.233521)
shape = SubResource("BoxShape3D_oux87")
[connection signal="area_entered" from="WorldChangeTrigger" to="WorldChangeTrigger" method="AreaEnteredHandler"]
[editable path="GenericItemOnGround"] [editable path="GenericItemOnGround"]
[editable path="GenericItemOnGround2"] [editable path="GenericItemOnGround2"]
[editable path="GenericItemOnGround3"] [editable path="GenericItemOnGround3"]
@@ -0,0 +1,56 @@
[gd_scene load_steps=11 format=3 uid="uid://cidjhvp38n4b4"]
[ext_resource type="Script" uid="uid://6aq8mr0sofrs" path="res://scripts/CSharp/Common/WorldManagement/World.cs" id="1_nat7a"]
[ext_resource type="PackedScene" uid="uid://bs3vs05wp5a20" path="res://prefabs/world_elements/world_change_trigger.tscn" id="5_tb7xe"]
[ext_resource type="PackedScene" uid="uid://dbxy2y85r1d8x" path="res://scenes/worlds/Babushka_world_item_pickup_testing.tscn" id="6_evakd"]
[ext_resource type="Script" uid="uid://c7eaa0neniiss" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs" id="8_pl6uc"]
[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="9_rutwt"]
[ext_resource type="Resource" uid="uid://cipetn2hmnew4" path="res://resources/spawnpoints/from_test_scene.tres" id="10_s5gm8"]
[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8tgff"]
albedo_color = Color(0.505882, 0.588235, 0.494118, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_t58di"]
size = Vector3(2.01563, 0.160522, 2.00824)
[sub_resource type="BoxShape3D" id="BoxShape3D_tydq3"]
size = Vector3(1, 1, 6.21814)
[node name="WorldItemPickupTest" type="Node3D"]
script = ExtResource("1_nat7a")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
mesh = SubResource("PlaneMesh_8yprl")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_8tgff")
[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915)
shape = SubResource("BoxShape3D_t58di")
[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="Spawnpoint" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.87715, 0, 1.54015)
script = ExtResource("8_pl6uc")
spawnPointResource = ExtResource("9_rutwt")
[node name="Spawnpoint tmp" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.00564, 0, 0.0870138)
script = ExtResource("8_pl6uc")
spawnPointResource = ExtResource("10_s5gm8")
[node name="WorldChangeTrigger" parent="." instance=ExtResource("5_tb7xe")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.82414, 0, 0)
switchToWorld = ExtResource("6_evakd")
switchToSpawnPoint = ExtResource("10_s5gm8")
[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldChangeTrigger"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.235657)
shape = SubResource("BoxShape3D_tydq3")
@@ -129,5 +129,11 @@ public partial class Player3D : CharacterBody3D
animatedSprite.Visible = false; animatedSprite.Visible = false;
} }
} }
public void Teleport(Vector3 newPosition)
{
GlobalPosition = newPosition;
ResetPhysicsInterpolation();
GD.Print("Player Teleported");
}
} }
@@ -15,6 +15,11 @@ public partial class VesnaBehaviour : Node
{ {
_farmingControls.FieldParent = _fieldParent; _farmingControls.FieldParent = _fieldParent;
} }
public void TeleportTo(Vector3 newPosition)
{
GetNode<Player3D>("CharacterBody3D").Teleport(newPosition);
}
#region Farming #region Farming
@@ -0,0 +1 @@
uid://xm0um640aes7
@@ -0,0 +1 @@
uid://12hleqx8amr8
@@ -12,6 +12,7 @@ public partial class InventoryInstance : Node
[Signal] [Signal]
public delegate void SlotAmountChangedEventHandler(); public delegate void SlotAmountChangedEventHandler();
[Signal] [Signal]
public delegate void InventoryContentsChangedEventHandler(); public delegate void InventoryContentsChangedEventHandler();
@@ -32,54 +33,99 @@ public partial class InventoryInstance : Node
_slots.Add(new InventorySlot()); _slots.Add(new InventorySlot());
} }
} }
EmitSignal(SignalName.SlotAmountChanged); EmitSignal(SignalName.SlotAmountChanged);
} }
} }
public InventoryActionResult AddItem(ItemInstance newItem, int inventorySlot = -1) public InventoryActionResult AddItem(ItemInstance newItem)
{ {
if (inventorySlot < 0) var result = AddItemAndStackRecursive(newItem, 0);
EmitSignal(SignalName.InventoryContentsChanged);
return result;
}
private InventoryActionResult AddItemAndStackRecursive(ItemInstance newItem, int slotSearch)
{
if (newItem.blueprint == null || newItem.amount == 0)
return InventoryActionResult.SourceDoesNotExists;
var slotIndex = -1;
// find stackable slot
for (var i = slotSearch; i < _slots.Count; i++)
{ {
inventorySlot = _slots.FindIndex(slot => slot.IsEmpty()); if (_slots[i].itemInstance?.blueprint == newItem.blueprint)
{
slotIndex = i;
break;
}
} }
if (inventorySlot < 0 || !_slots[inventorySlot].IsEmpty()) if (slotIndex < 0)
{
// find empty slot
for (var i = slotSearch; i < _slots.Count; i++)
{
if (_slots[i].IsEmpty())
{
slotIndex = i;
break;
}
}
}
if (slotIndex < 0)
{ {
return InventoryActionResult.DestinationFull; return InventoryActionResult.DestinationFull;
} }
if (inventorySlot >= _slots.Count) var itemInstance = _slots[slotIndex].itemInstance ?? new ItemInstance { blueprint = newItem.blueprint, amount = 0 };
{ var maxStack = itemInstance!.blueprint.maxStack;
return InventoryActionResult.DestinationDoesNotExists; var freeOnStack = maxStack - itemInstance.amount;
} var moveAmount = Math.Min(freeOnStack, newItem.amount);
itemInstance.amount += moveAmount;
_slots[inventorySlot].itemInstance = newItem; newItem.amount -= moveAmount;
EmitSignal(SignalName.InventoryContentsChanged); _slots[slotIndex].itemInstance = itemInstance;
return InventoryActionResult.Success; return newItem.amount <= 0
? InventoryActionResult.Success
: AddItemAndStackRecursive(newItem, slotIndex + 1);
} }
public InventoryActionResult RemoveItem(int inventorySlot, out ItemInstance? itemInstance ) public InventoryActionResult RemoveItem(int inventorySlot, out ItemInstance? itemInstance)
{ {
if (inventorySlot < 0 || inventorySlot >= _slots.Count) if (inventorySlot < 0 || inventorySlot >= _slots.Count)
{ {
itemInstance = null; itemInstance = null;
return InventoryActionResult.SourceDoesNotExists; return InventoryActionResult.SourceDoesNotExists;
} }
if (_slots[inventorySlot].IsEmpty()) if (_slots[inventorySlot].IsEmpty())
{ {
itemInstance = null; itemInstance = null;
return InventoryActionResult.SourceIsEmpty; return InventoryActionResult.SourceIsEmpty;
} }
itemInstance = _slots[inventorySlot].itemInstance; itemInstance = _slots[inventorySlot].itemInstance;
_slots[inventorySlot].itemInstance = null; _slots[inventorySlot].itemInstance = null;
EmitSignal(SignalName.InventoryContentsChanged); EmitSignal(SignalName.InventoryContentsChanged);
return InventoryActionResult.Success; return InventoryActionResult.Success;
} }
public InventoryActionResult RemoveItem(int inventorySlot) public InventoryActionResult RemoveItem(int inventorySlot)
{ {
return RemoveItem(inventorySlot, out _); return RemoveItem(inventorySlot, out _);
} }
}
public InventoryActionResult AddItemToSlot(ItemInstance itemInstance, int destinationSlot)
{
if (destinationSlot < 0 || destinationSlot >= _slots.Count)
return InventoryActionResult.DestinationDoesNotExists;
if (!_slots[destinationSlot].IsEmpty())
return InventoryActionResult.DestinationFull;
_slots[destinationSlot].itemInstance = itemInstance;
EmitSignal(SignalName.InventoryContentsChanged);
return InventoryActionResult.Success;
}
}
@@ -6,7 +6,7 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
public partial class InventoryManager : Node public partial class InventoryManager : Node
{ {
public static InventoryManager Instance { get; private set; } public static InventoryManager Instance { get; private set; }
public InventoryInstance playerInventory; public InventoryInstance playerInventory;
public override void _EnterTree() public override void _EnterTree()
@@ -23,11 +23,13 @@ public partial class InventoryManager : Node
public InventoryActionResult CreateItem( public InventoryActionResult CreateItem(
ItemResource itemBlueprint, ItemResource itemBlueprint,
InventoryInstance inventory, InventoryInstance inventory,
int amount = 1,
int inventorySlot = -1) int inventorySlot = -1)
{ {
var newItem = new ItemInstance { blueprint = itemBlueprint }; var newItem = new ItemInstance { blueprint = itemBlueprint, amount = amount };
var addResult = inventory.AddItem(newItem, inventorySlot); return inventorySlot < 0
return addResult; ? inventory.AddItem(newItem)
: inventory.AddItemToSlot(newItem, inventorySlot);
} }
public InventoryActionResult MoveItem( public InventoryActionResult MoveItem(
@@ -39,10 +41,11 @@ public partial class InventoryManager : Node
var remResult = sourceInventory.RemoveItem(sourceSlot, out var item); var remResult = sourceInventory.RemoveItem(sourceSlot, out var item);
if (remResult != InventoryActionResult.Success) return remResult; if (remResult != InventoryActionResult.Success) return remResult;
var addResult = destinationInventory.AddItem(item!, destinationSlot); var addResult = destinationInventory.AddItemToSlot(item!, destinationSlot);
if(addResult == InventoryActionResult.Success) return InventoryActionResult.Success; if (addResult == InventoryActionResult.Success) return InventoryActionResult.Success;
sourceInventory.AddItem(item!, sourceSlot); // can not fail ... in theory // if adding in the destination failed, re-add the item into the source
sourceInventory.AddItemToSlot(item!, sourceSlot); // can not fail ... in theory
return addResult; return addResult;
} }
@@ -60,8 +63,9 @@ public partial class InventoryManager : Node
{ {
return inventory.RemoveItem(inventorySlot); return inventory.RemoveItem(inventorySlot);
} }
public InventoryActionResult CollectItem(ItemInstance itemInstance) public InventoryActionResult CollectItem(ItemInstance itemInstance)
{ {
return playerInventory.AddItem(itemInstance); return playerInventory.AddItem(itemInstance);
} }
} }
+10 -2
View File
@@ -43,6 +43,12 @@ public partial class InventoryUi : Control
uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? ""; uiSlot!.nameLabel.Text = inventorySlot.itemInstance?.blueprint.name ?? "";
uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings; uiSlot!.nameLabel.LabelSettings = uiSlot!.nameLabel.LabelSettings.Duplicate() as LabelSettings;
uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White; uiSlot!.nameLabel.LabelSettings!.FontColor = inventorySlot.itemInstance?.blueprint.color ?? Colors.White;
var amountText = inventorySlot.itemInstance != null &&
inventorySlot.itemInstance.amount != 1
? inventorySlot.itemInstance.amount.ToString()
: "";
uiSlot!.amountLabel.Text = amountText;
} }
} }
@@ -99,6 +105,7 @@ public partial class InventoryUi : Control
{ {
InputInventoryOpenClose(); InputInventoryOpenClose();
} }
if (Input.IsActionJustPressed("ui_inventory_disadvance")) if (Input.IsActionJustPressed("ui_inventory_disadvance"))
{ {
_selectedSlot++; _selectedSlot++;
@@ -106,7 +113,8 @@ public partial class InventoryUi : Control
_selectedSlot = 0; _selectedSlot = 0;
SetSlotSelectPosition(); SetSlotSelectPosition();
} }
if(Input.IsActionJustPressed("ui_inventory_advance"))
if (Input.IsActionJustPressed("ui_inventory_advance"))
{ {
_selectedSlot--; _selectedSlot--;
if (_selectedSlot < 0) if (_selectedSlot < 0)
@@ -143,4 +151,4 @@ public partial class InventoryUi : Control
_slotOnMouse = null; _slotOnMouse = null;
} }
} }
} }
@@ -4,4 +4,13 @@ public class ItemInstance
{ {
public ItemResource blueprint; public ItemResource blueprint;
public int amount = 1; public int amount = 1;
public ItemInstance Clone()
{
return new ItemInstance
{
blueprint = blueprint,
amount = amount
};
}
} }
@@ -25,7 +25,7 @@ public partial class ItemOnGround : Node3D
{ {
GD.Print("Trying to pick up item"); GD.Print("Trying to pick up item");
var result = InventoryManager.Instance.CollectItem(itemInstance); var result = InventoryManager.Instance.CollectItem(itemInstance.Clone());
if (result == InventoryActionResult.Success) if (result == InventoryActionResult.Success)
{ {
if (!_infiniteSupply) if (!_infiniteSupply)
@@ -7,12 +7,14 @@ public partial class SlotUi : Control
{ {
public Label nameLabel; public Label nameLabel;
public int index; public int index;
public Label amountLabel;
[Signal] public delegate void ClickedEventHandler(int index); [Signal] public delegate void ClickedEventHandler(int index);
public override void _EnterTree() public override void _EnterTree()
{ {
nameLabel = GetNode<Label>("NameLabel"); nameLabel = GetNode<Label>("NameLabel");
amountLabel = GetNode<Label>("AmountLabel");
} }
public void _on_gui_input(InputEvent ev) public void _on_gui_input(InputEvent ev)
@@ -0,0 +1 @@
uid://bb4fc5y43ksfg
@@ -0,0 +1,8 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.WorldManagement;
public partial class SpawnPointMarker : Node3D
{
[Export] public SpawnPointResource spawnPointResource;
}
@@ -0,0 +1 @@
uid://c7eaa0neniiss
@@ -0,0 +1,14 @@
using Godot;
namespace Babushka.scripts.CSharp.Common.WorldManagement;
[GlobalClass]
public partial class SpawnPointResource : Resource
{
[Export] public string name;
public SpawnPointResource()
{
name = "";
}
}
@@ -0,0 +1 @@
uid://cjr2efpm660kr
@@ -0,0 +1,21 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using Babushka.scripts.CSharp.Common.WorldManagement;
public partial class World : Node
{
public IReadOnlyDictionary<SpawnPointResource, SpawnPointMarker> SpawnPoints;
public override void _EnterTree()
{
GD.Print("World Enter Tree");
// find all child nodes of type SpawnPoint
SpawnPoints = FindChildren("*")
.OfType<SpawnPointMarker>()
.Select(sp => new KeyValuePair<SpawnPointResource, SpawnPointMarker>(sp.spawnPointResource, sp))
.ToDictionary();
}
}
@@ -0,0 +1 @@
uid://6aq8mr0sofrs
@@ -0,0 +1,26 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.WorldManagement;
public partial class WorldChangeTrigger : Area3D
{
[Export] private PackedScene switchToWorld;
[Export] private SpawnPointResource switchToSpawnPoint;
public override void _EnterTree()
{
//AreaEntered += AreaEnteredHandler;
}
public override void _ExitTree()
{
//AreaEntered -= AreaEnteredHandler;
}
public void AreaEnteredHandler(Area3D area)
{
GD.Print("Area Entered");
var worldContainer = (WorldContainer)FindParent("WorldContainer");
worldContainer.SwitchWorld(switchToWorld, switchToSpawnPoint);
}
}
@@ -0,0 +1 @@
uid://cpbv0b3ahorep
@@ -0,0 +1,41 @@
using Godot;
using System;
using System.Linq;
using Babushka.scripts.CSharp.Common.WorldManagement;
public partial class WorldContainer : Node
{
[Export] private PackedScene startingWorld;
[Export] private SpawnPointResource startingSpawnPoint;
[Signal] public delegate void WorldChangedEventHandler(Vector3 spawnPointPosition);
public void SwitchWorld(PackedScene newWorldScene, SpawnPointResource spawnPoint)
{
// Unload the current world
if (GetChildCount() > 0)
{
GetChild(0).QueueFree();
}
// Load the new world
var newWorld = newWorldScene.Instantiate<World>();
AddChild(newWorld);
// Switch to the new spawn point
if (newWorld.SpawnPoints.TryGetValue(spawnPoint, out var spawnPointMarker))
{
EmitSignalWorldChanged(spawnPointMarker.GlobalPosition);
}
else
{
GD.PrintErr("Selected spawn point not found in the new world.");
EmitSignalWorldChanged(newWorld.SpawnPoints.First().Value.GlobalPosition);
}
}
public override void _Ready()
{
SwitchWorld(startingWorld,startingSpawnPoint);
}
}
@@ -0,0 +1 @@
uid://g338f4yomfo3