public void TestDeserializationFromAttributeTable() { IAttributeTable attributeTable = new AttributeTable(); AttributeTable entityAttributeTable = new AttributeTable(); const string TestValueString = "Test"; entityAttributeTable.SetValue(TestComponent.AttributeTestString, TestValueString); EntityConfiguration entityConfiguration = new EntityConfiguration { BlueprintId = TestBlueprintId, Configuration = entityAttributeTable }; attributeTable.SetValue(TestData.AttributeTestEntity, entityConfiguration); TestData testData = InspectorUtils.CreateFromAttributeTable <TestData>( this.testGame.EntityManager, InspectorType.GetInspectorType(typeof(TestData)), attributeTable); Assert.AreNotEqual(testData.TestEntity, 0); Assert.AreNotEqual(testData.TestEntity, -1); // Check entity. TestComponent testComponent = this.testGame.EntityManager.GetComponent <TestComponent>(testData.TestEntity); Assert.NotNull(testComponent); Assert.AreEqual(testComponent.TestString, TestValueString); }
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)); }
/// <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); }
public static void SaveToAttributeTable(EntityManager entityManager, object obj, AttributeTable attributeTable) { InspectorType inspectorType = InspectorType.GetInspectorType(obj.GetType()); if (inspectorType == null) { throw new ArgumentException("No inspector type for object " + obj.GetType()); } SaveToAttributeTable(entityManager, inspectorType, obj, attributeTable); }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { InspectorPropertyData dataContext = (InspectorPropertyData)this.DataContext; InspectorDataAttribute inspectorDataAttribute = (InspectorDataAttribute)dataContext.InspectorProperty; this.value = (IAttributeTable)dataContext.Value; this.inspectorFactory = new InspectorFactory(dataContext.EditorContext, null); InspectorType typeInfo = InspectorType.GetInspectorType(inspectorDataAttribute.PropertyType); this.inspectorFactory.AddInspectorControls(typeInfo, this.Controls, this.GetPropertyValue, this.OnPropertyValueChanged, false); }
/// <summary> /// Initializes an object by getting its inspector properties via reflection and /// look them up in the specified attribute table. /// </summary> /// <param name="entityManager"> /// Entity manager to use for initializing the object, e.g. for creating entities from entity /// configuration attributes. /// </param> /// <param name="obj">Object to initialize.</param> /// <param name="attributeTable">Attribute table to initialize from.</param> public static void InitFromAttributeTable( EntityManager entityManager, object obj, IAttributeTable attributeTable) { InspectorType inspectorType = InspectorType.GetInspectorType(obj.GetType()); if (inspectorType == null) { return; } InitFromAttributeTable(entityManager, inspectorType, obj, attributeTable); }
public void SetUp() { this.inspectorType = InspectorType.GetInspectorType(typeof(TestInspectorType)); this.testGame = new Game(); }
public void TestAddingDefaultItemToEmptyStringList() { var inspectorType = InspectorType.GetInspectorType(typeof(TestType)); this.TestAddingDefaultItemToEmptyList(inspectorType, TestType.AttributeMember1); }
public void SetUp() { this.parentInspectorType = InspectorType.GetInspectorType(typeof(TestDataParent)); this.dataInspectorType = InspectorType.GetInspectorType(typeof(TestData)); this.testGame = new Game(); }