Exemplo n.º 1
0
 public RiverMaker(IBrickRepo brick_repo, IBrickRiverPartSelector part_selector)
 {
     _brick_repo    = brick_repo;
     _part_selector = part_selector;
     _water_config  = MapConfig.GetSquareConfigurations().First(x => x.Type == SquareTypes.Water);
     _sea_type      = SquareTypes.Sea;
 }
Exemplo n.º 2
0
        public static void CreatePreviewImage(int squaresX, int squaresZ, List <MapSquare> map_squares)
        {
            var output_bmp = new Bitmap(squaresX, squaresZ);
            var sc         = MapConfig.GetSquareConfigurations();

            Color color_to_use;

            foreach (var square in map_squares)
            {
                color_to_use = sc.First(x => x.Type == square.Type).OutputColor;

                output_bmp.SetPixel(square.PositionX, square.PositionZ, color_to_use);
            }

            output_bmp.Save("result.png", System.Drawing.Imaging.ImageFormat.Png);
        }
Exemplo n.º 3
0
        private static List <MapSquare> ParseInputImage(int square_size, Bitmap bitmap)
        {
            var squaresX = bitmap.Width / square_size;
            var squaresZ = bitmap.Height / square_size;

            var   configs = MapConfig.GetSquareConfigurations();
            Color pixel;

            var result = new List <MapSquare>();

            for (var sz = 0; sz < squaresZ; sz++)
            {
                for (var sx = 0; sx < squaresX; sx++)
                {
                    for (var py = 0; py < square_size; py++)
                    {
                        for (var px = 0; px < square_size; px++)
                        {
                            pixel = bitmap.GetPixel((sx * square_size) + px, (sz * square_size) + py);

                            var square_config = configs.FirstOrDefault(x => x.InputColor == pixel);

                            if (square_config == null)
                            {
                                continue;
                            }

                            square_config.Count++;
                        }
                    }

                    var map_square = new MapSquare()
                    {
                        Type      = MapConfig.CalculateSquareType(configs),
                        PositionX = sx, PositionZ = sz
                    };

                    MapConfig.ResetCount();

                    result.Add(map_square);
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        public List <Brick> ParseList(int squaresX, int squaresZ,
                                      int sub_part_max_x, int sub_part_max_z,
                                      List <MapSquare> map_squares)
        {
            var rm = new RiverMaker(_brick_repo, new BrickRiverPartSelector());

            var result = new List <Brick>();

            var big_map = CreateMapFromInput(squaresX, squaresZ, map_squares);

            // ToDo Fix coasts.

            var group_counter = 0;

            CoastFixer.Go(big_map);

            rm.CreateBrickRivers(big_map, group_counter, result);

            //var maps = CreateMapsFromInput(squaresX, squaresZ, sub_part_max_x, sub_part_max_z, map_squares);
            var maps = SplitMap(big_map, sub_part_max_x, sub_part_max_z);

            var ref_counter = result.Count;

            group_counter++;


            var square_configs = MapConfig.GetSquareConfigurations();

            foreach (var map in maps)
            {
                foreach (SquareTypes current_type in (SquareTypes[])Enum.GetValues(typeof(SquareTypes)))
                {
                    if (current_type == SquareTypes.Ignore)
                    {
                        continue;
                    }

                    var material_id = square_configs.First(x => x.Type == current_type).MaterialId;

                    var brick_designs = _brick_repo.GetBrickSizesForMaterialId(material_id);

                    foreach (var brick_design in brick_designs)
                    {
                        for (int z = 0; z < map.GetLength(1); z++)
                        {
                            for (int x = 0; x < map.GetLength(0); x++)
                            {
                                var map_square = map[x, z];

                                if (map_square.Type == SquareTypes.Ignore)
                                {
                                    continue;
                                }

                                if (map_square.Type != current_type)
                                {
                                    continue;
                                }

                                if (_brick_repo.IfBrickMaxUsageHasBeenReached(material_id, brick_design.DesignID))
                                {
                                    continue;
                                }

                                if (DoesBrickFitOnMap(current_type, map, x, z, brick_design.SizeX, brick_design.SizeZ))
                                {
                                    var new_brick = _brick_repo.GetBrick(brick_design, material_id, ref_counter, map_square.PositionX, map_square.PositionZ);
                                    new_brick.GroupId = group_counter;
                                    ref_counter++;

                                    result.Add(new_brick);

                                    ClearAreaOfMap(map, x, z, brick_design.SizeX, brick_design.SizeZ);
                                }
                            }
                        }
                    }
                }
                group_counter++;
            }

            return(result);
        }