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.
47 lines
946 B
47 lines
946 B
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Farming;
|
|
|
|
[GlobalClass]
|
|
public partial class FieldService : Node3D
|
|
{
|
|
[Export] private Dictionary<Vector2I, FieldState> fields = new Dictionary<Vector2I, FieldState>();
|
|
|
|
//Create
|
|
|
|
public void AddEntry(Vector2I key, FieldState state)
|
|
{
|
|
fields.Add(key, state);
|
|
}
|
|
|
|
// Read
|
|
|
|
public FieldState Get(Vector2I key)
|
|
{
|
|
return fields[key];
|
|
}
|
|
|
|
//Update
|
|
public void UpdateEntry(Vector2I fieldPosition, FieldState state)
|
|
{
|
|
if (fields.ContainsKey(fieldPosition))
|
|
{
|
|
fields[fieldPosition] = state;
|
|
}
|
|
else
|
|
{
|
|
AddEntry(fieldPosition, state);
|
|
}
|
|
}
|
|
|
|
//Delete
|
|
|
|
public void RemoveEntry(Vector2I fieldPosition)
|
|
{
|
|
if (fields.ContainsKey(fieldPosition))
|
|
{
|
|
fields.Remove(fieldPosition);
|
|
}
|
|
}
|
|
} |