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(); }
public static void addAGF(AdventureGame ag) { if (!isAlreadyInLib(ag)) { AdventureGame.saveToFile(ag, getfname(ag)); } }
private async void saveAdventure_Click(object sender, RoutedEventArgs e) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; //dropdown of file types the user can create savePicker.FileTypeChoices.Add("Plain Text", new List <string>() { ".json", ".agf" }); savePicker.SuggestedFileName = "newAdv.json"; Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { Windows.Storage.CachedFileManager.DeferUpdates(file); await Windows.Storage.FileIO.WriteTextAsync(file, AdventureGame.saveToString(game.data)); Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file); if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) { //success } else { await new MessageDialog("Error Saving Adventure Game!", "Error").ShowAsync(); return; } } }
public static AdventureGame saveToFile(AdventureGame game, string path) { if (!File.Exists(path)) { string contents = saveToString(game); File.WriteAllText(path, contents); } throw new Exception("File already exists: " + path); }
public Creator() { game = new ActiveGame(AdventureGame.loadFromString(DEF_GAME_TXT)); game.start(); currentState = game.data.states[game.position]; this.InitializeComponent(); refresh(); }
//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 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(); }
//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 static string saveToString(AdventureGame adv_obj) { string ser = JsonConvert.SerializeObject(adv_obj); return(ser); //let's assume this works for now then fix it later }
public static AdventureGame loadFromString(string json_str) { AdventureGame ag = JsonConvert.DeserializeObject <AdventureGame>(json_str); return(ag); }
public string text; //after processing public ActiveGame(AdventureGame adventure_) { data = adventure_; interp = new AgfInterpreter(ref states); }
public static void removeFromLib(AdventureGame ag) { File.Delete(getfname(ag)); }
public static bool isAlreadyInLib(AdventureGame ag) { string file_path = getfname(ag); return(File.Exists(file_path)); }
//Parse files until we find the right one private static string getfname(AdventureGame ag) { string fileName = String.Format("{0}_{1}.json", ag.title, ag.author); return(advPath + fileName); }