Exemplo n.º 1
0
        public void MatchAllTypesIsEmpty()
        {
            var builder = new AspectBuilder()
                          .All();

            Assert.Empty(builder.AllTypes);
            Assert.Empty(builder.OneTypes);
            Assert.Empty(builder.ExclusionTypes);
        }
Exemplo n.º 2
0
        public void MatchOneOfType()
        {
            var builder = new AspectBuilder()
                          .One(typeof(Transform2), typeof(Sprite));

            Assert.Equal(2, builder.OneTypes.Count);
            Assert.Contains(typeof(Transform2), builder.OneTypes);
            Assert.Contains(typeof(Sprite), builder.OneTypes);
        }
Exemplo n.º 3
0
        public void ExcludeTypes()
        {
            var builder = new AspectBuilder()
                          .Exclude(typeof(Transform2), typeof(Sprite));

            Assert.Equal(2, builder.ExclusionTypes.Count);
            Assert.Contains(typeof(Transform2), builder.ExclusionTypes);
            Assert.Contains(typeof(Sprite), builder.ExclusionTypes);
        }
Exemplo n.º 4
0
        public void MatchAllTypes()
        {
            var builder = new AspectBuilder()
                          .All(typeof(Transform2), typeof(Sprite));

            Assert.Equal(2, builder.AllTypes.Count);
            Assert.Contains(typeof(Transform2), builder.AllTypes);
            Assert.Contains(typeof(Sprite), builder.AllTypes);
        }
Exemplo n.º 5
0
        public static AspectBuilder AddInterceptor(this AspectBuilder builder, IInterceptor interceptor)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (interceptor == null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            return(builder.AddAspect(next => interceptor.InvokeAsync));
        }
Exemplo n.º 6
0
        public void BuildAspect()
        {
            var componentManager = new ComponentManager();
            var builder          = new AspectBuilder()
                                   .All(typeof(Transform2), typeof(Sprite))
                                   .One(typeof(string))
                                   .Exclude(typeof(Texture2D));

            var aspect = builder.Build(componentManager);

            Assert.True(aspect.AllSet.Data != 0);
            Assert.True(aspect.OneSet.Data != 0);
            Assert.True(aspect.ExclusionSet.Data != 0);
        }
Exemplo n.º 7
0
        /// LoadContent called once and is the place to load all of your content.
        protected override void LoadContent()
        {
            /// Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            LoadTextures();

            // ***************Default Aspect Builder --Subject to change!--***************
            AspectBuilder defaultAspectBuilder = new AspectBuilder();

            fireGridMaxX  = (int)(screenWidth / fire_1.Width);
            fireGridMaxY  = (int)(screenHeight / fire_1.Height);
            fireGrid      = new int[fireGridMaxX, fireGridMaxY]; // initialize fireGrid to fit the users screen dimensions
            fireGridMaxX -= 1;
            fireGridMaxY -= 1;

            // Load world ***********************************************************************************
            _world = new WorldBuilder()
                     .AddSystem(new Systems.MovementSystem(screenWidth, screenHeight))
                     .AddSystem(new Systems.RenderSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.SpawnSystem())
                     .AddSystem(new Systems.EntityDestructSystem())
                     .AddSystem(new Systems.FireSpawnSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.UpdateFrontEndSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.DamageSystem(5))
                     .AddSystem(new Systems.AnimationSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.FireBurnoutSystem(defaultAspectBuilder))
                     /// Add systems here via ".AddSystem(new [SystemName](Parameters))"

                     .Build();

            //load and build village
            Entity VillageEntity = _world.CreateEntity();

            ECSComponents.PositionComponent    villageposition = new ECSComponents.PositionComponent((float)1 / 2 * screenWidth, (float)1 / 2 * screenHeight, 0);
            ECSComponents.StatusComponent      villagestatus   = new ECSComponents.StatusComponent(false, EntityType.Village);
            ECSComponents.SpriteComponent      villagesprite   = new ECSComponents.SpriteComponent(SpriteDict["village"], 1);
            ECSComponents.CollisionBoxComponet villageHitBox   = new ECSComponents.CollisionBoxComponet(villagesprite.Sprite, villageposition);
            ECSComponents.HealthComponent      villageHealth   = new ECSComponents.HealthComponent(100);

            VillageEntity.Attach(villageposition);
            VillageEntity.Attach(villagestatus);
            VillageEntity.Attach(villagesprite);
            VillageEntity.Attach(villageHitBox);
            VillageEntity.Attach(villageHealth);

            VillageID = VillageEntity.Id;
            // ***********************************************************************************************
        }
        public IAspectBuilder Create(AspectContext context)
        {
            var aspectBuilder = new AspectBuilder(ctx => ctx.Complete(), null);

            foreach (var interceptor in _interceptorCollector.Collect(context.ServiceMethod, context.ImplementationMethod))
            {
                if (interceptor is IScopeInterceptor scopedInterceptor)
                {
                    if (!_aspectContextScheduler.TryRelate(context as ScopeAspectContext, scopedInterceptor))
                    {
                        continue;
                    }
                }
                aspectBuilder.AddAspectDelegate(interceptor.Invoke);
            }

            return(aspectBuilder);
        }
Exemplo n.º 9
0
        private IAspectBuilder Create(Tuple <MethodInfo, MethodInfo> tuple)
        {
            var aspectBuilder = new AspectBuilder(context => context.Complete(), null);

            aspectBuilder.AddAspectDelegate((conext, next) =>
            {
                conext.AdditionalData.Add(AspectClientsExtensions.Context_IsRpcClient, true);
                return(next(conext));
            });
            foreach (var interceptor in interceptorCollector.Collect(tuple.Item1, tuple.Item2))
            {
                aspectBuilder.AddAspectDelegate(interceptor.Invoke);
            }
            var func = clientFactory.GetClientInvoker(tuple.Item1);

            aspectBuilder.AddAspectDelegate(func);
            return(aspectBuilder);
        }
Exemplo n.º 10
0
 public FireSpawnSystem(AspectBuilder aspect) : base(aspect)
 {
     ElapsedTime = 0;
 }
 public AnimationSystem(AspectBuilder aspect) : base(aspect)
 {
 }
Exemplo n.º 12
0
 protected EntityProcessingSystem(AspectBuilder aspectBuilder)
     : base(aspectBuilder)
 {
 }
Exemplo n.º 13
0
 public void SetUp()
 {
     _builder = new AspectBuilder(new AspectElementBuilder(new PointcutBuilder()), new PointcutBuilder());
 }
 public UpdateFrontEndSystem(AspectBuilder aspect) : base(aspect)
 {
 }
Exemplo n.º 15
0
 protected EntitySystem(AspectBuilder aspectBuilder)
 {
     _aspectBuilder = aspectBuilder;
 }
Exemplo n.º 16
0
 protected EntityDrawSystem(AspectBuilder aspect)
     : base(aspect)
 {
 }
Exemplo n.º 17
0
        /// LoadContent called once and is the place to load all of your content.
        protected override void LoadContent()
        {
            /// Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            map       = Content.Load <Texture2D>("map");
            village   = Content.Load <Texture2D>("Village");
            lightning = Content.Load <Texture2D>("lightning");
            meteor    = Content.Load <Texture2D>("meteor");
            fire      = Content.Load <Texture2D>("fire");


            /// Creates the SpriteTextureComponents so they can be attached to entities
            SpriteClass lightningSprite = new SpriteClass(GraphicsDevice, "Assets/Lightning.png", 1); // scale of sprites may be adjusted here
            SpriteClass meteorSprite    = new SpriteClass(GraphicsDevice, "Assets/Meteor.png", 1);    // scale of sprites may be adjusted here
            SpriteClass fireSprite      = new SpriteClass(GraphicsDevice, "Assets/Fire.png", 1);      // scale of sprites may be adjusted here
            SpriteClass villageSprite   = new SpriteClass(GraphicsDevice, "Assets/Village.png", 1);   // scale of sprites may be adjusted here

            SpriteDict.Add("lightning", lightningSprite);
            SpriteDict.Add("meteor", meteorSprite);
            SpriteDict.Add("fire", fireSprite);
            SpriteDict.Add("village", villageSprite);


            // ***************Default Aspect Builder --Subject to change!--***************
            AspectBuilder defaultAspectBuilder = new AspectBuilder();

            fireGridMaxX  = (int)(screenWidth / fire.Width);
            fireGridMaxY  = (int)(screenHeight / fire.Height);
            fireGrid      = new int[fireGridMaxX, fireGridMaxY]; // initialize fireGrid to fit the users screen dimensions
            fireGridMaxX -= 1;
            fireGridMaxY -= 1;

            // Load world ***********************************************************************************
            _world = new WorldBuilder()
                     .AddSystem(new Systems.MovementSystem(screenWidth, screenHeight))
                     .AddSystem(new Systems.RenderSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.SpawnSystem(90))
                     .AddSystem(new Systems.EntityDestructSystem())
                     .AddSystem(new Systems.FireSpawnSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.UpdateFrontEndSystem(defaultAspectBuilder))
                     .AddSystem(new Systems.DamageSystem(5))
                     /// Add systems here via ".AddSystem(new [SystemName](Parameters))"

                     .Build();

            //load and build village
            Entity VillageEntity = _world.CreateEntity();

            ECSComponents.PositionComponent    villageposition = new ECSComponents.PositionComponent((float)1 / 2 * screenWidth, (float)1 / 2 * screenHeight, 0);
            ECSComponents.StatusComponent      villagestatus   = new ECSComponents.StatusComponent(false, EntityType.Village);
            ECSComponents.SpriteComponent      villagesprite   = new ECSComponents.SpriteComponent(SpriteDict["village"], 1);
            ECSComponents.CollisionBoxComponet villageHitBox   = new ECSComponents.CollisionBoxComponet(villagesprite.Sprite, villageposition);
            ECSComponents.HealthComponent      villageHealth   = new ECSComponents.HealthComponent(100);

            VillageEntity.Attach(villageposition);
            VillageEntity.Attach(villagestatus);
            VillageEntity.Attach(villagesprite);
            VillageEntity.Attach(villageHitBox);
            VillageEntity.Attach(villageHealth);

            VillageID = VillageEntity.Id;
            // ***********************************************************************************************
        }
Exemplo n.º 18
0
 protected EntityUpdateSystem(AspectBuilder aspectBuilder)
     : base(aspectBuilder)
 {
 }
 public RenderSystem(AspectBuilder aspect) : base(aspect)       // EntityDrawSystem inherits from EntitySystem which takes an AspectBuilder upon construction
 {
 }
 // This system updates elapsed fire burn frames and destroys fires that have reached the burn interval
 public FireBurnoutSystem(AspectBuilder aspect) : base(aspect)
 {
 }