Beispiel #1
1
        private void TestAddRemoveListenerImpl(Game game)
        {
            var audio = game.Audio;
            var notAddedToEntityListener = new AudioListenerComponent();
            var addedToEntityListener = new AudioListenerComponent();

            // Add a listenerComponent not present in the entity system yet and check that it is correctly added to the AudioSystem internal data structures
            Assert.DoesNotThrow(() => audio.AddListener(notAddedToEntityListener), "Adding a listener not present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem does not contains the notAddedToEntityListener.");

            // Add a listenerComponent already present in the entity system and check that it is correctly added to the AudioSystem internal data structures
            var entity = new Entity("Test");
            entity.Add(addedToEntityListener);
            throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); 
            //game.Entities.Add(entity);
            Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener present in the entity system failed");
            Assert.IsTrue(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem does not contains the addedToEntityListener.");

            // Add a listenerComponent already added to audio System and check that it does not crash
            Assert.DoesNotThrow(()=>audio.AddListener(addedToEntityListener), "Adding a listener already added to the audio system failed.");

            // Remove the listeners from the AudioSystem and check that they are removed from internal data structures.
            Assert.DoesNotThrow(() => audio.RemoveListener(notAddedToEntityListener), "Removing an listener not present in the entity system failed.");
            Assert.IsFalse(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem still contains the notAddedToEntityListener.");
            Assert.DoesNotThrow(() => audio.RemoveListener(addedToEntityListener), "Removing an listener present in the entity system fails");
            Assert.IsFalse(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem still contains the addedToEntityListener.");

            // Remove a listener not present in the AudioSystem anymore and check the thrown exception
            Assert.Throws<ArgumentException>(() => audio.RemoveListener(addedToEntityListener), "Removing the a non-existing listener did not throw ArgumentException.");
        }
Beispiel #2
0
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            result.CannotSuspend = true;

            Script script = result.Get<Script>();

            Property<bool> executeOnLoad = result.GetProperty<bool>("ExecuteOnLoad");
            if (executeOnLoad && !main.EditorEnabled)
            {
                result.Add("Executor", new PostInitialization
                {
                    delegate()
                    {
                        if (executeOnLoad)
                            script.Execute.Execute();
                    }
                });
            }

            Property<bool> deleteOnExecute = result.GetOrMakeProperty<bool>("DeleteOnExecute", true, false);
            if (deleteOnExecute)
                result.Add(new CommandBinding(script.Execute, result.Delete));

            this.SetMain(result, main);
        }
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            this.SetMain(result, main);

            Transform transform = result.Get<Transform>();
            Sound sound = result.Get<Sound>("Sound");

            sound.Add(new Binding<Vector3>(sound.Position, transform.Position));

            result.CannotSuspendByDistance = !sound.Is3D;
            result.Add(new NotifyBinding(delegate()
            {
                result.CannotSuspendByDistance = !sound.Is3D;
            }, sound.Is3D));

            Property<float> min = result.GetProperty<float>("MinimumInterval");
            Property<float> max = result.GetProperty<float>("MaximumInterval");

            Random random = new Random();
            float interval = min + ((float)random.NextDouble() * (max - min));
            result.Add(new Updater
            {
                delegate(float dt)
                {
                    if (!sound.IsPlaying)
                        interval -= dt;
                    if (interval <= 0)
                    {
                        sound.Play.Execute();
                        interval = min + ((float)random.NextDouble() * (max - min));
                    }
                }
            });
        }
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            this.SetMain(result, main);
            result.CannotSuspendByDistance = true;

            Transform transform = result.Get<Transform>();

            ModelAlpha model = new ModelAlpha();
            model.Color.Value = new Vector3(1.2f, 1.0f, 0.8f);
            model.Editable = false;
            model.Serialize = false;
            model.Filename.Value = "Models\\electricity";
            model.DrawOrder.Value = 11;
            result.Add("Model", model);

            result.GetOrMakeProperty<bool>("IsMapEdge", true, true);

            PhysicsBlock block = result.Get<PhysicsBlock>();
            block.Box.BecomeKinematic();
            this.boundaries.Add(result);
            result.Add(new CommandBinding(result.Delete, delegate() { this.boundaries.Remove(result); }));
            block.Add(new TwoWayBinding<Matrix>(transform.Matrix, block.Transform));
            model.Add(new Binding<Matrix>(model.Transform, transform.Matrix));
            model.Add(new Binding<Vector3>(model.Scale, x => new Vector3(x.X * 0.5f, x.Y * 0.5f, 1.0f), block.Size));

            Property<Vector2> scaleParameter = model.GetVector2Parameter("Scale");
            model.Add(new Binding<Vector2, Vector3>(scaleParameter, x => new Vector2(x.Y, x.X), model.Scale));
            model.Add(new CommandBinding(main.ReloadedContent, delegate()
            {
                scaleParameter.Reset();
            }));
        }
Beispiel #5
0
 public void TestComponentDoubleAddition()
 {
     Entity entity = new Entity();
     entity.Add(new ComponentA());
     entity.Add(new ComponentA());
     Assert.AreEqual(1, entity.ComponentCount);
 }
Beispiel #6
0
		public static void AttachEditorComponents(Entity result, ListProperty<Entity.Handle> target)
		{
			Transform transform = result.Get<Transform>();

			Property<bool> selected = result.GetOrMakeProperty<bool>("EditorSelected");

			Command<Entity> toggleEntityConnected = new Command<Entity>
			{
				Action = delegate(Entity entity)
				{
					if (target.Contains(entity))
						target.Remove(entity);
					else if (entity != result)
						target.Add(entity);
				}
			};
			result.Add("ToggleEntityConnected", toggleEntityConnected);

			LineDrawer connectionLines = new LineDrawer { Serialize = false };
			connectionLines.Add(new Binding<bool>(connectionLines.Enabled, selected));

			Color connectionLineColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
			ListBinding<LineDrawer.Line, Entity.Handle> connectionBinding = new ListBinding<LineDrawer.Line, Entity.Handle>(connectionLines.Lines, target, delegate(Entity.Handle entity)
			{
				return new LineDrawer.Line
				{
					A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
					B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(entity.Target.Get<Transform>().Position, connectionLineColor)
				};
			}, x => x.Target != null && x.Target.Active);
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, selected));
			result.Add(new NotifyBinding(delegate() { connectionBinding.OnChanged(null); }, () => selected, transform.Position));
			connectionLines.Add(connectionBinding);
			result.Add(connectionLines);
		}
Beispiel #7
0
		public static void AttachEditorComponents(Entity entity, string name, Property<Entity.Handle> target)
		{
			entity.Add(name, target);
			if (entity.EditorSelected != null)
			{
				Transform transform = entity.Get<Transform>("Transform");

				LineDrawer connectionLines = new LineDrawer { Serialize = false };
				connectionLines.Add(new Binding<bool>(connectionLines.Enabled, entity.EditorSelected));

				connectionLines.Add(new NotifyBinding(delegate()
				{
					connectionLines.Lines.Clear();
					Entity targetEntity = target.Value.Target;
					if (targetEntity != null)
					{
						Transform targetTransform = targetEntity.Get<Transform>("Transform");
						if (targetTransform != null)
						{
							connectionLines.Lines.Add
							(
								new LineDrawer.Line
								{
									A = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(transform.Position, connectionLineColor),
									B = new Microsoft.Xna.Framework.Graphics.VertexPositionColor(targetTransform.Position, connectionLineColor)
								}
							);
						}
					}
				}, transform.Position, target, entity.EditorSelected));

				entity.Add(connectionLines);
			}
		}
Beispiel #8
0
 public void TestTwoComponentAddition()
 {
     Entity entity = new Entity();
     entity.Add(new ComponentA());
     entity.Add(new ComponentB());
     Assert.AreEqual(2, entity.ComponentCount);
 }
Beispiel #9
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Prop");
            result.Add("Transform", new Transform());
            result.Add("Model", new Model());

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "ParticleEmitter");

            result.Add("Transform", new Transform());
            result.Add("ParticleEmitter", new ParticleEmitter());

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "AmbientSound");

            result.Add("Transform", new Transform());
            result.Add("Sound", new Sound());

            return result;
        }
Beispiel #12
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "MapBoundary");
            result.Add("Transform", new Transform());
            PhysicsBlock block = new PhysicsBlock();
            block.Size.Value = new Vector3(100.0f, 50.0f, 2.0f);
            result.Add("PhysicsBlock", block);

            return result;
        }
Beispiel #13
0
		public static IEnumerable<string> EditorProperties(Entity script)
		{
			script.Add("LastNode", property<string>(script, "LastNode"));
			script.Add("NextNode", property<string>(script, "NextNode"));
			return new string[]
			{
				"LastNode",
				"NextNode",
			};
		}
Beispiel #14
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "PropAlpha");
            result.Add("Transform", new Transform());
            Model model = new ModelAlpha();
            model.DrawOrder.Value = 11;
            result.Add("Model", model);

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "DirectionalLight");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            DirectionalLight directionalLight = new DirectionalLight();
            result.Add("DirectionalLight", directionalLight);

            return result;
        }
Beispiel #16
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Water");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            Water water = new Water();
            result.Add("Water", water);

            return result;
        }
Beispiel #17
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Fog");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            Fog fog = new Fog();
            result.Add("Fog", fog);

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "RandomAmbientSound");

            result.Add("Transform", new Transform());
            result.Add("Sound", new Sound());
            result.Add("MinimumInterval", new Property<float> { Value = 10.0f, Editable = true });
            result.Add("MaximumInterval", new Property<float> { Value = 20.0f, Editable = true });

            return result;
        }
Beispiel #19
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "SpotLight");

            Transform transform = new Transform();
            result.Add("Transform", transform);
            SpotLight spotLight = new SpotLight();
            result.Add("SpotLight", spotLight);

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "AmbientLight");
            result.CannotSuspendByDistance = true;

            result.Add("Transform", new Transform());
            AmbientLight ambientLight = new AmbientLight();
            ambientLight.Color.Value = Vector3.One;
            result.Add("AmbientLight", ambientLight);

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "AnimatedProp");
            result.Add("Transform", new Transform());
            AnimatedModel model = new AnimatedModel();
            result.Add("Model", model);

            result.Add("Animation", new Property<string> { Editable = true });
            result.Add("Loop", new Property<bool> { Editable = true });

            return result;
        }
Beispiel #22
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "PointLight");

            result.Add("Transform", new Transform());
            PointLight pointLight = new PointLight();
            pointLight.Attenuation.Value = 10.0f;
            pointLight.Color.Value = Vector3.One;
            result.Add("PointLight", pointLight);

            return result;
        }
Beispiel #23
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Script");

            result.Add("Transform", new Transform());

            result.Add("Script", new Script());

            result.Add("ExecuteOnLoad", new Property<bool> { Editable = true, Value = true });

            return result;
        }
Beispiel #24
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "PlayerSpawn");

            result.Add("PlayerSpawn", new PlayerSpawn());

            Transform transform = new Transform();
            result.Add("Transform", transform);

            result.Add("Trigger", new PlayerTrigger());

            return result;
        }
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "PlayerTrigger");

            Transform position = new Transform();

            PlayerTrigger trigger = new PlayerTrigger();
            trigger.Radius.Value = 10.0f;
            result.Add("PlayerTrigger", trigger);

            result.Add("Position", position);

            return result;
        }
Beispiel #26
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Skybox");

            Transform transform = new Transform();
            result.Add("Transform", transform);

            Model skybox = new Model();
            skybox.Filename.Value = "Models\\skybox";
            skybox.CullBoundingBox.Value = false;
            result.Add("Skybox", skybox);

            return result;
        }
Beispiel #27
0
		public override Entity Create(Main main, int offsetX, int offsetY, int offsetZ)
		{
			Entity entity = new Entity(main, "StaticSlider");

			// The transform has to come before the map component
			// So that its properties get bound correctly
			entity.Add("MapTransform", new Transform());
			entity.Add("Transform", new Transform());
			
			Voxel map = this.newVoxelComponent(offsetX, offsetY, offsetZ);
			entity.Add("Voxel", map);

			return entity;
		}
 public void AddSetsComponentEntityToMe()
 {
     var e = new Entity();
     var s = new StringComponent("abc");
     e.Add(s);
     Assert.That(s.Entity, Is.EqualTo(e));
 }
Beispiel #29
0
 public void TestComponentRemoval()
 {
     Entity entity = new Entity();
     entity.Add(new ComponentA());
     entity.Remove<ComponentA>();
     Assert.AreEqual(0, entity.ComponentCount);
 }
Beispiel #30
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Cloud");

            Transform transform = new Transform();
            result.Add("Transform", transform);

            ModelAlpha clouds = new ModelAlpha();
            clouds.Filename.Value = "Models\\clouds";
            clouds.CullBoundingBox.Value = false;
            clouds.DisableCulling.Value = true;
            clouds.DrawOrder.Value = -9;
            result.Add("Clouds", clouds);

            return result;
        }