2024-11-09 02:05:02 +00:00
|
|
|
namespace LyraApi.Ecs;
|
|
|
|
|
|
|
|
using ExampleWorld.wit.imports.lyra.api;
|
|
|
|
using LyraApi;
|
2024-11-12 23:57:46 +00:00
|
|
|
using LyraApi.Asset;
|
2024-11-09 02:05:02 +00:00
|
|
|
|
|
|
|
public class World(IEcs.EcsWorld world)
|
|
|
|
{
|
2024-11-12 23:57:46 +00:00
|
|
|
internal IEcs.EcsWorld inner = world;
|
2024-11-09 02:05:02 +00:00
|
|
|
|
|
|
|
private Entity Spawn(List<IEcs.ComponentInfo> infos, params object[] comps)
|
|
|
|
{
|
|
|
|
byte[] bytes = comps.SelectMany(c => MarshalUtils.GetBytes(c)).ToArray();
|
2024-11-12 23:57:46 +00:00
|
|
|
return new Entity(inner.Spawn(bytes, infos));
|
2024-11-09 02:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2024-11-12 23:57:46 +00:00
|
|
|
IEcs.EcsDynamicView dynamicView = inner.View(infos);
|
2024-11-09 02:05:02 +00:00
|
|
|
return new ViewResult(comps, dynamicView).Get<T1>();
|
|
|
|
}
|
2024-11-10 00:13:15 +00:00
|
|
|
|
|
|
|
public T? GetResource<T>() where T : IResource
|
|
|
|
{
|
2024-11-12 23:57:46 +00:00
|
|
|
IEcs.WorldResourceResult result = inner.GetResource(Utils.ToWasmTypeId(T.TypeId));
|
|
|
|
return (T?)T.FromWasmResult(result);
|
|
|
|
}
|
|
|
|
|
2024-11-14 00:11:26 +00:00
|
|
|
/* public AssetManager? GetAssetManager()
|
2024-11-12 23:57:46 +00:00
|
|
|
{
|
|
|
|
IAsset.AssetManager? assetManager = IAsset.AssetManager.FromWorld(inner);
|
|
|
|
|
|
|
|
if (assetManager != null)
|
|
|
|
{
|
|
|
|
return new AssetManager(assetManager);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2024-11-14 00:11:26 +00:00
|
|
|
} */
|
2024-11-09 02:05:02 +00:00
|
|
|
}
|