public ChangedAttributeEventArgs(Component component, string attributeName, object oldValue, object newValue)
 {
     Component = component;
     AttributeName = attributeName;
     OldValue = oldValue;
     NewValue = newValue;
 }
Example #2
0
        public void Init()
        {
            // Set up definition.
            definition = new ComponentDefinition("test-component");
            definition.AddAttribute<string>("a", "a_value");
            definition.AddAttribute<float>("b", 3.14f);

            // Set up containing entity.
            containingEntity = new Entity();

            // Create component.
            component = new Component(definition, containingEntity);
        }
        //        [Test()]
        //        public void FirstShouldSetupDatabase()
        //        {
        //            cfg = new Configuration ();
        //            cfg.Configure ();
        //
        //            //sessionFactory = cfg.BuildSessionFactory ();
        //
        //            cfg.AddAssembly (typeof(Entity).Assembly);
        //            new SchemaExport (cfg).Execute (true, true, false);
        //        }
        //
        //        [Test()]
        //        public void ShouldStoreAndRetrieveComponent()
        //        {
        //            ComponentDefinition myComponent = new ComponentDefinition("myComponent");
        //            myComponent.AddAttribute<int>("IntAttribute");
        //            myComponent.AddAttribute<string>("StringAttribute");
        //            componentRegistry.Register(myComponent);
        //
        //            if (plugin == null) {
        //                plugin = new PersistencePlugin ();
        //                plugin.Initialize ();
        //            }
        //
        //            Entity entity = new Entity();
        //
        //            World.Instance.Add(entity);
        //            entity["myComponent"]["IntAttribute"].Suggest(42);
        //            entity["myComponent"]["StringAttribute"].Suggest("Hello World!");
        //
        //            // De-Activate on-remove event handler, as for tests, we only want to remove the entity from the local registry, not from the
        //            // persistence storage
        //            World.Instance.RemovedEntity -= plugin.OnEntityRemoved;
        //            World.Instance.Remove(entity);
        //
        //            plugin.RetrieveEntitiesFromDatabase ();
        //
        //            Entity storedEntity = World.Instance.FindEntity(entity.Guid.ToString());
        //            Assert.AreEqual(42, storedEntity["myComponent"]["IntAttribute"].Value);
        //            Assert.AreEqual("Hello World!", storedEntity["myComponent"]["StringAttribute"].Value);
        //        }
        //
        //        [Test()]
        //        public void ShouldStoreAndRetrieveEntities()
        //        {
        //            Entity entity = new Entity();
        //
        //            if (plugin == null) {
        //                plugin = new PersistencePlugin ();
        //                plugin.Initialize ();
        //            }
        //
        //            plugin.AddEntityToPersisted(entity);
        //            plugin.RetrieveEntitiesFromDatabase ();
        //            Assert.True(World.Instance.Contains(entity));
        //        }
        //
        //        [Test()]
        //        public void ShouldDeleteEntity()
        //        {
        //            Entity entity = new Entity();
        //
        //            if (plugin == null) {
        //                plugin = new PersistencePlugin ();
        //                plugin.Initialize ();
        //            }
        //
        //            World.Instance.Add (entity);
        //            World.Instance.Remove (entity);
        //
        //            if (!plugin.GlobalSession.IsOpen)
        //                plugin.GlobalSession = plugin.SessionFactory.OpenSession();
        //            plugin.RetrieveEntitiesFromDatabase ();
        //
        //            Assert.False(entityRegistry.Contains(entity));
        //        }
        public static void TestUpgrader(Component oldComponent, Component newComponent)
        {
            var newF = (float)(int)oldComponent["i"].Value;
            newComponent["f"].Suggest(newF);

            var newI = (int)(float)oldComponent["f"].Value;
            newComponent["i"].Suggest(newI);

            newComponent["b"].Suggest(oldComponent["b"]);
        }
Example #4
0
        private void CreateComponent(string componentName)
        {
            var definition = componentRegistry.FindComponentDefinition(componentName);
            if (definition == null)
                throw new ComponentAccessException("Component with given name '" + componentName + "' is not registered.");

            Component component = new Component(definition, this);
            components[componentName] = component;

            // Register for attribute updates in new component.
            component.ChangedAttribute += HandleChangedComponentAttribute;

            if (CreatedComponent != null)
                CreatedComponent(this, new ComponentEventArgs(component));
        }
 public ComponentEventArgs(Component component)
 {
     Component = component;
 }