private void ContinueAdventure() { try { //IF IN ADVENTURE = RESUME, ELSE IF PREVIOUSLY IN ADVENTURE = RESUM, ELSE START NEW if (AppGlobals.currGlobalAdventure != null) { if (AppGlobals.player.isPaused) AppGlobals.player.UnPauseMusic(); Story storyPage = new Story(AppGlobals.currGlobalAdventure); this.NavigationService.Navigate(storyPage); } else if (AppGlobals.currGlobalAdventure == null) { DirectoryInfo currentDir = new DirectoryInfo(@AppGlobals.saveGameDir); FileInfo mostRecentGame = null; if (currentDir.GetFiles().Count() > 0) { mostRecentGame = currentDir.GetFiles().OrderByDescending(d => d.LastWriteTime).Where(d => d.Name.Contains(".advo")).First(); //CHANGE FROM .ADVO TO .XAML TO LOAD UP DATA File.Move(mostRecentGame.FullName, System.IO.Path.ChangeExtension(mostRecentGame.FullName, ".xaml")); using (FileStream fs = new FileStream(@System.IO.Path.ChangeExtension(mostRecentGame.FullName, ".xaml"), FileMode.Open)) { try { var document = (FlowDocument)XamlReader.Load(fs); AppGlobals.currGlobalAdventure = new Adventure(); AppGlobals.currGlobalAdventure.ongoingStory = document; } catch (SerializationException err) { exHand.LogException(err, "MainMenu-ContinueAdventure"); } finally { fs.Close(); } } } currentDir = new DirectoryInfo(@AppGlobals.saveGameMetaDir); if (currentDir.GetFiles().Count() > 0) { FileInfo mostRecentGameMeta = currentDir.GetFiles().OrderByDescending(d => d.LastWriteTime).Where(d => d.Name.Contains(".advm")).First(); //CHANGE FROM .ADVM TO .XAML TO LOAD UP DATA File.Move(mostRecentGameMeta.FullName, System.IO.Path.ChangeExtension(mostRecentGameMeta.FullName, ".xaml")); using (FileStream fs = new FileStream(@System.IO.Path.ChangeExtension(mostRecentGameMeta.FullName, ".xaml"), FileMode.Open)) { try { var document = (FlowDocument)XamlReader.Load(fs); if (document != null) { foreach (var block in document.Blocks) { TextRange textRange = new TextRange(block.ContentStart, block.ContentEnd); string[] storyMeta = textRange.Text.Split('['); foreach (string data in storyMeta) { if (data.Contains("%ARMOR%")) AppGlobals.currGlobalAdventure.Armor = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%ARMORSET%")) AppGlobals.currGlobalAdventure.ArmorSet.ArmorName = data.Split(']').Last(); if (data.Contains("%AUTHOR%")) AppGlobals.currGlobalAdventure.Author = data.Split(']').Last(); if (data.Contains("%GENRE%")) AppGlobals.currGlobalAdventure.Genre = data.Split(']').Last(); if (data.Contains("%CHARACTERNAME%")) AppGlobals.currGlobalAdventure.CharacterName = data.Split(']').Last(); if (data.Contains("%CHARACTERTITLE%")) AppGlobals.currGlobalAdventure.CharacterTitle = data.Split(']').Last(); if (data.Contains("%CURRENTCHAPTER%")) AppGlobals.currGlobalAdventure.CurrentChapter = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%DECISIONSMADE%")) AppGlobals.currGlobalAdventure.DecisionsMade = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%FOLDERPATH%")) AppGlobals.currGlobalAdventure.folderPath = data.Split(']').Last(); if (data.Contains("%HEALTH%")) AppGlobals.currGlobalAdventure.Health = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%LUCK%")) AppGlobals.currGlobalAdventure.Luck = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%MAGIC%")) AppGlobals.currGlobalAdventure.Magic = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%MELEEWEAPON%")) AppGlobals.currGlobalAdventure.MeleeWeapon.WeaponName = data.Split(']').Last(); if (data.Contains("%PUBLISHDATE%")) AppGlobals.currGlobalAdventure.PublishDate = data.Split(']').Last(); if (data.Contains("%RANGEDWEAPON%")) AppGlobals.currGlobalAdventure.RangedWeapon.WeaponName = data.Split(']').Last(); if (data.Contains("%SPEED%")) AppGlobals.currGlobalAdventure.Speed = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%STORYLENGTH%")) AppGlobals.currGlobalAdventure.StoryLength = Convert.ToInt32(data.Split(']').Last()); if (data.Contains("%SUMMARY%")) AppGlobals.currGlobalAdventure.Summary = data.Split(']').Last(); if (data.Contains("%TITLE%")) AppGlobals.currGlobalAdventure.Title = data.Split(']').Last(); } } } } catch (SerializationException err) { exHand.LogException(err, "StoryGenerator-SaveAdventure"); } finally { fs.Close(); } } } if (AppGlobals.currGlobalAdventure == null) { StorySelection storySelectionPage = new StorySelection(); this.NavigationService.Navigate(storySelectionPage); } else { Story storyPage = new Story(AppGlobals.currGlobalAdventure); this.NavigationService.Navigate(storyPage); } } else StartNewAdventure(); } catch (Exception err) { exHand.LogException(err, "MainMenu-ContinueAdventure"); } }
private void SelectAdventure() { try { //LOADS THE ADVENTURE BASED OFF THE SELECTED ITEM Adventure selectedAdventure = new Adventure(); var reconstrucedPath = lvAvailableAdventures.SelectedItem.ToString().ToLower() + "-adventuremeta.xaml"; using (FileStream fs = File.OpenRead(@AppGlobals.adventureDir + "/" + lvAvailableAdventures.SelectedItem.ToString().ToLower() + "/" + reconstrucedPath)) { FlowDocument document = (FlowDocument)XamlReader.Load(fs); //BREAK OUT INTO TAGS TO ASSIGN List<Block> docBlocks = document.Blocks.ToList(); foreach (Block indivBlock in docBlocks) { TextRange range = new TextRange(indivBlock.ContentStart, indivBlock.ContentEnd); string[] metaTexts = range.Text.Split('['); foreach (string indivString in metaTexts) { if (indivString.Contains("%TITLE%")) { selectedAdventure.Title = indivString.Split(']').Last(); } if (indivString.Contains("%AUTHOR%")) { selectedAdventure.Author = indivString.Split(']').Last(); } if (indivString.Contains("%PUBLISHDATE%")) { selectedAdventure.PublishDate = indivString.Split(']').Last(); } if (indivString.Contains("%SUMMARY%")) { selectedAdventure.Summary = indivString.Split(']').Last(); } if (indivString.Contains("%GENRE%")) { selectedAdventure.Genre = indivString.Split(']').Last(); } if (indivString.Contains("%THEME%")) { selectedAdventure.Theme = indivString.Split(']').Last(); } if (indivString.Contains("%MELEEWEAPON%")) { selectedAdventure.MeleeWeapon = new Weapon(); selectedAdventure.MeleeWeapon.WeaponName = indivString.Split(']').Last(); } if (indivString.Contains("%RANGEDWEAPON%")) { selectedAdventure.RangedWeapon = new Weapon(); selectedAdventure.RangedWeapon.WeaponName = indivString.Split(']').Last(); } if (indivString.Contains("%ARMORSET%")) { selectedAdventure.ArmorSet = new Armor(); selectedAdventure.ArmorSet.ArmorName = indivString.Split(']').Last(); } if (indivString.Contains("%CHARACTERNAME%")) { selectedAdventure.CharacterName = indivString.Split(']').Last(); } if (indivString.Contains("%CHARACTERTITLE%")) { selectedAdventure.CharacterTitle = indivString.Split(']').Last(); } if (indivString.Contains("%HEALTH%")) { selectedAdventure.Health = Convert.ToInt32(indivString.Split(']').Last()); } if (indivString.Contains("%ARMOR%")) { selectedAdventure.Armor = Convert.ToInt32(indivString.Split(']').Last()); } if (indivString.Contains("%SPEED%")) { selectedAdventure.Speed = Convert.ToInt32(indivString.Split(']').Last()); } if (indivString.Contains("%MAGIC%")) { selectedAdventure.Magic = Convert.ToInt32(indivString.Split(']').Last()); } if (indivString.Contains("%LUCK%")) { selectedAdventure.Luck = Convert.ToInt32(indivString.Split(']').Last()); } } selectedAdventure.folderPath = AppGlobals.adventureDir + "/" + lvAvailableAdventures.SelectedItem.ToString().ToLower(); } } AppGlobals.currGlobalAdventure = selectedAdventure; Story storyPage = new Story(AppGlobals.currGlobalAdventure); this.NavigationService.Navigate(storyPage); } catch (Exception err) { exHand.LogException(err, "StorySelection-SelectAdventure"); } }