30 lines
956 B
C#
30 lines
956 B
C#
|
namespace LyraApi.Ecs;
|
||
|
|
||
|
using ExampleWorld.wit.imports.lyra.api;
|
||
|
using LyraApi;
|
||
|
|
||
|
public class World(IEcs.EcsWorld world)
|
||
|
{
|
||
|
private IEcs.EcsWorld Inner { get; set; } = world;
|
||
|
|
||
|
private Entity Spawn(List<IEcs.ComponentInfo> infos, params object[] comps)
|
||
|
{
|
||
|
byte[] bytes = comps.SelectMany(c => MarshalUtils.GetBytes(c)).ToArray();
|
||
|
return new Entity(Inner.Spawn(bytes, infos));
|
||
|
}
|
||
|
|
||
|
public Entity Spawn<T1>(T1 c1) where T1 : IComponent
|
||
|
{
|
||
|
List<IEcs.ComponentInfo> infos = [ComponentInfo.FromType<T1>().info];
|
||
|
return Spawn(infos, c1);
|
||
|
}
|
||
|
|
||
|
public IEnumerable<(Entity, T1)> View<T1>() where T1 : IComponent
|
||
|
{
|
||
|
List<Component> comps = [Component.FromComponent<T1>()];
|
||
|
List<IEcs.ComponentInfo> infos = comps.Select(c => c.GetComponentInfo().info).ToList();
|
||
|
|
||
|
IEcs.EcsDynamicView dynamicView = Inner.View(infos);
|
||
|
return new ViewResult(comps, dynamicView).Get<T1>();
|
||
|
}
|
||
|
}
|