Beispiel #1
0
        public void Apply(LevelDescription levelDescription, EntityManager entityManager)
        {
            var slotArchitype = entityManager.CreateArchetype(typeof(SlotPosition), typeof(Slot), typeof(Position));

            for (int x = 0; x < levelDescription.Width; x++)
            {
                for (int y = 0; y < levelDescription.Height; y++)
                {
                    var slot     = entityManager.CreateEntity(slotArchitype);
                    var position = new int2(x, y);
                    entityManager.SetComponentData(slot, new SlotPosition()
                    {
                        Value = position
                    });
                    entityManager.SetComponentData(slot, new Slot());
                    entityManager.SetComponentData(slot, new Position()
                    {
                        Value = FieldUtils.GetPosition(x, y, levelDescription.Width, levelDescription.Height, _centerPosition)
                    });
                    _slotCache[position] = slot;

                    var slotDescription = levelDescription.GetSlotDescription(position);
                    if (slotDescription.Generator)
                    {
                        entityManager.AddComponentData(slot, new Generator());
                    }

                    if (slotDescription.Blocked)
                    {
                        entityManager.AddComponentData(slot, new Blocked());
                    }
                }
            }
        }