private void AddAttributes( Dictionary<string, object> attributes, Entity entity ) { // create and load data for all entity attributes foreach ( KeyValuePair<string, object> attributeData in attributes ) { // TODO: make sure these attributes are deep copied entity.AddAttribute( attributeData.Key, attributeData.Value ); } }
public static void AddTestComponent(Entity entity) { // Setup a velocity attribute Vector3 velocity = new Vector3(0, 0, -1.0f); entity.AddAttribute( Attributes.VELOCITY, velocity ); // Add the test component MoveComponent moveComponent = new MoveComponent( entity ); entity.AddComponent( moveComponent ); }
public static void AddTestComponent( Entity entity, GeometricPrimitiveType primitiveType, float size ) { Transform transform = new Transform(); entity.AddAttribute( Attributes.TRANSFORM, transform ); PrimitiveRenderComponent renderComponent = new PrimitiveRenderComponent( entity ); renderComponent.GeometricPrimitiveType = primitiveType; renderComponent.Color = Color.LimeGreen; renderComponent.Wireframe = false; renderComponent.m_size = size; entity.AddComponent( renderComponent ); }
private Entity CreateEntity(ParseTreeNode node, Scene scene, bool prototype) { Entity entity = new Entity() { Name = grammar.GetName(node), IsPrototype = prototype }; foreach (string name in grammar.GetPrototypes(node)) entity.AddPrototype(game.GetPrototype(name)); foreach (Tuple<string, object> attribute in GetProperties(node)) { ParseTreeNode attributeNode = (ParseTreeNode)attribute.Item2; entity.AddAttribute(new Attribute(attribute.Item1) { Value = new Value(getStrVal(attributeNode)) }); } foreach (ParseTreeNode componentNode in grammar.GetOfType(node, grammar.Component)) { // Adding a component adds any other components that the new component requires. // It is necessary to check if the component we are attempting to add already // exists. If it does, we should not attempt to create a new component. Plugin plugin = game.GetPlugin(grammar.GetName(componentNode)); Component component = entity.GetComponentByType(plugin.CoreType); if (null == component) { component = new Component(plugin); entity.AddComponent(component); } foreach (Tuple<string, object> property in GetProperties(componentNode)) { ParseTreeNode propertyNode = (ParseTreeNode)property.Item2; component.SetProperty(property.Item1, new Value(getStrVal(propertyNode))); } } foreach (ParseTreeNode eventNode in grammar.GetOfType(node, grammar.Evt)) { Event evt = CreateEvent(eventNode); entity.AddEvent(evt); } return entity; }
public void Entity_RemoveAttribute() { var entity = new Entity(); var attribute = new Attribute("test"); entity.AddAttribute(attribute); entity.SelectedAttribute = attribute; CommandHelper.TestUndoableCommand( () => Assert.AreEqual(1, entity.Attributes.Count), () => entity.RemoveAttributeCommand.Execute(null), () => Assert.AreEqual(0, entity.Attributes.Count) ); }
public static void ComponentTest() { XEngineComponentTest testGame = new XEngineComponentTest(); Entity entity1 = null; Entity entity2 = null; testGame.InitDelegate = delegate { entity1 = new Entity(); AddShipTestComponent( entity1 ); entity1.AddAttribute( Attributes.TRANSFORM, new Transform( new Vector3( 0, 1.0f, 0 ) ) ); entity1.Initialize(); entity2 = new Entity(); AddGridTestComponent( entity2 ); entity2.Initialize(); }; testGame.DrawDelegate = delegate( GameTime gameTime ) { entity1.Draw( gameTime ); entity2.Draw( gameTime ); }; testGame.Run(); }