예제 #1
0
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap, InstantiationRestrictions restrictions = null)
        {
            if (layeredTileMap != null)
            {
                var entitiesToRemove = new List <string>();

                foreach (var layer in layeredTileMap.MapLayers)
                {
                    CreateEntitiesFrom(entitiesToRemove, layer, layeredTileMap.TileProperties, layeredTileMap.WidthPerTile ?? 16, restrictions);
                }
                if (CurrentSettings.RemoveTileObjectsAfterEntityCreation)
                {
                    foreach (var entityToRemove in entitiesToRemove)
                    {
                        string remove = entityToRemove;
                        layeredTileMap.RemoveTiles(t => t.Any(item => (item.Name == "EntityToCreate" || item.Name == "Type") && item.Value as string == remove), layeredTileMap.TileProperties);
                    }
                }

                foreach (var shapeCollection in layeredTileMap.ShapeCollections)
                {
                    CreateEntitiesFromCircles(layeredTileMap, shapeCollection, restrictions);

                    CreateEntitiesFromRectangles(layeredTileMap, shapeCollection, restrictions);

                    CreateEntitiesFromPolygons(layeredTileMap, shapeCollection, restrictions);
                }
            }
        }
예제 #2
0
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap, IEnumerable <TileMapInfo> tileMapInfos)
        {
            // prob need to clear out the tileShapeCollection
            var entitiesToRemove = new List <string>();

            foreach (var layer in layeredTileMap.MapLayers)
            {
                CreateEntitiesFrom(entitiesToRemove, layer, tileMapInfos);
            }
            foreach (var entityToRemove in entitiesToRemove)
            {
                string remove = entityToRemove;
                layeredTileMap.RemoveTiles(t => t.EntityToCreate == remove, tileMapInfos);
            }
        }
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap, IEnumerable<TileMapInfo> tileMapInfos)
        {
            // prob need to clear out the tileShapeCollection
            var entitiesToRemove = new List<string>();

            foreach (var layer in layeredTileMap.MapLayers)
            {

                CreateEntitiesFrom(entitiesToRemove, layer, tileMapInfos);
            }
            foreach (var entityToRemove in entitiesToRemove)
            {
                string remove = entityToRemove;
                layeredTileMap.RemoveTiles(t => t.EntityToCreate == remove, tileMapInfos);
            }
        }
예제 #4
0
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap)
        {
            var entitiesToRemove = new List<string>();

            foreach (var layer in layeredTileMap.MapLayers)
            {
                CreateEntitiesFrom(entitiesToRemove, layer, layeredTileMap.TileProperties);
            }
            foreach (var entityToRemove in entitiesToRemove)
            {
                string remove = entityToRemove;
                layeredTileMap.RemoveTiles(t => t.Any(item => (item.Name == "EntityToCreate" || item.Name == "Type") && item.Value as string == remove), layeredTileMap.TileProperties);
            }
            foreach (var shapeCollection in layeredTileMap.ShapeCollections)
            {
                var polygons = shapeCollection.Polygons;
                for (int i = polygons.Count - 1; i > -1; i--)
                {
                    var polygon = polygons[i];
                    if (!string.IsNullOrEmpty(polygon.Name) && layeredTileMap.ShapeProperties.ContainsKey(polygon.Name))
                    {
                        var properties = layeredTileMap.ShapeProperties[polygon.Name];
                        var entityAddingProperty = properties.FirstOrDefault(item => item.Name == "EntityToCreate");

                        var entityType = entityAddingProperty.Value as string;
                        if (!string.IsNullOrEmpty(entityType))
                        {
                            IEntityFactory factory = GetFactory(entityType);

                            var entity = factory.CreateNew(null) as PositionedObject;

                            entity.Name = polygon.Name;
                            ApplyPropertiesTo(entity, properties, polygon.Position);
                            shapeCollection.Polygons.Remove(polygon);

                            if (entity is Math.Geometry.ICollidable)
                            {
                                var entityCollision = (entity as Math.Geometry.ICollidable).Collision;
                                entityCollision.Polygons.Add(polygon);
                                polygon.AttachTo(entity, false);
                            }

                        }
                    }
                }
            }
        }
예제 #5
0
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap)
        {
            var entitiesToRemove = new List <string>();

            foreach (var layer in layeredTileMap.MapLayers)
            {
                CreateEntitiesFrom(entitiesToRemove, layer, layeredTileMap.TileProperties);
            }
            foreach (var entityToRemove in entitiesToRemove)
            {
                string remove = entityToRemove;
                layeredTileMap.RemoveTiles(t => t.Any(item => (item.Name == "EntityToCreate" || item.Name == "Type") && item.Value as string == remove), layeredTileMap.TileProperties);
            }
            foreach (var shapeCollection in layeredTileMap.ShapeCollections)
            {
                CreateEntitiesFromCircles(layeredTileMap, shapeCollection);

                CreateEntitiesFromRectangles(layeredTileMap, shapeCollection);

                CreateEntitiesFromPolygons(layeredTileMap, shapeCollection);
            }
        }
        public static void CreateEntitiesFrom(LayeredTileMap layeredTileMap, Dictionary <string, TileMapInfo> tileMapInfos)
        {
            // prob need to clear out the tileShapeCollection
            var   entitiesToRemove = new List <string>();
            float dimension        = float.NaN;
            float dimensionHalf    = 0;

            foreach (var layer in layeredTileMap.MapLayers)
            {
                var dictionary = layer.NamedTileOrderedIndexes;
                foreach (var info in tileMapInfos)
                {
                    if (!string.IsNullOrEmpty(info.Value.EntityToCreate) && dictionary.ContainsKey(info.Key))
                    {
                        var factories = Assembly.GetExecutingAssembly()
                                        .GetTypes()
                                        .Where(t => t.GetInterfaces().Contains(typeof(IEntityFactory)) &&
                                               t.GetConstructor(Type.EmptyTypes) != null)
                                        .Select(
                            t =>
                        {
                            var propertyInfo = t.GetProperty("Self");
                            var value        = propertyInfo.GetValue(null, null);
                            return(value as IEntityFactory);
                        }).ToList();

                        foreach (var factory in factories)
                        {
                            var type             = factory.GetType();
                            var methodInfo       = type.GetMethod("CreateNew", new[] { typeof(Layer) });
                            var returntypeString = methodInfo.ReturnType.Name;

                            if (info.Value.EntityToCreate.EndsWith(returntypeString))
                            {
                                entitiesToRemove.Add(info.Value.EntityToCreate);
                                var indexList = dictionary[info.Key];

                                foreach (var index in indexList)
                                {
                                    float left;
                                    float bottom;
                                    layer.GetBottomLeftWorldCoordinateForOrderedTile(index, out left, out bottom);

                                    if (float.IsNaN(dimension))
                                    {
                                        dimension     = layer.Vertices[index + 1].Position.X - left;
                                        dimensionHalf = dimension / 2.0f;
                                    }

                                    var entity = factory.CreateNew() as PositionedObject;


                                    if (entity != null)
                                    {
                                        entity.X = left + dimensionHalf;
                                        entity.Y = bottom + dimensionHalf;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            foreach (var entityToRemove in entitiesToRemove)
            {
                string remove = entityToRemove;
                layeredTileMap.RemoveTiles(t => t.EntityToCreate == remove, tileMapInfos.Values);
            }
        }