public void Can_create_instance_with_default_vaules()
        {
            var entity = new EmptyEntity();

            entity.Id.ShouldBe(default(int));
            entity.Name.ShouldBeNull();
        }
    /// <summary>
    /// Copies components on this entity at <paramref name="indices"/> in the <see cref="EmptyComponentsLookup"/> to
    /// <paramref name="copyToEntity"/>. If <paramref name="replaceExisting"/> is true any of the components that
    /// <paramref name="copyToEntity"/> has that this entity has will be replaced, otherwise they will be skipped.
    /// </summary>
    public void CopyTo(EmptyEntity copyToEntity, bool replaceExisting, params int[] indices)
    {
        for (var i = 0; i < indices.Length; ++i)
        {
            var index = indices[i];

            // Validate that the index is within range of the component lookup
            if (index < 0 && index >= EmptyComponentsLookup.TotalComponents)
            {
                const string OUT_OF_RANGE_WARNING =
                    "Component Index [{0}] is out of range for [{1}].";

                const string HINT = "Please ensure any CopyTo indices are valid.";

                throw new IndexOutOfLookupRangeException(
                          string.Format(OUT_OF_RANGE_WARNING, index, nameof(EmptyComponentsLookup)),
                          HINT);
            }

            if (!HasComponent(index))
            {
                continue;
            }

            if (!copyToEntity.HasComponent(index) || replaceExisting)
            {
                var component = GetComponent(index);
                copyToEntity.CopyComponentTo(component);
            }
        }
    }
        private void SpawnCreditsImage()
        {
            var credits = new EmptyEntity {
                Depth    = 100,
                Position = new Vector2(Engine.Game.CanvasWidth / 2, Engine.Game.CanvasHeight / 2)
            };

            credits.AddSprite("main", new Sprite(SpriteSheetHolder.SpriteSheet.GetRegion(AvailableRegions.Extra.Credits)));
            Engine.SpawnInstance(credits);
        }
Ejemplo n.º 4
0
        public void EqualsWithObject()
        {
            var id1 = Guid.NewGuid();

            var entity = new EmptyEntity() { ID = id1 };
            var entity2 = new EmptyEntity() { ID = id1 };

            Assert.IsFalse(entity.Equals(null));
            Assert.IsTrue(entity.Equals(entity as Object));
            Assert.IsFalse(entity.Equals(new ScheduleItem()));
        }
Ejemplo n.º 5
0
        public void CompareShouldReturnConstantTrueWhenTargetTypeDoesNotHaveProperty()
        {
            var entity = new EmptyEntity();
            var testee = new CustomOperatorNoDescriptionAttribute("");
            var left   = new BlankOperand();
            var right  = new Operand(Expression.Constant(true), typeof(bool));

            var actual = testee.Compare(Expression.Constant(entity), left, right);

            Assert.IsInstanceOf <ConstantExpression>(actual.Expression);
            Assert.IsTrue((bool)Expression.Lambda(actual.Expression).Compile().DynamicInvoke());
            Assert.AreEqual(typeof(bool), actual.OperandType);
        }
Ejemplo n.º 6
0
        public void Equals()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

            var entity = new EmptyEntity() { ID = id1 };
            var entity2 = new EmptyEntity() { ID = id1 };
            var entity3 = new EmptyEntity() { ID = id2 };

            Assert.IsFalse(entity.Equals(null));
            Assert.IsTrue(entity.Equals(entity));
            Assert.IsTrue(entity.Equals(entity2));
            Assert.IsFalse(entity.Equals(entity3));
            Assert.IsFalse(entity.Equals(new Word()));
        }
    /// <summary>
    /// Copies all components on this entity to <paramref name="copyToEntity"/>; if <paramref name="replaceExisting"/>
    /// is true any of the components that <paramref name="copyToEntity"/> has that this entity has will be replaced,
    /// otherwise they will be skipped.
    /// </summary>
    public void CopyTo(EmptyEntity copyToEntity, bool replaceExisting)
    {
        for (var i = 0; i < EmptyComponentsLookup.TotalComponents; ++i)
        {
            if (!HasComponent(i))
            {
                continue;
            }

            if (!copyToEntity.HasComponent(i) || replaceExisting)
            {
                var component = GetComponent(i);
                copyToEntity.CopyComponentTo(component);
            }
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Collisions triggered.
        /// </summary>
        /// <param name="collided">The collided.</param>
        public override void CollisionTriggered(CollisionInfo collided)
        {
            if (Vector2.Dot(collided.NormalVector, new Vector2(0.0f, 1.0f)) > 0)
            {
                _isGrounded = false;
            }
            else
            {
                _isGrounded = true;
            }

            if (!_alreadySpawnedDust && Vector2.Dot(collided.NormalVector, new Vector2(0.0f, -1.0f)) > 0)
            {
                Entity dust = new EmptyEntity(
                    collided.PointOfCollision + new Vector2(0, 16.0f),
                    "Effects_Dust_Ground",
                    0.5f,
                    true);
                LevelManager.Instance.SpawnTempEntity(dust.Id, dust);
                _alreadySpawnedDust = true;
            }
        }
    /// <summary>
    /// Copies all components on this entity to <paramref name="copyToEntity"/>.
    /// </summary>
    public void CopyTo(EmptyEntity copyToEntity)
    {
        for (var i = 0; i < EmptyComponentsLookup.TotalComponents; ++i)
        {
            if (HasComponent(i))
            {
                if (copyToEntity.HasComponent(i))
                {
                    throw new EntityAlreadyHasComponentException(
                              i,
                              "Cannot copy component '" +
                              EmptyComponentsLookup.ComponentNames[i] +
                              "' to " +
                              this +
                              "!",
                              "If replacement is intended, please call CopyTo() with `replaceExisting` set to true.");
                }

                var component = GetComponent(i);
                copyToEntity.CopyComponentTo(component);
            }
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Applies all components in the blueprint to <paramref name="entity"/>.
    /// </summary>
    /// <param name="entity"></param>
    public void ApplyToEntity(EmptyEntity entity)
    {
        for (var i = 0; i < _components.Count; i++)
        {
            var component = _components[i];
            if (_components[i] == null)
            {
                continue;
            }

            var index = EmptyComponentsLookup.GetComponentIndex(component);
            if (index != -1)
            {
                entity.CopyComponentTo(component);
            }
            else
            {
                Debug.LogWarningFormat(
                    JCMG.EntitasRedux.RuntimeConstants.COMPONENT_INDEX_DOES_NOT_EXIST_FOR_TYPE_FORMAT,
                    component.GetType(),
                    typeof(EmptyComponentsLookup));
            }
        }
    }