private void ExportFieldMapData() { // Reading Palette FDPalette palette = new FDPalette(@".\color"); ShapeDataFile shapeData = new ShapeDataFile(@".\FDSHAP.DAT"); shapeData.LoadData(); FieldDataFile fieldData = new FieldDataFile(@".\FDFIELD.DAT"); fieldData.LoadData(); for (int m = 0; m < 33; m++) { FieldMap map = fieldData.GetField(m); HashSet <int> shapes = new HashSet <int>(); for (int i = 0; i < map.Width; i++) { for (int j = 0; j < map.Height; j++) { var shapeIndex = map.GetShapeIndexAt(i, j); shapes.Add(shapeIndex); } } var shapePanel = shapeData.GetPanel(m); foreach (int shapeIndex in shapes) { ShapeInfo shapeInfo = shapePanel.Shapes[shapeIndex]; FieldShape shape = new FieldShape(); shape.Type = shapeInfo.Type; shape.BattleGroundId = shapeInfo.BattleGroundId; map.Shapes[shapeIndex] = shape; } string mapString = JsonConvert.SerializeObject(map, Formatting.Indented); int mm = m + 1; File.WriteAllText(string.Format(@"D:\Temp\FDII\Chapter_{0}.txt", (mm < 10 ? "0" + mm.ToString() : mm.ToString())), mapString); } }
public void ExportToPng(string pngFileFullPath) { canvasData = new byte[canvasWidth * canvasHeight * 4]; for (int xx = 0; xx < fieldMap.Width; xx++) { for (int yy = 0; yy < fieldMap.Height; yy++) { var shapeIndex = fieldMap.GetShapeIndexAt(xx, yy); if (shapeIndex < 0) { continue; } ShapeInfo shape = shapePanel.Shapes[shapeIndex]; if (shape == null) { continue; } DrawOnCanvas(shape.Image.GenerateBitmap(palette), xx, yy); } } Image[] blockTypes = new Image[6] { Image.FromFile(@".\resources\MapBlock_0.png"), Image.FromFile(@".\resources\MapBlock_1.png"), Image.FromFile(@".\resources\MapBlock_2.png"), Image.FromFile(@".\resources\MapBlock_3.png"), Image.FromFile(@".\resources\MapBlock_4.png"), Image.FromFile(@".\resources\MapBlock_5.png") }; using (FileStream output = new FileStream(pngFileFullPath, FileMode.Create, FileAccess.Write)) { unsafe { fixed(byte *ptr = canvasData) { using (Bitmap image = new Bitmap(canvasWidth, canvasHeight, canvasWidth * 4, PixelFormat.Format32bppPArgb, new IntPtr(ptr))) { using (Graphics g = Graphics.FromImage(image)) { for (int xx = 0; xx < fieldMap.Width; xx++) { for (int yy = 0; yy < fieldMap.Height; yy++) { var shapeIndex = fieldMap.GetShapeIndexAt(xx, yy); if (shapeIndex < 0) { continue; } ShapeInfo shape = shapePanel.Shapes[shapeIndex]; if (shape == null) { continue; } int blockType = shape.Type.GetHashCode(); g.DrawImage(blockTypes[blockType], 24 * (xx + 1), 24 * (yy + 1), 24, 24); } } } image.Save(output, ImageFormat.Png); } } } } }