Ejemplo n.º 1
0
        protected void HandleConstructionFinished(ConstructionFinished message)
        {
            Entity entity = System.EntityManager.SingleOrDefault(e => e.Id == message.EntityId);

            if (entity is null)
            {
                // TODO: Log error/warning.
                Sender.Tell(new CouldNotProcessMessage(message, CouldNotProcessMessage.EntityNotFound));
                return;
            }

            entity.RemoveAll <ConstructionSite>();
            var building = new Components.Building
            {
                Name = message.Building
            };

            entity.Add(building);
            // TODO: Add building specific components.
        }
        public void TestMessagesFromComponent()
        {
            var scene = new Scene();
            ConstructionSystem system = SetupMock(scene);
            var building = new Systems.Construction.Building()
            {
                Name   = "Test",
                Stages =
                {
                    new Systems.Construction.Building.Stage()
                    {
                        NeededResources = new Dictionary <string, int>
                        {
                            { "Wood", 2 }
                        },
                        Steps = 2,
                    },
                }
            };

            system.AddBuilding(building);
            var component = new ConstructionSite()
            {
                Building = "Test",
            };
            var entity = new Entity
            {
                component,
            };

            scene.Entities.Add(entity);

            Assert.NotNull(entity.Get <ConstructionSite>());
            Assert.Null(entity.Get <Components.Building>());
            system.Actor.Tell(new Systems.Construction.Messages.ConstructionFinished(entity.Id, component.Building));
            ExpectNoMsg(500);
            Assert.Null(entity.Get <ConstructionSite>());
            Components.Building entBuilding = entity.Get <Components.Building>();
            Assert.NotNull(building);
            Assert.Equal(component.Building, entBuilding.Name);
        }