🚧 reworked farming system to work with indices instead of positions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=486 format=3 uid="uid://c25udixd5m6l0"]
|
||||
[gd_scene load_steps=487 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"]
|
||||
@@ -286,6 +286,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://blh0t2ofqj2uq" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0016.png" id="472_wdxsr"]
|
||||
[ext_resource type="AudioStream" uid="uid://dymoalptxmge" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_04_R.wav" id="473_8hbu5"]
|
||||
[ext_resource type="Texture2D" uid="uid://l5ym7gi82l1b" path="res://art/ui/UI/Watercan-ui/Tropfen-ui-6.png" id="473_g32y8"]
|
||||
[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="474_ogmln"]
|
||||
[ext_resource type="AudioStream" uid="uid://4555a4w30tda" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_05_R.wav" id="474_t1d6r"]
|
||||
[ext_resource type="Texture2D" uid="uid://3t1m2xi4ks75" path="res://art/animation/Vesna2D/Vesna Anims Tools/F01-Idle-Gießkanne/0018.png" id="474_tu801"]
|
||||
[ext_resource type="AudioStream" uid="uid://dpqvnogggvgea" path="res://audio/sfx/Footsteps/Single/Gravel/Reverb/SFX_Footstep_Gravel_06_R.wav" id="475_83c4i"]
|
||||
@@ -2163,6 +2164,7 @@ _movingPlayer = NodePath("../CharacterBody2D")
|
||||
_wateringParticles = NodePath("../pouring water vfx")
|
||||
_wateringCanParticlesVerticalOffset = -100.0
|
||||
_fieldOffsetVector = Vector2i(735, 600)
|
||||
_cursorOnField = ExtResource("474_ogmln")
|
||||
|
||||
[node name="pouring water vfx" type="CPUParticles2D" parent="."]
|
||||
position = Vector2(-652, -599)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://b1d2e7ely6hyw"]
|
||||
[gd_scene load_steps=23 format=3 uid="uid://b1d2e7ely6hyw"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://j2mhvb45egej" path="res://scripts/CSharp/Low Code/Variables/VariableNode.cs" id="1_4mg73"]
|
||||
[ext_resource type="Script" uid="uid://bdffon388rkty" path="res://scripts/CSharp/Common/Farming/FieldBehaviour2D.cs" id="1_qa01x"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgmu3qlovdr22" path="res://art/masks/field_outline_1.png" id="2_w8caw"]
|
||||
[ext_resource type="Texture2D" uid="uid://50qn027e5lvh" path="res://art/masks/field_outline_2_outline.png" id="3_2eegd"]
|
||||
@@ -18,10 +19,17 @@
|
||||
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="15_i4qwg"]
|
||||
[ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="16_i4qwg"]
|
||||
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="17_1mi0u"]
|
||||
[ext_resource type="Script" uid="uid://dfpyjxivcuidr" path="res://scripts/CSharp/Low Code/Variables/VariableSetter.cs" id="19_lgya6"]
|
||||
[ext_resource type="Resource" uid="uid://fnb0n0w2ktuc" path="res://resources/low code/farming/var_cursorOnField.tres" id="20_lgya6"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_57jmp"]
|
||||
size = Vector2(600, 400)
|
||||
|
||||
[node name="BaseField" type="Node2D"]
|
||||
script = ExtResource("1_4mg73")
|
||||
Payload = 0
|
||||
|
||||
[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea")]
|
||||
[node name="FieldBehaviour" type="Sprite2D" parent="." node_paths=PackedStringArray("_fieldSprite", "_maskSprite", "_outlineSprite", "PlantingInteraction", "PlantingPlaceholder", "FieldInteractionArea", "_fieldIndex")]
|
||||
z_index = -1
|
||||
scale = Vector2(0.9, 1)
|
||||
script = ExtResource("1_qa01x")
|
||||
@@ -37,6 +45,7 @@ PlantingPlaceholder = NodePath("PlantPlaceholder")
|
||||
ItemRepository = ExtResource("7_w8caw")
|
||||
FieldInteractionArea = NodePath("../InteractionArea")
|
||||
_sceneKeyProvider = ExtResource("11_cjahb")
|
||||
_fieldIndex = NodePath("..")
|
||||
|
||||
[node name="MaskedField" type="Sprite2D" parent="FieldBehaviour"]
|
||||
clip_children = 1
|
||||
@@ -71,7 +80,24 @@ _itemResourcesToListenFor = Array[Object]([ExtResource("15_i4qwg"), ExtResource(
|
||||
script = ExtResource("14_w08sx")
|
||||
_itemResourcesToListenFor = Array[Object]([ExtResource("17_1mi0u")])
|
||||
|
||||
[node name="FieldCreationBlocker" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="FieldCreationBlocker"]
|
||||
shape = SubResource("RectangleShape2D_57jmp")
|
||||
|
||||
[node name="CursorOnFieldSetter" type="Node" parent="FieldCreationBlocker"]
|
||||
script = ExtResource("19_lgya6")
|
||||
_variableResource = ExtResource("20_lgya6")
|
||||
_payloadToSet = true
|
||||
|
||||
[node name="CursorNotOnFieldSetter" type="Node" parent="FieldCreationBlocker"]
|
||||
script = ExtResource("19_lgya6")
|
||||
_variableResource = ExtResource("20_lgya6")
|
||||
_payloadToSet = false
|
||||
|
||||
[connection signal="Planted" from="FieldBehaviour" to="PlantCreationEventRaiser" method="RaiseEvents"]
|
||||
[connection signal="Interacted" from="InteractionArea" to="FieldBehaviour" method="Farm"]
|
||||
[connection signal="ItemInstanceActivated" from="InventoryListener Seeds" to="FieldBehaviour" method="ActivatedSeedInInventory"]
|
||||
[connection signal="ItemInstanceActivated" from="InventoryListener watering can" to="FieldBehaviour" method="ActivateWateringCanInInventory"]
|
||||
[connection signal="mouse_entered" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorOnFieldSetter" method="Set"]
|
||||
[connection signal="mouse_exited" from="FieldCreationBlocker" to="FieldCreationBlocker/CursorNotOnFieldSetter" method="Set"]
|
||||
|
||||
@@ -173,6 +173,7 @@ directories/tres_directory={
|
||||
"unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres",
|
||||
"var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres",
|
||||
"var_Counter": "res://resources/low code/test/var_Counter.tres",
|
||||
"var_cursorOnField": "res://resources/low code/farming/var_cursorOnField.tres",
|
||||
"var_sceneNameProvider": "res://resources/low code/farming/var_sceneNameProvider.tres",
|
||||
"vesna_style": "res://addons/dialogic/vesna_style.tres",
|
||||
"vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://fnb0n0w2ktuc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_nm02e"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_nm02e")
|
||||
Payload = false
|
||||
metadata/_custom_type_script = "uid://dtvx2cakx0bey"
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=117 format=3 uid="uid://gigb28qk8t12"]
|
||||
[gd_scene load_steps=115 format=3 uid="uid://gigb28qk8t12"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"]
|
||||
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
|
||||
@@ -211,13 +211,6 @@ shader_parameter/tiling_scale = Vector2(1, 20)
|
||||
shader = ExtResource("13_kt1wx")
|
||||
shader_parameter/tiling_scale = Vector2(1, 25)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_p6n74"]
|
||||
resource_local_to_scene = true
|
||||
size = Vector2(7150, 941.9418)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2nee2"]
|
||||
size = Vector2(5782, 896.7792)
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_lwk6t"]
|
||||
shader = ExtResource("13_7p0hq")
|
||||
shader_parameter/hue_shift = 0.0
|
||||
@@ -2099,22 +2092,6 @@ rotation = 1.5708
|
||||
scale = Vector2(0.1, 10.8)
|
||||
texture = ExtResource("21_if5vh")
|
||||
|
||||
[node name="Farming Colliders" type="Area2D" parent="YSorted/Farm visuals"]
|
||||
position = Vector2(5, 4.098892)
|
||||
scale = Vector2(1, 0.993819)
|
||||
collision_mask = 5
|
||||
collision_priority = 10.0
|
||||
|
||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"]
|
||||
position = Vector2(11913.995, 3085.0288)
|
||||
scale = Vector2(0.9999998, 0.9999998)
|
||||
shape = SubResource("RectangleShape2D_p6n74")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="YSorted/Farm visuals/Farming Colliders"]
|
||||
position = Vector2(2895.9988, 3088.6096)
|
||||
scale = Vector2(0.9999998, 0.9999998)
|
||||
shape = SubResource("RectangleShape2D_2nee2")
|
||||
|
||||
[node name="Blocker" type="Node2D" parent="YSorted"]
|
||||
|
||||
[node name="Fence Door2" type="Sprite2D" parent="YSorted/Blocker"]
|
||||
@@ -2156,6 +2133,7 @@ position = Vector2(-113.561, 193.035)
|
||||
shape = SubResource("RectangleShape2D_2vojv")
|
||||
|
||||
[node name="ducks" type="Node2D" parent="YSorted"]
|
||||
visible = false
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
script = ExtResource("49_uxa2m")
|
||||
@@ -2232,6 +2210,7 @@ position = Vector2(-4659, 2897)
|
||||
position = Vector2(-5016, 3361)
|
||||
|
||||
[node name="trash" type="Node2D" parent="YSorted"]
|
||||
visible = false
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
|
||||
@@ -2428,8 +2407,6 @@ _payloadToSet = "farmOutside"
|
||||
[connection signal="SuccessfulPickUp" from="YSorted/SeedPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||
[connection signal="SuccessfulPickUp" from="YSorted/SeedPickup2" to="YSorted/Vesna" method="HandlePickUp"]
|
||||
[connection signal="InteractedTool" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadSceneAtIndex"]
|
||||
[connection signal="mouse_entered" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CanCreateFields"]
|
||||
[connection signal="mouse_exited" from="YSorted/Farm visuals/Farming Colliders" to="YSorted/Vesna/FarmingControls" method="CannotCreateFields"]
|
||||
[connection signal="InteractedTool" from="YSorted/Blocker/InteractionArea" to="." method="LoadSceneAtIndex"]
|
||||
[connection signal="GoalReached" from="YSorted/ducks" to="YSorted/ducks/DialogicToggle" method="ToggleDialogue"]
|
||||
[connection signal="DuckCollected" from="YSorted/ducks/Duck2" to="YSorted/ducks" method="Increment"]
|
||||
|
||||
@@ -1716,6 +1716,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField2" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(1226, 3098.15)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 1
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField2" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1727,6 +1728,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField3" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(1782, 2606.11)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 2
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField3" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1738,6 +1740,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField4" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(2559, 2624.22)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 3
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField4" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1749,6 +1752,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField5" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(3305, 2624.22)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 4
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField5" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1760,6 +1764,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField6" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(4033, 2618.18)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 5
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField6" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1771,6 +1776,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField7" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(4755, 2630.26)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 6
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField7" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1782,6 +1788,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField8" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(4418, 3226.95)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 7
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField8" index="0"]
|
||||
FieldState = 3
|
||||
@@ -1793,6 +1800,7 @@ _field = NodePath("../..")
|
||||
[node name="BaseField9" parent="YSorted/Farm visuals/FieldParent" instance=ExtResource("40_efblm")]
|
||||
position = Vector2(5317, 3208.83)
|
||||
scale = Vector2(1, 1.00622)
|
||||
Payload = 8
|
||||
|
||||
[node name="FieldBehaviour" parent="YSorted/Farm visuals/FieldParent/BaseField9" index="0"]
|
||||
FieldState = 3
|
||||
|
||||
@@ -9,17 +9,16 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class FarmingControls2D : Node2D
|
||||
{
|
||||
[Export] private VariableResource _sceneKeyProvider;
|
||||
[Export] private PackedScene? _fieldPrefab = null!;
|
||||
[Export] private Node2D _movingPlayer;
|
||||
[Export] private Camera2D _camera;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
||||
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
||||
[Export] private Node2D _fieldParent;
|
||||
[Export] private VariableResource _cursorOnField;
|
||||
|
||||
private int _toolId = -1;
|
||||
private bool _wateringCanFilled = false;
|
||||
private bool _canCreateFields = false;
|
||||
|
||||
[Signal] public delegate void WateringFieldEventHandler();
|
||||
|
||||
@@ -59,6 +58,7 @@ public partial class FarmingControls2D : Node2D
|
||||
{
|
||||
if (@event.IsActionPressed("click"))
|
||||
{
|
||||
bool cursorOnField = _cursorOnField.Payload.AsBool();
|
||||
if (_toolId == WateringCanState.WATERING_CAN_ID
|
||||
&& WateringCanState.GetFillState() > 0)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public partial class FarmingControls2D : Node2D
|
||||
WaterTheField(adjustedPosition);
|
||||
}
|
||||
|
||||
if (_canCreateFields && _toolId == 0)
|
||||
if ( _toolId == 0)
|
||||
{
|
||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||
MakeField(adjustedPosition);
|
||||
@@ -87,16 +87,6 @@ public partial class FarmingControls2D : Node2D
|
||||
return input.Snapped(step);
|
||||
}
|
||||
|
||||
public void CanCreateFields()
|
||||
{
|
||||
_canCreateFields = true;
|
||||
}
|
||||
|
||||
public void CannotCreateFields()
|
||||
{
|
||||
_canCreateFields = false;
|
||||
}
|
||||
|
||||
#region WATERING
|
||||
public void FillWateringCan()
|
||||
{
|
||||
@@ -108,7 +98,8 @@ public partial class FarmingControls2D : Node2D
|
||||
|
||||
private void WaterTheField(Vector2I fieldPosition)
|
||||
{
|
||||
FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition);
|
||||
int potentialFieldIndex = FieldService.Instance.PositionToIndex(fieldPosition);
|
||||
FieldBehaviour2D? field = FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex);
|
||||
if (field == null || field.FieldState == FieldState.Watered)
|
||||
{
|
||||
return;
|
||||
@@ -123,31 +114,11 @@ public partial class FarmingControls2D : Node2D
|
||||
#endregion
|
||||
|
||||
#region FIELD CREATION
|
||||
private void MakeField(Vector2I fieldPosition)
|
||||
private void MakeField(Vector2I mousePosition)
|
||||
{
|
||||
if(_fieldPrefab == null)
|
||||
return;
|
||||
|
||||
// only instantiate a field if there isn't one already.
|
||||
if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), fieldPosition) == null)
|
||||
{
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
if (fieldInstance is Node2D field2d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
Array<Node> fields = field2d.FindChildren("*", nameof(FieldBehaviour2D));
|
||||
if (fields.Count > 0)
|
||||
{
|
||||
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), fieldPosition, fields[0] as FieldBehaviour2D);
|
||||
}
|
||||
|
||||
// reposition and reparent the instance
|
||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);
|
||||
|
||||
_fieldParent.AddChild(fieldInstance);
|
||||
EmitSignal(SignalName.FieldCreated);
|
||||
}
|
||||
}
|
||||
int potentialFieldIndex = FieldService.Instance.PositionToIndex(mousePosition);
|
||||
if(FieldService.Instance.TryGet(_sceneKeyProvider.Payload.AsString(), potentialFieldIndex) == null)
|
||||
EmitSignal(SignalName.FieldCreated);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -22,6 +22,8 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] public ItemRepository ItemRepository;
|
||||
[Export] public InteractionArea2D FieldInteractionArea;
|
||||
[Export] public VariableResource _sceneKeyProvider;
|
||||
[Export] private VariableNode _fieldIndex;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
|
||||
@@ -54,7 +56,7 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
public override void _Ready()
|
||||
{
|
||||
UpdateFieldState(FieldState);
|
||||
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(), (Vector2I) GlobalPosition, this);
|
||||
FieldService.Instance.TryAddEntry(_sceneKeyProvider.Payload.AsString(),_fieldIndex.Payload.AsInt32(), this);
|
||||
int randomIndex = new Random().Next(0, _maskTexture.Length);
|
||||
_maskSprite.Texture = _maskTexture[randomIndex];
|
||||
_outlineSprite.Texture = _maskOutlineTextures[randomIndex];
|
||||
@@ -140,4 +142,5 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,9 +22,9 @@ public partial class FieldService : Node
|
||||
|
||||
|
||||
//Create
|
||||
public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field)
|
||||
public bool TryAddEntry(string sceneName, int fieldIndex, FieldBehaviour2D field)
|
||||
{
|
||||
GD.Print("Trying to add a field at: " + position);
|
||||
GD.Print("Trying to add a field at: " + fieldIndex);
|
||||
if (_outerDict != null )
|
||||
{
|
||||
FieldsInScene innerDict;
|
||||
@@ -36,21 +36,25 @@ public partial class FieldService : Node
|
||||
_outerDict.Add(sceneName, innerDict);
|
||||
}
|
||||
|
||||
if (!innerDict.fields.ContainsKey(position))
|
||||
if (!innerDict.fields.ContainsKey(fieldIndex))
|
||||
{
|
||||
innerDict.fields.Add(position, field);
|
||||
innerDict.fields.Add(fieldIndex, field);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("Duplicate field at: " + fieldIndex);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read
|
||||
public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition)
|
||||
public FieldBehaviour2D? TryGet(string key, int fieldIndex)
|
||||
{
|
||||
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||
{
|
||||
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance))
|
||||
if (field.fields.TryGetValue(fieldIndex, out FieldBehaviour2D? fieldInstance))
|
||||
{
|
||||
return fieldInstance;
|
||||
}
|
||||
@@ -60,42 +64,47 @@ public partial class FieldService : Node
|
||||
|
||||
|
||||
//Update
|
||||
public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state)
|
||||
public void UpdateEntry(string key, int fieldIndex, FieldBehaviour2D state)
|
||||
{
|
||||
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||
{
|
||||
if (field.fields.ContainsKey(fieldPosition))
|
||||
if (field.fields.ContainsKey(fieldIndex))
|
||||
{
|
||||
field.fields[fieldPosition] = state;
|
||||
field.fields[fieldIndex] = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
TryAddEntry(key, fieldPosition, state);
|
||||
TryAddEntry(key, fieldIndex, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Delete
|
||||
|
||||
public void RemoveEntry(string key, Vector2I fieldPosition)
|
||||
public void RemoveEntry(string key, int fieldIndex)
|
||||
{
|
||||
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||
{
|
||||
if (field.fields.ContainsKey(fieldPosition))
|
||||
if (field.fields.ContainsKey(fieldIndex))
|
||||
{
|
||||
field.fields.Remove(fieldPosition);
|
||||
field.fields.Remove(fieldIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PositionToIndex(Vector2 position)
|
||||
{
|
||||
// some awesome code here
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal class FieldsInScene
|
||||
{
|
||||
public Dictionary<Vector2I, FieldBehaviour2D?> fields;
|
||||
public Dictionary<int, FieldBehaviour2D?> fields;
|
||||
|
||||
public FieldsInScene()
|
||||
{
|
||||
fields = new Dictionary<Vector2I, FieldBehaviour2D?>();
|
||||
fields = new Dictionary<int, FieldBehaviour2D?>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Low_Code.Variables;
|
||||
|
||||
public partial class VariableNode : Node
|
||||
{
|
||||
[Export] public Variant Payload { get; set; }
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://j2mhvb45egej
|
||||
Reference in New Issue
Block a user