You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
using System.Diagnostics;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
[GlobalClass]
|
|
public partial class FieldService : Node3D
|
|
{
|
|
[Export] private Dictionary<Vector2I, FieldBehaviour> fields = new Dictionary<Vector2I, FieldBehaviour>();
|
|
|
|
//Create
|
|
public bool TryAddEntry(Vector2I key, FieldBehaviour field)
|
|
{
|
|
if (!fields.ContainsKey(key))
|
|
{
|
|
fields.Add(key, field);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Read
|
|
public FieldBehaviour Get(Vector2I key)
|
|
{
|
|
if (fields.TryGetValue(key, out FieldBehaviour field))
|
|
return field;
|
|
return field;
|
|
|
|
return null;
|
|
}
|
|
|
|
//Update
|
|
public void UpdateEntry(Vector2I fieldPosition, FieldBehaviour 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);
|
|
}
|
|
}
|
|
} |