MoonTools.ECS/src/DebugSystem.cs

45 lines
1.0 KiB
C#
Raw Normal View History

2022-04-08 05:52:03 +00:00
// NOTE: these methods are very inefficient
2022-03-25 19:32:35 +00:00
// this class should only be used in debugging contexts!!
#if DEBUG
2022-04-08 05:52:03 +00:00
using System;
using System.Collections.Generic;
2022-03-25 19:32:35 +00:00
namespace MoonTools.ECS
{
public abstract class DebugSystem : System
{
protected DebugSystem(World world) : base(world)
{
}
protected IEnumerable<dynamic> Debug_GetAllComponents(Entity entity)
2022-03-25 19:32:35 +00:00
{
foreach (var typeIndex in EntityStorage.ComponentTypeIndices(entity.ID))
{
yield return ComponentDepot.Debug_Get(entity.ID, typeIndex);
}
2022-03-25 19:32:35 +00:00
}
protected IEnumerable<Entity> Debug_GetEntities(Type componentType)
2022-03-25 19:32:35 +00:00
{
foreach (var entityID in ComponentDepot.Debug_GetEntityIDs(ComponentTypeIndices.GetIndex(componentType)))
{
yield return new Entity(entityID);
}
2022-03-25 19:32:35 +00:00
}
protected IEnumerable<Type> Debug_SearchComponentType(string typeString)
{
foreach (var type in ComponentTypeIndices.Types)
{
if (type.ToString().ToLower().Contains(typeString.ToLower()))
{
yield return type;
}
}
2022-03-25 19:32:35 +00:00
}
}
}
#endif