예제 #1
0
        public void ReadFromCsvFile(ref SpellBook spellBook, string spellBookName = masterSpellFile)
        {
            var csvReader = new CsvReader(new StreamReader(spellBookName));

            var records = csvReader.GetRecords<Spell>();

            foreach (var record in records.OrderBy(x => x.name))
            {
                spellBook.spells.Add(record);
            }
        }
예제 #2
0
        public void ReadBinaryFile(string spellBookName, ref SpellBook spellBook)
        {
            if (spellBook == null)
            {
                throw new ArgumentNullException("spellBook");
            }

            using (var stream = File.OpenRead(spellBookName))
            {
                var newObj = (SpellBook)new BinaryFormatter().Deserialize(stream);

                spellBook = newObj;
            }
        }
예제 #3
0
파일: Book.cs 프로젝트: cusmonaut/SpellBook
 /// <summary>
 /// selects a spell book to load
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SelectSpellBookToolStripMenuItemClick(object sender, EventArgs e)
 {
     var ofd = new OpenFileDialog { Title = "Open Spell Book", Filter = "SpellBook Files | *.sb" };
     try
     {
         DialogResult result = ofd.ShowDialog();
         if (result == DialogResult.OK)
         {
             PlayerSpellBook = new SpellBook();
             _player = new PlayerBook();
             PlayerSpellBook.BookName = ofd.SafeFileName;
             _handler.ReadBinaryFile(PlayerSpellBook.BookName, ref PlayerSpellBook);
             PlayerBook.PlayerSpellBook = PlayerSpellBook;
             PreparePlayerForm();
             _player.Show();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.ToString());
     }
 }
예제 #4
0
파일: Book.cs 프로젝트: cusmonaut/SpellBook
        /// <summary>
        /// Creates a new spell book
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewSpellBookToolStripMenuItemClick(object sender, EventArgs e)
        {
            var newSpellBookDialog = new CreateSpellBook();

            if (newSpellBookDialog.ShowDialog(this) == DialogResult.OK)
            {
                PlayerSpellBook = new SpellBook { BookName = newSpellBookDialog.BookName };

                _player = new PlayerBook();
                PlayerBook.PlayerSpellBook = PlayerSpellBook;
                PreparePlayerForm();
                _player.Show();
            }

            newSpellBookDialog.Dispose();
        }
예제 #5
0
 public void WriteBinaryFile(string fileName, SpellBook spellbook)
 {
     using (var stream = File.OpenWrite(fileName + FileExtention))
     {
         new BinaryFormatter().Serialize(stream, spellbook);
     }
 }