Exemplo n.º 1
0
        public void CreateEntityWithRotationComponent()
        {
            var entities = new MockEntitiesRunner(typeof(Rotate));
            var entity   = new MockEntity().Add(0.5f).Start <Rotate>();

            Assert.AreEqual(0.5f, entity.Get <float>());
            entities.RunEntities();
            Assert.AreEqual(0.55f, entity.Get <float>());
        }
        public void AddEntityAndAttachHandlerLater()
        {
            var entity = new MockEntity().Add(0);

            entities.RunEntities();
            Assert.AreEqual(0, entity.Get <int>());
            entity.Start <IncrementCounter>();
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
            entity.Stop <IncrementCounter>();
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
        }
Exemplo n.º 3
0
        public void PauseTimeShouldNotUpdateAnyEntityAnymore()
        {
            var entities = new MockEntitiesRunner(typeof(EntitiesRunnerTests.IncrementCounter));
            var entity   = new MockEntity().Add(0).Start <EntitiesRunnerTests.IncrementCounter>();

            Assert.AreEqual(0, entity.Get <int>());
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
            Time.SpeedFactor = 0;
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
            Time.SpeedFactor = 1;
        }
        public void AddingBehaviorTwiceIsIgnored()
        {
            var entity   = new MockEntity().Start <IncrementCounter>().Add(0);
            var behavior = EntitiesRunner.Current.GetUpdateBehavior <IncrementCounter>();

            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
            entity.Start <IncrementCounter>();
            Assert.AreEqual(behavior, EntitiesRunner.Current.GetUpdateBehavior <IncrementCounter>());
            entities.RunEntities();
            Assert.AreEqual(2, entity.Get <int>());
            Assert.AreEqual(1, EntitiesRunner.Current.NumberOfEntities);
        }
        public void ActiveEntityRunsBehavior()
        {
            var entity = new MockEntity();

            entity.Start <IncrementCounter>().Add(0);
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
        }
        public void InactiveEntityDoesntRunBehavior()
        {
            var entity = new MockEntity();

            entity.Start <IncrementCounter>().Add(0);
            entity.IsActive = false;
            entities.RunEntities();
            Assert.AreEqual(0, entity.Get <int>());
        }
        public void AddingAndRemovingTheSameHandlerDoesNothing()
        {
            var entity = new MockEntity().Add(0);

            entity.Start <IncrementCounter>();
            entity.Stop <IncrementCounter>();
            entities.RunEntities();
            Assert.AreEqual(0, entity.Get <int>());
        }
        public void ReactivatedEntityRunsBehavior()
        {
            var entity = new MockEntity();

            entity.Start <IncrementCounter>().Add(0);
            entity.IsActive = false;
            entity.IsActive = true;
            entities.RunEntities();
            Assert.AreEqual(1, entity.Get <int>());
        }
Exemplo n.º 9
0
        public void SelectingEntityHandlerProcessesEntitiesThatPassTheSelectionCriteria()
        {
            var entities = new MockEntitiesRunner(typeof(IncludeOnlyEntitiesWithPositiveFloats));
            var first    = new MockEntity().Start <IncludeOnlyEntitiesWithPositiveFloats>().Add(3.0f);
            var excluded = new MockEntity().Start <IncludeOnlyEntitiesWithPositiveFloats>().Add(-1.0f);
            var second   = new MockEntity().Start <IncludeOnlyEntitiesWithPositiveFloats>().Add(2.0f);

            entities.RunEntities();
            var start = first.Get <int>();

            Assert.IsFalse(excluded.Contains <int>());
            Assert.AreEqual(start + 1, second.Get <int>());
        }
Exemplo n.º 10
0
        public void AddAndRemoveComponent()
        {
            Assert.AreEqual(1, entities.NumberOfEntities);
            var entity = new MockEntity().Add(new object());

            Assert.AreEqual(2, entities.NumberOfEntities);
            Assert.AreEqual(1, entity.NumberOfComponents);
            Assert.IsNotNull(entity.Get <object>());
            entity.Remove <object>();
            Assert.AreEqual(0, entity.NumberOfComponents);
            Assert.IsFalse(entity.Contains <object>());
            Assert.Throws <ArgumentNullException>(() => new MockEntity().Add <object>(null));
        }