Inspector tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using MoonTools.ECS;
|
||||
using Nerfed.Editor.Components;
|
||||
using Nerfed.Runtime.Serialization;
|
||||
|
||||
#if DEBUG
|
||||
namespace Nerfed.Editor.Systems
|
||||
@@ -29,19 +31,40 @@ namespace Nerfed.Editor.Systems
|
||||
|
||||
private void DrawEntityComponents(Entity entity)
|
||||
{
|
||||
World.ComponentTypeEnumerator components = World.Debug_GetAllComponentTypes(entity);
|
||||
|
||||
foreach (Type type in components)
|
||||
World.ComponentTypeEnumerator componentTypes = World.Debug_GetAllComponentTypes(entity);
|
||||
|
||||
ImGui.Text("ComponentInspectorByType");
|
||||
foreach (Type componentType in componentTypes)
|
||||
{
|
||||
ImGui.Text(type.Name);
|
||||
if (ComponentHelper.ComponentInspectorByType.TryGetValue(componentType, out Action<World, Entity> componentInspector))
|
||||
{
|
||||
componentInspector(World, entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.Text(componentType.Name);
|
||||
}
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
||||
ImGui.Dummy(new Vector2(16, 16));
|
||||
|
||||
ImGui.Text("GetComponentByType");
|
||||
foreach (Type componentType in componentTypes)
|
||||
{
|
||||
if (!ComponentHelper.GetComponentByType.TryGetValue(componentType, out Func<World, Entity, ValueType> componentGetter)) continue;
|
||||
ValueType component = componentGetter.Invoke(World, entity);
|
||||
ImGui.Text(component.ToString());
|
||||
ImGui.Separator();
|
||||
}
|
||||
|
||||
ImGui.Dummy(new Vector2(16, 16));
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
ImGui.Text("Reflection");
|
||||
// TODO: explore something without reflection.
|
||||
// Maybe generate some look up dictionary<type, Action<world, entity>> for 'custom editors'.
|
||||
// Look into serializing of entities and components.
|
||||
foreach (Type component in components)
|
||||
foreach (Type component in componentTypes)
|
||||
{
|
||||
System.Reflection.MethodInfo getMethodInfo = typeof(World).GetMethod("Get");
|
||||
System.Reflection.MethodInfo getComponentMethod = getMethodInfo.MakeGenericMethod(component);
|
||||
|
Reference in New Issue
Block a user