예제 #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);
        }
예제 #2
0
        public bool OutputWfc(string outPath)
        {
            var collapsedTiles = ToTilesList(_grid);

            Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles);

            BitmapOperations.SaveBitmapToFile(outPath, tilesetRedux);

            return(true);
        }
예제 #3
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]);
            }
        }
예제 #4
0
        public Bitmap GetBitmap()
        {
            var collapsedTiles = ToTilesList(_grid);

            return(BitmapOperations.CreateBitmapFromTiles(collapsedTiles));
        }
예제 #5
0
 public static Bitmap ToBitmap(WcfGrid grid, TilesetConfiguration TilesConfig)
 {
     return(BitmapOperations.CreateBitmapFromTiles(ToTilesList(grid, TilesConfig)));
 }
예제 #6
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);
        }
예제 #7
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);
            }
        }