🚧 reworking Fieldservice

feature/farming_bugfixes_and_magic_word
kziolkowski 2 months ago
parent 63fd81e54d
commit 6ba26c360d

@ -10,6 +10,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACharacterBody2D_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fbba0bbd7a98ee58286e9484fbe86e01afff6232283f6efd3556eb7116453_003FCharacterBody2D_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fjonathan_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe37dc1faf08a4d5ea030ad59bdf77522523400_003Fd4_003Fbd338aeb_003FDictionary_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExportToolButtonAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe37dc1faf08a4d5ea030ad59bdf77522523400_003F31_003F3e05ef15_003FExportToolButtonAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGD_005Fconstants_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fdf61b6148ca71eef8cf4e56545a9319fd2647f05d2f959dad42d9fcbe95192_003FGD_005Fconstants_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMustBeVariantAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe37dc1faf08a4d5ea030ad59bdf77522523400_003Fda_003Fbb06d681_003FMustBeVariantAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Ff1d69ec2da76ccf9bc8a75c8e0fdca9a7ba1adf8c8c9d5047e2fa5991c02eca_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AResourceLoader_002Ecs_002Fl_003AC_0021_003FUsers_003FJonathan_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F9f4e8eb124d11f8219cb513a19bed22b2120ed29f9d6785ba56e3367b48d581_003FResourceLoader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

@ -12,7 +12,7 @@ radius = 300.0
resource_local_to_scene = true
radius = 300.0
[node name="Beet2" instance=ExtResource("1_2u3jr")]
[node name="Beet" instance=ExtResource("1_2u3jr")]
[node name="Seed1" parent="Seeds" index="0"]
texture = ExtResource("2_agmuy")
@ -47,6 +47,9 @@ shape = SubResource("CircleShape2D_hiixr")
[node name="SpawnWithItem" parent="ReadyPlantInventoryItem" index="0"]
_blueprint = ExtResource("3_agmuy")
[node name="PickupInteractionArea" parent="ReadyPlantInventoryItem" index="3"]
_active = false
[node name="CollisionShape3D" parent="ReadyPlantInventoryItem/PickupInteractionArea/Area2D" index="0"]
shape = SubResource("CircleShape2D_ae08q")

@ -56,6 +56,7 @@ public partial class FarmingControls2D : Node2D
&& _toolId == WateringCanState.WATERING_CAN_ID
&& WateringCanState.GetFillState() > 0)
{
GD.Print("Trying to use the watering can.");
Vector2I adjustedPosition = GetAdjustedMousePosition();
WaterTheField(adjustedPosition);
}
@ -117,11 +118,15 @@ public partial class FarmingControls2D : Node2D
{
FieldBehaviour2D field = FieldService.Get(fieldPosition);
if (field == null || field.FieldState == FieldState.Watered)
{
GD.Print($"The field at position {fieldPosition} is null!");
return;
}
field.Water();
_wateringParticles.GlobalPosition = new Vector2(field.GlobalPosition.X, field.GlobalPosition.Y + _wateringCanParticlesVerticalOffset);
WateringCanState.Water();
GD.Print($"Watered the field at {fieldPosition}.");
EmitSignal(SignalName.WateringField);
}

@ -20,11 +20,13 @@ public partial class FieldBehaviour2D : Sprite2D
public Vector2 FieldPosition;
public FieldService2D FieldService;
[Signal] public delegate void PlantedEventHandler();
public override void _Ready()
{
UpdateFieldState(FieldState);
int randomIndex = new Random().Next(0, _maskTexture.Length);
_maskSprite.Texture = _maskTexture[randomIndex];

@ -0,0 +1,77 @@
using System.Collections.Generic;
using Godot;
namespace Babushka.scripts.CSharp.Common.Farming;
public partial class FieldService : Node2D
{
private Dictionary<PackedScene, FieldsInScene>? fieldsPerScene;
[Signal] public delegate void FieldCreatedEventHandler();
//Create
public bool TryAddEntry(PackedScene scene, Vector2I key, FieldBehaviour2D field)
{
if (!fieldsPerScene.ContainsKey(scene))
{
FieldsInScene fieldInstance = new FieldsInScene();
fieldsPerScene.Add(scene, fieldInstance);
EmitSignal(SignalName.FieldCreated);
return true;
}
return false;
}
// Read
public FieldBehaviour2D Get(PackedScene key, Vector2I fieldPosition)
{
if (fieldsPerScene.TryGetValue(key, out FieldsInScene field))
{
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D fieldInstance))
return fieldInstance;
}
return null;
}
//todo:
// - Make this a singleton
// - Let this interact with the FarmingControls and the FieldBehaviours
// - Replace FieldService2D and remove it from scenes.
/*
//Update
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour2D 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);
}
}
*/
}
internal class FieldsInScene
{
public Dictionary<Vector2I, FieldBehaviour2D> fields;
}
Loading…
Cancel
Save