public SaveGameInfo(string title_, string author_, string saveDate_, ActiveGame gameref_) { title = title_; author = author_; saveDate = saveDate_; gameRef = gameref_; }
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 Creator() { game = new ActiveGame(AdventureGame.loadFromString(DEF_GAME_TXT)); game.start(); currentState = game.data.states[game.position]; this.InitializeComponent(); refresh(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { dynamic g = e.Parameter; if (g is ActiveGame) { game = g; } else if (g is AdventureGame) { game = new ActiveGame(g); } base.OnNavigatedTo(e); refresh(); }
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 static ActiveGame loadFromString(string json_str) { ActiveGame ag = JsonConvert.DeserializeObject <ActiveGame>(json_str); return(ag); }
public static string saveToString(ActiveGame adv_obj) { string ser = JsonConvert.SerializeObject(adv_obj); return(ser); }