feature/showcase_bugfixing_kathi_partII #16
@@ -1,7 +1,9 @@
|
||||
[gd_scene load_steps=480 format=3 uid="uid://c25udixd5m6l0"]
|
||||
[gd_scene load_steps=482 format=3 uid="uid://c25udixd5m6l0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"]
|
||||
[ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"]
|
||||
[ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="2_dnm27"]
|
||||
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="3_e04c3"]
|
||||
[ext_resource type="Script" uid="uid://n7oihifvqp23" path="res://scripts/CSharp/Common/Animation/VesnaAnimations.cs" id="3_f6xmn"]
|
||||
[ext_resource type="Texture2D" uid="uid://7jrac5ii3ah3" path="res://art/animation/Vesna2D/Vesna Anims Sequences/B01-Idle/0001.png" id="3_tb2wl"]
|
||||
[ext_resource type="Texture2D" uid="uid://c06b551t2qlo6" path="res://art/animation/Vesna2D/Vesna Anims Sequences/B01-Idle/0002.png" id="4_dy5kt"]
|
||||
@@ -2079,6 +2081,8 @@ script = ExtResource("1_yd5ep")
|
||||
_farmingControls = NodePath("FarmingControls")
|
||||
_player2d = NodePath("CharacterBody2D")
|
||||
_vesnaAnimations = NodePath("CharacterBody2D/visuals")
|
||||
_hoe = ExtResource("2_dnm27")
|
||||
_wateringCan = ExtResource("3_e04c3")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." groups=["PlantGrowing"]]
|
||||
position = Vector2(0, 374)
|
||||
|
||||
@@ -40,6 +40,7 @@ _bigPlants = [NodePath("BigPlant/01"), NodePath("BigPlant/02"), NodePath("BigPla
|
||||
_readyPlants = [NodePath("ReadyPlantInventoryItem/ReadyPlant/01"), NodePath("ReadyPlantInventoryItem/ReadyPlant/02"), NodePath("ReadyPlantInventoryItem/ReadyPlant/03"), NodePath("ReadyPlantInventoryItem/ReadyPlant/04")]
|
||||
_harvestablePlant = NodePath("ReadyPlantInventoryItem")
|
||||
_magicEffect = NodePath("magic vfx")
|
||||
_magicWordNeeded = false
|
||||
|
||||
[node name="Seeds" type="Node2D" parent="."]
|
||||
position = Vector2(0, 0.5)
|
||||
@@ -225,6 +226,7 @@ color = Color(0.400601, 0.62444, 0.791217, 1)
|
||||
hue_variation_max = 0.4
|
||||
|
||||
[connection signal="Interacted" from="GrowingInteractionArea" to="." method="Grow"]
|
||||
[connection signal="SuccessfulPickUp" from="ReadyPlantInventoryItem" to="." method="queue_free"]
|
||||
|
||||
[editable path="GrowingInteractionArea"]
|
||||
[editable path="ReadyPlantInventoryItem"]
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bqjx3luofm6yi"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://coqch6yjvjuc0" path="res://scripts/CSharp/Common/Farming/SeedRepository.cs" id="1_i7nvs"]
|
||||
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="2_jetk1"]
|
||||
[ext_resource type="PackedScene" uid="uid://gishbn0a8eke" path="res://prefabs/farm/tomato_plant.tscn" id="3_ulp3m"]
|
||||
|
||||
[node name="SeedRepository" type="Node2D"]
|
||||
script = ExtResource("1_i7nvs")
|
||||
seedToPlantRepository = Dictionary[Object, Node]({
|
||||
ExtResource("2_jetk1"): ExtResource("3_ulp3m")
|
||||
})
|
||||
+1
-2
@@ -28,11 +28,10 @@ buses/default_bus_layout="uid://b6dwkmkyb0axk"
|
||||
SceneTransition="*res://scenes/SceneTransition.tscn"
|
||||
Dialogic="*res://addons/dialogic/Core/DialogicGameHandler.gd"
|
||||
InventoryManager="*res://scripts/CSharp/Common/Inventory/InventoryManager.cs"
|
||||
Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd"
|
||||
QuestManager="*res://prefabs/quests/quest_manager_autoload.tscn"
|
||||
FightManagerAutoload="*res://prefabs/fight/fight_manager_autoload.tscn"
|
||||
InputService="*res://scripts/CSharp/Common/Services/InputService.cs"
|
||||
SeedRepository="*res://prefabs/seed_repository.tscn"
|
||||
Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd"
|
||||
|
||||
[dialogic]
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=3 format=3 uid="uid://d1uuxp1lp4aro"]
|
||||
[gd_resource type="Resource" script_class="ItemResource" load_steps=4 format=3 uid="uid://d1uuxp1lp4aro"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbskymrxs6ksu" path="res://scripts/CSharp/Common/Inventory/ItemResource.cs" id="1_dustj"]
|
||||
[ext_resource type="Texture2D" uid="uid://ce04nexh36uwe" path="res://art/ui/UI/icons/icon-seed-tomatoe.png" id="1_u15c2"]
|
||||
[ext_resource type="PackedScene" uid="uid://gishbn0a8eke" path="res://prefabs/farm/tomato_plant.tscn" id="2_xhgqu"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_dustj")
|
||||
@@ -9,4 +10,5 @@ name = "Tomato Seed"
|
||||
color = Color(0.135039, 0.307214, 0.333128, 1)
|
||||
icon = ExtResource("1_u15c2")
|
||||
maxStack = 20
|
||||
itemPrefab = ExtResource("2_xhgqu")
|
||||
metadata/_custom_type_script = "uid://cbskymrxs6ksu"
|
||||
|
||||
@@ -1036,7 +1036,6 @@ z_index = 1
|
||||
position = Vector2(9322, 2018)
|
||||
_fieldParent = NodePath("../Farm visuals/FieldParent")
|
||||
_hoe = ExtResource("28_6b2nr")
|
||||
_wateringCan = ExtResource("28_ipqaa")
|
||||
|
||||
[node name="FarmingControls" parent="YSorted/Vesna" index="1" node_paths=PackedStringArray("_camera")]
|
||||
_camera = NodePath("../../../Camera2D")
|
||||
|
||||
@@ -15,7 +15,7 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] private Texture2D Watered;
|
||||
[Export] public FieldState FieldState = FieldState.Tilled;
|
||||
[Export] public InteractionArea2D PlantingInteraction;
|
||||
[Export] public Node PlantingPlaceholder;
|
||||
[Export] public Node2D PlantingPlaceholder;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
@@ -48,6 +48,7 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
break;
|
||||
case FieldState.Planted:
|
||||
FieldState = FieldState.Planted;
|
||||
_fieldSprite.Texture = Tilled;
|
||||
PlantingInteraction.IsActive = false;
|
||||
break;
|
||||
default:
|
||||
@@ -82,10 +83,10 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
int currentSlotIndex = InventoryManager.Instance.CurrentSelectedSlotIndex;
|
||||
ItemInstance? item = InventoryManager.Instance.playerInventory.Slots[currentSlotIndex].itemInstance;
|
||||
|
||||
if (item == null)
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0)
|
||||
return success;
|
||||
|
||||
PackedScene? plantPrefab = SeedRepository.Instance.GetPlant(item.blueprint);
|
||||
|
||||
PackedScene? plantPrefab = item.blueprint.itemPrefab;
|
||||
|
||||
if (plantPrefab != null)
|
||||
{
|
||||
@@ -93,6 +94,15 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
if (plantInstance is Node2D plant2d)
|
||||
{
|
||||
PlantingPlaceholder.AddChild(plant2d);
|
||||
plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition;
|
||||
PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D;
|
||||
|
||||
if (plantBehaviour != null)
|
||||
{
|
||||
plantBehaviour.Field = this;
|
||||
plantBehaviour.Grow();
|
||||
}
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Animation;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
@@ -24,6 +25,15 @@ public partial class PlantBehaviour2D : Node2D
|
||||
private string _magicWordDialogicEventName = "MagicWord";
|
||||
private Sprite2D _currentPlantSprite = null;
|
||||
private bool _magicWordSaid = false;
|
||||
|
||||
/// <summary>
|
||||
/// public accessor for the field reference
|
||||
/// </summary>
|
||||
public FieldBehaviour2D Field
|
||||
{
|
||||
get => _field;
|
||||
set => _field = value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -34,7 +44,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded)
|
||||
return;
|
||||
|
||||
//GetTree().CallGroup("PlantGrowing", PlayerMovement.MethodName.PlayFarmingAnimation);
|
||||
GetTree().CallGroup("PlantGrowing", VesnaAnimations.MethodName.PlayFarmingAnimation);
|
||||
// todo:
|
||||
// find out why the last plant stage is being skipped the second time around
|
||||
switch (_state)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
|
||||
public partial class SeedRepository : Node
|
||||
{
|
||||
public static SeedRepository Instance { get; private set; } = null!;
|
||||
|
||||
// todo: Find out how to not use PackedScene here because it does not inherit from Node
|
||||
[Export] private Dictionary<ItemResource, PackedScene> seedToPlantRepository;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public PackedScene? GetPlant(ItemResource resource)
|
||||
{
|
||||
if (seedToPlantRepository.ContainsKey(resource))
|
||||
{
|
||||
return seedToPlantRepository[resource];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://coqch6yjvjuc0
|
||||
@@ -15,11 +15,15 @@ public partial class ItemResource : Resource
|
||||
|
||||
[Export]
|
||||
public int maxStack;
|
||||
|
||||
[Export]
|
||||
public PackedScene? itemPrefab;
|
||||
|
|
||||
|
||||
public ItemResource()
|
||||
{
|
||||
name = "";
|
||||
color = Colors.Red;
|
||||
maxStack = 1;
|
||||
itemPrefab = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user
Ich musste im Code nachschauen, um zu verstehen, wofür das überhaupt ist. Ich denke, das braucht mindestens einen anderen Namen.
Besser aber noch, das kommt in eine neue Klasse oder eine abgeleitete Klasse (z. B.
PlantableItemResource)Außerdem habe ich Angst, da hier ne PackedScene referenziert wird, dass wir wieder irgendwann in ein cyclic dependency problem geraten, das super schwer zu debuggen ist.
Ich habe noch einmal darüber nachgedacht und bin mir sehr sicher, dass wir damit in eine cyclic dependency geraten, sobald eine Tomatenpflanze nicht nur Tomaten, sondern auch selbst wieder Samen droped. Selbst wenn das Gamedesign technisch nicht vorgesehen ist, schaffen wir uns hier einen ganz gefährlichen Sonderfall.
Wir sollten stattdessen lieber eine Lookup-Table-Resource haben. Darin ist ein Array aus Paaren von ItemResource und PackedScene. Die FieldBehaviour Klasse kann sich basierend auf dem Item das richtige Prefab für die Pflanze raus suchen
Lass mal bei Gelegenheit darüber callen.
Ich bin mir fast sicher, dass deine Bedenken hier unbegründet sind. Der Lösungsvorschlag mit der Lookup-Tabelle ließe sich zwar auch umsetzen, allerdings nicht mit ItemResources als Keys, weil diese nicht von Godot serialisiert werden können und damit in Godot Dictionaries Fehler werfen.
Man kann das umgehen, indem man strings oder enums als identifier benutzt und dazwischenschaltet, das ist aber im Verhältnis zu dieser Lösung sehr viel komplexer und meiner Meinung nach nicht notwendig, da wir ja nicht auf Instanzen direkt zugreifen, sondern nur auf Prefabs / Resourcen verweisen.