Exemple #1
0
        private void MoveGenForm_Load(object sender, EventArgs e)
        {
            moveBinder.DataSource = moves;
            moveBox.DataSource    = moveBinder;
            moveBox.DisplayMember = "name";
            typeBinder.DataSource = types;
            typeBox.DataSource    = typeBinder;
            typeBox.DisplayMember = "name";
            if (File.Exists(@"PBS\types.txt"))
            {
                try {
                    StreamReader sr  = new StreamReader(File.OpenRead(@"PBS\types.txt"));
                    string       dat = sr.ReadToEnd();
                    sr.Close();
                    if (string.IsNullOrEmpty(dat))
                    {
                        emptyFile("Move Editor", "types");
                        terminate = true;
                        Close();
                        return;
                    }
                    List <string> data = new List <string>();
                    data = dat.Split('[').ToList();
                    for (int i = 1; i < data.Count; i++)
                    {
                        try
                        {
                            types.Add(data[i].Split(new string[] { "InternalName=" }, StringSplitOptions.None)[1].Split(new string[] { "\r\n" }, StringSplitOptions.None)[0]);
                        }
                        catch (Exception)
                        {
                            SuperForm.invalidLine("types", data[i], "Move Editor");
                            terminate = true;
                            Close();
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Something went wrong while converting data from \"types.txt\".");
                    terminate = true;
                    Close();
                    return;
                }
            }
            else
            {
                SuperForm.fileNotFound("types", "Move Editor");
                terminate = true;
                Close();
                return;
            }
            if (File.Exists(@"PBS\moves.txt"))
            {
                try {
                    StreamReader sr  = new StreamReader(File.OpenRead(@"PBS\moves.txt"));
                    string       dat = sr.ReadToEnd();
                    sr.Close();
                    if (string.IsNullOrEmpty(dat))
                    {
                        emptyFile("Move Editor", "moves");
                        terminate = true;
                        Close();
                        return;
                    }
                    List <string> data = dat.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
                    moves.Clear();
                    for (int i = 0; i < data.Count; i++)
                    {
                        if (!data[i].StartsWith("#") && !data[i].StartsWith(" ") && !data[i].StartsWith("\r\n") && data[i].Length > 0)
                        {
                            try
                            {
                                List <string> move      = data[i].Split(',').ToList();
                                int           id        = Convert.ToInt32(move[0]);
                                string        name      = move[2];
                                string        intname   = move[1];
                                string        effect    = move[3];
                                int           basepower = Convert.ToInt32(move[4]);
                                string        type      = move[5];
                                string        category  = move[6];
                                string        target    = null;
                                switch (move[10])
                                {
                                case "00": target = "Single Non-User"; break;

                                case "01": target = "No Target"; break;

                                case "02": target = "Random Opposing"; break;

                                case "04": target = "All Opposing"; break;

                                case "08": target = "All Non-Users"; break;

                                case "10": target = "User"; break;

                                case "20": target = "User's Side"; break;

                                case "40": target = "Both Sides"; break;

                                case "80": target = "Opposing Side"; break;

                                case "100": target = "Partner"; break;

                                case "200": target = "User Or Partner"; break;

                                case "400": target = "Single Opposing"; break;

                                case "800": target = "Opposite Opposing"; break;

                                default: target = "Single Non-User"; break;
                                }
                                int    priority    = Convert.ToInt32(move[11]);
                                int    addeff      = Convert.ToInt32(move[9]);
                                int    accuracy    = Convert.ToInt32(move[7]);
                                int    pp          = Convert.ToInt32(move[8]);
                                string flags       = move[12];
                                string description = null;
                                for (int j = 13; j < move.Count; j++)
                                {
                                    string temp = null;
                                    foreach (char c in move[j])
                                    {
                                        if (c == '�')
                                        {
                                            temp += "é";
                                        }
                                        else if (c != '"')
                                        {
                                            temp += c;
                                        }
                                    }
                                    move[j] = temp;
                                    if (j == 13)
                                    {
                                        description += move[j];
                                    }
                                    else
                                    {
                                        description += $",{move[j]}";
                                    }
                                }
                                moves.Add(new Move(id, name, intname, effect, type, category, target, priority, addeff, basepower, accuracy, pp, flags, description));
                            }
                            catch (Exception)
                            {
                                invalidLine("moves", data[i], "Move Editor");
                                terminate = true;
                                Close();
                                return;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Something went wrong while converting data from \"moves.txt\".");
                    terminate = true;
                    Close();
                    return;
                }
            }
            else
            {
                fileNotFound("moves", "Move Editor");
                terminate = true;
                Close();
                return;
            }
            moveBinder.ResetBindings(false);
            typeBinder.ResetBindings(false);
            checkSortMethod(SuperGen.Properties.Settings.Default.MoveSortMethod);
            bool found = false;

            if (!string.IsNullOrEmpty(SuperGen.Properties.Settings.Default.MoveIntName))
            {
                for (int i = 0; i < moves.Count; i++)
                {
                    if (moves[i].intname == SuperGen.Properties.Settings.Default.MoveIntName)
                    {
                        moveBox.SelectedIndex = i; found = true;
                    }
                }
            }
            if (!found && moves.Count > 0)
            {
                moveBox.SelectedIndex = 0;
            }
            moveBox_SelectedIndexChanged(sender, e);
        }