namespace LyraApi.Ecs; using ExampleWorld.wit.imports.lyra.api; using LyraApi; using LyraApi.Asset; public class World(IEcs.EcsWorld world) { internal IEcs.EcsWorld inner = world; private Entity Spawn(List infos, params object[] comps) { byte[] bytes = comps.SelectMany(c => MarshalUtils.GetBytes(c)).ToArray(); return new Entity(inner.Spawn(bytes, infos)); } public Entity Spawn(T1 c1) where T1 : IComponent { List infos = [ComponentInfo.FromType().info]; return Spawn(infos, c1); } public IEnumerable<(Entity, T1)> View() where T1 : IComponent { List comps = [Component.FromComponent()]; List infos = comps.Select(c => c.GetComponentInfo().info).ToList(); IEcs.EcsDynamicView dynamicView = inner.View(infos); return new ViewResult(comps, dynamicView).Get(); } public T? GetResource() where T : IResource { IEcs.WorldResourceResult result = inner.GetResource(Utils.ToWasmTypeId(T.TypeId)); return (T?)T.FromWasmResult(result); } public AssetManager? GetAssetManager() { IAsset.AssetManager? assetManager = IAsset.AssetManager.FromWorld(inner); if (assetManager != null) { return new AssetManager(assetManager); } else { return null; } } }