예제 #1
0
        public void EntityQuery()
        {
            // No system Add's
            var systems = new Systems(Helpers.NewWorld());

            systems.Create();

            var querySingleInclude =
                systems.World
                .GetEntityQuery <EntityQuery <SampleStructs.Foo> >();

            int listenerCount = 0;

            querySingleInclude.AddEntityAddedListener((in Entity entity) => listenerCount++);
            querySingleInclude.AddEntityRemovedListener((in Entity entity) => listenerCount--);

            // Create test entities
            var entity1 = systems.World.NewEntity();
            var entity2 = systems.World.NewEntity();

            Assert.Equal(0, querySingleInclude.GetEntityCount());
            Assert.Equal(querySingleInclude.GetEntityCount(), listenerCount);

            // Add inclusion #1
            entity1.GetComponent <SampleStructs.Foo>();

            Assert.Equal(1, querySingleInclude.GetEntityCount());
            Assert.Equal(querySingleInclude.GetEntityCount(), listenerCount);

            // Add inclusion #2
            entity2.GetComponent <SampleStructs.Foo>();

            Assert.Equal(2, querySingleInclude.GetEntityCount());
            Assert.Equal(querySingleInclude.GetEntityCount(), listenerCount);

            // Remove inclusion #1
            entity1.RemoveComponent <SampleStructs.Foo>();

            Assert.Equal(1, querySingleInclude.GetEntityCount());
            Assert.Equal(querySingleInclude.GetEntityCount(), listenerCount);

            // Remove inclusion #2 - should place entity in query results.
            entity2.RemoveComponent <SampleStructs.Foo>();

            Assert.Equal(0, querySingleInclude.GetEntityCount());
            Assert.Equal(querySingleInclude.GetEntityCount(), listenerCount);
        }
예제 #2
0
        public async Task New([Remainder] string systemName = null)
        {
            if (ContextEntity != null)
            {
                throw Errors.NotOwnSystemError;
            }
            if (Context.SenderSystem != null)
            {
                throw Errors.ExistingSystemError;
            }

            var system = await Systems.Create(systemName);

            await Systems.Link(system, Context.User.Id);

            await Context.Channel.SendMessageAsync($"{Emojis.Success} Your system has been created. Type `pk;system` to view it, and type `pk;help` for more information about commands you can use now.");
        }
예제 #3
0
        public void DependencyInjection()
        {
            HashSet <int> set = new HashSet <int>();

            var world   = Helpers.NewWorld();
            var systems =
                new Systems(world)
                .Add(new SystemDependencyInjection())
                .Inject(new SystemDependencyInjection.FooClass(set));

            systems.Create();

            Assert.DoesNotContain(2, set);

            systems.Run(1);

            Assert.Contains(2, set);
        }
예제 #4
0
        public void TwoSystemsOneWorld()
        {
            var systemFoo = new SystemFoo();

            var world    = Helpers.NewWorld();
            var systems1 =
                new Systems(world)
                .Add(systemFoo);

            systems1.Create();

            var query = world.GetEntityQuery <EntityQuery <SampleStructs.Foo> >();

            var systems2 =
                new Systems(world)
                .Add(systemFoo);

            systems2.Create();

            var     entity = world.NewEntity();
            ref var comp   = ref entity.GetComponent <SampleStructs.Foo>();
예제 #5
0
        public void EntityQueryMultiType()
        {
            // No system Add's
            var systems =
                new Systems(Helpers.NewWorld());

            systems.Create();

            var query =
                systems.World
                .GetEntityQuery <EntityQuery <SampleStructs.Foo, SampleStructs.Bar> >();

            var entity3 = systems.World.NewEntity();

            entity3.GetComponent <SampleStructs.Foo>();

            Assert.Equal(0, query.GetEntityCount());

            entity3.GetComponent <SampleStructs.Bar>();

            Assert.Equal(1, query.GetEntityCount());
        }
예제 #6
0
        public void EntityQuery_IncludeExclude()
        {
            var systems = new Systems(Helpers.NewWorld());

            systems
            // No system Add's
            .Create();

            var queryWithExclude =
                systems.World
                .GetEntityQuery <EntityQuery <SampleStructs.Foo> .Exclude <SampleStructs.Bar, SampleStructs.Baz> >();

            // Create 2 entities, one with exclusions
            var entity1 = systems.World.NewEntity();

            entity1.GetComponent <SampleStructs.Foo>();
            var entity2 = systems.World.NewEntity();

            // Include
            entity2.GetComponent <SampleStructs.Foo>();
            // Exclude #1
            entity2.GetComponent <SampleStructs.Bar>();
            // Exclude #2
            entity2.GetComponent <SampleStructs.Baz>();

            Assert.Equal(1, queryWithExclude.GetEntityCount());

            // Remove exclusion #1
            entity2.RemoveComponent <SampleStructs.Bar>();

            Assert.Equal(1, queryWithExclude.GetEntityCount());

            // Remove exclusion #2 - should place entity in query results.
            entity2.RemoveComponent <SampleStructs.Baz>();

            Assert.Equal(2, queryWithExclude.GetEntityCount());
        }
예제 #7
0
 public void Create()
 {
     _update.Create();
     _fixedUpdate.Create();
 }