private void GenerateCode(ProgrammingLanguage language) { int index = _map.FindLayerIndexWithName(lbLayers.SelectedItem.ToString()); if (index == -1) { MessageBox.Show("Please select a layer", "Generate Code"); return; } tbCode.Text = CodesGenerator.GenerateCodes(index, _map, _map_info.Format, _tile_library, language); }
public Boolean ExportMap(ref Tile[] tileLibrary, string path, ListBox lbLayers, ExportLayer exportLayer, ProgrammingLanguage language, ImageFormat format) { path = path + "\\D2D_" + Path.GetFileNameWithoutExtension(MapFileName); Directory.CreateDirectory(path); StreamWriter sw; string layerPath; switch (exportLayer) { case ExportLayer.SelectedOnly: int index = FindLayerIndexWithName(lbLayers.SelectedItem.ToString()); if (index == -1) { MessageBox.Show("No layer selected.", "Export Failed"); return(false); } layerPath = path + "\\" + Layers[index].Name + ".txt"; sw = new StreamWriter(layerPath); sw.Write(CodesGenerator.GenerateCodes(index, this, format, tileLibrary, language)); sw.Flush(); sw.Close(); break; case ExportLayer.VisibleOnly: foreach (Layer layer in Layers) { if (layer.Visible) { layerPath = path + "\\" + layer.Name + ".txt"; sw = new StreamWriter(layerPath); sw.Write(CodesGenerator.GenerateCodes(FindLayerIndexWithId(layer.LayerId), this, format, tileLibrary, language)); sw.Flush(); sw.Close(); } } break; case ExportLayer.All: foreach (Layer layer in Layers) { layerPath = path + "\\" + layer.Name + ".txt"; sw = new StreamWriter(layerPath); sw.Write(CodesGenerator.GenerateCodes(FindLayerIndexWithId(layer.LayerId), this, format, tileLibrary, language)); sw.Flush(); sw.Close(); } break; default: break; } // save tiles path = path + "\\" + Path.GetFileNameWithoutExtension(MapFileName); Directory.CreateDirectory(path); for (int i = 0; i < tileLibrary.Length; i++) { TilesManagement.SaveTileImage(ref tileLibrary, i, path, format); } return(true); }