🚧 WIP trying to fix a bug that won't let me have more than 9 fields. Dont ask me why.
This commit is contained in:
+2
-1
@@ -11,7 +11,7 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Babushka"
|
config/name="Babushka"
|
||||||
run/main_scene="uid://bopv10dqm1knc"
|
run/main_scene="uid://c6wnoif01ltld"
|
||||||
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
|
||||||
run/max_fps=120
|
run/max_fps=120
|
||||||
boot_splash/fullsize=false
|
boot_splash/fullsize=false
|
||||||
@@ -147,6 +147,7 @@ directories/tres_directory={
|
|||||||
"default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres",
|
"default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres",
|
||||||
"event_PickedUpInteractable": "res://resources/low code/interactables/event_PickedUpInteractable.tres",
|
"event_PickedUpInteractable": "res://resources/low code/interactables/event_PickedUpInteractable.tres",
|
||||||
"event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres",
|
"event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres",
|
||||||
|
"event_fieldCreated": "res://resources/low code/farming/event_fieldCreated.tres",
|
||||||
"event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres",
|
"event_newPlantCreated": "res://resources/low code/farming/event_newPlantCreated.tres",
|
||||||
"event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres",
|
"event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres",
|
||||||
"farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres",
|
"farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres",
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://cvgs0ojdo1jyu"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_x3jnq"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_x3jnq")
|
||||||
|
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
|
||||||
@@ -13,6 +13,7 @@ public partial class FarmingControls2D : Node2D
|
|||||||
[Export] private Camera2D _camera;
|
[Export] private Camera2D _camera;
|
||||||
[Export] private CpuParticles2D _wateringParticles;
|
[Export] private CpuParticles2D _wateringParticles;
|
||||||
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
[Export] private float _wateringCanParticlesVerticalOffset = 50f;
|
||||||
|
[Export] private Vector2I _fieldOffsetVector = new Vector2I(735, 651);
|
||||||
|
|
||||||
private int _toolId = -1;
|
private int _toolId = -1;
|
||||||
private bool _wateringCanFilled = false;
|
private bool _wateringCanFilled = false;
|
||||||
@@ -20,6 +21,8 @@ public partial class FarmingControls2D : Node2D
|
|||||||
|
|
||||||
[Signal] public delegate void WateringFieldEventHandler();
|
[Signal] public delegate void WateringFieldEventHandler();
|
||||||
|
|
||||||
|
[Signal] public delegate void FieldCreatedEventHandler();
|
||||||
|
|
||||||
#region Tools
|
#region Tools
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,13 +55,22 @@ public partial class FarmingControls2D : Node2D
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (@event.IsActionPressed("click")
|
if (@event.IsActionPressed("click"))
|
||||||
&& _toolId == WateringCanState.WATERING_CAN_ID
|
|
||||||
&& WateringCanState.GetFillState() > 0)
|
|
||||||
{
|
{
|
||||||
GD.Print("Trying to use the watering can.");
|
if (_toolId == WateringCanState.WATERING_CAN_ID
|
||||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
&& WateringCanState.GetFillState() > 0)
|
||||||
WaterTheField(adjustedPosition);
|
{
|
||||||
|
GD.Print("Trying to use the watering can.");
|
||||||
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||||
|
WaterTheField(adjustedPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_toolId == 0)
|
||||||
|
{
|
||||||
|
GD.Print("Trying to create a field.");
|
||||||
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||||
|
MakeField(adjustedPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +78,7 @@ public partial class FarmingControls2D : Node2D
|
|||||||
{
|
{
|
||||||
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
||||||
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
||||||
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, _fieldOffsetVector);
|
||||||
return adjustedPosition;
|
return adjustedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +90,9 @@ public partial class FarmingControls2D : Node2D
|
|||||||
/// <param name="shapeIndex"></param>
|
/// <param name="shapeIndex"></param>
|
||||||
public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex)
|
public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex)
|
||||||
{
|
{
|
||||||
|
// Bug is here: Whenever I use the collider to limit the farming area, Godot crashes after 10 fields.
|
||||||
|
/*
|
||||||
|
GD.Print($"Input event registered on {node.Name} as {inputEvent.GetType().Name}.");
|
||||||
if (!inputEvent.IsPressed())
|
if (!inputEvent.IsPressed())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -103,6 +118,7 @@ public partial class FarmingControls2D : Node2D
|
|||||||
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||||
MakeField(adjustedPosition);
|
MakeField(adjustedPosition);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#region WATERING
|
#region WATERING
|
||||||
@@ -152,18 +168,11 @@ public partial class FarmingControls2D : Node2D
|
|||||||
// reposition and reparent the instance
|
// reposition and reparent the instance
|
||||||
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
field2d.Position = new Vector2(fieldPosition.X, fieldPosition.Y);;
|
||||||
FieldService.Instance.AddChild(fieldInstance);
|
FieldService.Instance.AddChild(fieldInstance);
|
||||||
|
EmitSignal(SignalName.FieldCreated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int AdjustValue(float value)
|
|
||||||
{
|
|
||||||
float adjustedValue = value / 500;
|
|
||||||
adjustedValue = Mathf.RoundToInt(adjustedValue);
|
|
||||||
adjustedValue *= 500;
|
|
||||||
return (int)adjustedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
private Vector2I AdjustValue(Vector2I input, Vector2I step)
|
||||||
{
|
{
|
||||||
return input.Snapped(step);
|
return input.Snapped(step);
|
||||||
|
|||||||
@@ -5,37 +5,39 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
|||||||
|
|
||||||
public partial class FieldService : Node
|
public partial class FieldService : Node
|
||||||
{
|
{
|
||||||
private Dictionary<string, FieldsInScene>? outerDict;
|
private Dictionary<string, FieldsInScene>? _outerDict = null!;
|
||||||
|
|
||||||
[Signal] public delegate void FieldCreatedEventHandler();
|
|
||||||
|
|
||||||
public static FieldService Instance { get; private set; } = null!;
|
public static FieldService Instance { get; private set; } = null!;
|
||||||
|
|
||||||
public override void _EnterTree()
|
public override void _EnterTree()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
outerDict = new Dictionary<string, FieldsInScene>();
|
_outerDict = new Dictionary<string, FieldsInScene>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
Instance = null;
|
||||||
|
_outerDict = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field)
|
public bool TryAddEntry(string sceneName, Vector2I position, FieldBehaviour2D field)
|
||||||
{
|
{
|
||||||
if (outerDict != null )
|
if (_outerDict != null )
|
||||||
{
|
{
|
||||||
FieldsInScene fieldsInScene;
|
FieldsInScene innerDict;
|
||||||
bool outerDictEntryExists = outerDict.TryGetValue(sceneName, out fieldsInScene);
|
bool outerDictEntryExists = _outerDict.TryGetValue(sceneName, out innerDict);
|
||||||
|
|
||||||
if (!outerDictEntryExists)
|
if (!outerDictEntryExists)
|
||||||
{
|
{
|
||||||
fieldsInScene = new FieldsInScene();
|
innerDict = new FieldsInScene();
|
||||||
outerDict.Add(sceneName, fieldsInScene);
|
_outerDict.Add(sceneName, innerDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fieldsInScene.fields.ContainsKey(position))
|
if (!innerDict.fields.ContainsKey(position))
|
||||||
{
|
{
|
||||||
fieldsInScene.fields.Add(position, field);
|
innerDict.fields.Add(position, field);
|
||||||
EmitSignal(SignalName.FieldCreated);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,13 +47,15 @@ public partial class FieldService : Node
|
|||||||
// Read
|
// Read
|
||||||
public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition)
|
public FieldBehaviour2D? TryGet(string key, Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance))
|
if (field.fields.TryGetValue(fieldPosition, out FieldBehaviour2D? fieldInstance))
|
||||||
{
|
{
|
||||||
|
GD.Print("Getting field...");
|
||||||
return fieldInstance;
|
return fieldInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GD.Print($"No field found for key: {key} and position: {fieldPosition} ");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +63,7 @@ public partial class FieldService : Node
|
|||||||
//Update
|
//Update
|
||||||
public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state)
|
public void UpdateEntry(string key, Vector2I fieldPosition, FieldBehaviour2D state)
|
||||||
{
|
{
|
||||||
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
if (field.fields.ContainsKey(fieldPosition))
|
if (field.fields.ContainsKey(fieldPosition))
|
||||||
{
|
{
|
||||||
@@ -76,7 +80,7 @@ public partial class FieldService : Node
|
|||||||
|
|
||||||
public void RemoveEntry(string key, Vector2I fieldPosition)
|
public void RemoveEntry(string key, Vector2I fieldPosition)
|
||||||
{
|
{
|
||||||
if (outerDict != null && outerDict.TryGetValue(key, out FieldsInScene? field))
|
if (_outerDict != null && _outerDict.TryGetValue(key, out FieldsInScene? field))
|
||||||
{
|
{
|
||||||
if (field.fields.ContainsKey(fieldPosition))
|
if (field.fields.ContainsKey(fieldPosition))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user