예제 #1
0
        private void Button_Click_Gen_Map_Json(object sender, RoutedEventArgs e)
        {
            MapJson map = new MapJson();

            if (json.md5 == null)
            {
                System.Windows.MessageBox.Show("你没有list怎么可以生成map???");
                return;
            }
            map.md5 = json.md5;
            if (!Regex.IsMatch(TBoxMapName.Text, outputPattern))
            {
                System.Windows.MessageBox.Show("不要给我乱搞");
                return;
            }
            map.name    = TBoxMapName.Text;
            map.width   = maxWidth;
            map.height  = maxHeight;
            map.content = new Dictionary <int, string>();
            StringBuilder sb    = new StringBuilder();
            int           lastV = 0;

            for (int i = 0; i <= finalIndex; i++)
            {
                var btn = buttonlist[i];
                if (lastV != btn.Y)
                {
                    map.content.Add(lastV, sb.ToString(0, sb.Length - 1));
                    sb.Clear();
                    lastV = btn.Y;
                    if (lastV > maxHeight)
                    {
                        break;
                    }
                }
                if (btn.C == null)
                {
                    sb.Append(0);
                }
                else
                {
                    sb.Append(btn.C.idx);
                }
                sb.Append(" ");
            }
            JsonHelp.MapToFile(map, fileDirectory);
        }