Though it works I wonder if there might be a better way to do this. I would like to reuse this loading and establishing of fields of another class(es) (the static TileMapper class mentioned at the end) in a C#/.net/XNA environment.
I noticed that when moving through the OpenFileDialog to find files it felt sluggish. Is that because I had to set [STAThreadAttribute] just to get it to open?
private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Title = "Select a File";
openFile.InitialDirectory = Application.StartupPath + @"\Content\Map\";
openFile.Filter = "MAP Files (.MAP)|*.MAP";
openFile.FilterIndex = 1;
openFile.Multiselect = false;
if (openFile.ShowDialog() != DialogResult.Cancel)
{
try
{
// Example file - _W25_H25_SET_GL_test.Map
TileMapper.LoadMap(new FileStream(openFile.FileName, FileMode.Open));
// remove directory information
string[] _mapname = openFile.FileName.Split('\\');
string tempmap = _mapname.Last();
// remove .map
string[] removemap = tempmap.Split('.');
MapName = removemap.First();
//print file name
txtMapName.Text = MapName;
//get info stored in file name
string[] nameParts = MapName.Split('_');
string[] widthPart = nameParts[1].Split('W');
string[] heightPart = nameParts[2].Split('H');
TileMapper.MapWidth = int.Parse(widthPart[1]);
TileMapper.MapHeight = int.Parse(heightPart[1]);
}
catch
{
System.Diagnostics.Debug.Print("Unable to load map file");
}
}
else return;
}