Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// Registers a new component definition. An exception will be raised if the component with the same name is
        /// already registered.
        /// </summary>
        /// <param name="definition">New component definition.</param>
        public void Register(ComponentDefinition definition)
        {
            if (registeredComponents.ContainsKey(definition.Name))
            {
                throw new ComponentRegistrationException("Component with the same name is already registered.");
            }

            registeredComponents.Add(definition.Name, definition);

            if (RegisteredComponent != null)
            {
                RegisteredComponent(this, new RegisteredComponentEventArgs(definition));
            }
        }
Beispiel #3
0
        public void Init()
        {
            // TODO: mock ComponentDefinition
            ComponentDefinition test = new ComponentDefinition("test");

            test.AddAttribute <int>("a", 42);
            test.AddAttribute <int?>("n", 5);

            mockComponentRegistry = new Mock <IComponentRegistry>();
            mockComponentRegistry.Setup(r => r.FindComponentDefinition("test")).Returns(test);

            entity = new Entity();
            entity.componentRegistry = mockComponentRegistry.Object;

            mockHandlers = new Mock <IMockHandlers>();
        }
Beispiel #4
0
        public void ShouldConvertCompatibleDefaultValues()
        {
            ComponentDefinition def = new ComponentDefinition("defTypeTest");

            def.AddAttribute <double>("c", 42.0);
            def.AddAttribute <int?>("e", null);
            def.AddAttribute <int?>("f", 34);

            Assert.Catch <AttributeDefinitionException>(delegate {
                def.AddAttribute <double>("d", 42);
            });

            Assert.Catch <AttributeDefinitionException>(delegate {
                def.AddAttribute <double>("a", 42);
            });

            Assert.Catch <AttributeDefinitionException>(delegate {
                def.AddAttribute <double>("b", 42f);
            });

            Assert.Catch <AttributeDefinitionException>(delegate {
                def.AddAttribute <int>("g", 3.14);
            });
        }
Beispiel #5
0
 public void Init()
 {
     registry   = new ComponentRegistry();
     definition = new ComponentDefinition("test2");
     definition.AddAttribute <int>("a", 42);
 }
Beispiel #6
0
 public void Init()
 {
     definition = new ComponentDefinition("test-name");
 }
 public RegisteredComponentEventArgs(ComponentDefinition definition)
 {
     ComponentDefinition = definition;
 }