private async void importEdit_Click(object sender, RoutedEventArgs e) { //open up windows dialog to pick file FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".json"); picker.FileTypeFilter.Add(".agf"); picker.ViewMode = PickerViewMode.List; StorageFile file = await picker.PickSingleFileAsync(); if (file == null) { return; } string contents = ""; try { contents = await UWPIO.storageFileToString(file); game = new ActiveGame(AdventureGame.loadFromString(contents)); } catch (Exception x) { await new MessageDialog("Invalid Adventuregame Selected", "Error").ShowAsync(); return; } refresh(); }
protected override async void OnNavigatedFrom(NavigationEventArgs e) { //auto-save if game not finished if (!game.isEnd()) { string fullName = UWPIO.SAVEDIR + "\\" + game.getTitle() + game.getAuthor() + ".json"; await UWPIO.createFile(fullName, saveToString(game)); } base.OnNavigatedFrom(e); }
//when a dude is clicked on a play button should appear, and when they're unclicked it should disappear private async void UpdateFiles() { List <string> files = await UWPIO.listFiles(UWPIO.GAMEDIR); foreach (string file in files) { // Limit to only json or agf files. int l = file.Length; if (file.Substring(l - 5) == ".json" || file.Substring(l - 4) == ".agf") { string fname = UWPIO.GAMEDIR + "\\" + file; AdventureGame ag = AdventureGame.loadFromString(await UWPIO.readFile(fname)); Games.Add(new GameInfo(ag.title, ag.author, file, await UWPIO.dateCreatedAsync(fname), await UWPIO.dateModifiedAsync(fname))); } } }
private async void ConfirmationButton_Click(object sender, RoutedEventArgs e) { await UWPIO.createFile(UWPIO.GAMEDIR + "\\" + curFile.Name, fileContents); //do some notification to let the user know it happened ConfirmationButton.IsEnabled = false; ConfirmationButtonText.Text = "Success!"; Regex rgx = new Regex(@"\b\w+\b"); fileContents = rgx.Replace(fileContents, "Success!"); title = "Success!"; author = "Success!"; gamevars = "Success!"; start_state = "Success!"; updateDisplay(); }
private async void ImportButton_Click(object sender, RoutedEventArgs e) { //open up windows dialog to pick file FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".json"); picker.FileTypeFilter.Add(".agf"); picker.ViewMode = PickerViewMode.List; StorageFile file = await picker.PickSingleFileAsync(); if (file == null) { return; } string contents = ""; try { contents = await UWPIO.storageFileToString(file); loadedGame = AdventureGame.loadFromString(contents); } catch (Exception x) { await new MessageDialog("Invalid Adventuregame Selected", "Error").ShowAsync(); return; } title = loadedGame.title; author = loadedGame.author; gamevars = loadedGame.gamevars.ToString(); start_state = loadedGame.start_state; fileContents = contents; currentPath = file.Path; curFile = file; updateDisplay(); }
async void updateGames() { Games = new ObservableCollection <SaveGameInfo>(); List <string> fileList = await UWPIO.listFiles(UWPIO.SAVEDIR); foreach (string f in fileList) { int l = f.Length; if (f.Substring(l - 5) == ".json" || f.Substring(l - 4) == ".agf") { string fname = UWPIO.SAVEDIR + "\\" + f; string content = await UWPIO.readFile(fname); ActiveGame ag = loadFromString(content); Games.Add(new SaveGameInfo(ag.getTitle(), ag.getAuthor(), await UWPIO.dateModifiedAsync(fname), ag)); } } updateProperty(nameof(Games)); }
//option click handler protected override async void OnNavigatedTo(NavigationEventArgs e) { //depending on who entered, we do different things dynamic g = e.Parameter; if (g is ActiveGame) { game = g; } else { //load from path dynamic btn = e.Parameter; string file_path = btn.Tag; AdventureGame ag = AdventureGame.loadFromString(await UWPIO.readFile(UWPIO.GAMEDIR + "\\" + file_path)); game = new ActiveGame(ag); game.start(); } base.OnNavigatedTo(e); refresh(); }
public MainPage() { this.InitializeComponent(); UWPIO.initLocalOnStartupAsync(); updateTitle(); }