Exemplo n.º 1
0
        public MMCellData Read(string datafile, string headerfile)
        {
            //this.cellData.Reset();
            this.cellData = new MMCellData();
            List <string> tiles = new List <string>();

            if (File.Exists(headerfile))
            {
                using (BinaryReader binReader = new BinaryReader(File.Open(headerfile, FileMode.Open)))
                {
                    tiles = this.ReadHeader(binReader);
                }
            }
            if (tiles.Count > 0 && File.Exists(datafile))
            {
                using (BinaryReader binReader = new BinaryReader(File.Open(datafile, FileMode.Open)))
                {
                    this.cellData = this.ReadPack(binReader, tiles);
                }
            }
            return(this.cellData);
        }
Exemplo n.º 2
0
 public MMCellReader()
 {
     this.cellData = new MMCellData();
 }
Exemplo n.º 3
0
        public void PlotData(MMCellData cellData, string outputDir, int cellx, int celly)
        {
            using (Graphics gfx = Graphics.FromImage(this.subCell))
            {
                int          drawx = 0;
                int          drawy = 0;
                MMGridSquare gs;
                for (int subx = 0; subx < this.subDiv; subx++)
                {
                    for (int suby = 0; suby < this.subDiv; suby++)
                    {
                        for (int z = 0; z < 8; z++)
                        {
                            if (this.dolayers)
                            {
                                if (File.Exists(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_layer_" + z + ".png"))
                                {
                                    Console.WriteLine("Skipping {0}x{1}_{2}x{3} layer {4} because file exists", cellx, celly, subx, suby, z);
                                    continue;
                                }
                            }
                            else
                            {
                                if (File.Exists(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_full.png"))
                                {
                                    Console.WriteLine("Skipping {0}x{1}_{2}x{3} layer full because file exists", cellx, celly, subx, suby);
                                    continue;
                                }
                            }
                            int drawCnt = 0;
                            for (int x = 0; x < this.subWH; x++)
                            {
                                for (int y = 0; y < this.subWH; y++)
                                {
                                    drawx = this.startX + (x - y) * 64;
                                    if (this.dolayers == true)
                                    {
                                        drawy = this.startY + (x + y) * 32;
                                    }
                                    else
                                    {
                                        drawy = (this.startY + (x + y) * 32) - (192 * z);
                                    }

                                    gs = cellData.GetSquare(x + (subx * this.subWH), y + (suby * this.subWH), z);

                                    if (gs != null)
                                    {
                                        for (Int32 i = MMGridSquare.FLOOR; i <= MMGridSquare.TOP; i++)
                                        {
                                            foreach (MMTile mmtile in gs.GetTiles(i))
                                            {
                                                bool   isJumbo = false;
                                                String tile    = mmtile.tile;
                                                if (tile.Replace("JUMBO", "") != tile)
                                                {
                                                    isJumbo = true;
                                                }
                                                if (tile != null && this.textures.Textures.ContainsKey(tile))
                                                {
                                                    this.textures.Textures[tile].Draw(gfx, drawx + mmtile.offX, drawy + mmtile.offY);
                                                    // Console.WriteLine("Drawing {0} at {1}+{2}x{3}+{4}", tile, drawx, mmtile.offX, drawy, mmtile.offY);
                                                    drawCnt++;
                                                }
                                                else
                                                {
                                                    //Console.WriteLine("tile {0} not found", tile);
                                                    String needle = tile.Split('_')[0] + "_" + tile.Split('_')[1];
                                                    // Console.WriteLine("Searching for collage: {0}", needle);
                                                    if (this.collages.ContainsKey(needle.Replace("JUMBO", "")))
                                                    {
                                                        // Console.WriteLine("Drawing from collage instead");
                                                        Dictionary <String, List <String> > collageCategory;
                                                        this.collages.TryGetValue(needle, out collageCategory);

                                                        IEnumerable <String> sprites;
                                                        sprites = collageCategory.ElementAt(rand.Next(0, collageCategory.Count)).Value;
                                                        foreach (String sprite in sprites)
                                                        {
                                                            if (this.textures.Textures.ContainsKey(sprite))
                                                            {
                                                                String rSprite = sprite;
                                                                if (isJumbo && bigtree)
                                                                {
                                                                    String[] splits = new String[4];
                                                                    splits  = sprite.Split('_');
                                                                    rSprite = splits[0] + "_" + splits[1] + "JUMBO_" + splits[2] + "_" + splits[3];
                                                                }
                                                                this.textures.Textures[rSprite].Draw(gfx, drawx + mmtile.offX, drawy + mmtile.offY);
                                                                drawCnt++;
                                                                //} else {
                                                                //Console.WriteLine("Collages contain Unknown texture: {0}", sprite);
                                                            }
                                                        }
                                                        //} else {
                                                        //Console.WriteLine("Unknown texture: {0}", tile);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (this.dolayers == true && drawCnt > 0)
                            {
                                Bitmap resized = new Bitmap(this.subCell, new Size(this.subCell.Width / this.scale, this.subCell.Height / this.scale));
                                resized.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_layer_" + z + ".png", System.Drawing.Imaging.ImageFormat.Png);

                                //this.subCell.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_layer_" + z + ".png", System.Drawing.Imaging.ImageFormat.Png);
                                gfx.Clear(Color.Transparent);
                            }
                        }
                        if (this.dolayers == false)
                        {
                            Bitmap resized = new Bitmap(this.subCell, new Size(this.subCell.Width / this.scale, this.subCell.Height / this.scale));
                            resized.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_full.png", System.Drawing.Imaging.ImageFormat.Png);

                            //this.subCell.Save(outputDir + "cell_" + cellx + "_" + celly + "_subcell_" + subx + "_" + suby + "_full.png", System.Drawing.Imaging.ImageFormat.Png);
                            gfx.Clear(Color.Transparent);
                        }
                    }
                }
            }
        }