Esempio n. 1
0
        public void LoadTileset(string path, bool horizontalMirror = true, string debugFilePath = null, bool hasSpacing = false)
        {
            //Chop up tileset
            Bitmap tilesetImg = Image.FromFile(path) as Bitmap;

            if (horizontalMirror)
            {
                tilesetImg = tilesetImg.AddHorizontalMirror(hasSpacing);
            }
            _tileset = BitmapOperations.GetBitmapTiles(tilesetImg, _tileWidth, _tileHeight, hasSpacing);

            if (debugFilePath != null)
            {
                Bitmap quickcheck = BitmapOperations.CreateBitmapFromTiles(_tileset, true);
                BitmapOperations.SaveBitmapToFile(debugFilePath, quickcheck);
            }


            //setup wfcTiles (and neighbors)
            var distinctTiles = GetDistinctBitmaps(_tileset);

            //why does this mess things up
            //distinctTiles.AddRange(GetWeightedTiles(_tileWidth, _tileHeight, hasSpacing));

            //List<List<Bitmap>> distinctElements = new List<List<Bitmap>>();
            //distinctElements.Add(distinctTiles);

            _wfcTiles = ToOpinionatedList(distinctTiles);
            SetAcceptableItems(_wfcTiles, _tileset);
        }
Esempio n. 2
0
 public void SaveResult(string folderpath)
 {
     BitmapOperations.SaveBitmapToFile(
         folderpath + "Seed" + LastSeed.ToString() + "Effective" + LastEffectiveSeed.ToString() + ".bmp"
         , LastResult.TileMap
         );
 }
Esempio n. 3
0
        public bool OutputWfc(string outPath)
        {
            var collapsedTiles = ToTilesList(_grid);

            Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles);

            BitmapOperations.SaveBitmapToFile(outPath, tilesetRedux);

            return(true);
        }
Esempio n. 4
0
        private List <Bitmap> ChopUpTilesWithMirror(Bitmap img)
        {
            List <Bitmap> result   = new List <Bitmap>();
            var           tilesImg = img.AddHorizontalMirror(true);
            var           tiles    = BitmapOperations.GetBitmapTiles(tilesImg, 6, 6, true);
            //bad form
            var path = TilesetDebugFolderPath;

            if (path != null)
            {
                BitmapOperations.SaveBitmapToFile(path + /*"../../TilesetsDebug/Current/" +*/ "mainTilesetDebug" + ".bmp", BitmapOperations.CreateBitmapFromTiles(tiles, true));
            }
            foreach (var row in tiles)
            {
                result.AddRange(row);
            }
            return(result);
        }
Esempio n. 5
0
        private static void printLists(List <List <OpinionatedItem <Bitmap> > > ElementsList, string debugFolderPath)
        {
            List <Bitmap> Bitmaps = new List <Bitmap>();
            var           path    = debugFolderPath;

            foreach (var Elements in ElementsList)
            {
                var list = new List <List <Bitmap> >();
                list.Add(new List <Bitmap>());
                list[0].AddRange(Elements.Select(x => x.actualItem).ToList());
                var bmp = BitmapOperations.CreateBitmapFromTiles(list);
                Bitmaps.Add(bmp);
            }

            for (var i = 0; i < Bitmaps.Count; i++)
            {
                BitmapOperations.SaveBitmapToFile(path + "/" + /*"../../TilesetsDebug/Current/" +*/ i.ToString() + ".bmp", Bitmaps[i]);
            }
        }
Esempio n. 6
0
 private void GetTypeGrid()
 {
     for (var x = 0; x < TileGrid.Count; x++)
     {
         for (var y = 0; y < TileGrid[x].Count; y++)
         {
             var tileType = GetTileType(TileGrid[x][y]);
             try
             {
                 TypeGrid[x, y] = tileType.Value;
             }
             catch (Exception ex)
             {
                 if (Config.DebugTypeGridFolder != null)
                 {
                     Console.WriteLine("Could Not Determine tile type.  Logged to file system.");
                     BitmapOperations.SaveBitmapToFile(Config.DebugTypeGridFolder + "//unknownTile-" + x.ToString() + "-" + y.ToString() + ".bmp", TileGrid[x][y]);
                 }
             }
         }
     }
 }
Esempio n. 7
0
        public static void DebugWfcPrint(List <OpinionatedItem <Bitmap> > Attempted, WcfGrid WcfGrid, int x, int y, string folderPath)
        {
            if (folderPath == null)
            {
                return;
            }


            Console.WriteLine("Collapse To Specific Item failed.");
            List <Bitmap> topBmps    = new List <Bitmap>();
            List <Bitmap> bottomBmps = new List <Bitmap>();
            List <Bitmap> leftBmps   = new List <Bitmap>();
            List <Bitmap> rightBmps  = new List <Bitmap>();

            if (y - 1 >= 0)
            {
                topBmps = WcfGrid.SuperPositions[x, y - 1, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (y + 1 < WcfGrid.Height)
            {
                bottomBmps = WcfGrid.SuperPositions[x, y + 1, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (x - 1 >= 0)
            {
                leftBmps = WcfGrid.SuperPositions[x - 1, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (x + 1 < WcfGrid.Width)
            {
                rightBmps = WcfGrid.SuperPositions[x + 1, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }

            List <Bitmap> currentBmps  = Attempted.Select(s => (Bitmap)s.GetItem()).ToList();
            List <Bitmap> existingBmps = WcfGrid.SuperPositions[x, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            //string folderPath = ConfigurationManager.AppSettings["WfcDebugFolder"].ToString();//../../WfcDebug/Current/";
            var subPath  = "Top/";
            var FileInfo = new FileInfo(folderPath + subPath);

            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < topBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, topBmps[i]);
            }
            subPath  = "Bottom/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < bottomBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, bottomBmps[i]);
            }
            subPath  = "Left/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < leftBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, leftBmps[i]);
            }
            subPath  = "Right/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < rightBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, rightBmps[i]);
            }
            subPath  = "CurrentOptions/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < currentBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, currentBmps[i]);
            }

            subPath  = "Existing/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < existingBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, existingBmps[i]);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            //setup hierarchical map
            var Random = new Random(0);

            HierarchicalMap.RelativeScales = new double[] { 4 };
            var map = new HierarchicalMap(12, 12, Random, 4, 3);

            map.DefaultSetup();
            //map.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"]);
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
            var mastermap     = map.GetMasterMap();
            var masterPortals = map.GetMasterPortal();


            map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main_map.bmp"));
            map.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main__map.bmp"));

            var tileSize = 5;

            var editor = new LevelEditor(tileSize, tileSize, 12, 12, ConfigurationManager.AppSettings["errorTile"], ConfigurationManager.AppSettings["cautionTile"]);

            editor.LoadTileset(ConfigurationManager.AppSettings["TilesetInput"], true, "..//..//Output//mainTileset.bmp", true);
            editor.SetupBorderTiles(ConfigurationManager.AppSettings["borderInput"]);
            editor.SetupHEntranceTiles(ConfigurationManager.AppSettings["hEntranceInput"]);
            editor.SetupVEntranceTiles(ConfigurationManager.AppSettings["vEntranceInput"]);
            editor.SetupCornersAndIntersectionTiles(ConfigurationManager.AppSettings["cornerTraverseInput"], true);
            editor.SetupTraversableTiles(
                ConfigurationManager.AppSettings["hTraverseInput"],
                ConfigurationManager.AppSettings["vTraverseInput"],
                true
                );


            //must be divisible by 3 for paths?!
            var scale = 12;

            var finalBitmap = new Bitmap(mastermap.GetLength(0) * scale * tileSize, mastermap.GetLength(1) * scale * tileSize);

            int bmpIndex = 0;

            for (var y = 0; y < mastermap.GetLength(1); y++)
            {
                for (var x = 0; x < mastermap.GetLength(0); x++)
                {
                    var roomLevelMap = mastermap[x, y].FirstOrDefault(mm => mm.flatZones.Count == 0 && mm.contents == null);
                    if (roomLevelMap != null)
                    {
                        bmpIndex += 1;
                        for (var attempt = 0; attempt < 8; attempt++)
                        {
                            var room = roomLevelMap.ToRoom(scale);

                            editor.SetDimensions(room.Width, room.Height);
                            editor.InitWcfGrid(Random.Next());

                            var result = true;
                            result = result && editor.AddBorder(room);
                            if (!result)
                            {
                                Console.WriteLine("Failed Add Border");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            result = result && editor.AddPaths(room);
                            if (!result)
                            {
                                Console.WriteLine("Failed Add Paths");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            if (Random.NextDouble() < .25)
                            {
                                result = result && editor.MakeSpacesIntraversable();
                                if (!result)
                                {
                                    Console.WriteLine("Failed Intraversable");
                                    //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                    Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                    continue;
                                }
                            }

                            result = result && editor.CollapseWcf();
                            if (!result)
                            {
                                Console.WriteLine("Failed Collapse");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            //if we made it here, we have succeeded
                            break;
                        }

                        roomLevelMap.contents = editor.GetBitmap();

                        //draw to larger bitmap
                        Graphics g = Graphics.FromImage(finalBitmap);
                        g.DrawImage(roomLevelMap.contents, new Point(x * scale * tileSize, y * scale * tileSize));

                        //draw portals
                        var portals = roomLevelMap._Portals;//.Where(p=>/*p.DestinationPortal!= null &&*/ p.id.CompareTo(((HierarchicalMapPortal)p.DestinationPortal).id) == -1).ToList();
                        foreach (var portal in portals)
                        {
                            if (portal.direction == new Point())
                            {
                                var breaka = "here";
                            }
                            var startPos = new Point(
                                (x * scale * tileSize) + (portal.portalOffsetFromRoom.X * tileSize),
                                (y * scale * tileSize) + (portal.portalOffsetFromRoom.Y * tileSize)
                                );
                            var endPos = new Point(
                                startPos.X + portal.direction.X * tileSize / 2,
                                startPos.Y + portal.direction.Y * tileSize / 2
                                );
                            var xDir    = Math.Sign(endPos.X - startPos.X);
                            var yDir    = Math.Sign(endPos.Y - startPos.Y);
                            var drawPos = startPos;
                            if (drawPos == endPos)
                            {
                                var breka = "here";
                            }
                            while (true)
                            {
                                var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
                                color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);

                                if (portal.directionOfPassage == ZonePortalDirection.In)
                                {
                                    color = Color.Red;
                                }
                                else if (portal.directionOfPassage == ZonePortalDirection.Out)
                                {
                                    color = Color.Green;
                                }

                                finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

                                if (drawPos == endPos)
                                {
                                    break;
                                }



                                //getNewPos
                                drawPos.X += xDir;
                                drawPos.Y += yDir;
                            }
                        }

                        //BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "_wcf_" + bmpIndex.ToString() + ".bmp"), roomLevelMap.contents);
                    }
                }
            }

            //draw portals
            //for (var y = 0; y < masterPortals.GetLength(1); y++)
            //{
            //    for (var x = 0; x < masterPortals.GetLength(0); x++)
            //    {
            //        var portals = masterPortals[x, y].Where(p => p.SubPortal == null && p.DestinationPortal != null && ((HierarchicalMapPortal)p.DestinationPortal).id.CompareTo(p.id) == -1);
            //        foreach(var portal in portals)
            //        {
            //            var startPos = new Point(
            //                    (x * scale * tileSize) + (tileSize*2),
            //                    (y * scale * tileSize) + (tileSize*2)
            //                );
            //            var endPos = new Point(
            //                    startPos.X + portal.direction.X * tileSize,
            //                    startPos.Y + portal.direction.Y * tileSize
            //                );
            //            var xDir = Math.Sign(endPos.X - startPos.X);
            //            var yDir = Math.Sign(endPos.Y - startPos.Y);
            //            var drawPos = startPos;
            //            while (true)
            //            {
            //                var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
            //                color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);
            //                finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

            //                if (drawPos == endPos)
            //                    break;

            //                //getNewPos
            //                drawPos.X += xDir;
            //                drawPos.Y += yDir;
            //            }
            //        }
            //    }
            //}

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["BitmapOutput"], finalBitmap);


            //map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main_map.bmp"));
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            //setup hierarchical map
            var seed = 3;

            var Random = new marcRandom(seed);

            HierarchicalMap.RelativeScales = new double[] { 4 };
            var map = new HierarchicalMap(16, 16, Random, 4, 3);

            map.DefaultSetup();

            //map.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"]);
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
            var mastermap     = map.GetMasterMap();
            var terminalmap   = map.GetMapTerminals();
            var masterPortals = map.GetMasterPortal();
            var thevar        = terminalmap.Select(tm => new { absX = tm._AbsX, absY = tm._AbsY }).ToList();

            map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["Output"].Replace(".bmp", "main_map.bmp"));
            map.PrintMasterToBitmap(ConfigurationManager.AppSettings["Output"].Replace(".bmp", "main__map.bmp"));

            var tileSize = 6;



            //must be divisible by 3 for paths?!
            var scale = 3;

            var finalBitmap = new Bitmap(mastermap.GetLength(0) * scale * tileSize, mastermap.GetLength(1) * scale * tileSize);


            ProcessFactory <AdvancedCircuitProcess.PuzzleProcess> factory = null;
            int        roomSeed = seed;
            PuzzleInfo roomResult;

            foreach (var roomLevelMap in terminalmap.OrderBy(x => x.SequentialId))
            {
                /*for (var y = 0; y < mastermap.GetLength(1); y++)
                 * {
                 *  for (var x = 0; x < mastermap.GetLength(0); x++)
                 *  {*/
                roomSeed = Random.Next();
                //var roomLevelMap = mastermap[x, y].FirstOrDefault(mm => mm.flatZones.Count == 0 && mm.contents == null);
                if (roomLevelMap != null)
                {
                    var room = roomLevelMap.ToRoom(scale);

                    if (factory == null)
                    {
                        factory = new ProcessFactory <AdvancedCircuitProcess.PuzzleProcess>(room.Width, room.Height, "..//..//WfcDebug//Current//", "..//..//TilesetsDebug//Current//");
                    }
                    else
                    {
                        factory.Reset(room.Width, room.Height);
                    }

                    int?KeyId = null;
                    if (roomLevelMap.IsItemRoom)
                    {
                        KeyId = roomLevelMap.RelationsAsItemRoom.First().LockInfo.LockId;
                    }
                    try
                    {
                        roomResult = factory.GetPuzzle(
                            roomSeed,
                            room.portals,
                            KeyId,
                            roomLevelMap.IsSkippable
                            );

                        var conFactory = new Construction.Factory("..//..//DebugGetTypeGrid//", 6, 6);
                        var result     = conFactory.GetGameElements(roomResult.TileMap, roomResult.Grid);
                    }
                    catch (Exception ex)
                    {
                        //do this so we don't end up trying again....
                        roomLevelMap.contents = new Bitmap(roomLevelMap._MapWidth * scale * tileSize, roomLevelMap._MapHeight * scale * tileSize);
                        continue;
                    }
                    if (roomResult.Success)
                    {
                        roomLevelMap.contents = roomResult.TileMap;
                    }
                    //factory.SaveResult(
                    //    ConfigurationManager.AppSettings["Output"].ToString()
                    //            .Replace("output.bmp", "")
                    //);


                    //draw to larger bitmap
                    Graphics g = Graphics.FromImage(finalBitmap);
                    var      x = roomLevelMap._AbsX;
                    var      y = roomLevelMap._AbsY;
                    g.DrawImage(roomLevelMap.contents, new Point(x * scale * tileSize, y * scale * tileSize));

                    //draw portals
                    var portals = roomLevelMap._Portals;    //.Where(p=>/*p.DestinationPortal!= null &&*/ p.id.CompareTo(((HierarchicalMapPortal)p.DestinationPortal).id) == -1).ToList();
                    foreach (var portal in portals)
                    {
                        if (portal.direction == new Point())
                        {
                            var breaka = "here";
                        }
                        var startPos = new Point(
                            (x * scale * tileSize) + (portal.portalOffsetFromRoom.X * tileSize),
                            (y * scale * tileSize) + (portal.portalOffsetFromRoom.Y * tileSize)
                            );
                        var endPos = new Point(
                            startPos.X + portal.direction.X * tileSize / 2,
                            startPos.Y + portal.direction.Y * tileSize / 2
                            );
                        var xDir    = Math.Sign(endPos.X - startPos.X);
                        var yDir    = Math.Sign(endPos.Y - startPos.Y);
                        var drawPos = startPos;
                        if (drawPos == endPos)
                        {
                            var breka = "here";
                        }
                        while (true)
                        {
                            var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
                            color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);

                            if (portal.directionOfPassage == ZonePortalDirection.In)
                            {
                                color = Color.Red;
                            }
                            else if (portal.directionOfPassage == ZonePortalDirection.Out)
                            {
                                color = Color.Green;
                            }

                            finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

                            if (drawPos == endPos)
                            {
                                break;
                            }



                            //getNewPos
                            drawPos.X += xDir;
                            drawPos.Y += yDir;
                        }
                    }


                    //draw keys
                    foreach (var key in roomResult.Grid.GetByMeaning(Meaning.Key))
                    {
                        g.DrawString("K", SystemFonts.DefaultFont, Brushes.Red, ((roomLevelMap._AbsX * scale + key.X) * tileSize), (roomLevelMap._AbsY * scale + key.Y) * tileSize);
                    }
                    //draw loot
                    foreach (var key in roomResult.Grid.GetByMeaning(Meaning.Loot))
                    {
                        g.DrawString("$", SystemFonts.DefaultFont, Brushes.Red, ((roomLevelMap._AbsX * scale + key.X) * tileSize), (roomLevelMap._AbsY * scale + key.Y) * tileSize);
                    }
                }
                //}
            }

            //draw line from clutch rooms
            foreach (var relation in map.ClutchRelations.Where(x => x.ItemRoom._AllSubChildren.Count == 0))
            {
                using (Graphics g = Graphics.FromImage(finalBitmap))
                {
                    g.DrawLine(Pens.Red,
                               new Point((relation.ItemRoom._AbsX * scale * tileSize), relation.ItemRoom._AbsY * scale * tileSize),
                               new Point(relation.LockedRoom._AbsX * scale * tileSize, relation.LockedRoom._AbsY * scale * tileSize)
                               );
                    g.DrawString("I", SystemFonts.DefaultFont, Brushes.Red, (relation.ItemRoom._AbsX * scale * tileSize), relation.ItemRoom._AbsY * scale * tileSize);

                    g.DrawString(" L", SystemFonts.DefaultFont, Brushes.Red, (relation.LockedRoom._AbsX * scale * tileSize), relation.LockedRoom._AbsY * scale * tileSize);
                }
            }

            foreach (var child in map._AllSubChildren.Where(x => x._AllSubChildren.Count == 0 && x.IsSkippable))
            {
                using (Graphics g = Graphics.FromImage(finalBitmap))
                {
                    g.DrawString("  S", SystemFonts.DefaultFont, Brushes.Red, child._AbsX * scale * tileSize, child._AbsY * scale * tileSize);
                }
            }


            //draw portals
            //for (var y = 0; y < masterPortals.GetLength(1); y++)
            //{
            //    for (var x = 0; x < masterPortals.GetLength(0); x++)
            //    {
            //        var portals = masterPortals[x, y].Where(p => p.SubPortal == null && p.DestinationPortal != null && ((HierarchicalMapPortal)p.DestinationPortal).id.CompareTo(p.id) == -1);
            //        foreach(var portal in portals)
            //        {
            //            var startPos = new Point(
            //                    (x * scale * tileSize) + (tileSize*2),
            //                    (y * scale * tileSize) + (tileSize*2)
            //                );
            //            var endPos = new Point(
            //                    startPos.X + portal.direction.X * tileSize,
            //                    startPos.Y + portal.direction.Y * tileSize
            //                );
            //            var xDir = Math.Sign(endPos.X - startPos.X);
            //            var yDir = Math.Sign(endPos.Y - startPos.Y);
            //            var drawPos = startPos;
            //            while (true)
            //            {
            //                var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
            //                color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);
            //                finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

            //                if (drawPos == endPos)
            //                    break;

            //                //getNewPos
            //                drawPos.X += xDir;
            //                drawPos.Y += yDir;
            //            }
            //        }
            //    }
            //}

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["Output"], finalBitmap);


            //map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main_map.bmp"));
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
        }
Esempio n. 10
0
        private static void Execute()
        {
            Bitmap tileset = Image.FromFile(ConfigurationManager.AppSettings["TilesetInput"]) as Bitmap;

            tileset = tileset.AddHorizontalMirror();
            List <List <Bitmap> > tiles = BitmapOperations.GetBitmapTiles(tileset, 5, 5);

            Bitmap hTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["hTraverseInput"]) as Bitmap;
            List <List <Bitmap> > hTraverseDbl = BitmapOperations.GetBitmapTiles(hTraverseBmp, 5, 5);
            Bitmap quickcheck = BitmapOperations.CreateBitmapFromTiles(hTraverseDbl, true);

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], quickcheck);
            List <Bitmap> hTraverse = new List <Bitmap>();

            foreach (var list in hTraverseDbl)
            {
                hTraverse.AddRange(list);
            }

            Bitmap vTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["vTraverseInput"]) as Bitmap;
            List <List <Bitmap> > vTraverseDbl = BitmapOperations.GetBitmapTiles(vTraverseBmp, 5, 5);
            List <Bitmap>         vTraverse    = new List <Bitmap>();

            foreach (var list in vTraverseDbl)
            {
                vTraverse.AddRange(list);
            }

            var distinctTiles = GetDistinctBitmaps(tiles);

            List <List <Bitmap> > distinctElements = new List <List <Bitmap> >();

            distinctElements.Add(distinctTiles);
            Bitmap tilemapWithSpacing = BitmapOperations.CreateBitmapFromTiles(distinctElements, true);

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], tilemapWithSpacing);


            var opinionatedItemsDistinct = ToOpinionatedList(distinctTiles);

            SetAcceptableItems(opinionatedItemsDistinct, tiles);

            var vTraverseOpinionated = opinionatedItemsDistinct.Where(element => vTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList();
            var hTraverseOpinionated = opinionatedItemsDistinct.Where(element => hTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList();


            for (var i = 0; i < 5; i++)
            {
                var wcf = new WcfGrid();
                wcf.Init(20, 10, 1, opinionatedItemsDistinct);
                List <WcfVector> shape = WcfVector.GetCross3dShape();
                wcf.SetInfluenceShape(shape);


                //Manual Edits
                //in and out
                AddDoor(wcf, opinionatedItemsDistinct[1], 5);
                //border
                AddBorder(wcf, opinionatedItemsDistinct[0], 5);
                //add path
                AddPath(wcf, hTraverseOpinionated, 5);


                var result = wcf.CollapseAllRecursive();
                //if (result == false)
                //continue;

                var collapsedTiles = ToTilesList(wcf);
                wcf.PrintStatesToConsole2d();

                Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles);
                BitmapOperations.SaveBitmapToFile(
                    ConfigurationManager.AppSettings["BitmapOutput"].Replace(
                        ".bmp",
                        i.ToString() + ".bmp"
                        ),
                    tilesetRedux);
            }
        }