public void ShouldRegisterAndExecuteComponentsAndSystems() { container.IsBuilt().Should().BeFalse(); container .AddComponent <SampleComponent>() .AddSystem <SampleSystem>() .Build(); container.IsBuilt().Should().BeTrue(); container.GetSystemTypes().Should().BeEquivalentTo(typeof(SampleSystem)); container.GetComponentTypes().Should().BeEquivalentTo(typeof(SampleComponent)); var storage = container.GetStorageFor <SampleComponent>(); storage.Should().NotBeNull(); Assert.NotNull(container.GetStorageFor(typeof(SampleComponent))); container.Resolve <IComponentCollection <SampleComponent> >().Should().BeSameAs(storage); var sampleSystem = container.GetSystem <SampleSystem>(); sampleSystem.Should().NotBeNull(); sampleSystem.Container.Should().Be(container); sampleSystem.EntityManager.Should().Be(container.EntityManager); Assert.NotNull(container.GetSystem(typeof(SampleSystem))); var entityManager = container.EntityManager; var entityCount = 5; var entityIds = Enumerable.Range(0, entityCount) .Select(i => entityManager.Create()) .ToList(); entityIds.ForEach(id => container.AddComponent <SampleComponent, object>(id)); // Initial state storage.GetCount().Should().Be(entityCount); storage.GetValues().Should().OnlyContain(c => c.Foo == 0.0f && c.Bar == false); // Execute the system once var pairs = new Dictionary <int, SampleComponent>(); container.InitializeSystems(); container.ExecuteSystems(); storage.ForEach((id, val, _) => pairs.Add(id, val), default(object)); pairs.AsEnumerable() .Should() .OnlyContain(kvp => kvp.Value.Foo == kvp.Key && kvp.Value.Bar == true); // Execute the system again and observe changes pairs.Clear(); container.ExecuteSystems(); storage.ForEach((id, val, _) => pairs.Add(id, val), default(object)); pairs.AsEnumerable() .Should() .OnlyContain(kvp => kvp.Value.Foo == kvp.Key + 1 && kvp.Value.Bar == false); }
void IPexExplorationPackage.Load( IContainer explorationContainer) { explorationContainer.AddComponent( "FieldAccessObserver", new FieldAccessObserver()); }
void IPexExplorationPackage.Load( IContainer explorationContainer) { explorationContainer.AddComponent( "InsufficientObjectFactoryObserver", new InsufficientObjectFactoryObserver()); }
private static int SpawnRandomEntity(IContainer <GameState> ecs, IConsoleBackend term) { var em = ecs.EntityManager; var id = em.Create(); // create an entity ID var screenSize = new Vector2(term.WindowWidth, term.WindowHeight); var maxSpeed = new Vector2(10f); // add physics component var position = RandomVector(Vector2.Zero, screenSize); var velocity = RandomVector(-maxSpeed, maxSpeed); ecs.AddComponent(id, new PhysicsObject(position, velocity)); // add drawable component var symbol = RandomElement(s_symbols); var color = RandomEnumValue <Color16>(); ecs.AddComponent(id, new Drawable(symbol, color)); return(id); }
private void RunScenePhysicsSimulationWindow(IContainer sceneContainer, string title, int width, int height) { var windowCreator = new ThreadStart(() => { var physicsSimulationWindow = sceneContainer.AddComponent(new PhysicsSimulationWindow(title, width, height)); physicsSimulationWindow.Run(PhysicsUtils.UPDATES_PER_SECOND, PhysicsUtils.FRAMES_PER_SECOND); }); var windowThread = new Thread(windowCreator); windowThread.Start(); }
void IPexPathPackage.Load(IContainer pathContainer) { pathContainer.AddComponent("FieldAccessPathObserver", new FieldAccessPathObserver()); }
public static T AddComponent <T>(T component) where T : IComponent { return(Components.AddComponent(component)); }
private void AddComponent(IContainer container, Image image) { container.AddComponent(new Panel { Margin = Spacer.Parse("1"), Border = Border.Parse("1 green"), Inner = image }); }
protected override void Load(IContainer engineContainer) { engineContainer.AddComponent(null, new ProblemTrackDatabase()); base.Load(engineContainer); }
public AbstractComponent(IContainer parent) { Parent = parent; SetDefaults(); parent?.AddComponent(this); }
void IPexExplorationPackage.Load(IContainer explorationContainer) { explorationObserver = new FieldAccessExplorationObserver(); explorationContainer.AddComponent("", explorationObserver); }