Exemplo n.º 1
0
        public void TestDeinitRemovesChildEntity()
        {
            var              entityManager   = this.testGame.EntityManager;
            const string     TestBlueprintId = "TestBlueprint";
            BlueprintManager blueprintManager;

            this.testGame.BlueprintManager = blueprintManager = new BlueprintManager();
            blueprintManager.AddBlueprint(TestBlueprintId, new Blueprint());

            TestInspectorTypeWithEntityProperty testType = new TestInspectorTypeWithEntityProperty();
            var                 testInspectorType        = InspectorType.GetInspectorType(typeof(TestInspectorTypeWithEntityProperty));
            IAttributeTable     configuration            = new AttributeTable();
            EntityConfiguration childConfiguration       = new EntityConfiguration {
                BlueprintId = TestBlueprintId
            };

            configuration.SetValue(TestInspectorTypeWithEntityProperty.AttributeMember1, childConfiguration);

            // Init.
            InspectorUtils.InitFromAttributeTable(entityManager, testInspectorType, testType, configuration);

            // Check that child entity was created.
            Assert.AreNotEqual(0, testType.EntityMember);

            // Deinit.
            InspectorUtils.Deinit(entityManager, testInspectorType, testType);

            // Check that child entity was removed.
            Assert.IsTrue(entityManager.EntityIsBeingRemoved(testType.EntityMember));
        }
Exemplo n.º 2
0
        public void TestInitFromNullAttributeTable()
        {
            TestInspectorType testInspectorType = new TestInspectorType();

            Assert.DoesNotThrow(
                () => InspectorUtils.InitFromAttributeTable(this.testGame.EntityManager, testInspectorType, null));
        }
        /// <summary>
        ///   Initializes the specified object via reflection with the specified property value.
        /// </summary>
        /// <param name="entityManager">Entity manager.</param>
        /// <param name="obj">Object to set property value for.</param>
        /// <param name="propertyValue">Property value to set.</param>
        public override void SetPropertyValue(EntityManager entityManager, object obj, object propertyValue)
        {
            IAttributeTable propertyAttributeTable = (IAttributeTable)propertyValue;

            propertyValue = Activator.CreateInstance(this.PropertyType);
            InspectorType propertyInspectorType = InspectorType.GetInspectorType(this.PropertyType);

            InspectorUtils.InitFromAttributeTable(entityManager, propertyInspectorType, propertyValue, propertyAttributeTable);

            base.SetPropertyValue(entityManager, obj, propertyValue);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Initializes the specified component with the specified attribute table.
        /// </summary>
        /// <param name="component">Component to initialize.</param>
        /// <param name="attributeTable">Attribute table which contains the data of the component.</param>
        private void InitComponent(IEntityComponent component, IAttributeTable attributeTable)
        {
            InspectorType inspectorType;

            if (!this.inspectorTypes.TryGetInspectorType(component.GetType(), out inspectorType))
            {
                this.game.Log.Warning(
                    "Entity component '" + component.GetType()
                    + "' not flagged as inspector type, can't initialize via reflection.");
                return;
            }

            var inspectorComponent = inspectorType.Attribute as InspectorComponentAttribute;

            if (inspectorComponent != null && inspectorComponent.InitExplicitly)
            {
                return;
            }

            InspectorUtils.InitFromAttributeTable(this, inspectorType, component, attributeTable);
        }
Exemplo n.º 5
0
 /// <summary>
 ///   Initializes this system with the data stored in the specified
 ///   attribute table.
 /// </summary>
 /// <param name="configuration">System configuration data.</param>
 public virtual void Init(IAttributeTable configuration)
 {
     // Initialize from configuration.
     InspectorUtils.InitFromAttributeTable(this.EntityManager, this, configuration);
 }