Beispiel #1
0
        public void LoadSession()
        {
            if (isDirty)
            {
                if (!Exit())
                {
                    return;
                }
            }
            OpenFileDialog load = new OpenFileDialog();

            if (startFolder != "")
            {
                load.InitialDirectory = startFolder;
            }

            load.Filter = "Session File (*.ssn)|*.ssn";
            DialogResult result = load.ShowDialog();

            FilePath = load.FileName;
            SessionDetail.FilePath = load.FileName;

            if (result == DialogResult.OK)
            {
                if (File.Exists(FilePath))
                {
                    saver = new BattleIO();
                    SessionDetail newParent = saver.LoadObject <SessionDetail>(FilePath);
                    if (newParent == null)
                    {
                        sendingForm.WriteToLog("Load failed. Invalid file loaded.");
                    }
                    else
                    {
                        sendingForm.ExtractFields(newParent);
                        if (newParent.combatants.Count > 0)
                        {
                            sendingForm.enableGlobalButtons(); sendingForm.enableTurnButtons();
                        }
                        else
                        {
                            sendingForm.ResetControls();
                        }

                        sendingForm.WriteToLog("===============  SESSION LOADED ON " + DateTime.Now + " ===============");
                        startFolder = Path.GetDirectoryName(FilePath);
                        Program.activeSessionName = Path.GetFileName(FilePath);
                        sendingForm.Text          = Program.ProgramName + " - " + Path.GetFileName(FilePath);

                        isDirty = false;
                    }
                }
            }
        }
        public void AutoSave(List <Fighter> combatants, bool[] checkBoxes, Settings settings, MainWindow sender)
        {
            string sessionPath = defaultPath + @"\Save\auto.ssn";

            if (sender.session.settings.UserAutoSaveDirectory != "")
            {
                sessionPath = sender.session.settings.UserAutoSaveDirectory + @"\auto.ssn";
            }
            SessionDetail saveSession = new SessionDetail();

            saveSession.CopySessionFieldsFromWindow(sender, Program.activeSessionName);
            SaveObject <SessionDetail>(saveSession, sessionPath);
            sender.session.SaveSettings(sessionPath);
            sender.session.ReinitializeSender(sender);
        }
Beispiel #3
0
        private bool Save()
        {
            SaveFileDialog saveBox = new SaveFileDialog();

            saveBox.Filter = "Session File (*.ssn)|*.ssn";
            if (startFolder != "")
            {
                saveBox.InitialDirectory = startFolder;
            }
            saveBox.FileName = Program.activeSessionName;
            DialogResult result = saveBox.ShowDialog();

            if (result == DialogResult.OK)
            {
                saver       = new BattleIO();
                FilePath    = saveBox.FileName;
                startFolder = Path.GetDirectoryName(FilePath);
                Program.activeSessionName = Path.GetFileName(FilePath);
                SessionDetail sessionData = new SessionDetail();
                sessionData.CopySessionFieldsFromWindow(sendingForm, Program.activeSessionName);
                //List<SerializableObject> saveableData = SerializableObject.PackageObjectList(sessionData);
                if (saver.SaveObject <SessionDetail>(sessionData, FilePath))
                {
                    sendingForm.WriteToLog("Session Saved as \"" + FilePath + "\"");

                    SaveSettings(FilePath);
                    isDirty          = false;
                    sendingForm.Text = Program.ProgramName + " - " + Path.GetFileName(FilePath);
                    return(true);
                }
                else
                {
                    sendingForm.WriteToLog("Save failed. Check the log for details.");
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
 public void SaveSession(bool SaveAs)
 {
     if (FilePath == null)
     {
         FilePath = SessionDetail.FilePath;
     }
     if (File.Exists(FilePath) && !SaveAs)
     {
         SessionDetail sessionData = new SessionDetail();
         sessionData.CopySessionFieldsFromWindow(sendingForm, Program.activeSessionName);
         saver = new BattleIO();
         saver.SaveObject <SessionDetail>(sessionData, FilePath);
         sendingForm.WriteToLog("Session Saved as \"" + FilePath + "\"");
         sendingForm.Text = Program.ProgramName + " - " + Program.activeSessionName;
         isDirty          = false;
     }
     else
     {
         Save();
     }
 }
        public List <Fighter> AutoLoad(MainWindow sender)
        {
            List <Fighter> fighters = new List <Fighter>();

            string sessionPath = defaultPath + @"\Save\auto.ssn";

            if (sender.session.settings.UserAutoSaveDirectory != "")
            {
                sessionPath = sender.session.settings.UserAutoSaveDirectory + @"\auto.ssn";
            }
            SessionDetail autoSesh = new SessionDetail();

            if (File.Exists(sessionPath))
            {
                autoSesh = LoadObject <SessionDetail>(sessionPath);
                if (autoSesh != null)
                {
                    Program.activeSessionName = autoSesh.SessionName;
                    sender.session.LoadSettings(sessionPath);
                    sender.ExtractFields(autoSesh);
                }
                LoadDefaultSkills(sender);
                if (autoSesh != null)
                {
                    return(autoSesh.combatants);
                }
                else
                {
                    return(new List <Fighter>());
                }
            }
            //LEGACY LOADER
            else
            {
                string path = defaultPath + @"\Save\auto.txt";
                if (sender.session.settings.UserAutoSaveDirectory != "")
                {
                    path = sender.session.settings.UserAutoSaveDirectory + @"\auto.txt";
                }
                if (File.Exists(path))
                {
                    string[] lines        = File.ReadAllLines(path);
                    int      fighterCount = lines.Length - 1;
                    int      fighterStart = 1;
                    try
                    {
                        fighterCount = Int32.Parse(lines[0]);
                    }
                    catch
                    {
                        fighterStart = 0;
                    }

                    for (int i = fighterStart; i < fighterCount + 1; i++)
                    {
                        string[] fStats = lines[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        try
                        {
                            Fighter f = new Fighter(fStats[0], Int32.Parse(fStats[3]), Boolean.Parse(fStats[4]));
                            f.Initiative = Int32.Parse(fStats[1]);
                            f.HP         = Int32.Parse(fStats[2]);
                            fighters.Add(f);
                        }
                        catch
                        {
                            MessageBox.Show("Unable to parse auto.txt. No AutoLoad available", "Error");
                            return(fighters);
                        }
                    }

                    if (fighterCount + 1 < lines.Length)
                    {
                        int checkIndex = fighterCount + 1;
                        try
                        {
                            bool[] checkBoxes = new bool[] { Boolean.Parse(lines[checkIndex]), Boolean.Parse(lines[checkIndex + 1]), Boolean.Parse(lines[checkIndex + 2]), Boolean.Parse(lines[checkIndex + 3]) };
                            sender.SetCheckBoxes(checkBoxes);
                        }
                        catch
                        {
                            Console.WriteLine("Bonus checkbox load failed");
                        }
                    }
                }

                path = defaultPath + @"\Save\NPCS";
                if (sender.session.settings.UserAutoSaveDirectory != "")
                {
                    path = sender.session.settings.UserAutoSaveDirectory + @"\NPCS";
                }
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                else
                {
                    int fighterCount = Directory.GetFiles(path).Length;
                    for (int i = 0; i < fighterCount; i++)
                    {
                        fighters.Add(LoadStatBlock(Directory.GetFiles(path)[i]));
                    }
                }
                LoadDefaultSkills(sender);


                path = defaultPath + @"\Save\Status.bin";
                if (sender.session.settings.UserAutoSaveDirectory != "")
                {
                    path = sender.session.settings.UserAutoSaveDirectory + @"\Status.bin";
                }

                List <Status> recent = LoadRecentlyUsedStatuses(path, sender);
                sender.recentlyUsedStatuses = recent;
                return(fighters);
            }
        }