MoonTools.ECS/src/TemplateStorage.cs

35 lines
735 B
C#
Raw Normal View History

2022-12-06 01:46:18 +00:00
using System.Collections.Generic;
2022-12-03 07:43:54 +00:00
namespace MoonTools.ECS
{
public class TemplateStorage
{
private int nextID = 0;
2022-12-06 01:46:18 +00:00
private Dictionary<int, HashSet<int>> TemplateToComponentTypeIndices = new Dictionary<int, HashSet<int>>();
2022-12-03 07:43:54 +00:00
public Template Create()
{
2022-12-06 01:46:18 +00:00
TemplateToComponentTypeIndices.Add(nextID, new HashSet<int>());
2022-12-03 07:43:54 +00:00
return new Template(NextID());
}
2022-12-06 01:46:18 +00:00
public bool SetComponent(int templateID, int componentTypeIndex)
{
return TemplateToComponentTypeIndices[templateID].Add(componentTypeIndex);
}
public IEnumerable<int> ComponentTypeIndices(int templateID)
{
return TemplateToComponentTypeIndices[templateID];
}
2022-12-03 07:43:54 +00:00
private int NextID()
{
var id = nextID;
nextID += 1;
return id;
}
}
}